Ask a questionAsk a question
 

Proposed AnswerCreating Rule Engine Policy as i wish

  • Wednesday, October 21, 2009 11:19 AMNeelathamara Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    hai,
     
    Now i am trying  the BRE event handler.
    I like to  create a Rule Engine  policy  in  which if certain condition is met  a value to my database table is  get inserted.
    For that what should i do?.
    Please help me to write such a policy.
    Regards ,
    Neelam

All Replies

  • Wednesday, October 21, 2009 1:40 PMPABerg Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer
    Hi.

    First of all open the business rule composer. Add new policy, from policy explorer. Then add a new rule. Then you can write something useful!

    A small example:

    In the IF pane:
    Add a predicate Equal: Insert your arguments here.
    In the THEN pane (for the DB stuff):
    Drag the database fields that you want to update into the pane, and set the values.

    When the policy is ready; save, publish and deploy (right click)

    Then go to RFID manager. If you do not have a process, create it. Then add a new component (In Component Bindings). In "Add Component" choose the "RuleEnginePolicyExecutor". Give it a name, click configure, add the database facts (connection string). Validate and then start the process. You may now test it.

    If you have to edit your policy, you cannot edit a ploicy that is published/deployed, so you will have to copy your old one and paste it. Then edit.

    Good luck!

    Arthur
  • Thursday, October 22, 2009 9:51 AMNeelathamara Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    hai,

      i tried your reply. But it is not working as i expected. Actually i want to insert a value when certain condition is met. It is not getting inserted. So i tried to upadate an existing value as you said. I don't know my policy is correct or not.
    My policy is as below

    Conditions
           |-->AND
                |-->RfidRuleEngineContext.get_TagIdAsHex is equal to MyRfidSink.TagPO.TagID
           |-->NOT
                |--> String.Equals(Convert.ToString(RfidRuleEngineContext.GetVenderSpecificData("PONumber")),MyRfidSink.TagPO.PONumber

    Actions
          |--->MyRfidSink.TagStatus='SuccessfullyInserted'

    Please help me.
    Regards,
    Neelam
     

  • Friday, October 23, 2009 8:06 AMPABerg Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi.

    From your code, I can see that something is missing in the "Actions" section. After performing a update like you have done, you have to call the RfidRuleEngineContext.UpdateDataConnections method. Try that.

    I am not sure if there are methods for inserting to database available. But you can insert to database from a policy, by writing your own class with a method that performs the wanted actions. A custom .net component that you add to GAC. And when it is in GAC you can get it from "Facts explorer" under ".NET Classes". Just GAC the your DLL, right click ".NET Assemblies", browse, and get your component. Then you can use the methods there in your policies. I have done that myself once. I wrote a class that had a static method that performed a insert. Called that method form the policy when a certain condition was met.

    Here is some sample code for a custom .net class:

    public class BRCHelpers
        {
            public BRCHelpers()
            {
            }

            public static void InsertToDB(parameters if needed)
            {
             //connect to DB and perform the insert

            }
    }

    Important:

    To use a custom .net component and it’s methods in business rule composer (when methods are static) without asserting an instance of the class, a registry key has to be set (or made if not existing). The key is
    StaticSupport(DWORD value), located under HKEY_LOCAL_MACHINE\Software\Microsoft\BusinessRules\3.0 with the value 1.


    If you need to change/rewrite your custom .net component. Uninstall the old from gac, gac the new one, and restart your rfid process. Maybe you also have to restart Rule Engine Update Service as well. (RuleEngineUpdateService.exe)

    Good luck!

    Arthur
  • Monday, October 26, 2009 4:29 AMNeelathamara Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hai  Arthur,
      
    I have changed my policy as below

    Conditions
           |-->AND
                |-->RfidRuleEngineContext.get_TagIdAsHex is equal to MyRfidSink.TagPO.TagID
           |-->NOT
                |--> String.Equals(Convert.ToString(RfidRuleEngineContext.GetVenderSpecificData("PONumber")),MyRfidSink.TagPO.PONumber

    Actions
          |--->MyRfidSink.TagStatus='SuccessfullyInserted'

          |----> RfidRuleEngineContext.UpdateDataConnections

    But it is not working.
    i tried to test my policy . The message i am getting is primary key is missing . How can i specify 'where' clause in my actions.
    Regards,
    Neelam
  • Monday, October 26, 2009 10:23 AMPABerg Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi.

    I am not sure if you can specify 'where'. You can make yourself a custom .net component that performs the preferred db actions. Or you can just add some other conditions that results in getting the row that you want to update:

    AND
    MyRfidSink.Field1=<someThing>
    MyRfidSink.Field2=<someThing>
    etc...
    Then
    Actions
    MyRfidSink.TagStatus='SuccessfullyInserted'

    What happens if you try to perform the same DB action by updating it by using SQL Server management Studio? Do you get the same primary key error?
    I guess this means that your policy is working now, when it actually tries to update your DB.

    Regards,
    Arthur
  • Tuesday, October 27, 2009 10:14 AMNeelathamara Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hai arthur,
      I tried that , but it is not working. I think my then part is wrong. In SQL Server management Studio i can update my db. Is anything wrong in my then part? Can you please help me .
    Regards,
    Neelam
  • Wednesday, October 28, 2009 8:55 AMPABerg Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hei.

    I suggest that you perform some logging to see if the THEN part is performed:

    Actions
          |--->MyRfidSink.TagStatus='SuccessfullyInserted'

          |----> RfidRuleEngineContext.UpdateDataConnections
          |----> RfidRuleEngineContext.LogMessage("Then Part Triggered",RfidRuleEngineContext.get_TagIdAsHex)

    It is the same what you put as the second parameter, we just want to see if this will write something to the log.
    The log is here: C:\Program Files\Microsoft BizTalk RFID\Processes\<processName>

    When I update I DB row, I do not use ' '. Remove that, and try again: |--->MyRfidSink.TagStatus=SuccessfullyInserted
    Also remember t restart your process and restart Rule Engine Update Service as well. (RuleEngineUpdateService.exe).

    Arthur
  • Thursday, November 05, 2009 4:51 AMNeelathamara Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hai,

    I tried to have some logging . In my process file i am getting upto 'Process Started' . What should i do ?



    Regards,
    Neelam.
  • Thursday, November 05, 2009 9:09 AMPABerg Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi.

    Is it something like this in your log?
    Info|110309 09:15:30|<desc>Process started</desc><params></params>|[<ProcessName>]

    If only so, I guess that your policy is not executed/starting. I maybe know why. And that is because you need a rule that starts it all (the policy). Some kind of initiation, It is not very logically, but you need it to start. The rule you need to have as a start rule must look like this:

    IF
    Conditions
      1 is equal to 1

    THEN
    RfidRuleEngineContext.set_ShouldTerminatePipeLine(True)


    Then set the priority of this rule the highest, meaning that this rule is executed first. Also, make som logging in this rule as well, to see if something is happening.

    Try this, and tell me how it went!

    Regards
    Arthur
  • Monday, November 09, 2009 5:19 AMNeelathamara Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hai,

     I tried as you said . My policy executed . But my database is not updated. I am getting my log file as below.
      12|   Info|110909 09:13:41|Server Info:
    BANNER
    SERVER NAME: CLIENT62
    SERVICE ACCOUNT: CLIENT62\RfidSvcAcc
    SERVER LOCATION: C:\WINDOWS\assembly\GAC_MSIL\Microsoft.Rfid.Util\3.7.0.0__31bf3856ad364e35\Microsoft.Rfid.Util.dll
    SERVER VERSION: 3.7.0.0
    NT PROCESS ID: 2908|[CompletelyNew]
      12|   Info|110909 09:13:41|LogLevel: Info|[CompletelyNew]
      12|   Info|110909 09:13:41|<desc>Starting process engine from state:</desc><params>NotRunning</params>|[CompletelyNew]
      12|   Info|110909 09:13:41|<desc>process Init parameters</desc><params>maxComponentInitiliazationTime:600000, singleEventProcessingTimeoutMilliseconds:60000</params>|[CompletelyNew]
      12|   Info|110909 09:13:41|<desc>Datastructures for process setup</desc><params></params>|[CompletelyNew]
      12|   Info|110909 09:13:41|<desc>Process counters created</desc><params></params>|[CompletelyNew]
      12|   Info|110909 09:13:42|<desc>Queue Setup.</desc><params></params>|[CompletelyNew]
       4|   Info|110909 09:13:42|About to start dedicated thread GetEventHandlerMetadata3|[CompletelyNew]
       3|   Info|110909 09:13:42|DedicThr About to invoke GetEventHandlerMetadata|[CompletelyNew]
       3|   Info|110909 09:13:42|DedicThr Finished invoke GetEventHandlerMetadata|[CompletelyNew]
       4|   Info|110909 09:13:42|Successfully regained control from dedicated thread GetEventHandlerMetadata3|[CompletelyNew]
       4|   Info|110909 09:13:42|starting logging for BREPolicyExecutor level Info|[BREPolicyExecutor]
       4|   Info|110909 09:13:42|Locating Policy DBBBPolicy Major -1 Minor 0|[BREPolicyExecutor]
       4|   Info|110909 09:13:45|Parameter Needs Synchronization set to False|[BREPolicyExecutor]
       4|   Info|110909 09:13:45|Parameter enable tracking set to False|[BREPolicyExecutor]
       4|   Info|110909 09:13:58|Loaded Policy DBBBPolicy Major Version 1 Minor Version 0|[BREPolicyExecutor]
       4|   Info|110909 09:13:58|SUCCESS found dbconnection fact for MyRfidSink TagPO|[BREPolicyExecutor]
      18|   Info|110909 09:13:58|About to start dedicated thread GetEventHandlerMetadata3|[CompletelyNew]
       3|   Info|110909 09:13:58|DedicThr About to invoke GetEventHandlerMetadata|[CompletelyNew]
       3|   Info|110909 09:13:58|DedicThr Finished invoke GetEventHandlerMetadata|[CompletelyNew]
      18|   Info|110909 09:13:58|Successfully regained control from dedicated thread GetEventHandlerMetadata3|[CompletelyNew]
      18|   Info|110909 09:13:58|8 parameters specified|[SqlServerSink]
      18|   Info|110909 09:13:58|Parameter Key DatabaseName Value rfidsink|[SqlServerSink]
      18|   Info|110909 09:13:58|Parameter Key ServerName Value (local)|[SqlServerSink]
      18|   Info|110909 09:13:58|Parameter Key Username Value |[SqlServerSink]
      18|   Info|110909 09:13:58|Parameter Key Password Value |[SqlServerSink]
      18|   Info|110909 09:13:58|Parameter Key EventTypes Value All|[SqlServerSink]
      18|   Info|110909 09:13:58|Parameter Key ConnectionStringOptions Value Integrated Security=SSPI;|[SqlServerSink]
      18|   Info|110909 09:13:58|Parameter Key IncludeEventData Value True|[SqlServerSink]
      18|   Info|110909 09:13:58|Parameter Key CommandTimeout Value 30|[SqlServerSink]
      18|   Info|110909 09:13:58|Actual parameters used Server (local) Db rfidsink IncludeEvData True CommandTimeout 30|[SqlServerSink]
      12|   Info|110909 09:13:58|<desc>Component pipeline setup</desc><params></params>|[CompletelyNew]
      12|   Info|110909 09:13:58|<desc>Process started</desc><params></params>|[CompletelyNew]

    Please help me.
  • Tuesday, November 17, 2009 7:07 AMNeelathamara Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    hai,

    I am  struggling with this.. Please help me...