예제 #1
0
        public void ToolkitIntegrationTests()
        {
            Helper             h      = new Helper();
            RuleApplicationDef source = RuleApplicationDef.Load(_sourcePath);
            RuleApplicationDef dest   = RuleApplicationDef.Load(_destPath);

            h.ImportToolkit(source, dest);
            Assert.IsTrue(source.Entities.Count == dest.Entities.Count);
            Assert.IsTrue(source.EndPoints.Count == dest.EndPoints.Count);
            Assert.IsTrue(source.UdfLibraries.Count == dest.UdfLibraries.Count);
            Assert.IsTrue(source.Categories.Count == dest.Categories.Count);
            Assert.IsTrue(source.DataElements.Count == dest.DataElements.Count);
            Assert.IsTrue(source.RuleSets.Count == dest.RuleSets.Count);
            string path = AppDomain.CurrentDomain.BaseDirectory + "\\Ruleapps\\dest_" + Guid.NewGuid() + ".ruleappx";

            dest.SaveToFile(path);

            h.RemoveToolkit(source, dest);
            Assert.IsTrue(dest.Entities.Count == 0);           //all imported entities are gone
            Assert.IsTrue(dest.RuleSets.Count == 0);           //all imported RuleSets are gone
            Assert.IsTrue(dest.EndPoints.Count == 0);          //all endpoints are gone
            Assert.IsTrue(dest.Categories.Count == 0);         //all categories are gone
            Assert.IsTrue(dest.DataElements.Count == 0);       //all data elements are gone
            Assert.IsTrue(dest.UdfLibraries.Count == 0);       //All udfs are gone
            Assert.IsTrue(dest.Attributes.Default.Count == 0); //the base 64 encoded source ruleapp is removed
        }
예제 #2
0
        internal void StoreSourceRuleapp(RuleApplicationDef source, RuleApplicationDef dest)
        {
            //Save temporarily to the filesystem
            string tmp = GetTmpPath();

            source.SaveToFile(tmp);
            string file = EncodeFile(tmp);
            //Store in target attribute with stamp
            string key = MakeKey(source);

            StoreFileInAttribute(file, key, dest);
        }
예제 #3
0
 private void save()
 {
     try {
         // Save the rule application to the file system.  Backup any existing file.
         if (File.Exists(ruleAppName + ".ruleapp"))
         {
             File.Copy(ruleAppName + ".ruleapp", ruleAppName + "." + System.Guid.NewGuid().ToString() + ".ruleapp");
             //InRule overwrites the file by default if it exists
         }
         ruleAppDef.SaveToFile(@ruleAppName + ".ruleapp");
         Console.WriteLine("Awesome! Your ruleapp named: " + ruleAppName + ".ruleapp may now be opened in irAuthor.");
     } catch (Exception e) {
         Console.WriteLine("An exception has occurred: " + e.Message +
                           "\nStack trace: " + e.StackTrace);
     }
 }
예제 #4
0
        public void ImportRuleAppIntegrationTests()
        {
            Helper             h      = new Helper();
            RuleApplicationDef source = RuleApplicationDef.Load(_sourcePath);
            RuleApplicationDef dest   = RuleApplicationDef.Load(_destPath);

            h.ImportRuleApp(source, dest);
            Assert.IsTrue(source.Entities.Count == dest.Entities.Count);
            Assert.IsTrue(source.EndPoints.Count == dest.EndPoints.Count);
            Assert.IsTrue(source.UdfLibraries.Count == dest.UdfLibraries.Count);
            Assert.IsTrue(source.Categories.Count == dest.Categories.Count);
            Assert.IsTrue(source.DataElements.Count == dest.DataElements.Count);
            Assert.IsTrue(source.RuleSets.Count == dest.RuleSets.Count);
            string path = AppDomain.CurrentDomain.BaseDirectory + "\\Ruleapps\\dest_import_only_" + Guid.NewGuid() + ".ruleappx";

            dest.SaveToFile(path);
        }
