|
This morning one of the users showed me an error (in an application I didn't write, but did modify) where a generated (file)path resulted in yyyy-MM instead of yyyy/MM . The error was of course that the file could not be found.
We solved it (or worked around it) by changing his regional settings. So I went back to the code where the log of the erroneous path was generated and found this:
string serverpath = Utilities.Settings.Setting["drawingpath"] + "/" +
D.DateTime.ToString("yyyy/MM") + "/" +
D.Prefix +
D.DateTime.ToString("yyyyMMddHHmm") + ".jpg";
string localpath = Utilities.Settings.Setting["drawingtemppath"] + "/" +
D.DateTime.ToString("yyyy/MM") + "/" +
D.Prefix +
D.DateTime.ToString("yyyyMMddHHmm") + ".jpg";
System.IO.Directory.CreateDirectory(Utilities.Settings.Setting["drawingtemppath"] + "/" + D.DateTime.ToString("yyyy/MM"));
try{
System.IO.File.Copy(serverpath, localpath, true);
}
catch(Exception ex){
string msg = "DSGUI_BulkAnalyze().goByStats(): Error:["+ex.Message+"]";
Utilities.Logger.WriteLog(Utilities.Logger.TYPE.ERROR, Utilities.Logger.ACTION.SYSTEM, Utilities.Logger.SEVERITY.HIGH, msg);
}
}
The error is thrown by the serverpath variable, but I'm confused how it generates yyyy-MM instead of yyyy/MM and how the regional settings of the machine are involved.
Anyone any idea?
I know it is the serverpath variable because of the "C:\archdrawings_dev" part of the path.
Here's an example of one of the logs:
DSGUI_BulkAnalyze().goByStats(): Error:[Could not find a part of the path 'C:\archdrawings_dev/2011-04/usd201104270615.jpg'.]
thanks.
|
|
|
|
|
Try
D.DateTime.ToString("yyyy") + "/" + D.DateTime.ToString("MM") instead of
D.DateTime.ToString("yyyy/MM") My guess is that as you are formatting the date as a string something may be getting replaced in the process(I know that's a very vague statement).
By trying what I suggest you will be ruling out that possibility.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
When you specify the date format, "/" does not mean "insert a slash", any more than "yyyy" means "insert four 'y's" - it means "insert the current culture date separator character": MSDN[^]
If you absolutely want a specific character, escape it:
string serverpath = Utilities.Settings.Setting["drawingpath"] + "/" +
D.DateTime.ToString("yyyy\\/MM") + "/" +
D.Prefix +
D.DateTime.ToString("yyyyMMddHHmm") + ".jpg"; (Remembering to escape the escape character or it'll be "swallowed" by the compiler - but you know that!)
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I would have never thought of that. The fact that "/" is often set as the separator only adds to the confusion. I will try this asap.
|
|
|
|
|
Very good.
Regards,
Rob Philpott.
|
|
|
|
|
It is generally not the best idea to leave your code to default to regional settings when you are expecting something specific from your results, as you are in this case. You can tell .net to use a specific culture when you do your ToString and you always get the format of that culture.
DateTime.Now.ToString("yyyy/MM", CultureInfo.CreateSpecificCulture("en-GB"));
However given you want a literal slash due to you creating a file path you're better with the escaping example provided in other post as that makes it unambiguous that you need a literal slash, ie for a path.
|
|
|
|
|
Another way to eliminate problems caused by variant cultures is to use the IFormatter versions of ToString() etc. When dealing with file names, data stored in files, etc., specify CultureInfo.InvariantCulture. When displaying dates, integers, etc., specify CultureInfo.CurrentUICulture.
This gives you the best of both worlds - data interchange will work irrespective of the UI culture, and data will always be displayed in the current culture's preferred format.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
Hi,
I have a table with 845 records, I Need to take 100 rows each time and push them to one service. This needs to repeat till records complete in datatable.
Help me on this.
With REgards,
Datta.G
|
|
|
|
|
int rowsLeft = yourDataTable.Rows.Count;
int batchSize = 100;
int rowsDone = 0;
while (rowsLeft > 0)
{
IEnumerable<DataRow> rows = yourDataTable.AsEnumerable().Skip(rowsDone).Take(batchSize);
rowsDone += batchSize;
rowsLeft -= batchSize;
}
|
|
|
|
|
A simple LINQ query using a combination of Take and Skip should get you the records. Take will get the records and Skip allows you to move past rows you have already taken.
|
|
|
|
|
hi
i have a server and many clients, the clients send a lot of request to server
i must keep them into a repository(queue) and do them.
my issue:
i need to a solution or pattern for when one of the request get exception or be failed , move to another queue and if in second queue get exception again go to another queue(just 3 level)
now I'll know how to management it
please help me
thanks
|
|
|
|
|
Sorry?
That doesn't make a lot of sense.
Perhaps if you give us an example, or run through the exact sequence of event you are having problems with in more detail?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
It sounds to me like you're asking about using a MessageQueue. Windows comes with its own implementation (MSMQ) but there are others available. The syntax you use depends on which one you want to use.
|
|
|
|
|
thanks for your answer
i need to a pattern for manage my queue
for example my clients send requests to server and server tell to them i do it and you can continue,
now i must create a repository(include two or three queue) for hold the requests
the severe have a windows service that call queue and process the request
i think it's clear , but what is my problem?
for example the requests connect to each server for get data ,note i have a lot of requests
now i need to a pattern or algorithm that when a request for each reason be failed (for example time out or server is shut down for two hours or ...)
move the request to second queue (because if it stay in first queue,my queue be long and response to other requests be difficult) and i must define a scheduler for second queue and again process the request if get error again move to third queue. and define a scheduler for third queue with low priority
please if it isn't clear tell me
thanks
|
|
|
|
|
OK - that makes sense.
So what part of this is giving you difficulties?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
thanks for your answer
implement it is my problem
i need to a pattern for identification the requests be failed
witch one is better two queue or one queue?
how to scheduler each queue ? (for example first queue must run non-stop and second queue what time must run)
when a request form fist queue move to second queue after scheduler do process again or move to first queue
please help me
thanks
|
|
|
|
|
I can't help you identify "requests that fail" - I have no idea what causes a request to fail, or how you detect it (remember, I can't see your screen or access your hard drive) - but as to the number of queues, that's easy.
Use multiple queues.
Have a "standard feed" queue, and move "failed" items to the "first generation failure" queue. If they fail again, move them to a "second generation failure" queue. (Use Locking to ensure thread safety while adding to or removing from a queue)
And have background tasks that periodically check the queue and retry. If the queue is empty, then it waits a while before looking again.
I'd probably add a timestamp to the "failure" queue, so I don't retry for a reasonable time, increasing with each generation.
But that isn't a pattern!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Or, as I indicated above, just use MSMQ - you kind of get this for free with it.
|
|
|
|
|
thanks for your tracking
i can identify "requests that fail", just if possible for you show me a solution or sample code for the rest of it,please.
and what is your suggest for use queue, for example rabbit or MSMQ or apachi.ActiveMQ or ...
thanks
|
|
|
|
|
Uhhh....there is no "rest of it". That code would be the bulk of your server and services! It's not possible for anyone else to write your code because none of us has any idea what you're doing, what types of messages your clients are supposed to be sending, what processing you need to do on these messages, what your validation and failure points are, what processing you need to do on a failed message, ... NOTHING.
The only person who's going to be able to write your code is YOU.
If you want examples on how to work with MSMQ, just Google for "C# MSMQ tutorials".
|
|
|
|
|
I just published an article on custom-drawing a Button control from scratch in Windows Forms, and after I published it, I found a link on this website that said that some articles are still in Pending status for a whole year due to being understaffed. Is that still the case?
I'm kind of scared right now. I don't want to wait a whole year!
How long do new articles usually take to get approved these days?
|
|
|
|
|
Evil Iceblock wrote: I'm kind of scared right now. I don't want to wait a whole year!
Don't be, it'll take just few months Just kidding!
The moderation is now done by the community so it'll take a short time to get responses and the article to be approved or rejected.
I had a look at it and as far as I can see there was no download included. I believe that adding a downloadable project would greatly help the article to be published.
|
|
|
|
|
Thanks for replying! I did upload files and a downloadable project though. I uploaded the whole C# solution inside a zip file. I will re-upload the files though and see if that fixes it.
|
|
|
|
|
After you have uploaded the ZIP, remember to use the "include selected files into the article" link just above the uploaded file list. Otherwise the zip doesn't become visible.
|
|
|
|
|
Ohhhhh! Thank you <a href="http://www.codeproject.com/Members/Mika">@Mika</a>, I didn't even see that option there.
|
|
|
|