|
|
<br />
<br />
try<br />
{<br />
FileStream fs = new FileStream(name, FileMode.Open, FileAccess.Read);<br />
using (fs) { fs.Close(); }<br />
}<br />
catch (Exception){continue;}<br />
And these are people I am actually supposed to work with
Ad. Btw the 'user' mentioned here doesn't even exist..this is code running in a Windows NT Service. What the author wants to do (I think ) is see if the user for whom he's retrieving the list of files has read permissions on the file, not the Windows NT User the Service is running under.
|
|
|
|
|
ErikDD wrote: What the author wants to do (I think ) is see if the user for whom he's retrieving the list of files has read permissions on the file, not the Windows NT User the Service is running under.
And your solution would be??
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Ah, I'd have to admit that I have no idea Afaik, this is one of the things that despite the power of the .NET Framework is still either very difficult or misunderstood.
I'd start my search in the FileIOPermission and the WindowsPrincipal/-Identity classes and see where I end up from there. Might be completely wrong though.
In any case the above check checks the Windows NT Service account's access, not the requested user's.
|
|
|
|
|
Clickety[^]
[edit]I forgot: read the discussion, too...
Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers! We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP Linkify!|Fold With Us!
|
|
|
|
|
Brilliant! I'll give this to my colleague to break his head over
|
|
|
|
|
I especially loved this snippit of code I encountered while rewriting an app:
<br />
FileInfo fi = new FileInfo(name);<br />
<br />
DateTime dt = fi.LastWriteTime;<br />
<br />
int yr = dt.Year;<br />
if (yr >= 2000)<br />
yr -= 2000;<br />
else<br />
yr -= 1900;<br />
<br />
string year = yr.ToString();<br />
if (yr < 10)<br />
year = year.PadLeft(2, '0');<br />
<br />
<br />
<br />
string date = dt.Day + "/" + dt.Month + "/" + year;<br />
Do I even need to post the alternative??
Me and my colleague (NOT the one who wrote the code. Spent at least 15 minutes laughing about the TODO: comment, too. :p
|
|
|
|
|
I was rewriting an application when I came across the following snippit:
<br />
System.Text.UTF8Encoding encoder8 = new System.Text.UTF8Encoding();<br />
System.Text.Decoder utf8Decode = encoder8.GetDecoder();<br />
byte[] todecode_byte8 = Convert.FromBase64String(_body);<br />
int charCount8 = utf8Decode.GetCharCount(todecode_byte8, 0, todecode_byte8.Length);<br />
char[] decoded_char8 = new char[charCount8];<br />
utf8Decode.GetChars(todecode_byte8, 0, todecode_byte8.Length, decoded_char8, 0);<br />
_body = new String(decoded_char8);<br />
Obviously, the culprit ".NET" programmer responsible kinda missed the alternative solution:
_body = Encoding.UTF8.GetString( Convert.FromBase64String( _body ) );
And I wish this was the only occurrence of this..
|
|
|
|
|
Could have been me -
I remember myself digging through that Encoding documentation in MSDN - it is really badly documented, no concepts, just a bunch of classes and members. (IIRC I had to serialize to/from base64, and it was driving me crazy)
Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers! We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP Linkify!|Fold With Us!
|
|
|
|
|
Oh I couldn't agree more on the level of documentation on this (or the lack thereof). If I were writing this, a little voice in the back of my head would go 'Come on man, there's an easier way to do this, right?'. And I've taught myself to listen to that voice
That, and using the Convert class A LOT :p
|
|
|
|
|
ErikDD wrote: a little voice in the back of my head would go 'Come on man, there's an easier way to do this, right?'. And I've taught myself to listen to that voice
I've got that voice a lot lately... but obviously, it only tells YOU about the solution
Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers! We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP Linkify!|Fold With Us!
|
|
|
|
|
Ooo I feel special
|
|
|
|
|
Once had the great pleasure of having to examine our banks End of Day processor.
part of the app had the ability to show the account transaction records, which they used to dump transactions to luvly excel spreadsheets for analysis....
the guy who wrote it obviously had never heard of SQL joins though
he used a SQL statement along the lines of "Select * from tran" to retrieve all the records, then entered into a mother loop.
for each row in result<br />
for each column in the result<br />
if the datatype is a int, it must be a foreign key <br />
do a whole load of messin to work out the foreign key table<br />
so do another sql statement to pull back the foreign key value from another table<br />
output the foreign key value<br />
else<br />
output the value<br />
end if<br />
next column<br />
next row.
worked out that each time a new transaction was entered onto the system this loop would have to do another 60 or so new SQL requests.
so instead of one sql query using multiple joins to get foreign key values, this numpty wrote over 60 queries, which fired for each and every row output.
and considering this was only a weeee bank, We did only have in the region of 5 million transactions with about another 100,000 or so a month getting added..
and they wondered why it could take ages to display only a few hundred thousand records and output them..........
|
|
|
|
|
Once upon a time, I had to maintain an MS Java application (first shame). In this application, threads were synchronized using the window-based interface.
At the start of a task, a thread was given a reference to a label. The thread was started and changed by itself the text property of the label to some kind of status. In the "textchange" event of the label, the text was checked. If it equalled "100%" another thread was started following the same pattern.
/Zorbek
|
|
|
|
|
I develop software to control scientific instruments. This is a different world to databases or financial software. The first rule is to insist on the electronic and mechanical designers proving that the hardware is working properly before you will consider that the software has a bug. (The first rule of the mechanical and electronic designers is, of course, "the software is faulty"). The second rule is that just when you've got it all working properly they will change the hardware.
I once worked on software to control a mass spectrometer. This detects a particle beam travelling down a vacuum tube. There were two types of detectors, the instrument could either be fitted with "high detectors" or "low detectors".
I was looking through the source one day when I came across this user error message (without the stars of course).
"Both high and low detectors fitted. B******S, THEY PROMISED ME THIS WOULD NEVER HAPPEN."
Regards
- Roger
|
|
|
|
|
That was hilarious. Thanks for sharing.
A friend is, as it were, a second self.
- Marcus Tullius Cicero
|
|
|
|
|
NOT SO FAST !!!!
Okay you think this is just horrible, and 99% of the time I would agree with you. However, let me explain my experience with this exact situation. I worked at a company where we had the usual daily meeting. The guy sitting next to be asks our manager about a request he's working on. The question went something like:
"This process compares records in out database to the client file and performs calculation "A" which is saved to our database. So, what do you want me to do if a client record cannot be matched up to an record in our database?"
To which the manager said, that will never happen. Being the logical programmer my buddy replies, "but what if it does happen?" To which Mr. Stubborn manager replies, "I just told you that it will NEVER happen.
Hence, the origin of the error message. Given the circumstances, wouldn't you cut this guy some slack?
|
|
|
|
|
It wasn't flagging the situation that I thought was the problem, but calling his colleagues b******s in a message that would be displayed to the users.
By all means write it to an internal log file or something, but don't swear at the users, it's not very professional.
Regards
- Roger
|
|
|
|
|
Color me stupid, I thought the b*****s was the person's name. Note, my initials are B.S. In my case, the manager's name was put into the message replacing the b******s.
Now that i understand your true meaning...
I have a client who is paying top price for a website face lift. I was doing an A/B compare on the test release of the site in FireFox and IE. I must admit they did a good job with absolutely no difference between the two browsers. Curious as a cat, I decided to view the source code in hopes of getting the link to their Java Script file and any style sheets for future reference. Paging down in the source i found a hidden DIV where a developer left a large does of his explicitive filled comments regarding the client. HOLY-COW! I couldn't believe what i was reading, and can't repeat any of it here.
Regardless, it's all pretty funny stuff.
|
|
|
|
|
...so read an error message I found in a customer's code a while back.
Needless to say it didn't last long once I found it!
|
|
|
|
|
I found a TODO: handle string thingie in some code the other day..until today I STILL don't know what the author ment to say
To reassure you, I long promoted that function to the recycle bin.
|
|
|
|
|
///
/// Fuegt solange Blanks an den String an, bis die
/// Laenge length erreicht wird.
///
/// <param name="inputString" />
/// <param name="length" />
/// <returns>
public static string AddBlanks(string inputString, int length)
{
string outString = inputString;
while (outString.Length < length)
{
outString = outString + " ";
}
return outString;
}
Not only a memory issue (using string instead of stringbuilder), but why have the gods^W BCL group created the string.PadRight(lenth, ' ') method?
What do you think?
Cheers,
Juergen
|
|
|
|
|
6o`clock wrote: Not only a memory issue (using string instead of stringbuilder), but why have the gods^W BCL group created the string.PadRight(lenth, ' ') method?
What do you think?
I would think someone is learning C#.
I can see me making mistakes of exactly the same type.
Ok, I know about stringbuilder, but there are whole top-level namespaces I never used. I certainly do not know their functions by heart.
Failure is not an option - it's built right in.
|
|
|
|
|
My colleague and I had an interesting discussion about this. According to us, there are two types of programmers out there. The first type thinks 'This is such a common thing to do, someone MUST have included it' and therefor ends up using the PadString method. The second type just churns away without seconds thoughts and ends up with the originally posted code.
The funny thing is that 9 out of 10 times people tend to refactor these snippits into a utilities class, calling the method 'PadString'
|
|
|
|
|
...so lets make it global.
This was the answer of a "Technical Consultant" that I worked with many years ago. All of his loops were for i = 1 to 10 next i. This was VB 3 - so some time ago!
To save himself the effort of dim i as integer at the beginning of every function he wanted to use "i" he just made it a global. I can't blame him too much - he was a COBOL programmer who had made the leap to VB.
It made for some surprisingly subtle bugs! Needless to say that I removed it after having to try quite hard to show him the benefits (I was a junior C++ programmer at the time).
|
|
|
|
|