|
RavensCry wrote: how to load the code in
interface and factory
RavensCry wrote: or if it's even practical yet.
Yes it is
|
|
|
|
|
Well, I've done POS systems in the past - my first one was probably 13 years ago, in Clipper - and what I would do is create a hierarchy database of formulas that should be evaluated according to the chain of events in your hierarchy. You can use that not only to discounts, but to other stuff. I come from Brazil and we're know to have the most complex tax systems in the world (do a search on Google and you would understand what I am talking about - even SAP has an engine specifically created to work with our out-of-this-world tax rules).
So, on the top of hierarchy you would have the more general items (for example, State, if you want people from out of state to have a different discount, for example) and go down the "tree".
The formula you're going to use is the one that goes to the utmost item (further down the tree). Then you can use any expression evaluator available in the internet (there are tons of them for C# and other languages). You can even create your own language - supporting IF statements, for example - to accomplish more complicated tasks. I've done this successfully in a pretty interesting project in the company I currently work for.
Hope this helps.
Robson Siqueira
Enterprise Architect
|
|
|
|
|
HI ,
I had worked on something similar like this , in our case the promotions were flowing from SAP ( eg : buy one get one free , combo , etc ) .There were combination of 5-6 of these ,which covers nearly most of the promotions which are given mostly at POS , so we coded each of them .
amit
|
|
|
|
|
It's easy enough to throw an exception from a method in a class you've written when the preconditions of the method haven't been met. You can do so while maintaining the class's invariants. It's harder, though, handling an exception thrown in the middle of the method from a source outside your control, say from an object you've invoked a method on. Enforcing a class's invariants is trickier here.
One approach is to treat the exception as an event. When it occurs, you have code in place that transitions your object to a state appropriate to the exception thrown, i.e. some kind of error state. The question then becomes how should the object behave in an error state? Are there steps to be taken to bring the object back to a useable state? If so, what are they?
I'll give an example. I have a Synthesizer class in my C# Synth Toolkit. It's capable of recording the waveform output as it is synthesized and writing it to a wave file. This takes place on thread other than the main one.
Let's say that an IO exception of some sort happens when attempting to write the waveform data to file. The exception is caught. Now what? I was thinking that it would be appropriate to raise an event on the main thread notifying the user that an error occurred. In addition, the Synthesizer would transition back to a non-recording state. The Synthesizer would continue to function normally.
Another situation has me a bit stumped, though. The Synthesizer uses an OutputDevice class for playing waveform data. If the OutputDevice object being used throws an exception, it's pretty much a show stopper. There's not much the Synthesizer can do if it's OutputDevice isn't useable. So I was thinking that in this situation, an error state would be appropriate. In this state, some of its methods would throw an InvalidOperationException ; they just can't be performed if the OutputDevice isn't working correctly. Other operations might be allowed in order to reset the OutputDevice to get it working or use a different one.
I guess what I'm getting at here is that I'm wondering how you deal with exceptions when they pretty much render an object unuseable.
|
|
|
|
|
Hi Leslie,
I see an analogy with a file system and a "disk full" situation.
The .NET Framework does not do anything special under "disk full" situations; you may
have created a file, and be happily wiriting to it, suddenly it throws an exception at
you. If you happen to be on a separate thread, you would use some mechanism (an event
probably) to signal it back to the requestor )e.g. the GUI).
The File class does not handle events, but it does not launch separate threads eiher;
they leave it open to the user to make such choices if and when required.
if you do create a thread, obviously it may encounter a problem and I think you should
indeed include an event mechanism to signal those.
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Luc Pattyn wrote: The File class does not handle events, but it does not launch separate threads eiher;
they leave it open to the user to make such choices if and when required.
if you do create a thread, obviously it may encounter a problem and I think you should
indeed include an event mechanism to signal those.
I was thinking about having an Error event that is raised when an exceptional situations happen on a thread other than the main one. The event will be marshaled to the main thread by using the SynchronizationContext class.
However, last night I did some research, particularly looking at Java's checked and unchecked exceptions. A best practises tutorial suggested that you should catch exceptions you can recover from but not those you cannot. Seems like common sense. So in those situations in which I can devise a strategy for recovering from an exception, I should catch it and deal with it. But there seems to be a class of exceptional situations in which there's not much that can be done. In those cases, the exception should not, according to the tutorial I was reading last night, be caught. I'm a little fuzzy on what happens to unhandled exceptions. I suppose there should be a strategy at the top level for dealing with them, notifying the user, and possibly shutting down the application.
|
|
|
|
|
Yes, I think along similar lines.
Some more remarks:
1.
you are allowed to catch Exceptions to your hearts content, but not to hide them:
i.e. you should remedy the problem or somehow let it ripple upwards. There are three ways
to do that:
- not catching the exception at all;
- rethrowing the same exception (a simple "throw;" does that);
- and the favorite: throw a new exception, more specific to your class or method, that
holds the original exception as an "inner Exception".
2.
Your background thread probably already has a Done event, thru which it reports results;
you could use that same event to report problems, so there may not be a need to add
another event.
3.
there are situations where exceptions are more difficult to catch, such as in a constructor,
on a thread you have no control over (say a timer tick), in native code, ... .
The framework has some provisions to catch and handle these too, but I haven't grasped it
completely yet. Things related to this are:
- having try-catch in static Main(); I recommend this, it helps during development,
especially is you show its entire ToString() as one always should.
- AppDomain.CurrentDomain.UnhandledException
- Forms.Application.ThreadException
Greetings,
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I was looking back at my first worthwhile project and I notices that I made a more than a few functions to separate my code as it was getting cramped. While it seems to do the job, it is harder to maintain and is far from the ideals of Object-Oriented Programming (OOP), especially the encapsulation aspect ! Refactoring the code seems attractive but the time expenditure doesn't seem to outweigh the advantages I'd have from fast maintenance and portability as it seems too project-specific. However, I'm looking for a general guideline so that I may approach the solution from a more distanced point of view.
Je vous salue du Québec !
|
|
|
|
|
DynV wrote: I'm looking for a general guideline
I have no experience with OOP effecting portability. That said, any decent (means not lousy) OO design that has minimal documentation is far easier to maintain/extend than spaghetti code. Furthermore any decent organized/structured non OO design that has minimal documentation is far easier to maintain ( extending might be different) than spaghetti code.
For me the bottom line is, if you are at all suspicious about frequent requirements to "extend" the system OO is the way to go.
|
|
|
|
|
If it's a persuading management thing then I'd always argue that if I left and someone else had to look after the code then it would be easier and more cost-effective with regards to training and hand-over for it to be written in a proper OO way. I'd also always argue that something written well is always easier to extend later on if needed, whereas something that isn't is more likely to cause problems later on.
That last argument is always easier to argue if the system hasn't been running without problems for a while.
|
|
|
|
|
Hi - I have an app that reads a csv file line by line, parses for two fields, sends a query to a web server, receives four data fields back, and then writes an output line with the new fields followed by the contents of the input line.
My problem is that the four fields are bracketed in quotes, and the entire input line is included in a set of quotes, so if I then open the output file with excel, the input line contents are treated as a single cell - not a series of csv fields.
I then changed the code to loop through the fields and put commas in the string - but the output line still has quotes at the start and end of the string - so I I wan to use in Excel - I still need to open as a text file an strip out the pesky quotes.
What to do ??
Here is the code doing the data assembly
ID = ID + 1
WriteOutputLine = ID & "," & response.GeocodedAddresses(i).Alternatives(0).Quality.ToString & "," & HouseNo & "," & Street & "," & City & "," & State & "," & Zip & ","
For DataFieldCount = 0 To lineArray.Length - 1
WriteOutputLine = WriteOutputLine & lineArray(DataFieldCount) & ","
Next
WriteLine(2, WriteOutputLine)
Here is a sample input line . .
37.30840674,-122.0333179,-122.029614,37.30833842,1083.826,179,299,WGS 84,SCMAD20070713,Murky Pool,,7/13/2007 21:43,IMG_6212 copy_tag.jpg,IMG_6212 copy.jpg,,,585992.34,4129519.64,10 N,7/13/2007 14:43,,178.7832,100.2,,,,Canon Canon EOS DIGITAL REBEL XT Adobe Photoshop Elements 4.0 Windows
Here is a sample output line
"1,Exact,7360,Fallenleaf Ln,Cupertino,CA,95014,37.30840674,-122.0333179,-122.029614,37.30833842,1083.826,179,299,WGS 84,SCMAD20070713,Murky Pool,,7/13/2007 21:43,IMG_6212copy_tag.jpg,IMG_6212copy.jpg,,,585992.34,4129519.64,10 N,7/13/2007 14:43,,178.7832,100.2,,,,Canon Canon EOS DIGITAL REBEL XT Adobe Photoshop Elements 4.0 Windows,"
rfrank5356
|
|
|
|
|
Have you tried windows version of sed or awk?
They will strip quotes instead of you
Attached code shouldn't return quoted string, so i think quotes are added during saving to file.
H.
|
|
|
|
|
Hi
I am looking for some 'ready to use' application framework for writing small or mid sized apps (both win and webforms). I have tried Lhotka's CSLA, but it has some disadvantages like lack of data paging or awful cooperation with nHibernate which I decided to use as the data layer.
My last found is the Developer Express OXP+eXpress App Framework. It seems to be complete - starts with data mapping, has included reporting solution, data controls and all of this stuff. I haven't tried to build anything on this, but it looks very promising, however it is beta version with no known official release date.
My needs are simple - ability to work wih MS SQL, less than 100 classes in project. Since we integrate our apps with existing solutions, databases are exist (or exist in part), so data mapping has to be flexible enough to use existing data (and all of goods like database schemes etc.)
So - what do you use? What can you suggest?
|
|
|
|
|
Forget about all this ORM stuff - you will regret it in the end.
|
|
|
|
|
Have seen CSLA go very badly, but it might have been simply the customized way it was implemented here. The higher ups want to have another go at it but I am doubtful.
Have you considered microsoft application blocks? After a cursory look it seemed promising, but I haven't had a chance to dig into it.
|
|
|
|
|
TopCoderJax wrote: Have seen CSLA go very badly
I am not sure what you mean, but I think DataPortal concept is a little bit too "enterpise" for the rest of the framework.
drinkwater wrote: Forget about all this ORM stuff - you will regret it in the end.
What I really appreciate in ORMs is dynamic SQL. The Microsoft Application Blocks documentation says (http://msdn2.microsoft.com/en-us/library/ms978510.aspx#daag_datapaging[^]):
<br />
The options for data paging are:<br />
<br />
* Using the Fill method of the SqlDataAdapter to fill a DataSet with a range of results from a query<br />
* Using ADO through COM interoperability and use a server-side cursor<br />
* Using stored procedures to implement data paging manually<br />
Best choice for me is the fourth one - dynamic SQL which is build during app's runtime with all the filters taken from UI, with all the order clauses needed, with paging etc..
Lower performace is the price I can pay for it in smaller apps (in bigger too, being honest )
Maybe I should find some runtime SQL query generator and build it into CSLA or any other nice framework?
|
|
|
|
|
..Hubert.. wrote: Best choice for me is the fourth one - dynamic SQL which is build during app's runtime with all the filters taken from UI, with all the order clauses needed, with paging etc..
Why is that "Best choice" rather than Stored Procedures and SqlCommand approach?
|
|
|
|
|
I really hate writing stored procedures
Small or mid projects are almost always not well specified which means, that there's huge risk of changes.
With ORM approach you can just add new properties to your objects then add new fields to tables and you're ready to go (yeah, most of them arent't so easy, but let's assume they are).
With SPs you have to change tables, SProcs and loading code. There's one more catch-up - deployment.
That's why I prefer ORMs in small apps.
However I've got one question - how do you write SPs which returns lists of objects with pagination and order passed from UI?
|
|
|
|
|
..Hubert.. wrote: how do you write SPs which
I am not a DBA. If you are serious about that question try asking in the SQL forum. I think there are some pretty sharp people in there.
So your answer to my question is "changes"? And there are less changes using embedded SQL than using stored procedures? In my experience I have not found that to be true.
Also your first post states that you want to use dynamic SQL (embedded SQL) and the last one talks about ORM. Which is it?
|
|
|
|
|
you could try mixing it up a bit. i'm trying diamond binding (dunnchurchill.com) at the moment (some guy on here suggested it recently), which takes care of the data-end really well. seems to be based on nhibernate - and you can do custom mappings manually using attributes.
it doesnt do the gui side though, but i've found the data layer it creates is really clean, so you could use whatever tool you wanted (i'm just using the inbuilt databinding in VS). not sure if anyone can suggest a good business object to gui framework?
|
|
|
|
|
I've written a synth toolkit in C#. I'm adding the capability to record the output as a wave file. I'm trying to nail down the design for doing this. Here's the approach I currently have implemented:
- User hits record (a check box with a button appearance).
- Synth engine begins recording output memory
- User hits record a second time
- Synth engine stops recording
- User is prompted and asked if he/she wants to save the wave data
- If user says yes, the user is prompted for a file name, and the wave data in memory is saved to disk
- If user says no, wave data is cleared
The problem with the above is that wave data takes up a lot of memory. If the user wants to record for say an hour or so, he/she could run out of memory. I found this out when I forgot to stop recording and ate dinner. When I came back, the computer was slugish due to low memory.
So I was thinking that a better approach would be to record directly to disk:
- User hits record (a check box with a button appearance).
- Synth engine begins recording output to a temporary file
- User hits record a second time
- Synth engine stops recording
- User is prompted and asked if he/she wants to save the wave data
- If user says yes, the user is prompted for a file name, and the temporary file is renamed to the new name
- If user says no, the temporary file is deleted
Perhaps I should set a limit on how large a file is acceptable so that it's not possible for the program to use up all available disk space. Hmm, maybe I could use that approach for recording to memory instead?
Any thoughts? Details I may be overlooking?
|
|
|
|
|
Hi Leslie,
I would suggest you add an options dialog, that lets the user choose the maximum capture
period (say radio buttons for 10 sec, 1 min, 10 min; or a textbox); then have the record
button record to memory for that time (or until clicked again), then do the save/saveto
dialog stuff you described.
I would not automatically save to temp file on disk, unless you take some precautions
limiting both the size and the number of such files; without limits, you may find yourself
cleaning up the disk quite often.
|
|
|
|
|
Luc Pattyn wrote: I would suggest you add an options dialog, that lets the user choose the maximum capture
period (say radio buttons for 10 sec, 1 min, 10 min; or a textbox); then have the record
button record to memory for that time (or until clicked again), then do the save/saveto
dialog stuff you described.
That sounds excellent. Will do. Thanks!
|
|
|
|
|
Glad to help.
The more challenging option could be: record for ... sec/min
or [checkbox] until 3 sec of silence occurs.
|
|
|
|
|
Also, you could add in support for both. This way for people who wish to record large amounts they have the option of recording to hard disk. But also include a restraint option in the config dialog similar to what you'll have for in memory recording.
This statement was never false.
|
|
|
|
|