|
Thank You, I have one more step to go. I'm getting the values into the variables, the only issue is getting the values that are in the item element.
<Item>
<ItemNumber id="0">
<Name>Coffee</Name>
<ItemDescrip>I Descrip1</ItemDescrip>
</ItemNumber>
<ItemNumber id="1">
<Name>Tea</Name>
<ItemDescrip>I Descrip 2</ItemDescrip>
</ItemNumber>
</Item>
The tricky part to me is that sometimes they exists and other times they don't.
|
|
|
|
|
In what kind of data structure do you need them in your program? Or do you just need to write them to the console?
If so, in which format should it be written to the console? Can you give an example?
|
|
|
|
|
I will be writing the records to a database. I thought the best way of doing that was getting the data into a datatable. to do that I need to add rows and populate the columns with the individual elements or attributes. The element Item and ItemNumber are only present in some conditions.
So when I add them to the variables I should see something like this:
+If all items exist
Time = (string)c.Element("Time"),
Description = (string)c.Element("Description"),
ItemId = (int)c.Attribute("Itemid"), ***Note not HomeItemId****
Name = (string)c.Element("Name"), //Coffee
ItemDescrip = (string)c.Element("ItemDescrip"),
+If NO items exist
Time = (string)c.Element("Time"),
Description = (string)c.Element("Description"),
ItemId = ""
Name = ""
ItemDescrip = ""
Thanks,
Sue
|
|
|
|
|
Try that one, joining with subItems and adding a null item in the case that no subitem exists:
public void Today3()
{
XDocument xDoc = XDocument.Load(@"C:\Results\XMLTry.xml");
var q = from homeItem in xDoc.Descendants("HomeItem")
from subItem in homeItem.Element("Item").Descendants("ItemNumber").Any () ? homeItem.Element("Item").Descendants("ItemNumber") : new List<XElement>(){null}
select new
{
Description=(string)homeItem.Element("Description"),
Time = (string)homeItem.Element("Time"),
Id=(int)homeItem.Attribute("id"),
ItemId = subItem == null ? "" : (string)subItem.Attribute("id"),
Name = subItem == null ? "" : (string)subItem.Element("Name"),
ItemDescrip = subItem == null ? "" : (string)subItem.Element("ItemDescrip")
};
foreach (var item in q)
Console.WriteLine(@"Description = {0}
Time = {1}
Id = {2}
ItemId = {3}
Name = {4}
ItemDescrip = {5}
--------------", item.Description, item.Time, item.Id, item.ItemId, item.Name, item.ItemDescrip);
}
|
|
|
|
|
That's exactly what I need.
Thank You So Very Much! 
|
|
|
|
|
Just looking for guidance or examples in using MEF from a windows services to read in available devices and selecting the one device defined in a configuration file(if present). User would be able to open an app to define and save desired attributes, and have system start monitoring the selected device with the new configuration file. Service would then broadcast data to ports defined in the configuration file. Using NET 4.0
|
|
|
|
|
Member 10272748 wrote: Just looking for guidance or examples Google has enough examples on MEF and creating services.
Keep in mind that a service isn't meant to interact with the user, and that they run under system-credentials (not under a users' account); it will run before any user logs in, and it should not display a UI. Any UI part would be a normal application, running independent from the service.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Personally I think MEF is a sledge-hammer to a picture nail. There seems to be an extraordinary amount of scaffolding required to load/execute plugins.
I gave up on MEF some time ago and went over to Mono.AddIns[^]. Its a hell of a lot simpler and can be very powerful if you want it to be.
|
|
|
|
|
Hi,
I have a rakefile that compile a C++ code.
now I have a C# app that change something in the C++ code and I want to recompile it automatically.
I did:
Process p = new Process();
p.StartInfo.FileName = "rake";
p.StartInfo.Arguments = my_expected_args;
p.StartInfo.WorkingDirectory = my_dir;
p.StartInfo.UseShellExecute = false;
p.start();
I'm getting error: The system canot find the file specified.
Let say that if I open a cmd prompt and do:
> cd my_dir
> rake my_expected_args
this is fine.
Thanks for any solution
|
|
|
|
|
It looks like you are getting confused about what WorkingDirectory is used for. It is not a path to the file when you set UseShellExecute=false; - if the executable doesn't exist somewhere in the PATH settings, you need to specify a directory as part of the filename, so you would have
p.StartInfo.FileName = Path.Combine(my_dir, "rake.exe"); Have a look here[^] to understand what's happening with your code.
|
|
|
|
|
Thanks,
I tried to do as you said but still getting the same error.
what can be the problem?
|
|
|
|
|
What does your code look like now?
|
|
|
|
|
Process p = new Process();
p.StartInfo.FileName = Path.Combine(my_dir, "rake.exe");
p.StartInfo.Arguments = my_expected_args;
p.StartInfo.UseShellExecute = false;
p.start();
I Also tried the following :
Directory.SetCurrentDirectory(my_dir);
Process p = new Process();
p.StartInfo.FileName = "rake.exe";
p.StartInfo.Arguments = my_expected_args;
p.StartInfo.UseShellExecute = false;
p.start();
|
|
|
|
|
Either of those should have worked. Have you verified that my_dir actually points to the directory that contains rake? Put a break point on Process p = new Process(); and see what's in my_dir.
|
|
|
|
|
replace "rake" with the full path and the full filename including its extension of that executable.
|
|
|
|
|
Hello
I filling My Datagridview with Linq Query in C#. in my program I want to filter This datagridview with Textbox. the code of Textbox changed is:
DataTable dt = new DataTable();
dt = (DataTable)(dataGridViewX4.DataSource);
dt.DefaultView.RowFilter = string.Format("T_P = '{0}'", Txt_T_P_Se.Text);
dataGridViewX4.DataSource = dt;
after Runnig program, this Error Appear:
Invalid Cast Exception Was Unhandled
Please Help me.
|
|
|
|
|
dt = (DataTable)(dataGridViewX4.DataSource);
I suspect that the DataSource of your grid is not a DataTable .
Veni, vidi, abiit domum
|
|
|
|
|
hi
thanks for your reply.
my DataSource is :
var Query=
(from p in QcGerdBaf.Taghes where p.QGI_Id_Fk == QGI_Id_Selected select new { p.T_P, p.T_Id });
dataGridViewX4.DataSource = Query.ToList();
|
|
|
|
|
That is not a DataTable .
Veni, vidi, abiit domum
|
|
|
|
|
Ok,
Please give your suggestion
|
|
|
|
|
Suggestion for what? You cannot cast a List to a DataTable ; read your .NET reference.
Veni, vidi, abiit domum
|
|
|
|
|
Is there any Way to fill Datatable with this Query?
If yes,Please Tell Codes.
|
|
|
|
|
You would have to "Select New" DataRow objects and add them to the DataTable.Rows collection.
No, I don't have an example, because I never had the need to do such a thing.
|
|
|
|
|
I wanted to see how close the performance of a loop in C# is to something written in assembly.
uint x = int.MaxValue;
DateTime st = DateTime.Now;
for (uint i = 0; i < x; i++) ;
TimeSpan sp = new TimeSpan(DateTime.Now.Ticks - st.Ticks);
Console.WriteLine("looped: {0} in {1}", x, sp);
In Debug it ran in 6+ seconds. Oh, idiot! Compile it! Ran in 2.1+ to 2.2 seconds. It's rated at 2.1 GHz so it should have finished in just under 2 seconds, so close enough to assembler speeds.
Did some more changes elsewhere in the code and used uint to define x. Wha?? Over 6 seconds, went back to int, now it is 3 seconds.
looped: 4294967295 in 00:00:06.2643583
looped: 2147483647 in 00:00:03.0888054
It's like it changed from 2 flops per loop to 3 flops. When I checked performance logs, it runs at 50% CPU on a dual core machine, so it is showing 100% of one CPU is dedicated to this loop for the 3 seconds.
Any ideas why changes in other sections of logic might affect this piece? I'm normally running 90-97% idle with occasional dips to the 80's.
Modified:
1. Subject to be more specific
2. added last line of code segment because it was missing.
modified 22-Jan-14 1:29am.
|
|
|
|
|
You cannot rely on DateTime values to time in a multi-tasking operating system. You are measuring elapsed time, which will include any switching between applications and OS overhead.
Veni, vidi, abiit domum
|
|
|
|