コード例 #1
0
        private void BuildRules()
        {
            log("Building rules...");

            log("Creating RuleCondition condRouteFillOccurred");
            RuleCondition condRouteFillOccurred = new RuleCondition("RouteFillOccurred", new RouteFillOccurred(this));

            log("RuleCondition condRouteFillOccurred created.");

            log("Creating Action actShowRouteFill");
            Action actShowRouteFill = this.rmsx.CreateAction("ShowRouteFill", new ShowRouteFill(this));

            log("Action actShowRouteFill created");

            log("Creating RuleSet demoRouteRuleSet");
            RuleSet demoRouteRuleSet = this.rmsx.CreateRuleSet("DemoRouteRuleSet");

            log("RuleSet demoRouteRuleSet created");

            log("Creating Rule ruleRouteFilled");
            Rule ruleRouteFilled = demoRouteRuleSet.AddRule("RouteFilled");

            log("Rule ruleRouteFilled created");

            log("Assign RuleCondition condRouteFillOccurred to Rule ruleRouteFilled");
            ruleRouteFilled.AddRuleCondition(condRouteFillOccurred);

            log("Assign Action actShowRouteFill to Rule ruleRouteFilled");
            ruleRouteFilled.AddAction(actShowRouteFill);

            log("Rules built.");
        }
コード例 #2
0
        public void TestTemplates()
        {
            Dictionary       test = CreateDictionary("Test");
            NameSpace        n1   = CreateNameSpace(test, "N1");
            Structure        s1   = CreateStructure(n1, "S1");
            StructureElement el1  = CreateStructureElement(s1, "E1", "Boolean");
            Structure        s2   = CreateStructure(n1, "S2");
            StructureElement el2  = CreateStructureElement(s2, "E2", "S1");
            Variable         v    = CreateVariable(n1, "V", "S2");

            v.setDefaultValue("N1.S1 { E1 => True }");

            Compiler.Compile_Synchronous(true, true);
            RuleCondition     rc      = CreateRuleAndCondition(n1, "Rule1");
            BaseEditorTextBox textBox = new BaseEditorTextBox();
            {
                //              0         1         2
                //              012345678901234567890123456789
                textBox.Text     = "T";
                textBox.Instance = rc;
                SortedSet <ObjectReference> choices = textBox.AllChoices(0, "T");
                Assert.IsNotNull(choices);
                Assert.AreEqual(2, choices.Count);
                Assert.IsTrue(Contains(choices, "THERE_IS X IN <collection> | <condition>"));
                Assert.IsTrue(Contains(choices, "TARGETS"));
            }
        }
コード例 #3
0
        public static TradeRule LoadRule(string ruleFileName)
        {
            TradeRule rule = null;

            try
            {
                XmlSaveRule xsr = (XmlSaveRule)EZAPI.Toolbox.Serialization.Xml.Deserialize(typeof(XmlSaveRule), ruleFileName);

                rule        = new TradeRule(xsr.Name, xsr.RuleCombination, xsr.RuleType);
                rule.Active = xsr.Active;

                foreach (var xsrc in xsr.RuleConditions)
                {
                    IDataProvider dataProvider1 = MonkeyFactory.CreateDataProviderInstance(xsrc.Value1.Name);
                    IDataProvider dataProvider2 = MonkeyFactory.CreateDataProviderInstance(xsrc.Value2.Name);
                    dataProvider1.SaveData = xsrc.Value1;
                    dataProvider2.SaveData = xsrc.Value2;

                    RuleValue       value1    = new RuleValue(dataProvider1);
                    RuleValue       value2    = new RuleValue(dataProvider2);
                    IRuleComparison compare   = MonkeyFactory.CreateRuleComparisonInstance(xsrc.Compare.Name);
                    RuleCondition   condition = new RuleCondition(value1, compare, value2);

                    rule.AddRuleCondition(condition);
                }
            }
            catch (Exception ex)
            {
                // If there is a problem loading the rule, then we return null (not some partial rule).
                rule = null;
                ExceptionHandler.TraceException(ex);
            }

            return(rule);
        }
コード例 #4
0
        protected override AlertRuleResource CreateSdkCallParameters()
        {
            WriteWarning("*** Add-AzureRMLogAlertRule cmdlet will be deprecated in a future release.");

            RuleCondition condition = this.CreateRuleCondition();

            WriteVerboseWithTimestamp(string.Format("CreateSdkCallParameters: Creating rule object"));
            var rule = new AlertRuleResource()
            {
                Description           = this.Description ?? Utilities.GetDefaultDescription("log alert rule"),
                Condition             = condition,
                Actions               = this.Actions,
                Location              = this.Location,
                IsEnabled             = !this.DisableRule,
                AlertRuleResourceName = this.Name,

                // DO NOT REMOVE OR CHANGE the following. The two elements in the Tags are required by other services.
                Tags = new Dictionary <string, string>(),
            };

            if (!string.IsNullOrEmpty(this.TargetResourceId))
            {
                rule.Tags.Add("$type", "Microsoft.WindowsAzure.Management.Common.Storage.CasePreservedDictionary,Microsoft.WindowsAzure.Management.Common.Storage");
                rule.Tags.Add("hidden-link:" + this.TargetResourceId, "Resource");
            }

            return(rule);
        }
