|
|
You can limit the number of items that the Split returns, so that you get everything after the fifth quotation mark in the sixth item:
string[] values = s.Split(new char[] { '"' }, 6);
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
how to receive a frame from serilal port
I want to receive a frame that this frame has CRC start bit ,stop bitplz help to me that how to start this work
|
|
|
|
|
|
Hi, i got some problem here reading my XML using DOM method.
This is my XML file
<invoice>
<number>INV-4773-282009</number>
<date>2/8/2009</date>
<sellerid>2828</sellerid>
<buyerid>2828</buyerid>
<orderid>PO-565029-282009</orderid>
<billingaddress>123 Tampines St 1 #01-55</billingaddress>
<orderitems>
<item>
<productid>P-0003</productid>
<quantity>3</quantity>
<unitprice>42</unitprice>
<description>OCZ Ram</description>
</item>
</orderitems>
</invoice>
This is my code for reading the code
<code>invoiceDoc = new XmlDocument();
invoiceDoc.Load(windir + "\\" + lstFiles.SelectedItem.ToString() + ".xml");
string invNumber = null;
string invDate = null;
string invSellerID = null;
string invBuyerID = null;
string invOrderID = null;
string invBillAddress = null;
string invProductID = null;
string invProductQty = null;
double invUnitPrice = 0.0;
string invProductDesc = null;
XmlNodeList invList = invoiceDoc.GetElementsByTagName("Invoice");
foreach (XmlNode node in invList)
{
if (node.HasChildNodes)
{
XmlElement childNode = (XmlElement)node.FirstChild;
for (int i = 0; i < node.ChildNodes.Count; i++)
{
switch (childNode.Name)
{
case "Number":
invNumber = childNode.InnerText;
break;
case "Date":
invDate = childNode.InnerText;
break;
case "SellerID":
invSellerID = childNode.InnerText;
break;
case "BuyerID":
invBuyerID = childNode.InnerText;
break;
case "OrderID":
invOrderID = childNode.InnerText;
break;
case "BillingAddress":
invBillAddress = childNode.InnerText;
break;
case "ProductID":
invProductID = childNode.InnerText;
break;
default:
break;
}
childNode = (XmlElement)childNode.NextSibling;
}
}
}</code>
<b>Problem : when it comes to productID, it got problem reading. I got nullreferenceexception </b>
<div class="ForumMod">modified on Sunday, February 8, 2009 3:11 AM</div>
|
|
|
|
|
Your XML doesn't show up. Use the "Ignore HTML" option when posting markup code.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
|
Using the XML and code you have provided (except for the casing of node names), I had no exception. It does not access the ProductId node at all and hence i am confused by your problem. What particular line to you get exception on ?
|
|
|
|
|
In the code I'm linking below (feel free to use royalty free by the way), I have an appdomain that is misbehaving.
The classes involved are PluginManager, and PluginFinder. PluginManager creates an AppDomain, using the following code:
public ArrayList LoadPlugins()
{
AppDomainSetup setup = new AppDomainSetup();
setup.PrivateBinPath = AppDomain.CurrentDomain.BaseDirectory;
setup.ApplicationBase = pluginPath;
setup.ApplicationName = "PluginLoader";
setup.ShadowCopyDirectories = pluginPath;
setup.ShadowCopyFiles = "true";
pluginDomain = AppDomain.CreateDomain("Plugins", null, setup);
Type addInManagerType = typeof(PluginFinder);
pluginFinder = (PluginFinder)pluginDomain.CreateInstanceFromAndUnwrap(
addInManagerType.Assembly.Location, addInManagerType.FullName);
ArrayList FoundPlugins = pluginFinder.Search(pluginPath);
...
}
and the finder class has this code:
[Serializable]
internal class PluginFinder
{
private ArrayList FoundPlugins = new ArrayList();
public PluginFinder()
{
}
public ArrayList Search(string path)
{
FoundPlugins.Clear();
try
{
foreach(string file in Directory.GetFiles(path,"*.dll"))
{
TryLoadingPlugin(file);
}
}
catch{}
return FoundPlugins;
}
private void TryLoadingPlugin(string filename)
{
try
{
FileInfo file = new FileInfo(filename);
filename = file.Name.Remove(
file.Name.Length - file.Extension.Length,
file.Extension.Length);
Assembly asm = AppDomain.CurrentDomain.Load(filename);
foreach(Type t in asm.GetTypes())
{
Type baseType = t.BaseType;
bool Complete = false;;
while(!Complete)
{
if (baseType == typeof(BasePlugin))
{
if( !t.IsInterface && !t.IsAbstract)
{
FoundPlugins.Add(t);
Complete = true;
break;
}
}
else if (baseType == typeof(System.Object))
Complete = true;
else
baseType = baseType.BaseType;
}
}
}
catch(Exception e){throw e;}
}
}
The problem is, when the AppDomain calls Load, it looks in the wrong directory! pluginPath of the Manager is set when Instantiating it, using "Plugins\", but Debugging AppDomain.CurrentDomain.BaseDirectory within the Finder returns different than pluginDomain.BaseDirectory! Basically, the Search method of the finder is finding the files, but the TryLoadingPlugin throws an exception due to the AppDomain problem. Any ideas? I have the TestPlugins Project compile to the Apps \Debug\Plugins directory, which is where the Manager is set to look, but I end up needing to copy the Plugins to the \Debug\ directory if I want them to load. :/
Source Code: GMail Notifier[^]
|
|
|
|
|
try
foreach(string file in Directory.GetFiles(path,"Plugins\*.dll"))
The working directory of the executable equals the directory where that executable is launched from. I guess that the plugins are loaded as a part of that executable and therefore share the same working-directory.
Hope this helps
I are troll
|
|
|
|
|
Unfortunately that won't work, if you follow the code posted closely. "Plugins\" is given to the path, and "*.dll" the mask of the file. using your method, and without trying it, I'd guess it'd look for Plugins\Plugins\*.dll and crap out because the path doesn't exist. Also, you forgot a "\", should be "Plugins\\*.dll" or @"Plugins\*.dll", but that's just me being a perfectionist.
I figured out what the problem was, anyway, to a point. I forgot to inherit MarshalByRefObject, but adding that has caused other problems. Namely when code returns to the Manager from the Finder, I get a file not found exception when copying the Finder's array to the array in the Manager. Note the Bold line:
AppDomain domain = AppDomain.CreateDomain("PluginLoadingDomain", null, setup);
Type finderType = typeof(PluginFinder);
PluginFinder finder = (PluginFinder)domain.CreateInstanceFromAndUnwrap(
finderType.Assembly.Location, finderType.FullName);
FoundPlugins = finder.Search(pluginPath);
AppDomain.Unload(domain);
It seems that my main appdomain wants to load the files, based off the fusion binding logs (Mentions that cant load file under \Debug\, instead of \Debug\Plugins\), so any help there would be appreciated.
|
|
|
|
|
Out of my league, obviously
(path + "\\Plugins\\", "*.dll")
iAmEntity wrote: @"Plugins\*.dll", but that's just me being a perfectionist
The compiler interprets them very differently, so it's not an insignificant detail. I got them mixed up regularly, until I changed the syntax-coloring of the C#-verbatim string. In my defense, CP doesn't have syntax highlighting (yet)
I are troll
|
|
|
|
|
Eddy Vluggen wrote: Out of my league, obviously Sniff
Really, it's out of my league too, but jumping into the deep end is how I learn
Eddy Vluggen wrote: it's not an insignificant detail
In this context, i think it is, due to the highlighting we have while coding. Like you mentioned, we don't have that here, so its negligible. As to the code you just posted, still wouldn't work . In this case, the variable path IS "Plugins\". The problem is not in the search method, but in the second method, TryLoadingPlugin. Basically, it was an OOP fart on my behalf in regards to the MarshalByRefObject thing.
|
|
|
|
|
hello friends,
i have a doubt how to write coding for login page in ASP dot net with c# coding????
plz send your answers to me
as quick as possible
|
|
|
|
|
karthimca143 wrote: as quick as possible
Well Google[^] returned over 6.5 million results in 0.19 seconds - is that quick enough for you?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
I'm writing a program which runs on a specific directory with images, reads them to a Bitmap file and then resize them, and add the resized image to a Bitmap hashmap. The naive code to do this is like this:
Bitmap bmp = new Bitmap(flFileArray[i].FullName);
Bitmap bmp2 = new Bitmap(bmp, (int)(nudWidth.Value / nudNumOfPics.Value),
(int)(nudHight.Value / nudNumOfPics.Value));
m_hshBitmapArray.Add(bmp2, GetAvgPixelVal(bmp2));
It's quite simple, but i'm wondering if there is a faster way to do this. Can anyone think of something?
|
|
|
|
|
Hi,
your code looks fine. If anything is slow, it must be the piece you did not show nor discuss,
i.e. GetAvgPixelVal()
It is my guess you are enumerating all pixels there, which is bound to be very slow or slow,
depending on how you do it. If you want more help, show that code too, and please provide an estimate
to the image size.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Friday, June 10, 2011 11:30 PM
|
|
|
|
|
Thanks for the reply. It doesn't run slow (actually it runs very fast), I just wanted to know if there is a more efficient way to do it. I am building a program that makes a picture mosaic from a given directory of images, which can be made from thousand images with different sizes.
I don't believe that I can improve GetAvgPixelVal() and it runs quite fast. The code for it is this:
unsafe private Color GetAvgPixelVal(Bitmap bmp)
{
Color RetVal;
int r = 0;
int g = 0;
int b = 0;
int nWidth = bmp.Width;
int nHeight = bmp.Height;
BitmapData data = bmp.LockBits(new Rectangle(0, 0,
nWidth, nHeight), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int remain = data.Stride - data.Width * 3;
byte* ptr = (byte*)data.Scan0;
for (int i = 0; i < nHeight; i++)
{
for (int j = 0; j < nWidth; j++)
{
b += ptr[0];
g += ptr[1];
r += ptr[2];
ptr += 3;
}
ptr += remain;
}
bmp.UnlockBits(data);
RetVal = Color.FromArgb(r / (nWidth * nHeight), g / (nWidth * nHeight), b / (nWidth * nHeight));
return (RetVal);
}
|
|
|
|
|
Hi,
performance wise that code is perfect.
BTW: I assume your original code (with bmp and bmp2) sits inside a loop; if you no longer need the bmp (i.e. before you assign the next image to it, you should call Dispose(), that will release its memory sooner and improve your apps overall performance.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Friday, June 10, 2011 11:30 PM
|
|
|
|
|
I'm already doing it
Thank you for the reply.
|
|
|
|
|
Not sure if you can use this idea, but some image formats (like TIFF) allow compression. Using compressed images will reduce the time it takes to read/write them from/to disk files.
Generally it takes more time to transfer an image to/from disk than to process it, so if you can compress the images the process will be faster.
|
|
|
|
|
The only problem is that I don't have any control in selecting what images the program would use. If I could control it i would make all the pictures JPEG 100*100 and save time in reading and resizing them...
|
|
|
|
|
I have developed a game in C# and i want to convert it to a executable file.
|
|
|
|
|
Did you try compiling the code? In your IDE there should be an option somewhere to build the project / solution. Although to be honest you should know that already.
Unless of course, your not using an IDE. In which case, go and get SharpDevelop or something, create a project and add your code, then click 'Build -> Build Solution' or press F8.
My current favourite word is: Delicious!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
why not just change the extension from .cs to .exe? that results in an exe file, doesn't it?
BTW: Visual Studio C# Express is downloadable for free and it works well.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|