Wednesday, March 04, 2009

On powershell exit ....

Trying to invoke a method when the powershell host is exiting...

How to register an event to make the final callback

till so far I discovered that (get-host)Runspace | get-member
does have an event "StateChanged" that I can maybe use.

To be continued

Friday, April 25, 2008

External function calls

The latest release of the Rule Manager allows to import external functions into the business vocabulary. As a little exercise I tried to get the current weather condition for a zipcode (maybe I can write some rules if I should bring my umbrella while I leave my house in L.A.)

Initially I intended to call a webservice, but it seems that all free weather webservice calls is something from the past. Yahoo offers weather information as an RSS feed. So a simple XPath query can select the information that I'm interested in:

Here is the code (note the FunctionAttribute decoration on the method)


1 using System.IO;

2 using System.Net;

3 using System.Xml;

4 using AcumenBusiness.IModel;

5 using Type=AcumenBusiness.IModel.Type;

6

7 namespace TestCallWebService

8 {

9 [Concept("Weather info", "Try to get weather forecast from different services")]

10 public class WeatherInfoProvider

11 {

12 private static readonly string YahooWeatherURLFormat = "http://weather.yahooapis.com/forecastrss?p={0}";

13

14 [Term("workaround", "import function requires one field. (bug)")]

15 private string dummyField;

16 public string DummyField

17 {

18 get { return dummyField; }

19 set { dummyField = value; }

20 }

21

22 [Function("Get temperature", "Get the weather info from Yahoo",

23 ReturnType = Type.text,

24 ArgumentTypes = new Type[] { Type.integer })]

25 public static string GetWeatherInfoAsFeed(int zipCode)

26 {

27 HttpWebRequest request = (HttpWebRequest) WebRequest.Create(string.Format(YahooWeatherURLFormat, zipCode));

28 // execute the request

29 HttpWebResponse response = (HttpWebResponse) request.GetResponse();

30

31 // we will read data via the response stream

32 Stream resStream = response.GetResponseStream();

33 XmlDocument rssFeed = new XmlDocument();

34 rssFeed.Load(resStream);

35

36 //set an XmlNamespaceManager since we have to make explicit namespace searches

37 XmlNamespaceManager xmlnsManager = new System.Xml.XmlNamespaceManager(rssFeed.NameTable);

38 //Add the namespaces used in the xml doc to the XmlNamespaceManager.

39 xmlnsManager.AddNamespace("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");

40

41 XmlNode weatherCondition = rssFeed.SelectSingleNode("/rss/channel/item/yweather:condition/@temp", xmlnsManager);

42 if (weatherCondition != null) {

43 return weatherCondition.Value;

44 }

45 return null;

46 }

47 }

48 }



With the Import Schema adapter I can import this function and call it from my business rules. The coolest part is that you can invoke this from the Interactive Rule Map. So you can see how your rules are executing with this external data. It seems to be 76 fahrenheid in L.A.
Nice weather to jump on the bike and cycle to work...





Thursday, January 10, 2008

.NET SOA BizTalk: BizTalk Tools and guidelines

Kishore Dharanikota has created a nice list of tools and guidelines for BizTalk developers and designers .NET SOA BizTalk: BizTalk Tools and guidelines. The Rule Manager is mentioned in the Development category. Interesting to see this classification. I probably would have placed it in the Design category. But that all depends on your frame of reference. Or it might hint that many BizTalk developers are playing a dual role of business analyst and developer.

Tuesday, October 30, 2007

RenewCert - Renew Expired Certificates

It's been just over a year when I deployed the RuleManager with a ClickOnce certificate. Today it expired. Visual Studio 2005 would suggest to generate a new certificate file, however none of the existing users would be able to update the Application (because of different certificate keys).
The error you would get is:

System.NullReferenceException: Object reference not set to an instance of an object.
at System.Deployment.Application.ApplicationTrust.RequestTrust(SubscriptionState subState, Boolean isShellVisible, Boolean isUpdate, ActivationContext actCtx, TrustManagerContext tmc)
at System.Deployment.Application.DeploymentManager.DetermineTrustCore(Boolean blocking, TrustParams tp)
at System.Deployment.Application.DeploymentManager.DetermineTrust(TrustParams trustParams)
at System.Deployment.Application.ApplicationDeployment.CheckForDetailedUpdate()



There is a workaround made by Cliff Stanford RenewCert, which allows you to regenerate an expired certification.

Thanks Cliff!

Sunday, October 14, 2007

Graphical Rule Editor for RuleML format