コード例 #5
0
        public void NoProposalWhenInstanceIsNull()
        {
            Dictionary       test = CreateDictionary("Test");
            NameSpace        n1   = CreateNameSpace(test, "N1");
            Structure        s1   = CreateStructure(n1, "S1");
            StructureElement el1  = CreateStructureElement(s1, "E1", "Boolean");
            Structure        s2   = CreateStructure(n1, "S2");
            StructureElement el2  = CreateStructureElement(s2, "E2", "S1");
            Variable         v    = CreateVariable(n1, "V", "S1");

            v.setDefaultValue("N1.S1 { E1 => True }");

            Compiler.Compile_Synchronous(true, true);
            RuleCondition     rc      = CreateRuleAndCondition(n1, "Rule1");
            BaseEditorTextBox textBox = new BaseEditorTextBox();

            {
                //              0123456789
                textBox.Text     = "V <- N2.";
                textBox.Instance = rc;
                SortedSet <ObjectReference> choices = textBox.AllChoices(7, "");
                Assert.IsNotNull(choices);
                Assert.AreEqual(0, choices.Count);
            }
        }
コード例 #6
0
        public void TestCleanUp1()
        {
            Dictionary dictionary = CreateDictionary("Test");
            NameSpace  nameSpace1 = CreateNameSpace(dictionary, "N1");
            NameSpace  nameSpace2 = CreateNameSpace(nameSpace1, "N2");

            Enum enumeration = CreateEnum(nameSpace2, "Mode");

            CreateEnumValue(enumeration, "E1");
            CreateEnumValue(enumeration, "E2");

            Variable variable1 = CreateVariable(nameSpace1, "V", "N1.N2.Mode");

            variable1.Default = "N1.N2.Mode.E1";

            RuleCondition ruleCondition = CreateRuleAndCondition(nameSpace1, "Test");
            PreCondition  preCondition  = CreatePreCondition(ruleCondition, "V == N1.N2.Mode.E1");
            Action        action        = CreateAction(ruleCondition, "V <- N1.N2.Mode.E2");

            Variable variable2 = CreateVariable(nameSpace2, "V2", "Mode");

            variable2.Default = "N1.N2.Mode.E1";

            CleanUpModel();
            Assert.AreEqual("V == N2.Mode.E1", preCondition.ExpressionText);
            Assert.AreEqual("V <- N2.Mode.E2", action.ExpressionText);
            Assert.AreEqual("N2.Mode.E1", variable1.Default);
            Assert.AreEqual("Mode.E1", variable2.Default);
        }
コード例 #7
0
        public void TestRefactorStateMachine3()
        {
            Dictionary dictionary = CreateDictionary("Test");
            NameSpace  nameSpace  = CreateNameSpace(dictionary, "N1");

            StateMachine stateMachine = CreateStateMachine(nameSpace, "TestSM");
            State        state1       = CreateState(stateMachine, "S1");
            State        state2       = CreateState(stateMachine, "S2");

            stateMachine.Default = "S1";

            StateMachine stateMachine2 = state2.StateMachine;
            State        state21       = CreateState(stateMachine2, "S21");
            State        state22       = CreateState(stateMachine2, "S22");

            stateMachine.Default = "S21";

            RuleCondition ruleCondition = CreateRuleAndCondition(state21.StateMachine, "Test");
            Action        action        = CreateAction(ruleCondition, "THIS <- TestSM.S2.S22");

            Refactor(stateMachine, "TestSM2");
            Assert.AreEqual("THIS <- TestSM2.S2.S22", action.ExpressionText);

            Refactor(state2, "S3");
            Assert.AreEqual("THIS <- S3.S22", action.ExpressionText);

            Refactor(nameSpace, "N2");
            Assert.AreEqual("THIS <- S3.S22", action.ExpressionText);
        }
コード例 #8
0
        public void TestRefactorStateMachine()
        {
            Dictionary dictionary = CreateDictionary("Test");
            NameSpace  nameSpace  = CreateNameSpace(dictionary, "N1");

            StateMachine stateMachine = CreateStateMachine(nameSpace, "TestSM");
            State        state1       = CreateState(stateMachine, "S1");
            State        state2       = CreateState(stateMachine, "S2");

            stateMachine.Default = "S1";

            RuleCondition ruleCondition = CreateRuleAndCondition(stateMachine, "Test");
            PreCondition  preCondition  = CreatePreCondition(ruleCondition, "THIS in S1");
            Action        action        = CreateAction(ruleCondition, "THIS <- S2");

            Variable var = CreateVariable(nameSpace, "TheVariable", "TestSM");

            var.setDefaultValue("TestSM.S1");

            Refactor(stateMachine, "TestSM2");

            Assert.AreEqual("THIS in S1", preCondition.ExpressionText);
            Assert.AreEqual("THIS <- S2", action.ExpressionText);
            Assert.AreEqual(var.Type, stateMachine);
        }
