|
What confuses me is that the previous version works fine even with this "random sort"
Yeah, I'll try to add a field and fill it with random value before sort. Also, that struct is a gift from previous developer.
Oxfords English < Official CCC Players Dictionary
Excuse me for my improper grammar and typos.
It's because English is my primary language, not my first language.
My first languages are C# and Java.
VB, ASP, JS, PHP and SQL are my second language.
Indonesian came as my third language.
My fourth language? I'm still creating it, I'll let you know when it's done!
|
|
|
|
|
A sort algorithm should always return consistent results, i.e. don't do the random thing. If two items are sort-order-equivalent, the comparison should return 0.
Why are you doing that weird XOR check when it seems to be equivalent to [ if(x.Confirmed == y.Confirmed) ]? Not that I think that's responsible for the problem but it is needlessly confusing.
What types are TA and State, and do they have comparators (or equality operator overrides) which could mess things up?
Did you override Equals on ShipSprite, and if so did you do it correctly?
As an aside, why is this a struct? It looks complex enough that it should be a class. Sorting a list of structs requires moving around and copying a lot more bits of memory.
|
|
|
|
|
Well, TA is a DateTime and State is an int, so they shouldn't mess things up. I have also checked Equals on ShipSprite and it seems fine. I will do as Luc's suggestion, create a new field and fill it with random value before sorting.
That XOR and struct is results of fluctuate requirement and management's motto "Previous developer did it fine this way, don't change it!"
Oxfords English < Official CCC Players Dictionary
Excuse me for my improper grammar and typos.
It's because English is my primary language, not my first language.
My first languages are C# and Java.
VB, ASP, JS, PHP and SQL are my second language.
Indonesian came as my third language.
My fourth language? I'm still creating it, I'll let you know when it's done!
|
|
|
|
|
Hi all,
I'm porting a C# 2 application from Visual Studio 2005 to 2010 .Net 4, and getting a baffling error:
"Error 1 'Could not load file or assembly 'Aurigma.GraphicsMill' or one of its dependencies. Could not find or load a specific file. (Exception from HRESULT: 0x80131621)' C:\Alan\Label Designer\64-bit\Source\LabelDesigner\LC LabelDesigner"
It's complaining about not being able to load Aurigma.GraphicsMill but the damn DLL is there! It's maddening. The same files run perfectly under VS 2005. It also mentions an "LC" file, but no file has anything like that name anywhere under this project folder, or the original which compiles.
I tried deleting the GraphicsMill reference and re-adding it, but got the same results.
Wasted hours on this; I'm calling it a day.
Can anyone make any suggestions of what to try next?
modified 12-Dec-11 11:24am.
|
|
|
|
|
I noticed the 64-bit in your path above. Could it be that you are creating a 64-bit app and this dll is a) stored in the 32-bit directory or b) not available in 64-bit? Just a guess.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Thanks for the suggestion, but at this point it's 32-bit. (64-bit is a later goal, but the first step is just to get it working under VS 2010.)
|
|
|
|
|
I put that error code into Google and came up with this[^]; the first link looks like it may be of use - if you understand what they are saying.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Thanks. I did the same thing! Great minds think alike. Microsoft has no workaround for this artificial "bug" they've caused. I've emailed Aurigma to see they have an updated DLL for .NET 4.
|
|
|
|
|
|
Hi,
I have a "asp:listview" bind to web service without database.
I don't use "ObjectDataSource" and in my contol "ListView" : I haven't atribut "DataKeyNames" and "DataSourceID"
I bind to it in code-behind
protected void Page_Load(object sender, System.EventArgs e)
{
Act ActWEBService = WebServiceFactory.CreateInstance().CreateActWebService();
ActStruct[] myActs = ActWEBService.GetActs(nameIdItemDataBound);
mSeenFromPageState.Acts = new ActStruct[myActs.Length];
foreach(ActStruct act in myActs)
{
ListViewActs.DataSource = ActWEBService.GetActs(nameIdItemDataBound);
ListViewActs.DataBind();
}
protected void OurListView_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
System.Data.DataRowView rowView = e.Item.DataItem as System.Data.DataRowView;
ListViewDataItem dataItem = (ListViewDataItem)e.Item;
Act ActWEBService = WebServiceFactory.CreateInstance().CreateActWebService();
ActStruct[] myActs = ActWEBService.GetActs(nameIdItemDataBound);
So here is my list on screen :
nameIdItemDataBound....thatOneId............name
11BB...................................1..............................john
13AA...................................3..............................alice
15AAA..................................2..............................roxy
16TXQ..................................1..............................jean
But I want items that have [3] in their [thatOneId], does not appear in my list!
"if statement" does not use with Listview so I must put a filter...
like this : Where(a => a.name != value);
oreach(ActStruct act in myActs)
{
ListViewActs.DataSource = ActWEBService.GetActs(nameIdItemDataBound).Where(d => d.thatOneId != 3);
ListViewActs.DataBind();
}
I have a message error :
'ListView with id 'ListViewActs' must have a data source that either implements ICollection or can perform data source paging if AllowPaging is true.' (line Ligne : 82 )
Could you help me for this ?
|
|
|
|
|
Hi all,
I seem to be having a problem with value validation of a list in a foreach loop and was wondering if you could please point out where the logic/syntactic error is?
Basically I am enumerating the Windows Application log for an eventid value then for a timewritten value. If the value is not found the code should run. If the value is found but is older than 1 hour then the code should run. If the value is found and is not 1 hour old then the code should not run. This is what I have but the code runs on my 2-minute timer anyway indicating that the value is not being found (I think)
public void OnTimedEvent(object source, ElapsedEventArgs e)
{
int run;
run = 0;
EventLog eLog = new EventLog("Application");
foreach (EventLogEntry entry in eLog.Entries)
{
if (entry.EventID == 13162)
{
List<int> evid = new List<int>();
evid.Add(entry.EventID);
foreach (int IDNo in evid)
{
if (entry.TimeWritten > DateTime.Now.AddHours(-1))
{
run = 1;
}
else run = 2;
}
}
}
if(run == 0 ||run == 1)
{
}
if (!EventLog.SourceExists("mylog")) EventLog.CreateEventSource("mylog", "Application");
EventLog.WriteEntry("mylog", "code has run", EventLogEntryType.Information, 13162);
}
This has been driving me nuts for nearly 3 days now and I just can't figure it out. I have tried evid.contains and evid.find methods but either the //do stuff won't run at all or it keeps running on the timedevent, i.e. every 2 minutes. Could you help please?
|
|
|
|
|
I would change this piece of code
foreach (EventLogEntry entry in eLog.Entries)
{
if (entry.EventID == 13162)
{
List<int> evid = new List<int>();
evid.Add(entry.EventID);
foreach (int IDNo in evid)
{
if (entry.TimeWritten > DateTime.Now.AddHours(-1))
{
run = 1;
}
else run = 2;
}
}
}
for
foreach (EventLogEntry entry in eLog.Entries)
{
if (entry.EventID == 13162)
{
if (entry.TimeWritten > DateTime.Now.AddHours(-1))
{
run = 1;
}
else run = 2;
}
}
}
Please let me know if it works.
|
|
|
|
|
Hi emardini,
Nope, still runs every 2 minutes. I am currently thinking that "13162" is not a valid eventid number. By calling the other numbers it seems that are not ints, they are bytes[] converted to ints for legibility.
Still investigating but will advise
|
|
|
|
|
I have a question about a C#. net 2008 desktop where I am working with .XSD files (datasets and dataadapters). I need to add a capability for a user to enter a 'alt-id' key as a search key to look up lots of information about a customer. To accomplish this goal a stored procedure with lots of 'left outer join statments' is called to obtain the information.
When the stored procedure is executed on its own, it runs in all cases. When the C#.net app executes in runs in all cases, except when there there is only data in the 'alt-key' column. Basically all the other tables that are associated in the join do not data the correspsonding data.
I am getting the error 'Failed to enable constraints. One or more rows contain values violating non-null,unique, or foreign-key constraints.'
The error occurs on the statment where I try to fill a dataset.
Thus to solve this problem, I am trying to decide what to do.
What you do think my options are:
1. Is there some setting I should change in the dataset so at least the 'alt-key' value is returning and all the other joined columns contain null as their value?
2. Should I do some kind of a preselect to see if any real data exists? if so how would you code that?
3. Do you have other suggestions? If so, can you tell me and/or point me to a reference where I can solve this problem?
|
|
|
|
|
I have a list of these models:
public class NodeModel : ViewModelBase
{
public Guid Id { get; set; }
public string Caption { get; set; }
public string Description { get; set; }
public bool IsActive { get; set; }
public int Sequence { get; set; }
public ImageSource Image { get; set; }
public bool IsExpanded { get; set; }
public string FileName { get; set; }
public NodeType Type { get; set; }
public List<NodeModel> Children { get; set; }
public NodeModel()
{
Children = new List<NodeModel>();
FileName = string.Empty;
}
}
The list is contained in a collection called Folders. I want to remove an object from the collection, so I'm using:
Folders.Remove(f => f.Id == model.Id);
But it's not removing it, What's wrong here?
Everything makes sense in someone's mind
|
|
|
|
|
I know I'm stating the bloody obvious, but have you placed a breakpoint on the Folders.Remove statement to make sure you have a proper model.Id? You can also convert the statement into a foreach temporarily so that you have more debugging visiblity. Once the problem is solved, I would certainly return the statement into the linq syntax, though.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Remove doesn't take a predicate as far as I know.
Either use .RemoveAll(f => f.Id == model.Id) or use Remove(specificInstanceOfNode)
All the best,
Dan
|
|
|
|
|
Ok, so now I have this:
NodeModel folder = (from f in Folders
where f.Id == model.Id
select f).FirstOrDefault();
Folders.Remove(folder);
The query is returning null. It's not finding the folder.
It appears that the query is only looking at the first level and not drilling down into the collection.
Everything makes sense in someone's mind
|
|
|
|
|
Yes. It sure doesn't. I completely missed the inner list.
So you want to remove from the ChildNode inner list or from the main/upper list or from both?
All the best,
Dan
|
|
|
|
|
I want to find i anywhere in the list and remove it.
Everything makes sense in someone's mind
|
|
|
|
|
Well this is more complicated then it looks. Cause you don't know upfront how
many nested levels you have.
As each node has a list of childnodes and then each node in the nested childNodes list could have an
even deeper nested level list of childNodes ...
The only thing that comes to mind wright now is a brute force step by step actions:
1)ForEach item in the upper level list check to see if it has the id and remove it if so.
2) Else loop through the inner collection if Count>0 and remove from there else loop through it's inner collection if Count>0
and so on.
Unless you do know that there are only 2 levels.
All the best,
Dan
|
|
|
|
|
There can be any levels. I could write a recursive method, but I think that will cause problems modifying the collection.
Everything makes sense in someone's mind
|
|
|
|
|
True, a faster approach would be to use a boolean filed like obsolete/deleted/visible.
Then instead of deleting/altering the collection you would just set the value to true(no list and/or memory reallocation).
When populating UI or whatever, based on the boolean field you'll show it or not.
All the best,
Dan
|
|
|
|
|
Only if you use foreach ... it's a list so you can use integer indices. Not thread-safe but self-modification-safe:
void Remove<T>(IList<T> list, T node) where T:INested<T> {
if(list == null) return;
for(int i = list.Count; i >= 0; i--){
if(list[i] == node) list.RemoveAt(i);
else Remove(list[i].ChildNodes, node);
}
}
where
interface INested<T> { IList<T> ChildNodes; }
If this is the only place you need something like this, you don't have to generic it, but it is a general algorithm so you might want to put it in a utility library and have your class implement that interface.
|
|
|
|
|
Definition of the INested<T> interface will not compile since ChildNodes is a field. So, for testing your code, I'll be starting with this:
interface INested<T>
{
IList<T> ChildNodes { get; set; }
} In your code, where you compare:
if (list[i] == node) list.RemoveAt(i); the compiler throws an error: " Operator '==' cannot be applied to operands of type 'T' and 'T' "
best, Bill
"For no man lives in the external truth among salts and acids, but in the warm, phantasmagoric chamber of his brain, with the painted windows and the storied wall." Robert Louis Stevenson
|
|
|
|