Building dynamic rule set and validating against multiple objects in runtime C# - c#

I already have a custom-built CMS using which we define promo cards which are consumed by another site and display it. Until now it is showing all the promo cards declared over there in custom CMS, Right now the requirement is, I want to introduce rulesets to be assigned to these cards under CMS so the consuming site has to validate it against the respective object properties in the consuming app and show it if the ruleset passes the validation.
I have gone through a couple of libraries out there that provides an option of defining dynamic rulesets
against dynamic objects,
This one looks promising
https://github.com/microsoft/RulesEngine
As it provides an option to define ruleset dynamically, but i am not sure whether the path i going through the right path so that it will be future proof, and also i need to know the best practies while implementing the dynamic access check behavior.
Any assistance would greatly help. Thanks and looking forward to your suggestions and advice on the above

I do not know if this might help however the NRules engine might help you in what you are trying to achieve for dynamic rule engine based on properties:
https://github.com/NRules/NRules/wiki/Getting-Started

Related

Content type lifecycle management

I saw thisarticle in the link below and I wonder if you could help me with some questions I have
http://msdn.microsoft.com/en-us/library/ee330223(v=office.12).aspx
In our current project, which we didn’t not develop but we have to maintain, we are facing some issues, it looks like the first time the other firm developed the content types, they were done fine, using xml definitions, creating list templates and list instances was also done fine and in an organized way.
However at some point in time and after the content types and lists were already running on production, some changes had to be done (adding new fields to existing content types, changing translations of displayname or groupname, changing properties like required, showinnewform, showineditform, etc)
Across the internet I have found that many people have problems with unghosted content types, which means that the content type is detached from its XML definition, as far as I know this happens when somebody modified the child content type or list using the UI.
I am trying to collect a list of best practices for managing content types after they are deployed:
1.How to add a new field to an existing content type?
For this we have used UpgradeActions and AddFieldRef
2.How to remove an existing field from a content type?
For this, we haven’t needed it yet, but I have see that there also exist the RemoveFieldRef element which could be used inside UpgradeActions
3.How to reorder fields in a content type?
We do this by code in a custom upgrade action.
4.How to change a translation in an existing field?
We do this by code in a custom upgrade action.
5.How to change properties like ShowInDisplayForm, ShowInNewForm, Hidden, Required, etc.
We do this by code in a custom upgrade action.
I wonder if my list above specially points 3,4 and 5 can be called best practices, or if I am missing something or doing something wrong? Why? A few weeks ago we had a lot of problems, when doing changes via code and pushing down the changes was not working, the changes were not pushed(we were not seeing the changes in the lists). After reading for many hours, I saw that this might be possible due to that the list content type LINK is broken from its Parent content type definition.
I found that a way to restablish this link can be done using SQL but it’s not supported of course.
http://www.olavaukan.com/2010/10/content-types-can-be-unghosted-too/
http://soerennielsen.wordpress.com/2007/09/08/convert-%E2%80%9Dvirtual-content-types%E2%80%9D-to-physical/
Maybe somebody can guide me in the right direction?

Is there an easy way to generate Javascript models based on POC Entity Framework entities (e.g. for ExtJs)?

I have an existing ASP.NET MVC3 application and want to incorporate ExtJs primarily for charting now, but for more functionality later. I already have a set of POCO Entities in my architecture, and would like to have them all available for the javascript-based model. Also, I don't want to have to maintain two sets of entities. I figure it's probably not hard to write something that will creat JSON representations of the entities, but someone must have done this already, right? I couldn't find it in my own searching. Any assistance is appreciated!
I don't really understand what you're asking, but perhaps a C# to JavaScript compiler can help you. Alternatives I know of:
Saltarelle (mine)
Script#
SharpKit
That's an interesting idea! I can certainly understand the motivation. A nice solution may be to generate a javascript file from your C# models using the T4 templating engine.
This way you could create a template that uses reflection to grab all the types defined under a certain project or namespace and iterate over them, writing out a javascript definition for each. A little more reflection to list the public property names, and whatever javascript syntax you'd like surrounding them and you're all sorted!
You add a reference to newtonsoft.json and you do like that
var model = #Html.Raw(JsonConvert.SerializeObject(Model, new IsoDateTimeConverter()));
Is it what you're looking for ?
I've been looking to do something simlar for a personal project and have found DataContractJsonSerializer on MSDN which would allow you to serialize your POCOs to JSON. There is also an article on CodeProject entitled JSON Serialization and Deserialization in ASP.NET by SummiG that gives a good -- and at first glance complete -- example of creating a static helper class.
That being said, I haven't tried it myself yet and would appreciate any feedback if you do go that route.

How can I make a program to support custom requirements for multiple customers with a single codebase?

