New answers tagged

0

If you are using UOW/Generic repository pattern you can include a WCF layer to fire a save and forget when your payment transaction fires on UnitOfWork.SaveChangesAsync(). This pattern worked for my auditing but had to be built into a separate thread as to not affect the application.


1

Many of the problems with these test have already been pointed out, but allow me to pile on for a moment. The test you have here is arguably not "self verfying" - as per the FIRST guidelines. What does that mean? Well at its simplest level it means that the test should have an assertion and shouldn't require manual intervention or interpretation to verify if ...


0

Rather than re-inventing the wheel, you may want to look into using an MVVM framework, like Caliburn.Micro, that takes care of a lot of plumbing when creating a shell (or dashboard) style application: http://caliburnmicro.com/documentation/composition


-2

Put it on the server. It's faster to write and more secure


-1

Make your loader static and put your load function in the static constructor. Then when the static constructor is called the list will be loaded and essentially cached in the static list until the application is unloaded. This will ensure your data is loaded once since static constructors are thread safe. For testing proposes you could put an interface ...


2

Because Microsoft decided to only support properties in Entity Framework. There are many reasons why properties are preferred over public fields, but I'll just mention the one that I think is most relevant here: changing from public fields to properties (if the need arises) is a binary breaking change.


2

Is it significantly easier, faster, better for testing and management, etc. to write the code in C# on the server than in JS on the client? It depends entirely on your Developmental ecosystem. If you write and test lots of JavaScript code, then there might be some gain in doing so. If, however, you spend all your time cutting server-side, C# code and ...


1

I have little mathematical background but I do see an approach that might work. I would assign a value to each coordinate in the grid that is determined by the amount and closeness of dotted neighbors. Then apply a threshold: only keep the coordinates that exceed the threshold value. Those will form the result path.


1

Have a look at Activator.CreateInstance. It will allow you to instantiate arbitrary classes at runtime based on a string representing the name of the assembly and class you want to instantiate. You can then plug in any class that conforms to the Interface you've specified, and configure it using an XML file accessible to your consumers. You should also ...


0

Some of your architectural constraints are: Client workstation machines running native Win application No centralized server Centralized database Outbound MQ interface The only feasible solution that scales that I can see under these constraints are: Maintain a user session table User session table is regularly updated every [interval] with a timestamp ...


0

The most feasible solution is some variation of Websockets. Luckily, C# supports it. When a user starts the application, a connection between him and a server is created indicating the application runs. When the application is terminated (properly or killed), the process ends and so does the connection. There's a catch, though. Your current architecture, ...


3

Frameworks/SDK's probably use instantance methods because it makes dependency injection possible, which is not really the case for static methods. However, if you don't use DI, a static method is the simplest way. KISS.


4

Static class methods are basically global functions, and are considered a bad idea in OO design. The reason why they are considered bad is hard to see in a simple code example where you are just comparing the difference between calling the same method on an instance or on the class itself. But when you get into slightly more complicated design global ...


0

I did some research and testing and here are my results: Analysis We have several possibilities when reading and writing messages for web services under the .Net platform. Strongly Typed Classes using XmlSerializer Strongly Typed Classes implementing IXmlSerializable Strongly Typed Classes using Data Contract Serializer Loading to XElement/Document and ...


14

You can always add a file into your project and set its build type to Embedded Resource so that it is embedded directly into the application itself. Alternatively a file that is encrypted and placed in an accessible location.


21