コード例 #9
0
        public void TestUpdateFunction()
        {
            Dictionary       dictionary = CreateDictionary("Test");
            NameSpace        nameSpace  = CreateNameSpace(dictionary, "N1");
            Structure        structure  = CreateStructure(nameSpace, "S");
            StructureElement el1        = CreateStructureElement(structure, "A", "Boolean");
            RuleCondition    condition  = CreateRuleAndCondition(structure, "Cond");
            Action           action     = CreateAction(condition, "A <- True");
            Procedure        procedure  = CreateProcedure(structure, "P");
            Parameter        parameter  = CreateParameter(procedure, "V", "Boolean");
            RuleCondition    condition2 = CreateRuleAndCondition(procedure, "Cond");
            Action           action2    = CreateAction(condition2, "A <- V");

            Dictionary dictionary2 = CreateDictionary("TestUpdate");

            dictionary2.setUpdates(dictionary.Guid);

            Structure updatedStructure = structure.CreateStructureUpdate(dictionary2);

            Compiler.Compile_Synchronous(true);
            RuleCheckerVisitor visitor = new RuleCheckerVisitor(dictionary);

            visitor.visit(updatedStructure);

            Assert.IsNull(ErrorMessage(updatedStructure));
        }
コード例 #10
0
        /// <summary>
        ///     Indicates whether a rule condition has been activated at the time provided
        /// </summary>
        /// <param name="ruleCondition">The rule condition that should be activated</param>
        /// <param name="time">the time when the rule condition should be activated</param>
        /// <param name="variable">The variable impacted by this rule condition, if any</param>
        /// <returns>True if the provided rule condition has been activated</returns>
        public bool RuleActivatedAtTime(RuleCondition ruleCondition, double time, IVariable variable)
        {
            bool retVal = false;

            if (variable != null)
            {
                foreach (ModelEvent modelEvent in Events)
                {
                    RuleFired ruleFired = modelEvent as RuleFired;
                    if (modelEvent.Time == time && ruleFired != null)
                    {
                        if (ruleFired.RuleCondition == ruleCondition)
                        {
                            retVal = ruleFired.ImpactVariable(variable);

                            if (retVal)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            return(retVal);
        }
コード例 #11
0
        protected override RuleCreateOrUpdateParameters CreateSdkCallParameters()
        {
            RuleCondition condition = this.CreateRuleCondition();

            WriteVerboseWithTimestamp(string.Format("CreateSdkCallParameters: Creating rule object"));
            var rule = new RuleCreateOrUpdateParameters()
            {
                Location   = this.Location,
                Properties = new Rule()
                {
                    Name            = this.Name,
                    IsEnabled       = !this.DisableRule,
                    Description     = this.Description ?? Utilities.GetDefaultDescription("log alert rule"),
                    LastUpdatedTime = DateTime.Now,
                    Condition       = condition,
                    Actions         = this.Actions,
                },

                // DO NOT REMOVE OR CHANGE the following. The two elements in the Tags are required by other services.
                Tags = new LazyDictionary <string, string>(),
            };

            if (!string.IsNullOrEmpty(this.TargetResourceId))
            {
                rule.Tags.Add("$type", "Microsoft.WindowsAzure.Management.Common.Storage.CasePreservedDictionary,Microsoft.WindowsAzure.Management.Common.Storage");
                rule.Tags.Add("hidden-link:" + this.TargetResourceId, "Resource");
            }

            return(rule);
        }
コード例 #12
0
 private void BuildCondition()
 {
     if (ruleValue1 != null && ruleValue2 != null && ruleComparison != null)
     {
         condition = new RuleCondition(ruleValue1, ruleComparison, ruleValue2);
     }
 }
コード例 #13
0
 public RuleTest(
     string type,
     RuleCondition condition)
 {
     Type      = type;
     Condition = condition;
 }
コード例 #14
0
        public void TestMapExpression()
        {
            Dictionary       test     = CreateDictionary("Test");
            NameSpace        n1       = CreateNameSpace(test, "N1");
            Structure        s1       = CreateStructure(n1, "S1");
            StructureElement el1      = CreateStructureElement(s1, "E1", "Boolean");
            Structure        s2       = CreateStructure(n1, "S2");
            StructureElement el2      = CreateStructureElement(s2, "E2", "S1");
            Function         function = CreateFunction(n1, "f", "S1");

            Collection collection = CreateCollection(n1, "Col", "S1", 10);
            Variable   v          = CreateVariable(n1, "V", "Col");

            Compiler.Compile_Synchronous(true, true);

            RuleCondition rc     = CreateRuleAndCondition(n1, "Rule1");
            Parser        parser = new Parser();

            {
                MapExpression expression = parser.Expression(rc, "MAP V | X. USING X IN X.E2", null, true, null, true, true) as MapExpression;
                Assert.IsNotNull(expression);

                DerefExpression deref = expression.Condition as DerefExpression;
                Assert.IsNotNull(deref);

                ITypedElement element = deref.Arguments[0].Ref as ITypedElement;
                Assert.IsNotNull(element);
                Assert.AreEqual(element.Type, s1);
            }
        }
コード例 #15
0
        public void TestApplyStatement()
        {
            Dictionary       test     = CreateDictionary("Test");
            NameSpace        n1       = CreateNameSpace(test, "N1");
            Structure        s1       = CreateStructure(n1, "S1");
            StructureElement el1      = CreateStructureElement(s1, "E1", "Boolean");
            Structure        s2       = CreateStructure(n1, "S2");
            StructureElement el2      = CreateStructureElement(s2, "E2", "S1");
            Function         function = CreateFunction(n1, "f", "S1");

            Collection collection = CreateCollection(n1, "Col", "S1", 10);
            Variable   v          = CreateVariable(n1, "V", "Col");

            Compiler.Compile_Synchronous(true, true);

            RuleCondition rc     = CreateRuleAndCondition(n1, "Rule1");
            Parser        parser = new Parser();

            {
                ApplyStatement statement = parser.Statement(rc, "APPLY X <- X", true, true) as ApplyStatement;
                Assert.IsNotNull(statement);
            }

            {
                ApplyStatement statement = parser.Statement(rc, "APPLY X <- X ON V | X.", true, true) as ApplyStatement;
                Assert.IsNotNull(statement);

                DerefExpression deref = statement.ConditionExpression as DerefExpression;
                Assert.IsNotNull(deref);

                ITypedElement element = deref.Arguments[0].Ref as ITypedElement;
                Assert.IsNotNull(element);
                Assert.AreEqual(element.Type, s1);
            }
        }
コード例 #16
0
 public void settingInit(Guid pricePolicy, RuleCondition rule)
 {
     this.KeyValue   = pricePolicy;
     this.RuleObject = rule;
     this.cpSettingManufacturerList.ClientInstanceName = rule.MainCpClientInstanceName;
     settingJavascript();
 }
コード例 #17
0
 private void conditionTextBox_Validating(object sender, CancelEventArgs e)
 {
     if (this.rulesListView.SelectedItems.Count == 0)
     {
         return;
     }
     try
     {
         Rule          rule          = this.rulesListView.SelectedItems[0].Tag as Rule;
         RuleCondition ruleCondition = this.ruleParser.ParseCondition(this.conditionTextBox.Text);
         rule.Condition = ruleCondition;
         if (!string.IsNullOrEmpty(this.conditionTextBox.Text))
         {
             this.conditionTextBox.Text = ruleCondition.ToString().Replace("\n", "\r\n");
         }
         UpdateItem(this.rulesListView.SelectedItems[0], rule);
         conditionErrorProvider.SetError(this.conditionTextBox, string.Empty);
     }
     catch (Exception ex)
     {
         conditionErrorProvider.SetError(this.conditionTextBox, ex.Message);
         DesignerHelpers.DisplayError(Messages.Error_ConditionParser + "\n" + ex.Message, this.Text, this.serviceProvider);
         e.Cancel = true;
     }
 }
コード例 #18
0
        private void AddCondition()
        {
            if (_listboxConditions.Count == 8)
            {
                MessageBox.Show(GlobalStrings.Rule_MaxConditions, GlobalStrings.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            RuleCondition rc = new RuleCondition()
            {
                address = $"/sensors/{_selectedSensor.Id}/state/{_selectedPropertyInfo.Name}", op = _selectedOperator, value = _selectedOperator != "dx" ?_conditionvalue : null
            };

            if (_listboxConditions.Any(x => x.address == rc.address))
            {
                if (MessageBox.Show(GlobalStrings.Rule_ConditionAlreadyExists, GlobalStrings.Warning, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
                {
                    return;
                }
                int index = _listboxConditions.FindIndex(x => x.address == rc.address);
                if (index == -1)
                {
                    return;
                }
                _listboxConditions.RemoveAt(index);
            }

            _listboxConditions.Add(rc);
            RemoveError(GlobalStrings.Rule_NoCondition, "ListConditions");
            ResetConditionFields();
        }
コード例 #19
0
        protected override RuleCreateOrUpdateParameters CreateSdkCallParameters()
        {
            this.VerifyRuleTypeToParametersConsistency();

            RuleCondition condition = this.CreateRuleCondition();

            return(new RuleCreateOrUpdateParameters()
            {
                Location = this.Location,
                Properties = new Rule()
                {
                    Name = this.Name,
                    IsEnabled = !this.DisableRule,
                    Description = this.Description ?? Utilities.GetDefaultDescription("alert rule"),
                    LastUpdatedTime = DateTime.Now,
                    Condition = condition,
                    Action = new RuleEmailAction()
                    {
                        CustomEmails = this.CustomEmails == null ? null : this.CustomEmails.Where(e => !string.IsNullOrWhiteSpace(e)).ToList(),
                        SendToServiceOwners = this.SendToServiceOwners,
                    },
                },

                // DO NOT REMOVE OR CHANGE the following. The two elements in the Tags are required by other services.
                Tags = new LazyDictionary <string, string>()
                {
                    { "$type", "Microsoft.WindowsAzure.Management.Common.Storage.CasePreservedDictionary,Microsoft.WindowsAzure.Management.Common.Storage" },
                    { "hidden-link:" + this.ResourceId, "Resource" },
                },
            });
        }
コード例 #20
0
        protected override RuleCreateOrUpdateParameters CreateSdkCallParameters()
        {
            this.VerifyRuleTypeToParametersConsistency();

            RuleCondition condition = this.CreateRuleCondition();

            return(new RuleCreateOrUpdateParameters()
            {
                Location = this.Location,
                Properties = new Rule()
                {
                    Name = this.Name,
                    IsEnabled = !this.DisableRule,
                    Description = this.Description ?? Utilities.GetDefaultDescription("alert rule"),
                    LastUpdatedTime = DateTime.Now,
                    Condition = condition,
                    Action = new RuleEmailAction()
                    {
                        CustomEmails = this.CustomEmails == null ? null : this.CustomEmails.Where(e => !string.IsNullOrWhiteSpace(e)).ToList(),
                        SendToServiceOwners = this.SendToServiceOwners,
                    },
                },

                // NOTE: Do not change this since the portal uses these tags and their contents.
                // Example: if the value associated with $type changes the portal will not show the alert rule event if it is working
                Tags = new LazyDictionary <string, string>()
                {
                    { "$type", "Microsoft.WindowsAzure.Management.Common.Storage.CasePreservedDictionary,Microsoft.WindowsAzure.Management.Common.Storage" },
                    { "hidden-link:" + this.ResourceUri, "Resource" },
                },
            });
        }
コード例 #21
0
        public void Define_rule()
        {
            var conditions = new RuleCondition[]
            {
                Conditions.Equal((Order x) => x.Name, "JOE"),
                Conditions.GreaterThan((Order x) => x.Amount, 10000.0m),
            };

            var consequence  = new DelegateConsequence <Order>((session, x) => { _result = x; });
            var consequence1 = new DelegateConsequence <Order>((session, x) => { _resultB = x; });
            var consequences = new RuleConsequence[]
            {
                consequence,
                consequence1,
            };

            _rule  = new SemanticRule("RuleA", conditions, consequences);
            _rule2 = new SemanticRule("RuleB", conditions, consequences);

            conditions = new RuleCondition[]
            {
                Conditions.Equal((Account a) => a.Name, "JOE"),
            };

            var consequence2 = new DelegateConsequence <Account>((Session session, Account a) => { });

            consequences = new RuleConsequence[]
            {
                consequence2,
            };

            _rule3 = new SemanticRule("RuleC", conditions, consequences);
        }
コード例 #22
0
        public void Define_rule()
        {
            var conditions = new RuleCondition[]
                {
                    Conditions.Equal((Order x) => x.Name, "JOE"),
                    Conditions.GreaterThan((Order x) => x.Amount, 10000.0m),
                };

            var consequences = new RuleConsequence[]
                {
                    Consequences.Delegate<Order>((session,x) => { _result = x; }),
                    Consequences.Delegate<Order>((session,x) => { _resultB = x; }),
                };

            _rule = new OdoyuleRule("RuleA", conditions, consequences);
            _rule2 = new OdoyuleRule("RuleB", conditions, consequences);

            conditions = new RuleCondition[]
                {
                    Conditions.Equal((Account a) => a.Name, "JOE"),
                };

            consequences = new RuleConsequence[]
                {
                    Consequences.Delegate((Session session, Account a) => { }),
                };

            _rule3 = new OdoyuleRule("RuleC", conditions, consequences);
        }
コード例 #23
0
        public void TestRefactorNameSpaceName3()
        {
            Dictionary       test = CreateDictionary("Test");
            NameSpace        n0   = CreateNameSpace(test, "N0");
            NameSpace        n1   = CreateNameSpace(n0, "N1");
            Structure        s1   = CreateStructure(n1, "S1");
            StructureElement el1  = CreateStructureElement(s1, "E1", "Boolean");
            Structure        s2   = CreateStructure(n1, "S2");
            StructureElement el2  = CreateStructureElement(s2, "E2", "S1");
            Variable         v    = CreateVariable(n1, "V", "S1");

            v.setDefaultValue("S1 { E1 => True }");
            Function f = CreateFunction(n1, "f", "S2");

            NameSpace     n2 = CreateNameSpace(n0, "N2");
            RuleCondition rc = CreateRuleAndCondition(n2, "Rule1");
            PreCondition  p  = CreatePreCondition(rc, "N1.f().E2.E1");
            Action        a  = CreateAction(rc, "N1.V <- N1.S1 { E1 => False }");

            Refactor(n1, "NewN1");
            Assert.AreEqual("S1 { E1 => True }", v.getDefaultValue());
            Assert.AreEqual("NewN1.V <- NewN1.S1 { E1 => False }", a.ExpressionText);
            Assert.AreEqual("NewN1.f().E2.E1", p.ExpressionText);

            RefactorAndRelocate(p);
            Assert.AreEqual("NewN1.f().E2.E1", p.ExpressionText);
        }
コード例 #24
0
        protected override AlertRuleResource CreateSdkCallParameters()
        {
            WriteWarning("*** This cmdlet will be removed in the 5.0 release (November 2017.)");
            WriteWarning("*** Note: After October 1st using this cmdlet will no longer have any effect as this functionality is being transitioned to Activity Log Alerts. Please see https://aka.ms/migratemealerts for more information.");

            RuleCondition condition = this.CreateRuleCondition();

            WriteVerboseWithTimestamp(string.Format("CreateSdkCallParameters: Creating rule object"));
            var rule = new AlertRuleResource()
            {
                Description           = this.Description ?? Utilities.GetDefaultDescription("log alert rule"),
                Condition             = condition,
                Actions               = this.Actions,
                Location              = this.Location,
                IsEnabled             = !this.DisableRule,
                AlertRuleResourceName = this.Name,

                // DO NOT REMOVE OR CHANGE the following. The two elements in the Tags are required by other services.
                Tags = new Dictionary <string, string>(),
            };

            if (!string.IsNullOrEmpty(this.TargetResourceId))
            {
                rule.Tags.Add("$type", "Microsoft.WindowsAzure.Management.Common.Storage.CasePreservedDictionary,Microsoft.WindowsAzure.Management.Common.Storage");
                rule.Tags.Add("hidden-link:" + this.TargetResourceId, "Resource");
            }

            return(rule);
        }
コード例 #25
0
ファイル: EventDescriptor.cs プロジェクト: fgeraci/CS195-Core
    /// <summary>
    /// Creates a new EventDescriptor from metadata
    /// </summary>
    public EventDescriptor(
        string name,
        Type type,
        Type[] requiredTypes,
        string[] sentiments,
        StateCondition[] stateReqs,
        RelationCondition[] relationReqs,
        RuleCondition[] ruleReqs,
        StateCondition[] stateEffects,
        RelationCondition[] relationEffects,
        int[] canEqualPairs)
    {
        this.Name = name;

        this.Type = type;
        this.RequiredTypes = requiredTypes;
        this.Sentiments = sentiments;

        this.StateReqs = stateReqs;
        this.RelationReqs = relationReqs;
        this.RuleReqs = ruleReqs;
        this.StateEffects = stateEffects;
        this.RelationEffects = relationEffects;

        this.StateRequirements = this.CollectStateRequirements();
        this.canEqual = this.PopulateCanEqual(canEqualPairs);
    }
コード例 #26
0
        public override void OnResponse(NetState state, RelayInfo info)
        {
            Mobile from = state.Mobile;

            if (info.ButtonID == 0 || info.ButtonID == 98)
            {
                from.SendGump(new TourneyStoneUseGump(from, m_TourneyStone));
                return;
            }

            if (info.ButtonID > ConfigOptions.Count)
            {
                return;
            }

            // Condition of this rule that we need to change :
            // (1 + condition number) index in ConfigOptions

            // ((RuleCondition) ConfigOptions[ info.ButtonID - 1 ]);
            RuleCondition rc = (RuleCondition)ConfigOptions[info.ButtonID - 1];

            from.Prompt = new AlterCondValPrompt(info.ButtonID - 1, m_iRule, ref m_TourneyStone, from);
            //from.SendGump( new TourneyStoneEditGump( from, ref m_TourneyStone, m_iRule ) );
            return;
        }
コード例 #27
0
        public void TestListExpression()
        {
            Dictionary       test     = CreateDictionary("Test");
            NameSpace        n1       = CreateNameSpace(test, "N1");
            Structure        s1       = CreateStructure(n1, "S1");
            StructureElement el1      = CreateStructureElement(s1, "E1", "Boolean");
            Structure        s2       = CreateStructure(n1, "S2");
            StructureElement el2      = CreateStructureElement(s2, "E2", "S1");
            Function         function = CreateFunction(n1, "f", "S1");

            Collection collection = CreateCollection(n1, "Col", "S1", 10);
            Variable   v          = CreateVariable(n1, "V", "Col");

            Compiler.Compile_Synchronous(true, true);

            RuleCondition rc     = CreateRuleAndCondition(n1, "Rule1");
            Parser        parser = new Parser();

            {
                VariableUpdateStatement statement = parser.Statement(rc, "V <- [S1 { E1 => Tr", true, true) as VariableUpdateStatement;
                Assert.IsNotNull(statement);

                UnaryExpression unaryExpression = statement.Expression as UnaryExpression;
                Assert.IsNotNull(unaryExpression);
                ListExpression listExpression = unaryExpression.Term.LiteralValue as ListExpression;
                Assert.IsNotNull(listExpression);
                Assert.AreEqual(listExpression.ListElements.Count, 1);

                StructExpression structExpression = listExpression.ListElements[0] as StructExpression;
                Assert.IsNotNull(structExpression);
            }
        }
コード例 #28
0
ファイル: Apriori.cs プロジェクト: dmitrykudin/Demo
        public List <AssociationRule> SaveToDatabase(List <AssociationRule> associationRules)
        {
            IAssociationRuleRepository associationRuleRepository = new AssociationRuleRepository();
            IRuleConditionRepository   ruleConditionRepository   = new RuleConditionRepository();
            IRuleResultRepository      ruleResultRepository      = new RuleResultRepository();
            List <AssociationRule>     createdAssociationRules   = new List <AssociationRule>();

            foreach (var associationRule in associationRules)
            {
                AssociationRule createdRule = associationRuleRepository.CreateRule(associationRule);
                if (createdRule != null)
                {
                    foreach (var condition in associationRule.RuleConditions)
                    {
                        condition.RuleId = createdRule.Id;
                        RuleCondition createdCondition = ruleConditionRepository.CreateCondition(condition);
                        createdRule.RuleConditions.Add(createdCondition);
                    }

                    foreach (var result in associationRule.RuleResults)
                    {
                        result.RuleId = createdRule.Id;
                        RuleResult createdResult = ruleResultRepository.CreateResult(result);
                        createdRule.RuleResults.Add(createdResult);
                    }
                    createdAssociationRules.Add(createdRule);
                }
            }
            return(createdAssociationRules);
        }
コード例 #29
0
        private void listConditions_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            listConditions.SelectedItems.Clear();
            listConditions.Items[e.Index].Selected = true;
            listConditions.Items[e.Index].Focused  = true;
            RulePart rp = (RulePart)listConditions.Items[e.Index].Tag;

            switch (pageNr)
            {
            case 0:
                if (e.NewValue == CheckState.Checked)
                {
                    RuleCondition rc = (RuleCondition)rp.Clone();
                    if (rule.Conditions.FindByFormat(rc.TextFormat) == null)
                    {
                        rule.Conditions.Add(rc);
                    }
                }
                else
                {
                    rule.Conditions.Remove((rule.Conditions.FindByFormat(rp.TextFormat)));
                }
                break;

            case 1:
                if (e.NewValue == CheckState.Checked)
                {
                    RuleAction rc = (RuleAction)rp.Clone();
                    if (rule.Actions.FindByFormat(rc.TextFormat) == null)
                    {
                        rule.Actions.Add(rc);
                    }
                }
                else
                {
                    rule.Actions.Remove((rule.Actions.FindByFormat(rp.TextFormat)));
                }
                break;

            case 2:
                if (e.NewValue == CheckState.Checked)
                {
                    RuleCondition rc = (RuleCondition)rp.Clone();
                    if (rule.Exceptions.FindByFormat(rc.TextFormat) == null)
                    {
                        rule.Exceptions.Add(rc);
                    }
                }
                else
                {
                    rule.Exceptions.Remove((rule.Exceptions.FindByFormat(rp.TextFormat)));
                }
                break;

            default:
                break;
            }
            ruleViewDetails.Display(rule);
        }
コード例 #30
0
        public void TestStructureDereference()
        {
            Dictionary       dictionary = CreateDictionary("Test");
            NameSpace        nameSpace  = CreateNameSpace(dictionary, "N1");
            Structure        structure  = CreateStructure(nameSpace, "Struct");
            StructureElement el1        = CreateStructureElement(structure, "e1", "Boolean");
            Function         f          = CreateFunction(nameSpace, "f", "Struct");
            Variable         v          = CreateVariable(nameSpace, "v", "Struct");
            Variable         v2         = CreateVariable(nameSpace, "v2", "Boolean");

            Parser parser = new Parser();
            {
                DerefExpression expression = parser.Expression(nameSpace, "N1.v.e1") as DerefExpression;
                Assert.IsNotNull(expression);
                Assert.AreEqual(3, expression.Arguments.Count);
                Assert.AreEqual(v, expression.Arguments[1].Ref);
                Assert.AreEqual(el1, expression.Arguments [2].Ref);
            }
            {
                DerefExpression expression = parser.Expression(nameSpace, "N1.f().e1") as DerefExpression;
                Assert.IsNotNull(expression);
                Assert.AreEqual(2, expression.Arguments.Count);
                Assert.AreEqual(structure, expression.Arguments [0].Ref);
                Assert.AreEqual(el1, expression.Arguments [1].Ref);
            }
            {
                DerefExpression expression = parser.Expression(nameSpace, "N1.Struct.e1") as DerefExpression;
                Assert.IsNotNull(expression);
                Assert.AreEqual(3, expression.Arguments.Count);
                Assert.AreEqual(structure, expression.Arguments[1].Ref);
                Assert.AreEqual(el1, expression.Arguments[2].Ref);
            }

            RuleCondition condition = CreateRuleAndCondition(nameSpace, "Test");
            Action        action1   = CreateAction(condition, "Struct.e1 <- True");
            Action        action2   = CreateAction(condition, "v2 <- Struct.e1");
            Action        action3   = CreateAction(condition, "f().e1 <- True");
            Action        action4   = CreateAction(condition, "v2 <- f().e1");

            Collection collection = CreateCollection(nameSpace, "Col", "Struct", 10);
            Variable   v3         = CreateVariable(nameSpace, "v3", "Col");
            Action     action5    = CreateAction(condition, "(FIRST X IN v3).e1 <- True");

            RuleCondition ruleCondition2 = CreateRuleAndCondition(structure, "Rule");
            Action        action6        = CreateAction(ruleCondition2, "THIS.e1 <- True");
            Action        action7        = CreateAction(ruleCondition2, "v2 <- THIS.e1");

            RuleCheckerVisitor visitor = new RuleCheckerVisitor(dictionary);

            visitor.visit(nameSpace);

            Assert.True(HasMessagePart(action1, "structure should not be used to reference an instance"));
            Assert.True(HasMessagePart(action2, "structure should not be used to reference an instance"));
            Assert.False(HasMessagePart(action3, "structure should not be used to reference an instance"));
            Assert.False(HasMessagePart(action4, "structure should not be used to reference an instance"));
            Assert.False(HasMessagePart(action5, "structure should not be used to reference an instance"));
            Assert.False(HasMessagePart(action6, "structure should not be used to reference an instance"));
            Assert.False(HasMessagePart(action7, "structure should not be used to reference an instance"));
        }
コード例 #31
0
        protected BinaryCondition([NotNull] RuleCondition leftOperand, [NotNull] RuleCondition rightOperand)
        {
            Assert.ArgumentNotNull(leftOperand, nameof(leftOperand));
            Assert.ArgumentNotNull(rightOperand, nameof(rightOperand));

            this.leftOperand  = leftOperand;
            this.rightOperand = rightOperand;
        }
コード例 #32
0
 public RuleConditionConfiguratorImpl(RuleCondition condition)
 {
     _condition = condition as RuleCondition <T>;
     if (_condition == null)
     {
         throw new ArgumentException("The condition fact type must match the configurator type");
     }
 }
コード例 #33
0
        public void Define_rule()
        {
            var conditions = new RuleCondition[]
                {
                    Conditions.GreaterThanOrEqual((Order x) => x.Amount, 10000.0m),
                };

            var consequences = new RuleConsequence[]
                {
                    Consequences.Delegate<Order>((session,x) => { _result = x; }),
                };

            Rule rule = new OdoyuleRule("RuleA", conditions, consequences);

            _engine = RulesEngineFactory.New(x => x.Add(rule));
        }
コード例 #34
0
ファイル: NotNull_Specs.cs プロジェクト: drusellers/Odoyule
        public void Define_rule()
        {
            var conditions = new RuleCondition[]
                {
                    Conditions.NotNull((Order x) => x.Customer),
                };

            var consequences = new RuleConsequence[]
                {
                    Consequences.Delegate<Order>((session,x) => { _result = x; }),
                };

            Rule rule = new OdoyuleRule("RuleA", conditions, consequences);

            _engine = RulesEngineFactory.New(x => x.Add(rule));
        }
コード例 #35
0
ファイル: Deep_Specs.cs プロジェクト: drusellers/Odoyule
        public void Define_rule()
        {
            var conditions = new RuleCondition[]
                {
                    Conditions.Equal((Order x) => x.Name, "JOE"),
                    Conditions.GreaterThan((Order x) => x.Amount, 10000.0m),
                    Conditions.Equal((Order x) => x.Purchaser.AccountNumber, "DIRT"),
                };

            var consequences = new RuleConsequence[]
                {
                    Consequences.Delegate((Session session, Order x) => { _result = x; }),
                    Consequences.Delegate((Session session, Order x) => { _resultB = x; }),
                };

            _rule = new OdoyuleRule("RuleA", conditions, consequences);
            _rule2 = new OdoyuleRule("RuleB", conditions, consequences);
        }
コード例 #36
0
ファイル: Exists_Specs.cs プロジェクト: drusellers/Odoyule
        public void Define_rule()
        {
            _results = new List<Order>();

            var conditions = new RuleCondition[]
                {
                    Conditions.Exists((Order x) => x.Lines), //,
                    //Conditions.Equal((OrderLine x) => x.ItemNumber == "123"));
                };

            var consequences = new RuleConsequence[]
                {
                    Consequences.Delegate<Order>((session,x) => _results.Add(x)),
                };

            Rule rule = new OdoyuleRule("RuleA", conditions, consequences);

            _engine = RulesEngineFactory.New(x => x.Add(rule));
        }
コード例 #37
0
ファイル: Each_Specs.cs プロジェクト: drusellers/Odoyule
        public void Define_rule()
        {
            _results = new List<Tuple<OrderLine, int>>();

            var conditions = new RuleCondition[]
                {
                    Conditions.Each<Order, IList<OrderLine>, OrderLine>(x => x.Lines),
                };

            var consequences = new RuleConsequence[]
                {
                    Consequences.Delegate<Token<Token<Order, IList<OrderLine>>, Tuple<OrderLine, int>>>(
                        (session,x) => _results.Add(x.Item2)),
                };

            Rule rule = new OdoyuleRule("RuleA", conditions, consequences);

            _engine = RulesEngineFactory.New(x => x.Add(rule));
        }
コード例 #38
0
ファイル: EventAttributes.cs プロジェクト: fgeraci/CS195-Core
 public RuleRequiredAttribute(
     int indexFrom,
     int indexTo,
     params RuleName[] tags)
 {
     this.Condition =
         new RuleCondition(indexFrom, indexTo, tags);
 }