|
thanks for the reply... i dont understand i tried to save the amount of buttons in ViewState["Counter"] , is that what i must do?
|
|
|
|
|
That not enough, you also have to recreate them outside the click event - which does not happening on other post-back events, like click on one of the radio buttons...
For instance you can add a loop of creation to page's OnLoad when it's post-back and the source isn't the button...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
When you check or uncheck the radio button, there is no code which does postback in your case. You have attached the event handler to the radio button but did not call the method.
|
|
|
|
|
Thanks for the reply.
may i know how to fix it? i am new to this programming language please guide me
|
|
|
|
|
I am trying to root out why this particular linq query is so expensive from a time standpoint, assuming it is the linq query that is causing it.
public static List<DocumentType> GetDocs()
{
List<DocumentType> output;
using (context = contextLogic())
{
output = (from d in context.DocumentTypes
select d).AsEnumerable().Select (x => new DocumentType
{
Id = x.iD,
Name = x.Name,
FlagA = x.FlagA,
IsActive = x.IsActive,
UpdateDate = x.UpdateDate,
CategoryName = x.DocumentCategory.Name,
Associations = string.Join(",", x.DocumentAssociations.Select(g => g.ADocID.ToString()))
}).ToList();
}
return output;
}
I tried flipping things around quite a bit. This was initially an observablecollection but it is a list right now as I try to tune it in different ways. Right now it is taking about 12 seconds to retrieve data from a table of 350 records. If I take out the CategoryName and the associations it times down to about six seconds, but that is still ridiculously slow.
|
|
|
|
|
Is the context local or is this on a server?
Try ruling out the new DocumentType by changing the .Select(...).ToList() to just be .Count() (change the assignment variable appropriately, it is just for testing...).
The .AsEnumerable() is totally unnecessary.
This is equivalent to what you have:
public static List<DocumentType> GetDocs()
{
using (var context = contextLogic())
{
return (from x in context.DocumentTypes
select new DocumentType {
Id = x.Id,
Name = x.Name,
FlagA = x.FlagA,
IsActive = x.IsActive,
UpdateDate = x.UpdateDate,
CategoryName = x.DocumentCategory.Name,
Associations = string.Join(",", x.DocumentAssociations.Select(g => g.ADocID.ToString()))
}).ToList();
}
}
|
|
|
|
|
Unfortunately, the AsEnumerable is necessary as L2E does not recognize string.Join. So you have to present it as an IEnumerable in order to join the Doc strings.
Regardless, I retooled the process to use a stored procedure but it is still a nightmare. The data access is fast, the stored procedure fills a list in less than a second, but assigning those items to the DocumentType model takes four or five seconds more.
It looks like it is the model itself. I am wondering if the implementation of INPC on the model is not causing a lot of slow down. Each time a new document type is added to the list it fires the OnPropertyChanged event for every single property. Not sure that is the problem, but it is a lot of events.
|
|
|
|
|
I had something a bit similar to this. I just put together SQL in the database to build the stuff I was trying to do in the LINQ query. This also involves changing your model so that it returns this field as a database calculated field so EF doesn't try to write to it.
|
|
|
|
|
I ended up moving all the data access logic to a SQL SP using STUFF for that very reason. The data access from SQL is a snap, but loading the data into the model is time consuming.
Frankly, I think that the nature of the design of the WPF screen is the issue. Each of the items is loaded into a list view and has two states, one editable state and one that is not editable. Any time you make a change to the property in the editable mode you have to fire the NotifyPropertyChanged event so that the UI will update it in the non-editable form.
As a result, every single property of every row fires an OnPropertyChanged event during the initial load. I think this is likely the problem. I just don't know how to work around it. If I could avoid that initial event firing I think that things would be much quicker.
|
|
|
|
|
XML File
<Log>
<HomeItem id="2">
<Time>1/8/2014 3:21:47 PM</Time>
<HasNewAddress>Y</HasNewAddress>
<AddressType>N</AddressType>
<Description>myDescrip</Description>
<Item/>
<Title/>
</HomeItem>
<HomeItem id="3">
<Time>1/8/2014 6:52:47 PM</Time>
<HasNewAddress>Y</HasNewAddress>
<AddressType>N</AddressType>
<Description>myDescrip2</Description>
<Item>
<ItemNumber id="0">
<Name>Coffee</Name>
<ItemDescrip>I Descrip1</ItemDescrip>
</ItemNumber>
<ItemNumber id="1">
<Name>Tea</Name>
<ItemDescrip>I Descrip 2</ItemDescrip>
</ItemNumber>
<ItemNumber id="2">
<Name>Milk</Name>
<ItemDescrip>I Descrip 3</ItemDescrip>
</ItemNumber>
</Item>
<Title/>
</HomeItem>
<HomeItem id="4">
<Time>1/8/2014 7:35:47 PM</Time>
<HasNewAddress>Y</HasNewAddress>
<AddressType>N</AddressType>
<Description>my Descrip 3</Description>
<Item>
<ItemNumber id="7">
<Name>Juice</Name>
<ItemDescrip>I Descrip 4</ItemDescrip>
</ItemNumber>
<ItemNumber id="8">
<Name>Tea</Name>
<ItemDescrip>I Descrip 6</ItemDescrip>
</ItemNumber>
<ItemNumber id="9">
<Name>Milk</Name>
<ItemDescrip>I Descrip 7</ItemDescrip>
</ItemNumber>
</Item>
<Title>The Title</Title>
</HomeItem>
<HomeItem id="5">
<Time>1/8/2014 12:21:47 PM</Time>
<HasNewAddress>Y</HasNewAddress>
<AddressType>N</AddressType>
<Description>myDescrip 8</Description>
<Item/>
<Title/>
</HomeItem>
</Log>
I want to loop through the results and assign variables. Here is my code
public void Today3()
{
XDocument xDoc = XDocument.Load(@"C:\Results\XMLTry.xml");
var q = from c in xDoc.Descendants("HomeItem")
select (string)c.Element("Description") + " " +
(string)c.Element("Time") + " Attribute = " +
(int)c.Attribute("id");
foreach (string name in q)
Console.WriteLine("My stuff = {0}", name);
}
My results are displayed as a string:(sample of results)
My stuff = myDescrip2 1/8/2014 6:52:47 PM Attribute = 3
My stuff = my Descrip 3 1/8/2014 7:35:47 PM Attribute = 4
How can I get the results to be like:
sDescrip = myDescrip2
time = 1/8/2014 6:52:47 PM
Id = 3
I tried name.value and q.value and many other combinations and can't come up with what I'm looking for.
Thank You
|
|
|
|
|
I'm not 100% sure if I understand your question correctly, but I could generate your desired result with this function:
public void Today3()
{
XDocument xDoc = XDocument.Load(@"C:\Results\XMLTry.xml");
var q = from c in xDoc.Descendants("HomeItem")
select new
{
Description=(string)c.Element("Description"),
Time = (string)c.Element("Time"),
Id=(int)c.Attribute("id")
};
foreach (var item in q)
Console.WriteLine(@"sDescrip = {0}
time = {1}
Id = {2}", item.Description, item.Time, item.Id);
}
Basically reading the XML elements into an anonymous type and using that to display the result.
modified 23-Jan-14 7:50am.
|
|
|
|
|
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.
|
|
|
|