In the last few weeks we have created the RuleML adapter for the Rule Manager. The RuleML adapter allows to export a business rules policy to the Reaction RuleML format.

Please bear with us that we are no experts in RuleML and certain rule constructions might be exported incorrectly. I hope the RuleML community can provide us with the feedback and we will incorporate any changes into our automatic update process as soon as possible. You can give feedback at the http://www.acumenbusiness.com/support forum.

Installation:
The Rule Manager product is available from the website http://www.acumenbusiness.com/

You can export to the RuleML format by installing the RuleML adapter module. See the screenshot [Menu: File\Options\Adapters\Rule ML]

The adapter will provide the new export format "RuleML (*.rrml)" in the Export wizard. [Menu: File\Export]
You can set .rrml as the default export type by changing the File Export type on the Import & Export options
[Menu: File\Options\Import & Export\File Export = RuleML (*.rrml)]

An example of the Driver Eligibility export is here
Posted by Picasa

Labels: , ,

Wednesday, August 08, 2007

Paul Andrew : What to use Windows Workflow Foundation for?

Paul Andrew has a nice write up on why you would use Windows Workflow Foundation. There are some excellent arguments for the use of the rules component: the visibility into the business logic and the ability to change this business logic.

That is exactly the reason why I'm currently designing a Windows Workflow Foundation architecture for a very large client. Performance will become critical...

Wednesday, July 18, 2007

Rule Vendors - Product Derby

Once a year, during the business rules symposium, vendors of rule engines can show how they implement a general use case that contains many business rules. This use case is known as the UServ Product Derby. You can read the specifications here.

A few years ago I was actively involved with the implementation using Aion (from CA). Last year I put together the web front-end for Corticon. And recently I've been examining the implementation from Microsoft with WF rules.

Microsoft's example (download here) illustrates the technical feasibility of using WF rules. Although this example shows that it's technical possible, it does not highlight the business rules management, rule audit trail and rule traceability.

For me it was a nice opportunity to see if the Rule Manager from Acumen Business could visualize the rules and perform rule verification on the policy to discover if the actual implementation was logically correct.

We start this blog series with a closer look at the 'Driver's Eligibility' policy as defined in the use case. After a few adjustments on the Rule Manager, I produced this report (PDF, XPS) from Microsoft's example implementation.

The part that got my attention right away was the discovered contradiction. On first look, the rule DA_7 is rather complicated. It is a typical programmer's construction to use a not (expr and expr)
Such a statement has probably a few nanoseconds advantage on your processor. However do we really want the business user to decipher this statement by applying De Morgan's law?

Just keep it simple stupid. Where possible, avoid negated nested expressions and split or-statements in multiple rules.

You might wonder if we found an error with the rules example? The example should work fine, however the example uses rule priorities to ensure that rule DA_7 (priority -1) , is executed after DA_8 (priority 0). The problem that I have with rule priorities is that you throw away the declarative features of a rule engine. Suddenly the rule writer has to be aware of priority values in order to achieve the desired result.

Also note that DA_7 does not halt the rules engine. In a case where we have a male driver of 71 years old, the rules engine first assign 'Senior' to the Driver class, and consecutively overwrites this value with 'Typical Driver'. Now we also have to make sure that rule 'DA_3' must be executed after DA_7 and DA_8. If DA_3 would fire before, we make the incorrect conclusion that a 71 year old senior is eligible without checking his training certificate.

A second problem related to the priority and overwriting conclusions is that a rule audit report would show incorrect results. So please use rule priorities careful. We will show below that the Driver Eligibility policy actually don't require priorities.

Finally, the generated rule graph shows two disjoint rule networks. We have to wonder what happened with the rules that determine the 'Training Certification'. Also how is the DUI related to the Training Certificate? It seems that the example is not a complete implementation of the specification. Visualizing a rule policy in a complete rule graph does make the business rules code review an easy task.

Again, Microsoft example was only illustrating the technical aspects of WF rules. And the example shows how you can achieve First Order Logic with WF rules. (For All Drivers do...)
I changed the Driver Eligibilty policy to remove the contradiction and remove the priorities to keep the rules 100% declarative. We let the rules engine decide which rule should be executed next. Here is a produced report of my rewrite (PDF, XPS).

There are no disjoint rule graphs, no self contradictions within the rules, and no rule anomalies among rules. We do discover some incompleteness. E.g. is a Female of 24 years old eligible?
This incompleteness can be a misinterpretation of the use case specification, or an actual incompleteness in the specification. But with this rule report it's very easy to get these issues clarified.

Labels: , ,

Technorati Profile