|
Thanks Guffa. I have tried XPath and it successfully worked with XPathNodeIterator . But it don't have any methods which can return the current node. So I did that in the following way, is any other method available other than this ?
while (iterator.MoveNext())
{
if (iterator.Current is IHasXmlNode)
{
XmlNode xNode = ((IHasXmlNode)iterator.Current).GetNode();
objList.Add(xNode);
}
} This code gives me a collection of Nodes got from the iterator. Any other efficient method for this ?
|
|
|
|
|
Ok, since you are asking for efficient code
N a v a n e e t h wrote: if (iterator.Current is IHasXmlNode)
{
XmlNode xNode = ((IHasXmlNode)iterator.Current).GetNode();
objList.Add(xNode);
}
is operator looks up type of iterator.Current and checks if it is of type IHasXmlNode or derived, and returns true or false.
Cast does the same lookup and check, only it returns IHasXmlNode or throws invalid cast exception.
For this pattern there is as operator, which does the same check, and return IHasXmlNode if it succeeds or null if it fails. One null check is faster then type lookup & check. While it is possible that JIT recognizes this pattern and optimize your code anyway, I wouldn't bet on it
[ My Blog] "Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn "Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe
|
|
|
|
|
dnh wrote: For this pattern there is as operator, which does the same check, and return IHasXmlNode if it succeeds or null if it fails. One null check is faster then type lookup & check.
That's good. That's a new information for me. Thanks
|
|
|
|
|
hi all i'am beginner in .net anybdy can u help me how to create connection to oracle or sqlserver 2000 with using by C#...?
thank's
biengupta
|
|
|
|
|
|
ok, thank's a lot!!
|
|
|
|
|
Hello frnds,
i am reading a Xml file using XmlReader,code is
XmlTextReader rdrXml = new XmlTextReader(strFilename);
xmlElement XmlEle = new xmlElement();
switch (rdrXml.NodeType)
{
case XmlNodeType.Element:
//here i want to store the Element in
saparate Element Variable like
XmlEle = rdrXml.LocalName
break;
}
The BOLD line gives me error..
where i am wrong ...i want to get the parent Name of that XMLElement
how can i do that???
please help...
Thankx in advance
koolprasad2003
Be a good listener...Because Opprtunity knoughts softly...N-Joy
|
|
|
|
|
Usually the error message gives some insight...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
hi
iam having an aspx page which is having a hyper link search.if it is clicked another message box(which is also an aspx page)will be opened which is having a text box and find button.i will enter some text in the text box and click the find button then the value in the text box is retrieved and shown in the text box in the aspx page...iam not getting any idea,can anyone tell me the javascript codr to do this.
Thanx in advance
pintoo
|
|
|
|
|
Hi,
as long as i known this control i've always used it by incrementing Known Steps
like a For Loop :
<br />
for (int i = 0; i < length; i++)<br />
{<br />
progressBar1.Increment(1);<br />
}<br />
now i want him to do so but for Operations Loke : (Do func1, and Func2....)
and to update the progres not by steps but with Time...
What i mean is to BIND the ProgressBar to an operation
Can anybody show my the way....
THANKS
Have Fun
Never forget it
|
|
|
|
|
You have to hand craft that binding. The simplest way is updating the progress bar status inside the operations themselves.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
|
half-life wrote: i thougt about it, but it's not that simple
(how said life is simple?, )
Oh, I know, of course: my sign is all about.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
i working on 2 parts application
windows service
and windows application
i want to attach them to the same configuration file.
is it possible.
and if it yes how shuold i do it ?
and if it is not?
what other solution.
regards
|
|
|
|
|
|
Hello Friends,
I am developing an application using C#.NET and SQL Server 2000 in this application i am getting date from server that is in (MM/DD/YYYY) format and match with system date but in system the date is in (DD-MM-YYYY) format whenever i match the date it shows an error message.
So can you give me the solution to set compatability between these two dates
|
|
|
|
|
Choose one step
1. Before comparing convert the system date to sql date formate.
2. Or before comparing convert the date formate in to system formate after comparing convert it aging to you working environment desire formate.
|
|
|
|
|
If you're using DateTime objects, surely they should compare correctly?
If you're using strings, how difficult is it to convert an MMDDYYYY string to DDMMYYYY or vice versa?
Cheers,
Vikram.
"If a trend is truly global, then that trend ought to be visible across ANY subset of that data" - fat_boy
|
|
|
|
|
... and use ISO 8601-compliant date formats (YYYY-MM-DD).
|
|
|
|
|
Hi guys
I am working on a project in which i need to add a pic an save it in any instance e,g dll etc. How can i create dll in running of an application and add something to it.
any link or hint will be appreciate.
|
|
|
|
|
|
I have a dataset with multiple tables in it. This dataset is created by reading an XML which has nested tables which is shown below.
<allocate>
<cabin cabintypeId="3" cabinType="deluxe" shareFlag="true" OccupancyType="TripleShare"
sameGender="true" cabinId="001" Adult="2" Child="0" Infant="0" availablebeds="1">
<occupant firstname="Micheal" lastname="Lauzon" age="adult" gender="male" nationality="UnitedStates"
usePackage="yes" roomrate="100" presold="true" />
<occupant firstname="John" lastname="Martin" age="adult" gender="male" nationality="Australia"
usePackage="yes" roomrate="100" presold="false" />
</cabin>
<cabin cabintypeId="1" cabinType="Standard" shareFlag="true" OccupancyType="single" sameGender="true"
cabinId="005" Adult="1" Child="0" Infant="0" availablebeds="0">
<occupant firstname="Jacob" lastname="Dror" age="adult" gender="male" nationality="UnitedStates"
usePackage="yes" roomrate="90" presold="false" />
</cabin>
</allocate>
once it is transferred to a dataset, it is divided into two independent tables "Cabin" and "occupant". With what reference can I read the data and identify it. What I mean is, in the above XML Set, how can I differentiate that for cabintypeId="3" there are two occupants named John and Michael. As well as for cabintypeId="1" occupant firstname="Jacob". As Cabin and Occupants are two different tables. I suppose I need to identify some Key value for the Relation defined internally for the datatables. How can I do this? Please help me out.. If I am not clear, I can Explain it more...
Thanks... Rijz
|
|
|
|
|
Hi,
In socket programming, I listen to the port using,
this.serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);
this.serverSocket.Bind(localEndPoint);
this.serverSocket.Listen(0);
this.serverSocket.BeginAccept(AsyncCallBackOnAcceptMethod, null);
When a client tries to connect to the port, I am able to connect to the client and send and receive messages.
The problem is, when the client disconnects by accident (ie... Killing the client application), I have to close the socket. How the server can be notified of the client disconnection? Is there any event for this in the socket class? or Do I need to ping the client frequently at regular intervals to check for connectivity?
Raja Pandian
|
|
|
|
|
Hi
There's no event for disconnecting in Socket or any other network class in .net (as far as i know...)
but there's an easy way to detect connection loss...
if i use sockets, i always use to write synchron and read asynchron.
that means, after connection you do a BeginRead on the socket (or network stream...).
in your callback - method you call EndRead with the IAsyncResult you receive. if EndRead returns 0 the connection is lost.
this gives you an immediate "Event" when the client disconnects correctly. if the Disconnect is accidently (like someone plugs out the network on the client, or the client crashes) you will get the event after the timeout (about 10-20 seconds i think...)
hope this helps
greets
m@u
|
|
|
|
|
I am working on creating a rich text box control to serve as a "visible" log of events. In order for it to work properly, it must be able to accept log entries from different threads.
I tried following the recommendations given by Microsoft on this page: http://msdn2.microsoft.com/en-ca/library/ms171728.aspx
The recommended method in the examples is to call a BackgroundWorker and perform the update in the BackgroudWorker's RunWorkerCompleted event.
In order to ensure that the text was available to the RunWorkerCompleted event, I added a DoWork event that, essentially, takes the text from it's EventArgs.Argument and puts it in the .Result area.
I have included a stripped down version of the code below. Executing this with only one call to AddEntry works wonderfully: AddEntry calls AddEntryInBackground.RunWorkerAsync, DoWork is executed, then RunWorkerCompleted and the desired text shows up in the textbox.
However, when there is a second call to AddEntry, it all falls apart. It seems as though the first call's DoWork execution is interrupted by the second call and never completes. The second call waits forever for IsBusy to be false.
I am unable to find anything that may explain why this occurring - Microsoft recommends this procedure as the "thread-safe" way to avoid simultaneous access to a form's control - which it does (in the same way that deliberately driving your car off a cliff keeps you from accidentally driving your car off a cliff). It appears that the BackgroundWorker only "works" for a very limited amount of time, after which control is passed back to the main thread and the BackgroundWorker remains in a permanent unfinished state.
Can anyone point me in the right direction?
Many thanks,
The main form
using System;
using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;
namespace TestVisibleLog
{
public class VisibleLog : RichTextBox
{
private string timeStampFmt;
private int maximumBytes;
private string[] timeStampTokens;
private BackgroundWorker AddEntryInBackground;
public VisibleLog ( )
{
this.Enabled = false;
timeStampFmt = "";
maximumBytes = 512;
timeStampTokens = "dow,yoc,moy,dom,hh,mm,ss".Split(',');
this.Text = "";
AddEntryInBackground = new System.ComponentModel.BackgroundWorker();
AddEntryInBackground.DoWork += new System.ComponentModel.DoWorkEventHandler(AddEntryInBackground_DoWork);
AddEntryInBackground.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(AddEntryInBackground_RunWorkerCompleted);
}
public string TimeStampFormat
{
set
{
timeStampFmt = value;
if ( value != "" )
{
timeStampFmt += ": ";
for ( int index = 0; index < timeStampTokens.Length; index++ )
timeStampFmt = timeStampFmt.Replace(timeStampTokens[index], "{" + index.ToString() + "}");
}
}
}
public int MaxBytes
{
set
{
maximumBytes = value;
}
}
public void AddEntry ( string EntryText )
{
while ( AddEntryInBackground.IsBusy )
Thread.Sleep(100);
AddEntryInBackground.RunWorkerAsync(EntryText);
}
private void AddEntryInBackground_DoWork ( object sender, DoWorkEventArgs e )
{
string entryFormat = timeStampFmt + "{" + (timeStampTokens.Length).ToString() + "}.";
string logEntry = string.Format(entryFormat,
DateTime.Now.DayOfWeek.ToString().Substring(0, 3),
(DateTime.Now.Year % 100).ToString("D2"),
DateTime.Now.Month.ToString("D2"),
DateTime.Now.Day.ToString("D2"),
DateTime.Now.Hour.ToString("D2"),
DateTime.Now.Minute.ToString("D2"),
DateTime.Now.Second.ToString("D2"),
e.Argument);
e.Result = logEntry;
}
private void AddEntryInBackground_RunWorkerCompleted ( object sender, RunWorkerCompletedEventArgs e )
{
int overage = this.Text.Length + ((string)(e.Result)).Length + 1 - maximumBytes;
if ( overage > 0 )
{
int cutoff = this.Text.IndexOf("\n", overage);
if ( cutoff == -1 )
this.Text = (string)e.Result;
else
this.Text = this.Text.Substring(cutoff + 1) + "\n" + (string)e.Result;
}
else
this.Text += ((this.Text.Length > 0) ? "\n" : "") + (string)e.Result;
}
}
}
The new control
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace TestVisibleLog
{
public class Form1 : Form
{
public Form1 ( )
{
InitializeComponent();
this.statusLogBox.TimeStampFormat = "yoc/moy/dom-hh:mm:ss - ";
this.statusLogBox.AddEntry("This is entry 1");
System.Threading.Thread.Sleep(60000);
this.statusLogBox.AddEntry("And here is another entry");
}
private System.ComponentModel.IContainer components = null;
private VisibleLog statusLogBox;
protected override void Dispose ( bool disposing )
{
if ( disposing && (components != null) )
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent ( )
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "Form1";
statusLogBox = new VisibleLog();
this.SuspendLayout();
this.statusLogBox.Location = new System.Drawing.Point(13, 13);
this.statusLogBox.Name = "statusLogBox";
this.statusLogBox.ReadOnly = true;
this.statusLogBox.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Both;
this.statusLogBox.Size = new System.Drawing.Size(256, 241);
this.statusLogBox.TabIndex = 0;
this.statusLogBox.Text = "";
this.statusLogBox.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
this.statusLogBox.Enabled = true;
this.Controls.Add(statusLogBox);
this.ResumeLayout();
}
}
static class Program
{
[STAThread]
static void Main ( )
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Clive Pottinger
Victoria, BC
|
|
|
|