|
You've pretty much answered the question yourself. Whatever deserializes this structure will contain a List<item> collection, and Item will be made up of Name, Data and Category. So, you'll have two classes there:
public class Item
{
public string Name;
public string Data;
public string Category;
}
public class MainList
{
public List<Item> Items = new List<Item>();
}
This space for rent
|
|
|
|
|
I have an example. I think my example can help you.
I have a class
public class Action_Info
{
public string valueResult { get; set; }
public string valueError { get; set; }
public string valueInfo { get; set; }
public long timeWait { get; set; }
}
And a list:
List<Action_Info> listActions;
I have a xml file:
<Script>
<Action>
<Result>Success</Result>
<ErrorReason>None</ErrorReason>
<InfoID></InfoID>
<TimeWait>10941</TimeWait>
</Action>
<Action>
<Result></Result>
<ErrorReason></ErrorReason>
<InfoID>NewRcvXbarRsData</InfoID>
<TimeWait>17666</TimeWait>
</Action>
<Action>
<Result></Result>
<ErrorReason></ErrorReason>
<InfoID>NewRcvXbarRsData</InfoID>
<TimeWait>17953</TimeWait>
</Action>
</Script>
Then I read from xml file to listActions:
XDocument doc = XDocument.Load(filePathXML);
listActions = doc.Descendants("Action").Select(d =>
new Action_Info
{
valueResult = d.Element("Result").Value,
valueError = d.Element("ErrorReason").Value,
valueInfo = d.Element("InfoID").Value,
timeWait = long.Parse(d.Element("TimeWait").Value)
}).ToList();
You can do what you want with your list.
|
|
|
|
|
Assuming:
1. you have deserialized the XML into an instance of a class named 'Main that contains a List<Item>
2. what you want to produce is a Dictionary<string, List<Item>> where each Key in the Dictionary is the Category, and the Value of each Key is a List of those Items with the same Category field value
using System.Linq;
public Dictionary<string, List<ItemTest>> GetItemsByCategory(List<Item> items)
{
return items
.ToLookup(itm => itm.Category)
.ToDictionary(ky => ky.Key, val => val.ToList());
} If you call the method shown here, passing it the list of Items, what is returned is a Dictionary of the Type mentioned in #2 here.
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
summary (on short)
PageMissing-is an event defined like this (on class called PrinterUserControl):
public event EventHandler<printereventargs> PageMissing;
PrinterEventArgs-inherit from EventArgs and adds info.
Iam trying to activate this code through a main class:
PrinterUserControl CurrentPrinter;//field..
CurrentPrinter.PageMissing+=this.OnPageError;//Placed on method or c`tor
//Here is the error, a very short red line just in the end of this argument saying "} expected"
public void OnPageError(object sender,PrinterEventArgs e)
{
.........
}
What do you think the problem is ?
|
|
|
|
|
You haven't shown enough of your code to be sure, but it looks like you are trying to attach the PageMissing error handler at the class level, not inside a method. This is not allowed. You should attach the OnPageError in the same method where you create and assign the instance of PrinterUserControl .
If this isn't the case, then provide more of the code so we can see what you are actually attempting to do.
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
Member 12176428 wrote: Here is the error, a very short red line just in the end of this argument saying "} expected" Somewhere in there you have an unpaired {. Go check each brace for a pairing.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have a queue in serverA, both the wcf service and client are on serverB. How to set the configuration file in this scenario? Everything is working fine if I create a queue in serverB.
|
|
|
|
|
|
I am looking for a good design at how to implement a Windows service which would need to run multiple jobs where each job will talk to different external systems. Like say, When i start the windows service, it should do the following
1. Invoke a process, which would connect to an external system A and perform its job.
2. Invoke another process which would connect to an external system B and perform its job.
3. Invoke another process which would connect to an external system C and perform its job.
What i was mostly interested is, when we start the windows service, if we have any connection exception to any one of the external system, the windows service should still start and connect to the remaining external systems which it was able to connect. In essence, the entire windows service should not go down if the service was not able to connect to any of the external system.
In my current implementation, whenever the windows service starts, i am invoking three different threads for the three external systems and if anyone of them fails , the windows service will not start.
Any inputs to implement the above solution in a better way is appreciated.
|
|
|
|
|
You said it yourself. The service starts and launches a PROCESS. A thread is not a process. It's a thread of execution doing some work.
Your service would be launching processes, separate .EXE's, that stand on their own and do work on their own.
In your current implementation, you're not supposed to be launching threads to do work from inside the code that starts the service. Also, it seems as though each worker is dependent on the same database objects (connection at least), meaning if one fails, they all fail. WRONG! Your design is flawed. Each worker should have it's own SQL support right down to its own SQL connection objects and possibly even connection string. That way they are completely independent of each other.
I've done something similar, but I went with a plug-in system where each plug-in (.dll) is loadable by the service when needed and is unloaded when not. This allows me to have each plug-in talk to the service for logging and exception handling purposes and also allows me to swap out .dll's without shutting down the entire service.
No, I'm not sharing the code with anyone. I put way too much work into it to give it away for free.
Hints: I used Log4Net, a custom log forwarder to cross AppDomain boundries, TopShelf, a heavily modified version of the Simple Plugins Framework from a SourceForge project, a custom scheduling engine and a new configuration module.
|
|
|
|
|
I need to wrap a stored procedure within the transaction and this stored procedure spans through 6 to 7 tables. So, there are high chances of dead lock in our application. What is the best approach to handle transaction here?
|
|
|
|
|
Member 10661997 wrote: What is the best approach to handle transaction here? Reading[^].
The transaction will be (and should be) rolled back, see here[^].
Member 10661997 wrote: So, there are high chances of dead lock in our application. Only if you update the data a lot.
In that case, it may be more interesting to find out whether those tuples would have fields that are updated more often than the others; a new table with a 1-1 relation might prevent the need to lock the record if it only contains fields that are rarely updated.
--edit
This is the C# forum, and the question is more related to "databases". You might get a better answer there.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I have been using a common tool that will create me a Timeline but i am having trouble understanding how to change how to timings work.
At the moment when i load my project up it looks like this:
http://i.imgur.com/Wp5LFdA.png
I want to be able to say that the EndTime of the Timelines are the length of a video i have uploaded e.g.
double length = axWindowsMediaPlayer.Length
Then I want the lines on the timeline to be split down every 5 minutes.
I am really struggling with this and would be great if someone could help further.
|
|
|
|
|
You have to show us some code. We can't guess how the timeline works, what code you have, anything.
This space for rent
|
|
|
|
|
Since you've indicated this is WPF, the Silverlight / WPF[^] forum might be abetter place to ask.
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed."
- G.K. Chesterton
|
|
|
|
|
Hi,
I am trying to send SMS using Jamaa SMPP but it's making me crazy! I keep getting:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 193.188.124.116:2775
The IP, user name, password are correct and I got it from my provider.
How can I fix it please? here is my code:
SmppClient client = new SmppClient();
SmppConnectionProperties properties = new SmppConnectionProperties();
TextMessage msg = new TextMessage();
client = new SmppClient();
properties = client.Properties;
properties.SystemID = txtUserID.Text;
properties.Password = txtPassword.Text;
properties.Port = Convert.ToInt32(txtPort.Text);
properties.Host = txtIP.Text;
properties.SystemType = txtType.Text;
properties.DefaultServiceType = ServiceType.DEFAULT;
client.AutoReconnectDelay = 3000;
client.KeepAliveInterval = 30000;
client.Start();
if (client.ConnectionState != SmppConnectionState.Connected) client.ForceConnect(5000);
msg = new TextMessage();
msg.DestinationAddress = txtMobile.Text;
msg.SourceAddress = txtSenderID.Text;
msg.Text = txtMessage.Text;
msg.RegisterDeliveryNotification = true;
client.SendMessage(msg, 1000);
client.Shutdown();
Thanks,
Jassim[^]
Technology News @ www.JassimRahma.com
|
|
|
|
|
Jassim Rahma wrote: The IP, user name, password are correct and I got it from my provider.
Is the port (2775 ) correct?
It's not a standard port, so is there a firewall between the two computers which need to be configured to allow traffic through on that port?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = global::System.Data.CommandType.Text;
cmd.CommandText = "SELECT * FROM Table1 WHERE RFID = '" + textBox1.Text + "'";
cmd.Connection = myCon;
this.table1TableAdapter.Adapter.SelectCommand = cmd;
this.table1TableAdapter.Adapter.Fill(mdb11DataSet.Table1);
dgvConnect = new NominalRollDBConnection();
conString = Properties.Settings.Default.NominalRollCS;
dgvConnect.connection_string = conString;
dgvConnect.Sql1 = "SELECT * FROM NominalRoll WHERE RFID = '" + textBox1.Text + "'";
ds = dgvConnect.GetConnection1;
this.nominalRollTableAdapter.Fill(nominalRollDataSet.NominalRoll);
class NominalRollDBConnection
{
private string strCon;
private string sql_string1;
System.Data.SqlClient.SqlDataAdapter da_1;
public string Sql1
{
set { sql_string1 = value; }
}
public string connection_string
{
set { strCon = value; }
}
public System.Data.DataSet GetConnection1
{
get
{ return MyDataSet1(); }
}
private System.Data.DataSet MyDataSet1()
{
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(strCon);
con.Open();
da_1 = new System.Data.SqlClient.SqlDataAdapter(sql_string1, con);
System.Data.DataSet dat_set = new System.Data.DataSet();
System.Data.DataTable dat_table = new System.Data.DataTable();
da_1.Fill(dat_set, "Table_Data_1");
con.Close();
return dat_set;
}
I have a difference in output when using datagridview to display my data tables.
For the code above it outputs as per my query.
However for the second code it outputs the entire data table, can anyone please explain ?
Thank you
edit: I have binded the datagridview using the GUI for the code above and below to respective datasources
modified 30-Nov-15 21:45pm.
|
|
|
|
|
Use the debugger to see exactly what command you are passing through, then look directly at the DB - without the data we would just be guessing what is in your two tables and text boxes.
But do yourself a favour: Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
OriginalGriff wrote: It leaves you wide open to accidental I'd love to hear the excuse for accidentally dropping the user table, Little Bobby Tables is not an accident!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Yeah, I know what you mean. But I like to presume Innocence instead of Guilt (unlike our current legal system)
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi, thanks for your help, I have tried using the debugger and it appears that for the code below it is not using my SQL query statements.
I have tried moving the query statements into the NominalRollDBConnection class and declaring the statements directly on my form part of the program but it still does not work.
I will try to resolve this via declaring all the SQL connections manually rather than use a separate class as now, am I headed the right way if I were to do this ?
Sorry if it looks as though as I am doing "crazy" things with the declarations. This is due to me being a total beginner to C# and my only prior lessons is very basic console applications using C++.
|
|
|
|
|
Member 12040781 wrote: cmd.CommandType = global::System.Data.CommandType.Text;
I know it's different to your original query but why are you setting the command type with a global reference to what is effectively an enum?
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
..and why set it explicitly to its default value?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Sorry, I did not have prior knowledge to enums, this is my first time using C#. From the example that I have on hand they're doing the declarations this way.
I will try to declare an enum class for the cmd object and see whether it will work.
|
|
|
|