If the data never changes and is read only, then just put it in a code file as a list of constants. public readonly string AppStartUpData = "MyAppNeedsThis"; If this data is different per deployment, then an external file is fine. .Net comes with built in .config files (App.Config). One should use those as there are standard ways (built in to the ...


13

A binary file would be the obvious answer, but it depends on how you are loading it - you might as well make life easy for yourself if you can. XML might be a good choice as there are built in methods in C# for reading this. You could add a checksum to your data, so that if the user alters it, the checksum will no longer match (you need to add a check to ...


6

If you don't want the user to even peek at the data, you should serialize it into a binary data file. Only the app would know the length of the chunks to read from it. I don't know C# but in Java you would create the file like this: FileOutputStream fos = new FileOutputStream(file); ObjectOutputStream oos = new ObjectOutputStream(fos); oos....


0

This is what JITters do. It's a good idea, but it won't help performance unless you do it for innermost code - i.e. the code where the program counter is most often found. There's little to be gained by optimizing code that is relatively seldom executed. It the program spends most of its time waiting for I/O, then optimizing it will also not help, not ...


0

There is a longer history of implementing languages by converting them to a second language and then with compiling it interpting the. C++ and NO were both done this way.


1

Would that be considered as a bad practice/idea? Enh? My first instinct is that you wouldn't gain much in performance. Spinning up a new process and sending in the data is a bit heavyweight. My second instinct is I'm not sure how general you're going to be able to do it. Just because methods return no data doesn't mean they don't work with data. You're ...


2

"Exception Handling". Two little words but which is more important? I would argue, it's the latter. In a critical piece of code, should exceptions describing a situation which does not makes sense be handled? Counter-question: If a situation occurs which "does not make sense", what can you[r code] do about it? If the answer is "something useful"...


1

To be fair, I wrote my own, very simple, MVVM-Framework (just for the sake of learning purposes) and you know what? I don't need this Implementation anymore: A very small code weaving tool named Fody.Propertychanged https://github.com/Fody/PropertyChanged does this for me. I can even set this on my base class and never have to care again about it.


0

OnXXX is a good name - used since time immemorial because its neither direct like NotifyXXX or misleading like RaiseXXX (that suggests you are about to raise an event) The only reason not to use OnXXX is feeble - that it was used extensively by MFC. MFC used it because it was a good naming choice.


0

Utility methods to raise NotifyPropertyChanged are a basic part of every MVVM framework. And MVVM frameworks are a basic part of every WPF project I've been involved with. Most places used existing frameworks like Prism or MVVMLight or DevExpress's MVVM extensions to create their ViewModelBase class, and I assume you do the same. So the best recommendation ...


2

I would go for the clone method if the class involved was polymorphic (so that an instance of the right runtime type was created). Otherwise it's a matter of taste in my opinion.


2

Premature Over-Engineering For example, I assert that you do not need any of those interfaces. If needed later, make them later. An interface (the C# keyword kind) is for giving common behavior to unrelated classes and then handle objects polymorphically. Think more carefully about what constitutes a more specific class. Think of what a shopping cart IS. ...


0

I post here my currents thought about that problem. So after I started implementing own IDatabaseTransaction I realize that root of the problem not in the transaction, but in the fact that my database layer still contains some business logic(generate some default values while inserting new rows). So my new decision was create and generate all needed data ...


4

From your applications toplevel point of view, you do want to "crash". If a "nonsense" (your words) exception happens. In a controlled way: Either via an UnhandledExceptionFilter or toplevel catch(Exception). It's also the easiest option: You don't have to do anything here. Just let the exception propagate. From comment: The point is that the code ...


2

Define "critical". If your software powers a pacemaker or Google.com, wrap the code to catch exceptions and log them in detail. And hope that somebody actually reads the logs and you promptly fix the problem. Otherwise, I prefer to just crash and throw an Exception. Quietly logging an unexpected fatal error is inferior since it will likely get ignored ...


3

Use copy constructors. Here's why: IClonable semantics are ambiguous. Microsoft never specified whether a clone should be a shallow or deep copy. You can specify custom behavior in your copy constructor, such as giving each copy its own unique ID or only copying some fields and not others. Further Reading Copy constructor vs Clone in C#


0

With respect to modifying records when the user presses "ok" in the dialog, you must compare it with the database record instance. You cannot rely on cloning the original HTTP get because someone may have modified the record before you and you get race conditions. If this is not the case, this has been covered by another thread and I am hoping it helps you ...


0

In terms of the SOLID principle, do not force implementation on classes that do not need it. Generics are nice but tend to lead to premature refactoring and pigeon hole you into using the expected type. If you wish to refactor your interfaces your generics will give you a lot of headaches. I would suggest separating your interfaces. Here is great example I ...


0

The purpose of having an interface is so that you can declare a variable to be of type of that interface, and then actually populate that variable with any class that implements the interface, and all the functions that are declared in the interface will be available. That is, the interface should declare all the functions that you want to use in cases where ...


0

There is no contradiction here. Machine Learning Programs can learn by themselves to arrive at a solution, without having been explicitly programmed for that solution. But of course, someone has to write the Machine Learning Programs. It's exactly the same as with any other program. You don't need to know programming to use a web browser, but you do need to ...


0

At this point, all you have observed is that in a server-side application, classes have a wide variety of dependency, creation, interaction, and scope management requirements. Some classes have temporal coupling between them; some classes need to Lazy<> all of their dependencies to delay their instantiations to the last possible moment. And threads are ...


1

I have a collection of cooperative classes whose behaviors are interdependent upon one another. But I wish to keep them loosely coupled... Careful now! When you are thinking that exact thought it's time to take a step back and look at what you are trying to achieve and why. Loose coupling is great, but it is not a goal of its own. Every time you make ...


0

You use programming to build a machine that can learn without you having to do any more programming. You use programming to build the machines mind. The mind goes on to learn things that were not programmed into it but learned by experience. It's not as powerful as a humans or even an ants mind, but there are many problems in computer science that are ...


0

What it's saying is implementation (or product) of machine learning provides computer with ability to learn. Machine learning as subject of study focuses on the development of the machine learning implementation. You can use general purpose programming languages (C#, Java, etc.), maybe you can use SQL (if you try hard) but not HTML/CSS. I suppose, since data ...


8

First of all, it seems to me you are missing (or perhaps misunderstanding) the "explicitly" bit in "without being explicitly programmed" (from the quote in the question). It doesn't mean that no programming is required at all, it means that you are not programming a specific solution to the problem, but instead what you are making is a more general program ...


1

You want to create a user control. You can predefine the layout, much like you would with a Form, and then create and add a new instance of the control to a Form, just like you'd dynamically add a new label, text box, etc.


0

I've seen it done with tabs after commas before so you get. {Reports.ReallyLongFoo, New ReportMetadata("Really Long Foo Report", PaperSize.A4, 8, 12, ...)}, {Reports.ShorterBar, New ReportMetadata("Shorter Bar Report", PaperSize.A4, 8, 14, ...)}, Unfortunately it fights against any automated formatting of the code block.


0

I like the idea of XML for simple things like this. If you restructure the XML the readability goes up. Something like this. Dim ReportConfigurations As XElement = <Reports> <Report> <name>Foo Report</name> <papaersize>A4</papaersize> <fontsize&...


4

In general, your view model should be implementing INotifyPropertyChanged. It should then fire the PropertyChanged event whenever a property that the view is listening changes, and this will be picked up by the WPF framework. As you suspect, ObservableCollection is only for when you have a collection of things you want to monitor.


1

The source to the method is now online: http://referencesource.microsoft.com/#mscorlib/system/string.cs


1

I think the solution you have is the right one. If the report metadata is declared in one place, it seems like that would be fairly readable? However, one way to make it more readable would be to create a builder for the ReportMetaData class. Here's an example for Java (though should apply equally well to C#): http://www.informit.com/articles/article.aspx?p=...


1

Are there any performance implications I need to know about when a thread of highest priority is entering the region v.s. a lower-priority thread trying to enter the region? A well-known problem with this situation is priority inversion: if a low-priority thread holds the lock, it may make the high-priority thread wait for a long time (because medium-...


4

A simple format for storing tabular data is CSV. Attach it as a resource, just like you planned to do with the excel document. In theory you can even edit it using standard spreadsheed software, though there will problems with that: CSV does not encode types, so Excel will use heuristics to detect e.g. dates, which may corrupt data that looks like a ...


3

If you don't modify the internal state and the checks does not have a lot of overhead a property is more appropriate. This article from MSDN provides some good guidelines to choose method vs property https://msdn.microsoft.com/en-us/library/ms229054(v=vs.100).aspx


0

This sounds to me to be exactly what the ICommand interface and command binding are for. You want to execute a command, with a certain parameter, when a certain UI action takes place. That is precisely what ICommand is designed to do. Just bind the sub-selection's Command to a corresponding ICommand property in your view model, and it's CommandParameter to ...



Top 50 recent answers are included