|
Yep, that would work with the code I posted... Notice it splits by commas first, then checks each term for hyphens... And since it works recursively, it can parse out those terms in any part of the address. Granted, I typed it directly into the reply and haven't tested it, so there might be typos, but the design should work. All it needs is the /xx section.
|
|
|
|
|
I'm gonna have to check it out tomorrow. If that works, I'm very impressed and slightly ashamed.
Thanks
2 U.S. coins equal 30 cents and one is NOT a nickle. Hmm..
|
|
|
|
|
I finally got a chance to look at it, and I think this could be expanded to work in well under the 400 lines that I mentioned before. I like it.
As it is, as you know, it doesn't parse even the simplest x.x.x.x address, but it is cleaner and more efficient than my approach.
2 U.S. coins equal 30 cents and one is NOT a nickle. Hmm..
|
|
|
|
|
Yeah, I never got around to the simple case... That's just another else inside the comma split.
|
|
|
|
|
While I can grasp what are your goal is, your use of delimiters is not clearly explained. How are "/" and "*" and "," being used, exactly in your expressions.
My first reaction to this problem would be to "decompose" it into four calls to one procedure ... that take your range-building parameters as input ... that returns a List<int> for each of the four IP numbers, and then work on the combinatorial algorithm that generates the final list, from these four lists; which I would guess could be done using Linq.
best, Bill
"Anyone who shows me my 'blind spots' gives me the gift of sight." ... a thought from the shallows of the deeply shallow mind of ... Bill
|
|
|
|
|
I'm sorry. I didn't explain well.
The , would be to say this,that (this AND that)
The - would be to say this-that (this TO that) (1-3 = 1,2,3)
The * would be to say all (1-254)
The /xx would be CIDR notation
eg. 192.168.0.0/24 would be 192.168.0.1 with a mask of 255.255.255.0, so it would be 192.168.0.1 - 192.168.0.254
eg2 10.96.248.0/22 would be 10.96.248.1 with a mask of 255.255.252.0, so it would be 10.96.248.1 - 10.96.249.254
Personally I don't know if I would include the option to use something like ; to include multiple ranges, or build with the intention of the user having multiple instances of the class; one for each range.
If you want to see how useful it would be to handle ip ranges this way use nmap, or lookup some nmap examples. It would be a great class for network applications, or even a standalone application that would output text that could be piped to do things like ping sweeps. Windows is greatly lacking in this area.
Thanks for the interest.
2 U.S. coins equal 30 cents and one is NOT a nickle. Hmm..
|
|
|
|
|
One more note, in case I didn't explain well enough. The part that really added difficulty for me was the ability to add multiple delimiters to each octet so that I could say
192.168.0.1
<no 193="">
194.168.0.1
195.168.0.1
196.168.0.1
by entering 192,194-196.168.0.1
This is valid input for nmap, but I don't know of any other application that will parse it correctly.
Nmap uses about 600 lines of C code to accomplish it. I'm curious if C# would be more or less. My bet is less.
2 U.S. coins equal 30 cents and one is NOT a nickle. Hmm..
|
|
|
|
|
Hi,
I am trying to calculate the duration between two dates in days. But it seems it is calculating always 1 less than the actual duration. I am not understanding is it a bug from MS or something. Following is the code to calculate it.
If you feel its correct one then can you please help me calculating the duration depending on the small date time in instead of calculating the date time on full date time.
string pendDuration = string.Empty;
if (pendActivityDetail.PostponeDate.HasValue)
{
pendDuration = pendActivityDetail.PostponeDate.Value.Subtract(pendActivity.ActivityDateTime).Days.ToString();
}
return pendDuration;
Thanks & Regards,
Abdul Aleem Mohammad
St Louis MO - USA
|
|
|
|
|
If I run this:
DateTime dt1 = new DateTime(2011, 11, 12);
DateTime dt2 = new DateTime(2011, 11, 13);
DateTime dt3 = new DateTime(2011, 11, 14);
DateTime dt4 = new DateTime(2011, 11, 15);
Console.WriteLine(dt4.Subtract(dt4).Days);
Console.WriteLine(dt4.Subtract(dt3).Days);
Console.WriteLine(dt4.Subtract(dt2).Days);
Console.WriteLine(dt4.Subtract(dt1).Days);
I get exactly what I expect:
0
1
2
3 So where do you think it is making a mistake? What values are you using, and what are you expecting?
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
OriginalGriff wrote: So where do you think it is I am making a mistake?
you are testing at midnight only. The surprises come in when the times are different.
|
|
|
|
|
You might be looking for the TimeSpan.TotalDays[^] property.
The Days property only gives you the day component of the time span... For example:
3 days, 23 hours, 59 minutes, 59 seconds:
... Days = 3, Hours = 23, Minutes = 59, Seconds = 59
... TotalDays = ~3.999, which you can round to 4
|
|
|
|
|
To start with your definition is not precise.
A timestamp consists of a date and a time.
So you MUST define exactly what values you expect with the following values.
2011-07-28 14:37:38 and 2011-08-28 14:37:38
2011-07-28 14:37:38 and 2011-08-28 14:37:37
2011-07-28 14:37:38 and 2011-08-28 14:37:39
Other variations might be important as well.
And if your timestamps have a daylight savings time component then you must define that as well.
|
|
|
|
|
I'm working on a project that requires my C# code to execute a Java program provided to me by my client.
I create a new ProcessStartInfo and setup the process as follows:
psi = new ProcessStartInfo();
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
psi.FileName = the java executable to be run;
psi.Arguments = the arguments for the code;
psi.WindowStyle = hidden;
I then execute the program using
using (Process exeProcess = Process.Start(psi))
{
exeProcess.WaitForExit();
}
when I execute the process the code crashes without any information.
Any thoughts on what I might be doing incorrect or
any thoughts on trying to get more information about why the crash occurs.
As a note, if I run this process outside my code in a command prompt then it works without failure.
Thanks
Jerry
Jerry W. Manweiler, Ph.D.
Fundamental Technologies, LLC
|
|
|
|
|
Please Wrap your code in "pre" Tag to give better readability to other users.
|
|
|
|
|
The process is not exiting without any information, you are just not capturing it.
I'm not sure what version you are using but the Process class doesn't have a static Start method, or one that returns a Process object that I can find.
using(Process p = new Process())
{
try
{
p.StartInfo = psi;
if(p.Start())
{
p.WaitForExit();
}
else
{
}
}
catch(Exception ex)
{
}
}
Also note the use of pre tags to format code snippets when posted.
No comment
modified 29-Nov-11 14:49pm.
|
|
|
|
|
I'm working in .NET 4.0 and there is a Process.Start(ProcessStartInfo) method available.
OK if the process is exiting with information what do I need to do to capture that information?
The C# code that I'm executing just simply crashes without any exceptions thrown or anything.
I am working in the Visual Studio 2010 IDE and it just simply stops.
Jerry W. Manweiler, Ph.D.
Fundamental Technologies, LLC
|
|
|
|
|
Indeed, I missed the overloaded method in the docs.
You should still be able to get the ExitCode. Is the Process being started? Did you try the provided sample?
No comment
|
|
|
|
|
I based my code off of the provided sample.
As far as I can tell the execute is occuring but when the process starts the system crashes.
Jerry W. Manweiler, Ph.D.
Fundamental Technologies, LLC
|
|
|
|
|
Is there no exception being thrown? Does the application run on its own, not using Process?
No comment
|
|
|
|
|
As I indicated in my original post,
There are no exceptions thrown and
the process works fine outside the C# environment
That is why I'm looking for help in trying to understand what is going on.
Jerry W. Manweiler, Ph.D.
Fundamental Technologies, LLC
|
|
|
|
|
Two suggestions:
1. Display the Exception message (and InnerException message).
2. After it crashes, look at the last entry in the Windows event viewer ([^] )
modified 2-Dec-11 15:01pm.
|
|
|
|
|
Jerry W. Manweiler, Ph.D. wrote: when I execute the process the code crashes without any information.
That says nothing.
A crash suggests a system (OS) exception occurred. I doubt that is the case.
Either nothing at all happened or something did just not what you wanted.
Jerry W. Manweiler, Ph.D. wrote: psi.FileName = the java executable to be run; psi.Arguments = the arguments
for the code;
In this context the above is non-sensical.
There are two possibilities.
1. You are running a java application.
2. You are running a java executable jar.
For the first it requires.
1. The java exectutable - java.exe
2. Appropriate class path
3. The FQN of the main class
For the second it requires.
1. The java exectutable - java.exe
2. Appropriate jar
3. Appropriate command line options
Regardless of the above the Process provides for the following
A. The exe exit code
B. Stdout
C. Stderr
The MOST likely failure is that the Process.ExitCode is 2 which means your "executable" (whatever that really is) is not pathed correctly or isn't even an executable (although then it is probably something besides 2.)
If in fact java is running at all then there should be stdout/err output which, as noted above, you can extract for more information.
|
|
|
|
|
I am running the 1st option that you indicate and provide the java application (java.exe) and the class that I am executing as one of the input parameters.
Regardless of the above,
the Process dies by killing all associated running processes including the IDE.
The entire process (java class parms) does run just fine if I do it outside my code.
So again the question is what in the code am I doing incorrectly or is it possible that you or others have run into this problem and figured out what is really going on.
And to be very explicit - here is the actual code that I'm using:
DirectoryInfo di = new DirectoryInfo(path);
FileInfo[] files = di.GetFiles("*.xml");
foreach (FileInfo file in files)
{
Text = "Converting: " + file.Name;
String[] parms = new String[1];
parms[0] = file.FullName;
ProcessStartInfo psi = new ProcessStartInfo();
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
psi.FileName = @"\\NASA\GSFC\CDF\CDFML2CDF.exe";
psi.Arguments = file.FullName;
psi.WindowStyle = ProcessWindowStyle.Hidden;
try
{
using (Process exeProcess = Process.Start(psi))
{
exeProcess.WaitForExit();
Text = " Processing successful for file = " + file.Name;
Text = " ---- Process output Begin---";
Text = exeProcess.StandardOutput.ReadToEnd();
Text = " ---- Process output End---";
}
}
catch
{
Text = " Processing failed for file = " + file.Name;
}
}
when it executes
Process exeProcess = Process.Start(psi)
The IDE and all threads die.
There is nothing logged in the System or application event logs.
There is nothing output to the system - IT JUST CRASHES the IDE and Threads.
Do you have any helpful ideas or suggestions?
Jerry W. Manweiler, Ph.D.
Fundamental Technologies, LLC
|
|
|
|
|
Hi Jerry,
Try saying:
psi.UseShellExecute = true;
instead.
(Really just a shot in the dark, but I think it's worth a try.)
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi Jerry,
I had another idea. If you're using Visual Studio 2010, you can step into the actual .NET framework code that is executing when you call Process.Start().
Just follow these steps:
HOW TO: Debug .NET Framework Source[^]
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|