Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I'm trying to find the name of what I want to achieve. We need to build a rules engine with some fallback or fail over logic.
When the request is JP, the first rule should be selected; for any other country, it should pick up the second one. I don't want to put an entry for all the countries we'll be dealing with, hence the '*'.
What is this called? How is this built in C#?
Thanks,
Arun
My guess that you are looking for a flavor of rule engine implementation for C#
One solution would be to use NRules library.
You can easily create any rule you want
public class DiscountNotificationRule : Rule
{
public override void Define()
{
Customer customer = null;
When()
.Match<Customer>(() => customer)
.Exists<Order>(o => o.Customer == customer, o => o.PercentDiscount > 0.0);
Then()
.Do(_ => customer.NotifyAboutDiscount());
}
}
Extra information in the getting started page of the library.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a class called Promotion (model class). I want a promotion to have a type called Category where Category is its own model class I'm assuming where I would define all the types of categories such as fast food foot wear jewelry and so on. I'm not quite sure of how to go about this though so for example, my class called category is already a set thing but my class promotion is something where before I create it I need to set it with a category with the viable category options. thank you!
why don't you create a property called Categories of type Category in the Promotion?
enum Algorithms
{
FCFS,
SJF,
PRIORITY,
RR
}
class Process
{
public Algorithm algorithms{get;}
}
For the detailed difference please read the answer from this SO answer
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Assuming:
"personList" is a list of Person objects
"agent" is an object that can provide activity about Shop objects (a property of Person)
"GetShopActivity" returns a list of shopping activity objects for a Person
I have this line in a test project:
personList.ForEach(p => new List<Person>(p.Shops)
.ForEach(t=> Assert.IsNotNull(agent.GetShopActivity(t, startDate, endDate))));
How can I make it better?
There is probably a lot you could do, but the first thing to do would be to make it more readable. Perhaps something like this:
var nullActivities =
from p in partnerList
from t in p.Tenants
let activity = agent.GetShopActivity(t, startDate, endDate)
where activity == null
select activity;
Assert.Empty(nullActivities);
Moreover:
you may want to think about
a test should be simple (i.e. it should have a Cyclomatic Complexity of 1).
it should be immediately evident to a person reading the test what scenario and behaviour is being tested (in case the values of startDate and endDate are significant it might be beneficial to give them less generic names).
prefer having only a single assertion as that makes it easy to know where the test failed when it fails.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
https://www.youtube.com/watch?v=K1xrlc32Tmw&list=PLJUoF2h8Z-brW94dTZ-ZIOhjFq90_lt5K&index=9
4:25 adds a new object in the lineCollection if product does not exist in lineCollection, but at 24:25 it shows duplicating orders? Did i misunderstood how it works?
https://github.com/jedjad/GitHubVS2013
Because the products in duplicate values are not same objects. They may have same names, quantity etc, but initializing a class with same values does not mean that it is the same object as the one initialized before. They are like 2 different apples with same color and size.
If you say that 2 products are same whenever the names are same, then implement IEquatable<Product> in Product class.
public bool Equals(Product other)
{
return Name == other.Name;
}
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
What is better method to use for object preparation logic:
a) with return value
List<Users> users = LoadUsers();
users = PrepareUsers(users);
b) or with void type
List<Users> users = LoadUsers();
PrepareUsers(users)
Are you setting properties on existing User objects or are you creating new ones?
If you're simply changing existing objects, then there's no reason why you'd want to return them, it's redundant. Worse, it's misleading - the client will think his objects were left untouched and that you're creating new objects when in fact you're not.
If you're creating new ones, well then, you obviously need to return them.
Alternative b. since you are working with the same user objects, there is no reason to reassign the variable.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a list of sites for which log files are generated. These logs have to be robocopied, unzipped, parsed and analysed with ruby code by running respective processes.
Can anybody suggest the best way to run these processes in parallel for all the site's logs?
Considering your data model like this:
class Website
{
public List<WebSiteLog> Logs;
}
A possible parallel solution using TPL (Task Parallel Library) is something like this:
// var sites = your sites list
var processTask = Task.Foreach(sites, site =>
{
Task.Factory.StartNew(theSite=>
{
theSite.UnzipLogs()
}.ContinueWith(unzipTask=>{
{
theSite.ParseLogs();
}.ContinueWith(parseTask=>{
{
theSite.AnalyzeLogs();
}
});
Task.WaitAll(processTask);
This is a very initial solution. Lots of exception management, partitioning and even more paralellizing on UnzipLogs, ParseLogs, AnalyzeLogs are applicable.