|
Looks to me like a repeated event of technically challenged boss entering the room of a stressed halfwit programmer shouting: We need to add this NOW!
|
|
|
|
|
Holy sh*t...thats just horrific man. as long as I don't encounter that ever!
|
|
|
|
|
This dude is clearly a Lisp-genius, stuck with the wrong programming languge. What a pity!
........................
Life is too shor
|
|
|
|
|
I think he meant to make a Ladder; Only that it's lying on the wrong wall
Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
|
|
|
|
|
So I am not sure if this is my "worst practices" or MS'. If you start a process (console app) which makes a call to Console.WindowWidth from C# (3.5) Process object, it crashes. I guess, I'm removing my fancy console screen formatting--for automated system testing, at least.
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "DummyTest.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.Start();
namespace DummyTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello world! My window is this wide:");
Console.WriteLine(Console.WindowWidth.ToString());
}
}
}
|
|
|
|
|
That makes sense because you're piping its IO (.RedirectStandardXxx = true ), so it is not connected to the console, just your starting program.
I have confirmed this by replicating your exception (in VB.NET) and then only changing to
.RedirectStandardOutput = False
and there is then no error, but it may of course not be the functionality you need.
Regards,
Mark Hurd, B.Sc.(Ma.) (Hons.)
|
|
|
|
|
Ahh... and it is by design. A little further reading indicates that when redirecting io the underlying io and error streams Console object has NOTHING to do with the console screen that might be displayed albeit blank. This was lost on me initially.
Console class members that work normally when the underlying stream is directed to a console might throw an exception if the stream is redirected, for example, to a file. Consequently, program your application to catch System.IO..::.IOException if you redirect a standard stream.
http://msdn.microsoft.com/en-us/library/system.console.aspx[^]
|
|
|
|
|
Console has a LargestWindowWidth property, you could try to check what value has when RedirectStandardOutput is true.
|
|
|
|
|
string dateStr = DateTime.Now.Day.ToString("00") + DateTime.Now.Month.ToString("00") + DateTime.Now.Year.ToString();
string timeStr = DateTime.Now.TimeOfDay.Hours.ToString("00") + DateTime.Now.TimeOfDay.Minutes.ToString("00") + DateTime.Now.TimeOfDay.Seconds.ToString("00");
string path = FileOutputDir + GetProviderName() + "-Summary-" + dateStr + "-" + timeStr + ".csv";
Another gem, from the gem of a project I've inherited. Now:
string path = string.Format("{0}{1}-Summary-{2}", FileOutputDir, GetProviderName(), DateTime.Now.ToString("ddMMyyyy-HHmmss") + ".csv");
[Edit]
I've now just discovered the method containing this code never gets called. Its a good job wwe don't have any unit tests, or I'de have to remove those too.....
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
Given the number of posts about DateTime and its formats posted here, I am totally unsurprised.
|
|
|
|
|
i get that a lot from ppl that "think" they know how to code... rather than taking the shorter quicker way to do it they take the longer, "Look at all the code ive wrote to look cool" way of doing it in the off chance it baffles with obsufacation...
View my CodePlex Projects here -> http://www.codeplex.com/site/users/view/john_crocker
|
|
|
|
|
string.Format("{0}{1}-Summary-{2:ddMMyyyy-HHmmss}.csv", ...
But please use an ISO 8601 compliant format: yyyyMMdd
|
|
|
|
|
Yep (& I should have spotted it ), except for the ISO 8061 bit, that's out of my hands...
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
OK I understand whats wrong with those:
string dateStr = DateTime.Now.Day.ToString("00") + DateTime.Now.Month.ToString("00") + DateTime.Now.Year.ToString();
string timeStr = DateTime.Now.TimeOfDay.Hours.ToString("00") + DateTime.Now.TimeOfDay.Minutes.ToString("00") + DateTime.Now.TimeOfDay.Seconds.ToString("00");
I would have been easier to do: DateTime.Now.ToString("mmDDYYYY") or whatever the format string was.
But I'm not quite sure what's wrong with these:
string path = FileOutputDir + GetProviderName() + "-Summary-" + dateStr + "-" + timeStr + ".csv";
string path = string.Format("{0}{1}-Summary-{2}", FileOutputDir, GetProviderName(), DateTime.Now.ToString("ddMMyyyy-HHmmss") + ".csv");
|
|
|
|
|
I think that the OP is saying that he replaced the first example block of code with the second. The first block is what it used to do; the second block is what it does now. Although, apparently it never gets called anyway so the whole thing is academic.
|
|
|
|
|
Exactly so!
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
That's nothing. Check this piece of pure art.
public static string GetStringDate(DateTime dt)
{
StringBuilder sb = new StringBuilder();
int mnth = dt.Month;
if (mnth < 10)
{
sb.Append('0');
sb.Append(mnth);
sb.Append('_');
}
else
{
sb.Append(mnth);
sb.Append('_');
}
int day = dt.Day;
if (day < 10)
{
sb.Append('0');
sb.Append(day);
sb.Append('_');
}
else
{
sb.Append(day);
sb.Append('_');
}
sb.Append(dt.Year);
return sb.ToString();
}
Among other spectacular utilities
|
|
|
|
|
Epic! Especially the sb.Append('_');
|
|
|
|
|
final boolean bKVSatzInklSonderbeitragProperty = getModulContext().isKVSatzInklSonderbeitrag();
final boolean bKVSatzInklSonderbeitrag = m_oKV_SatzInklSonderbeitrag.isTrue();
if(!(bKVSatzInklSonderbeitragProperty && bKVSatzInklSonderbeitrag
|| !bKVSatzInklSonderbeitragProperty && !bKVSatzInklSonderbeitrag)) {
if(bKVSatzInklSonderbeitragProperty) {
m_oKVSatzNeu.setDouble(m_oKVSatzNeu.getDouble() + 0.9);
}
else {
m_oKVSatzNeu.setDouble(m_oKVSatzNeu.getDouble() - 0.9);
}
}
return m_oKVSatzNeu;
I never finish anyth...
|
|
|
|
|
|
Or even:
if (bKVSatzInklSonderbeitragProperty ^ bKVSatzInklSonderbeitrag)
{
double dSatz = m_oKVSatzNeu.getDouble();
dSatz += 0.9;
if (bKVSatzInklSonderbeitrag)
dSatz -= 1.8;
m_oKVSatzNeu.setDouble( dSatz );
}
else
throw ArgumentException("Ha ha, see how smart my validation code is, eh?");
Greetings - Jacek
|
|
|
|
|
I think he's trying to do an exclusive or. If I'm interpreting that right, it boils down to:
NOT (both true OR both false)
|
|
|
|
|
yes, think so too. unfortunatly he managed to compare one boolean with itself, which makes it nonfunctional.
I never finish anyth...
|
|
|
|
|
I agree with KarstenK
it boils down to:
if(A!=B)
{
if(A)
{//do stuff}
else
{// do something else}
}
|
|
|
|
|
TorstenH. wrote: yes, think so too. unfortunatly he managed to compare one boolean with itself, which makes it nonfunctional.
It looks like he's comparing two similarly-named but different properties (bKVSatzInklSonderbeitragProperty and bKVSatzInklSonderbeitrag). The code is redundant in that it would be more efficient to say:
if (a && !b)
action1();
else if (b && !a)
action2();
than to say
if (!!(a) != !!(b))
{
if (a)
action1();
else
action2();
}
which is what the latter effectively does. On the other hand, the latter formulation would allow code to be executed before or after action1/action2 any time either was executed (e.g. if action1 or action2 set a visual property for a control, one could use common code to force a refresh).
|
|
|
|