|
I want to deserialize a dictionary with datacontractserializer, the xml schema is the following :
<General xmlns="http://schemas.datacontract.org/2004/07/MyProject" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Mydictionary xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a:KeyValueOfunsignedByteMyclass>
<a:Key>1</a:Key>
<a:Value>
....
</a:Value>
</a:KeyValueOfunsignedByteMyclass>
<a:KeyValueOfunsignedByteMyclass>
<a:Key>2</a:Key>
<a:Value>
....
</a:Value>
</a:KeyValueOfunsignedByteMyclass>
</Mydictionary>
But on deserializing, I get this error :
"An item with the same key has already been added."
(referencing KeyValueOfunsignedByteMyclass)
Can someone help me to resolve this problem please?
Thanks
|
|
|
|
|
I think you could get more helpful responses here if you posted the same code you posted on the same question on StackOverFlow: [^] ... where you show your code for the 'xml_todata method which does the deserilization.
And, if you do that post that code, which doesn't compile as shown, people here are going to ask you the same questions the SO folks asked you, so: please post code that will compile and in which you show us the declaration of the variable 'deserializ.
It also might be very useful if you show how you applied the DataContractAttribute and DataMemberAttribute Attributes to the Dictionary you serialized.
If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya
|
|
|
|
|
I am using AviFile api to make a screen capture video. I want to capture it as small videos of 2 minutes length instead of creating one single video at a stretch. When the video starts getting recorded, a pop-up box to chose the compression option is displayed by default when the avisaveoptions function is called. This creates a problem since I have to choose the option every 2 mins. I would like to avoid this by setting the default value to 'Microsoft Video 1'. How can I do this?
thanks in advance
|
|
|
|
|
Hello
I use this code
AviManager aviManager =new AviManager(@"new.avi", false);
//add a new video stream and one frame to the new file
VideoStream aviStream =aviManager.AddVideoStream(true, 2, bitmap);//(dlg,Rate, bmp);
how I can choice compression method without show dialog, I want microsoft video 1 compression method.
thanks.
|
|
|
|
|
I am using a tool that generates SQL table scripts.
How can I run the scripts from within a C# app?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Just a plain .sql script file? You just need to read the file into a string and execute that string as a command. The only potential issue is if the file contains a batch delimiter such as GO , in which case you need to execute each batch separately.
private static IEnumerable<string> ReadCommandBatches(IEnumerable<string> lines)
{
var builder = new StringBuilder();
forach (string line in lines)
{
if (string.Equals(line, "GO", StringComparison.OrdinalIgnoreCase))
{
if (builder.Length != 0)
{
yield return builder.ToString();
builder = new StringBuilder();
}
}
else
{
builder.AppendLine(line);
}
}
if (builder.Length != 0)
{
yield return builder.ToString();
}
}
public static void ExecuteScriptFile(SqlTransaction transaction, string filePath)
{
var lines = File.ReadLines(filePath);
foreach (string batch in ReadCommandBatches(lines))
{
using (var command = new SqlCommand(batch, transaction.Connection, transaction))
{
command.ExecuteNonQuery();
}
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you sir!
If it's not broken, fix it until it is
|
|
|
|
|
Read it in as a string and pass it to the command, if you pass it as a whole I think you don´t need to bother about anything.
Make sure to catch any thrown exeptions from the result though.
|
|
|
|
|
Hi
I have a dataset from the stockmarket. It's intraday data so there are many inputs for each date.
I am trying to create only one row of daily data for each new day, so I need to find the range for each date, then get some values from this.
If you're familiar with stockmarkets, basically I have intraday-data and need to build a new .txt file (or .csv) with end-of-day data.
I know how to do this in VBA, but it would take a couple of weeks to get the work done...
If anyone would care to help me I would appreciate it.
Here's an example on how my .txt data look:
1/3/2012,09:30:00,409.3,410,409,409.79,657901
1/3/2012,09:35:00,409.79,411.5,409.72,411.29,493743
1/3/2012,09:40:00,411.3,411.68,410.63,410.86,335420
1/3/2012,09:45:00,410.84,411.47,410.71,411.28,212007
1/3/2012,09:50:00,411.28,411.5,410.85,411,206154
1/3/2012,09:55:00,411,411.3,410.92,411.3,141447
1/3/2012,10:00:00,411.3,411.75,411.11,411.65,230247
1/3/2012,10:05:00,411.65,412,411.58,411.86,200034
1/3/2012,10:10:00,411.89,412.2,411.57,411.76,221007
1/3/2012,10:15:00,411.79,412.2,411.78,412.1,111159
1/3/2012,10:20:00,412.1,412.41,412.08,412.4,117193
1/3/2012,10:25:00,412.37,412.5,411.93,412.22,147114
1/3/2012,10:30:00,412.22,412.38,411.9,412.03,91461
1/3/2012,10:35:00,412,412.08,411.8,411.92,123093
1/3/2012,10:40:00,411.9,411.98,411.1,411.17,145873
1/3/2012,10:45:00,411.17,411.33,410.56,410.68,195539
1/3/2012,10:50:00,410.66,410.86,410.22,410.75,203342
I'm not experienced in C#, so I need pretty detailed information I think
Kind regards
Espen
|
|
|
|
|
|
Ok, thanks for the link. I'll check it out right away and see if I can understand it.
Kind regards
Espen
|
|
|
|
|
lordoftrades wrote: so I need pretty detailed information I think
So do we! How should we know how to help you, if you can't even describe what kind of data consolidation should be done.
Since it is comma separated you can start by reading the file line by line and splitting it into pieces using String.Split .
Then you'd parse the first column (date) with DateTime.Parse[^] ignore the second column (time)
and parse the rest of the columns using Double.Parse[^].
If it is the first line or the date hasn't changed yet do your data consolidation calculations.
If the date changed write out the last consolidated data and reinitialise the data consolidation with the values for the new date.
Rinse, lather, repeat!
Regards,
— Manfred
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
Yes you are right. Sorry. I need to get the following data:
For each date I need value from the
first row third column (or [2])
higest value from the fourth column
lowest value from fifth column
finally value from the last row sixth column.
This should all be written to new file adding the date to first column [0], and thereafter the data in same order as above.
I see your point on this:
Quote: If the date changed write out the last consolidated data and reinitialise the data consolidation with the values for the new date.
Not sure though, how to write it out.
Kind regards
Espen
|
|
|
|
|
This is really straight forward stuff. Either you do this yourself or hire a coder.
lordoftrades wrote: Not sure though, how to write it out.
This is not very descriptive. What exactly are you having difficulties with?
Have you even tried anything yet?
Another thing is that I just can't see how this would take weeks to accomplish.
Regards,
— Manfred
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
What you need to do does not seem that complex, but, as Manfred points out, to respond we need a complete specification.
Questions:
1. each day's data is transformed into a single line of cvs ?
2. 1/3/2012,09:30:00,409.3,410,409,409.79,657901, for example, maps to exactly what in the new file ?
3. statements like: for every fourth column-entry in the source cvs file, I need to: .... and return ... are helpful.
If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya
|
|
|
|
|
In a response to my answer OP posted something that some people would consider a "requirement specification".
Here it is![^]
Cheers!
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
Hi Manfred,
Yes, I read the OP's response to your query, and your response.
I agreed with your statement in your response to the OP: "This is not very descriptive."
And, that's why I asked the OP for a more "complete" specification
yours, Bill
If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya
|
|
|
|
|
Hi
If I understand your question right:
1. Yes, i want the data to be: date,open,high,low,close
2. When the second column is 09:30:00 we know that this is the first row for this date. But sometimes there are no records the first minutes/hours, so it doesn't necessarily have to be true that 09:30:00 is the first row. It could be 10:15:00 in a stock with less trading activity. Anyhow, the first row as in your example:
Quote: 1/3/2012,09:30:00,409.3,410,409,409.79,657901
should return 409.3 as "Open" value.
3. The statements would be something like this:
startrow for date X
endrow for date X
Return:
1. date = X
2. Open= Column(3) value in startrow
3. High = search for higest value in range startrow to endrow, column(4)
4. Low = search for lowest value in range...... Column(5)
5. Close = Column (6) value in endrow
Kind regards
Espen
|
|
|
|
|
lordoftrades wrote: so there are many inputs for each date.
And that means ten thousand? One million? One billion?
|
|
|
|
|
Hi
Sorry for not being clear, I'm so used to live in this bubble of stockmarket data.
If it is 5 min data, there could be up to 130 inputs (or lines) for a single date in one textfile. And if there are 400 days with data we could end up with a total of 52.000 lines, if my math is correct..
And at the end this should be 400 lines with end of day data..

|
|
|
|
|
That is a trivial amount of data and any method that you come up with that doesn't have bugs will process it in a trivial amount of time.
|
|
|
|
|
Now that your specification is clear(er), I can suggest to you some architectural features of the C# code you might employ. I won't "flesh that out," since if I did I think I'd be writing commercial code for free, and that's not what CP is for. Also, I am confident that if you can code this in VBA, you can code it in C# !
Given your possible 400 lines of distilled analysis, I'd see no problem reading/parsing your data into a generic List<struct>. The struct and the List<struct> might look like this:
private struct DayTrade
{
public DateTime DateOpen;
public DateTime StartTime;
public double OpenPrice;
public double StartPrice;
public double HighPrice;
public double LowPrice;
public int SharesTraded;
}
private List<DayTrade> DayTradeList = new List<DayTrade>(); I would create the generic List, and then serialize/deserialize it to save/access the data. For serialization to XML, or binary, you could evaluate .NET's built-in facilities in System.Xml and System.Runtime.Serialization; or, you could look into using the MS DataContractSerializer Class, or you could check out Mehdi Gholam's excellent fastJSON and fastBinaryJSON libraries published here on CodeProject.
To get ready to parse the data into structs, I'd define these variables:
private char[] splitLineBreak = Environment.NewLine.ToCharArray();
private char[] splitComma = new char[] {','};
private string currentLine;
private List<string> lineList = new List<string>();
private List<string> splitLineList = new List<string>(); Steps in parsing would be:
1. split the data into lines:
lineList = data.Split(splitLineBreak, StringSplitOptions.RemoveEmptyEntries).ToList<string>(); 2. in the parsing loop:
for (int i = 0; i < lineList.Count; i++)
{
// create a new struct
DayTrade OneDaysTrade = new DayTrade();
// get the current line
currentLine = lineList[i];
// split the current line by comma
splitLineList = currentLine.Split(splitComma, StringSplitOptions.RemoveEmptyEntries).ToList<string>();
// somewhere in your parsing algorithm you are going to be using code like this:
// OneDaysTrade.DateOpen = Convert.ToDateTime(splitLineList[0]);
// OneDaysTrade.StartTime = Convert.ToDateTime(splitLineList[1]);
// OneDaysTrade.OpenPrice = Convert.ToDouble(splitLineList[2]);
//
// and so forth
// finally you are going to add the fleshed out struct to your List
DayTradeList.Add(OneDaysTrade);
} Of course your parsing code will have to handle the transition in reading the data from one day to the next, but I am sure you are already aware of how to do that, and how to create any intermediate variables required. And I'm sure you know how to compare each current day's high and low, and save the highest high, and lowest low, etc.
If you seek to aid everyone that suffers in the galaxy, you will only weaken yourself … and weaken them. It is the internal struggles, when fought and won on their own, that yield the strongest rewards… If you care for others, then dispense with pity and sacrifice and recognize the value in letting them fight their own battles." Darth Traya
|
|
|
|
|
Thanks a lot!! This is a great help!
Kind regards
Espen
|
|
|
|
|
Hi there, I am using VS2012 and .NET Framework 4.5
I am making a simple picture viewer. I have completed,
Creating a picture viewer, which has open, previous, and next buttons.
Now i was wondering how i can add in the Zoom feature into this.
What i exactly want is, according to mouse wheel movement the picture should zoom in or out corresponding to direction of rotation of the mouse wheel. Also the image should zoom in or out based on the point where the mouse pointer is currently present.
One more thing, the picture viewer is fullscreen at all time.
I hope somebody could reply soon... Thank you
|
|
|
|
|
|