As the title states, I'm looking for a way to organize code with various customer "settings" that control program logic and sometimes display logic without introducing a nest of if/else branches in both the client (javascript) and the server (C#).
What mechanisms do I have to choose from for making a series of modules used for validation, field visibility, processing rules and such that can be loaded dynamically based on, say, a username or other bit of customer data? I am aware of IOC, I need something more specific than "configurable modules". Are there libraries out there to provide a structure for organizing code and loading it conditionally?
What about in javascript? Are there well-known mechanisms for dynamically loading javascript from small files to be executed conditionally?
Most of all, is there a name for what I'm describing? I don't want a rules engine or decision engine where the code is stored as a set of values and operators. I want to keep the code in its original files. I also want to use strong typing and interfaces where I can.
Any ideas?
You should look at either (or both) of
Microsoft's Managed Extensibility Framework
http://msdn.microsoft.com/en-us/magazine/ee291628.aspx
Mono.Addins
Here's the MSDN docs on the System.Addin namespace(s) as well: http://msdn.microsoft.com/en-us/library/gg145020.aspx
This discussion talks about the difference between MEF and System.Addin: Choosing between MEF and MAF (System.AddIn)
The wiring and configuration of your extension system is of course highly domain specific.
Good Luck!
If you wish to use strong typing and interfaces, then why not just go that route? You could create an interface that defines callable methods for your individual customer logic, and then create the implementation classes for each. That way you would only have one piece of conditional logic, perhaps a switch statement, in your system startup routine that loads the correct implementation.

How to Make a "Dashboard" Utility that Accepts Modules/Add-Ins

I hope this question makes sense. Basically, I am looking for a set of guidelines, or even a tutorial, that will show how to make an application that can easily add and remove "modules" or "add-ins"
For example, in Microsoft Office, you will commonly see programs that you can download and install and they will just add an extra tab into Microsoft Word (for example) that will implement some new feature.
I have several applications that use basically the same data source, and I'd like to consolidate them and also leave open the possibility of adding more functionality in the future without 1. Requiring a brand new install and 2. Tweaking every piece of my code.
I'm looking for a place to start, mostly.
Thanks in advance.
**
Edit: To elaborate a little more...
The thing I have in mind specifically is an application that accesses a large set of data that is stored in text files and uses some of the data to create a few graphs and maybe some tables. I'd like the ability to add different graphs in the future using the same data. So, you can click Button_A and generate Graph_A, then a few weeks later, you can click Button_B and generate Graph_B.
It would be really nice if I could come up with a way that only required reading the data from the file(s) once, but I know that would involve having to adjust my DataReader class a bit.
One place to start would be to define an interface for your future modules, and build a utility that scans all the dll's therein, looking for classes that implement said interface.
Once you've found supporting classes you can create instances at runtime and add to your application. That's a common idiom in .NET for supporting "plug-ins"
The Activator class is a common way to create instances from a Type at runtime.
http://msdn.microsoft.com/en-us/library/system.activator.aspx
It's hard to give more details without more info in your question. Can you elaborate a bit?
Take a look at the Composite Application Library from Microsoft.
It is aimed at WPF but you could get some ideas from there.
As Adam said, the first thing to do is define the interface for your plugin modules - what can they expect to receive from the container, and what methods must the container be able to call?
As far as the container itself goes, I'm partial to MEF as a location technology; you can create catalogs and re-compose the system when new DLLs are added. I've built a similar system to this for parsing dissimilar files, and the composition capabilities of MEF are awesome for runtime discovery.

Maintaining Consistency Between JavaScript and C# Object Models

I'm working on an ASP.NET web application that uses a lot of JavaScript on the client side to allow the user to do things like drag-drop reordering of lists, looking up items to add to the list (like the suggestions in the Google search bar), deleting items from the list, etc.
I have a JavaScript "class" that I use to store each of the list items on the client side as well as information about what action the user has performed on the item (add, edit, delete, move). The only time the page is posted to the server is when the user is done, right before the page is submitted I serialize all the information about the changes that were made into JSON and store it in hidden fields on the page.
What I'm looking for is some general advice about how to build out my classes in C#. I think it might be nice to have a class in C# that matches the JavaScript one so I can just deserealize the JSON to instances of this class. It seems a bit strange though to have classes on the server side that both directly duplicate the JavaScript classes, and only exist to support the JavaScript UI implementation.
This is kind of an abstract question. I'm just looking for some guidance form others who has done similar things in terms of maintaining matching client and server side object models.
Makes perfect sense. If I were confronting this problem, I would consider using a single definitive description of the data type or class, and then generating code from that description.
The description might be a javascript source file; you could build a parser that generates the apropriate C# code from that JS. Or, it could be a C# source file, and you do the converse.
You might find more utility in describing it in RelaxNG, and then building (or finding) a generator for both C# and Javascript. In this case the RelaxNG schema would be checked into source code control, and the generated artifacts would not.
EDIT: Also there is a nascent spec called WADL, which I think would help in this regard as well. I haven't evaluated WADL. Peripherally, I am aware that it hasn't taken the world by storm, but I don't know why that is the case. There's a question on SO regarding that.
EDIT2: Given the lack of tools (WADL is apparently stillborn), if I were you I might try this tactical approach:
Use the [DataContract] attributes on your c# types and treat those as definitive.
build a tool that slurps in your C# type, from a compiled assembly and instantiates the type, by using the JsonSerializer on a sample XML JSON document, that provides, a sort of defacto "object model definition". The tool should somehow verify that the instantiated type can round-trip into equivalent JSON, maybe with a checksum or CRC on the resulting stuff.
run that tool as part of your build process.
To make this happen, you'd have to check in that "sample JSON document" into source code and you'd also have to make sure that is the form you were using in the various JS code in your app. Since Javascript is dynamic, you might also need a type verifier or something, that would run as part of jslint or some other build-time verification step, that would check your Javascript source to see that it is using your "standard" objbect model definitions.

Categories

Resources