예제 #5
0
        public void TestImportDefByCategory()
        {
            Helper h          = new Helper();
            string sourcePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory.Substring(0,
                                                                                             AppDomain.CurrentDomain.BaseDirectory.IndexOf("bin")), @"Ruleapps\", "Unit_Test_SourceRuleApplication_Import_By_Category.ruleappx");

            string destPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory.Substring(0,
                                                                                           AppDomain.CurrentDomain.BaseDirectory.IndexOf("bin")), @"Ruleapps\", "Unit_Test_DestRuleApplication_Import_By_Category.ruleappx");

            RuleApplicationDef source = RuleApplicationDef.Load(sourcePath);
            RuleApplicationDef dest   = RuleApplicationDef.Load(destPath);

            h.ImportRuleApp(source, dest, "Category1");
            RuleRepositoryDefBase retval = h.FindDefDeep(dest, "FireNotification1");

            Assert.NotNull(retval);

            RuleApplicationValidationErrorCollection err = dest.Validate();
            string tempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory.Substring(0, AppDomain.CurrentDomain.BaseDirectory.IndexOf("bin")), @"Ruleapps\", Guid.NewGuid() + "TempRuleApplication.ruleappx");

            dest.SaveToFile(tempPath);
        }
예제 #6
0
        static void Main(string[] args)
        {
            var ruleAppDef = new RuleApplicationDef("CallWebServiceExample1");

            //Create a new Web Service Endpoint
            WebServiceDef webServiceDef = new WebServiceDef();

            webServiceDef.Name     = "WebService1";
            webServiceDef.WsdlUri  = "http://localhost/WcfService1/Service1.svc?wsdl";
            webServiceDef.PortName = "BasicHttpBinding_IService1";
            webServiceDef.Operations.Add(new WebServiceDef.OperationDef("GetData"));

            //Add the new Web Service Endpoint to the Rule Application
            ruleAppDef.EndPoints.Add(webServiceDef);

            //Add an Entity for output
            EntityDef entity1 = ruleAppDef.Entities.Add(new EntityDef("Entity1"));
            //Add field to the new Entity that will contain the output value
            FieldDef resultField1 = entity1.Fields.Add(new FieldDef("InputData", DataType.Integer));
            FieldDef resultField2 = entity1.Fields.Add(new FieldDef("OutputData", DataType.String));

            //Create a new Execute Web Service Action
            ExecuteWebServiceOperationActionDef executeWebServiceActionDef = new ExecuteWebServiceOperationActionDef();

            executeWebServiceActionDef.Name = "ExecuteWebService1";
            executeWebServiceActionDef.WebServiceEndPointName = "WebService1";
            executeWebServiceActionDef.OperationName          = "GetData";

            var inputMapping1 = new TypeMapping("value", "Int32");

            inputMapping1.FieldMappings.Add(new FieldMapping("InputData", "value", "Integer", false, false));
            executeWebServiceActionDef.Inputs.Add(inputMapping1);
            var outputMapping1 = new TypeMapping("[return]", "String");

            outputMapping1.FieldMappings.Add(new FieldMapping("OutputData", "[return]", "Text", false, false));
            executeWebServiceActionDef.Outputs.Add(outputMapping1);

            //Create a Rule Set container to hold the Action
            RuleSetDef ruleSetDef = new RuleSetDef("RuleSet");

            ruleSetDef.FireMode = RuleSetFireMode.Auto;
            ruleSetDef.RunMode  = RuleSetRunMode.Sequential;

            //Add the Rule Set to the Entity
            entity1.RuleElements.Add(ruleSetDef);
            //Add the Action to the Rule Set
            ruleSetDef.Rules.Add(executeWebServiceActionDef);

            ruleAppDef.SaveToFile(@"c:\temp\GeneratedRuleApp");

            //Confirm the Rule Application works by creating a Rule Session
            var session = new RuleSession(ruleAppDef);
            //Create a session Entity using the output Entity
            var entity1Runtime = session.CreateEntity("Entity1");

            entity1Runtime.Fields["InputData"].Value = "123";
            //Apply the Rule
            session.ApplyRules();

            //Get the result from the Entity used for the session and return the result from the Result Field
            string result = entity1Runtime.Fields["OutputData"];

            //Verify. Copy the TinyURL from the command and paste into a browser to confirm it takes you to http://www.inrule.com
            Console.WriteLine("Result: {0}", result);
            Console.Read();
        }
예제 #7
0
 public void RemoveToolkit(RuleApplicationDef source, RuleApplicationDef dest, string savePath)
 {
     RemoveToolkit(source, dest);
     dest.SaveToFile(savePath);
 }
예제 #8
0
 public void ImportRuleApp(RuleApplicationDef source, RuleApplicationDef dest, string savePath)
 {
     ImportRuleApp(source, dest);
     dest.SaveToFile(savePath);
 }