|
Thsi may be silliy, but your operator overload code doesn't do any checking to see if one of the object passed in is null or not before trying to use it. You should be check to see if you actually have an object, handle the case where the object is null , then check to see if it is a valid object type to compare against, ...
|
|
|
|
|
So your advice is to use overloading the == Operator but with additional checks like:
public static bool operator ==(UserList userlist1, UserList userlist2)
{
if (userlist1 == null) return false;
....
}
But by doing so i repeatedly call the ==-Operator recursivly. Is this ok? I believe i get the NullPointerExcception as well.
--> ok I tested it and I get a StackOverflowException. Thats sort of what I Expected.
modified on Friday, July 10, 2009 5:53 AM
|
|
|
|
|
How can I load an XML Document to an ObservableCollection class that preserves the XML tree structure?
My xml looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://none.none.none/webservices">
<TREENODES xmlns:sql="urn:schemas-microsoft-com:xml-sql">
<TREENODE code="1" text="None" >
<TREENODE code="2" text="America" >
<TREENODE code="16128" text="AUTOS">
<TREENODE code="ATO" text="ATO" />
<TREENODE code="ATO" text="ATO" />
</TREENODE>
</TREENODE>
</TREENODE>
<TREENODE code="11" text="None" >
<TREENODE code="21" text="America" >
<TREENODE code="3" text="AUTOS">
<TREENODE code="ATO44" text="ATO5" />
</TREENODE>
</TREENODE>
</TREENODE>
</TREENODES>
</string>
|
|
|
|
|
Depends on what you're loading it for. What is the consumer of the object?
You can make something like:
public class TreeNode
{
public string Code { get; set; }
public string Text { get; set; }
public List<TreeNode> Children { get; set }
public TreeNode()
{
Children = new List<TreeNode>();
}
}
In both WPF and Silverlight you could databind with a hierarchal template.
Again, it all depends on how/what/why you are using it.
You can populate the tree using LINQ to XML.
Jeremy Likness
http://csharperimage.jeremylikness.com/
|
|
|
|
|
So what would be the LINQ?
Thanks in Advance
|
|
|
|
|
Also this class it seems that will create a simple list. Not a tree like the XML.
|
|
|
|
|
It will create a hierarchal object graph. Something like this would populate it:
public TreeNode Populate(XDocument doc)
{
var retVal = (from treeNode in doc.Descendants("TreeNode")
select new TreeNode()
{
Code = treeNode.Attribute("Code").Value,
Text = treeNode.Attribute("Text").Value
}).SingleOrDefault();
retVal.Children = _Recurse((from treeNode in doc.Descendants("TreeNode")
select treeNode).SingleOrDefault());
return retVal;
}
private static List<TreeNode> _Recurse(XContainer root)
{
List<TreeNode> retVal = new List<TreeNode>();
var children = from child in root.Descendants("TreeNode") select child;
foreach(var child in children)
{
TreeNode node = new TreeNode
{
Code = child.Attribute("Code").Value,
Text = child.Attribute("Text").Value,
Children = _Recurse(child)
};
retVal.Add(node);
}
return retVal;
}
Jeremy Likness
http://csharperimage.jeremylikness.com/
|
|
|
|
|
Have you seen the Linq exception
"Sequence contains more than one element"? It comes from Populate.
|
|
|
|
|
it was the FirstOrDefault not SingleOrDefault.
Will this work if I change the class from List to ObservableCollection?
Thanks a bunch.
|
|
|
|
|
Hi All,
I am developing a Windows Service application.
It connects the SQL server for data.It uses the Integrated security = true for the connection string.
My serivice is running fine while the Service and SQL running in same NT domain.
It throws an error for (cross domain) while service in Domain1 and SQL server in Domain2.
Is there any way to resolve the issue without changing the Integrated security and passing the User name and password. Does it make sense?.
Thanks in advance.
Regards,
Arafath.
|
|
|
|
|
I am having some weird panel issues. In my program I have multiple panels of different contents. For example there is a welcome screen, the user clicks next and the welcome screen is not visible and the next screen is.When the screens are changed with the next button they work fine.
Here is where the problem is... However if I want to change them from a seperate thread, the panel is visible but the contents of the panel are not. I am calling the same function to change the panels' visiblity (and the contents have all been set to visible). I have made sure that all labels were changed using the invokerequired/settextcallback stuff. What am I forgetting?
|
|
|
|
|
Hi,
Threads (all kinds of them, including ThreadPool threads, and BackgroundWorkers) other than the thread that created a Control (BTW: a Form is also a Control), should not access that Control, except for the very few members explicitly allowed, including InvokeRequired and Invoke.
Before .NET 2.0 the app may behave badly, the GUI may freeze, anything can go wrong if you violate the rule.
Since 2.0 you get an InvalidOperationException by default; you can disable that by setting Control.CheckForIllegalCrossThreadCalls false, but that is a very bad idea, and it brings you back in the previous situation.
Since most if not all Controls are somehow related (they are on a Form, one Form owns another Form, etc), the natural consequence is all Controls get created and accessed exclusively by a single thread, typically your initial or main thread, often also called the "GUI thread".
There are lots of examples on InvokeRequired/Invoke available everywhere;
a rather advanced article on the subject is here.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
OK so I found something. Though I set the text values in a thread safe manner apparently I don't set the panel's visible property in a thread safe manner. Any suggestions on how to do that? Please don't say a timer, because I have had such bad luck with the form timers in this program. I just can't get them to tick, but that is another issue.
Edited to add:
Weird I didn't see that last reply until after I posted this.
I will check out the link. Thanks
|
|
|
|
|
OKay I got it.
static void SetVisible(Control ctrl, bool visible)
{
if (ctrl.InvokeRequired)
{
object[] params_list = new object[] { ctrl, visible };
ctrl.Invoke(new SetVisibleDelegate(SetVisible), params_list);
}
else
{
ctrl.Visible = visible;
}
}
|
|
|
|
|
How to convert html to image using webbrowser?
Write a code, please.
|
|
|
|
|
About all you can do, is take a screenshot.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
It is probably better that you write your own code to be fair.
|
|
|
|
|
Set DocumentText to the HTML code, then draw it to a Bitmap. If you have the web URL the source code came from - even better. Navigate to that, then draw to a Bitmap as before
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
|
Hello Everyone-
I am looking at making an application that will detect the square footage of a piece of wood that is placed on a table. I am thinking that the table will have a bright orange color, so the dark wood placed on it would provide a lot of contrast. I will use a camera to take a picture of the table (the table lets say is 6 FT by 6 FT) and analyze the image to figure out how big the piece of wood is that has been placed on this table.
I am wondering if anyone can point me in the right direction here code wise (like search terms, etc). I've so far made it to Blob Analysis and have been reading about that. Any help or pointers into exactly what I need to learn to make this possible would be appreciated immensely!
Thank you!
EDIT: I also am wondering if it would be possible to somehow equate each pixel with a real life measurement, such as 1mm, and if it was possible to somehow calculate the pixels that were not orange, and come up with a measurement that way (Because some times the pieces of wood are not going to be square or rectangular ... but I figured I would get the sq/rect down first because I just figured that would be the easiest). I'm in the middle of reading an awesome multi-part article on this site about it, but just trying to figure out which way to go next.
Thanks much!
modified on Thursday, July 9, 2009 9:42 AM
|
|
|
|
|
Hey,
is this the same[^] you are looking for ?
Thanks,
Sun Rays
To get something you must have to try once.
My Articles
|
|
|
|
|
Hi There-
That is the article that I am reading now! What I am trying to do is figure out how to take the edge detection from that article and apply it into my solution (ie, somehow take the edges and do some calculations to figure out the square footage). That's kind of where I am stumped, I don't know how to "link" the two.
Thank you!!
|
|
|
|
|
Basically, the edge detection filters will give you a high contrast result, which you can iterate over and find edges easily, because they are close to white, while the rest is basically black. The real issue is, knowing for sure that there's only two objects with edges in your image. I've done this sort of thing before, to calibrate the size of a photo in an xray scanner, so I could them measure other images. We scanned a sheet which had a series of dots on it. I didn't use any filters, I just walked the image looking for black pixels. Once this was done, we used the mapping of pixels to mm to provide measurements in a measure tool inside the software.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
First of all, your article series is AWESOME and I thank you for it as well as the help you've given me over the past few weeks!
I am wondering if this scenario would work. Your input would be greatly appreciated! The camera is set to produce a 1024x768 image. The camera looks down onto a table that is 10' by 10' (100 Square Feet). I position the camera so that the image it captures exactly covers this table. The table is painted a bright orange color (R-255,G-162,B-59). (Now I'm just trying to work this out in my head, I don't know if this will work, but what I am thinking is...)
The camera is looking on the table, so we know that the 1024x768 image that the camera is going to produce will cover exactly 100 Square Feet, every time. So, a grand total of 786,432 pixels. 100 Square Feet would be 30,480 sq millimeters. Each pixel would equate to approximately 0.03875732421875 of a millimeter. (I don't know if this is correct or logical or would work I'm just thinking out loud).
I open up the image. I walk through the image using GetPixel, pixel by pixel, and check the RGB value of that pixel. If it is close to 255/162/59, i disregard it. Any other color would add the 0.038... number to the global count. After it is all said and done, I should have a value of how many millimeters in the entire space is "in use" and be able to calculate the total area of the wood or stones that are currently on the table.
Basically a family member contacted me. He sells stone (they may be mosaic, so not necessarily always rectangular). I'm trying to think of a way to take pictures of the stone as he puts them into a bin in order to calculate the square footage on those stones that he is selling (ie, he sold 250 SQ feet to someone "by eye" and the person actually got out a measuring tape and measured all the pieces and realized there was only 240 SQ feet and had a hissy). So I was thinking if this method of analyzing an image pixel by pixel, when you know exactly how big the area is every time of that image, would work.
Thanks much for the response!!
|
|
|
|
|
It sound logical, but you would get a different result depending on how the stone / wood is oriented. Instead of using the whole image, just use a 768 * 768 portion of it, and each pixel can then be square (and 3.96875mm on a side, so your size calculation is a little iffy - 10 feet = 3048mm so 100 sq feet would be 3048 * 3048 sq mm).
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|