Esempio n. 1
0
        void SelectNode(RuleElement element)
        {
            TreeNode node = this.theTree.Nodes.Cast <TreeNode>().Single(tn => tn.Tag == element.Type);

            node.Expand();
            this.theTree.SelectedNode = node.Nodes.Cast <TreeNode>().Single(tn => tn.Tag == element);
        }
        private void MoveWithRule(string name, string fullPath, RuleElement rule)
        {
            StringBuilder fileNameResult = new StringBuilder();

            if (rule.IsIndexNumber)
            {
                int countOfElementsInDirectory = Directory.GetDirectories(rule.OutputFolder.FullName).Length;
                fileNameResult.Append(++countOfElementsInDirectory);
                fileNameResult.Append("_");
            }

            if (rule.IsRelocationDate)
            {
                fileNameResult.Append(DateTime.Now.ToString("dd.MM.yyyy_HH.mm"));
                fileNameResult.Append("_");
            }

            fileNameResult.Append(name);

            var pathResult = Path.Combine(rule.OutputFolder.FullName, fileNameResult.ToString());

            File.Move(fullPath,
                      pathResult);

            OnFileMoved(new MessageEventArgs {
                Message = string.Format(Resources.Resource.FileMoved, rule.OutputFolder.FullName)
            });
        }
        protected override void FillObject(XmlDescriptor d, RuleElement element)
        {
            XmlAttribute attr = d.Element.Attributes[RuleConstants.DayOfWeekAttrName];

            if (attr != null)
            {
                (element as GetClosestDay).DayOfWeek = new ItemDayOfWeek(attr.Value);
            }

            attr = d.Element.Attributes[RuleConstants.WeekCountAttrName];

            if (int.TryParse(attr?.Value, out int count))
            {
                (element as GetClosestDay).WeekCount = count;
            }

            if (d.Element.HasChildNodes)
            {
                (element as GetClosestDay).ChildDateExp = SerializerRoot.Container <DateExpression>()
                                                          .Deserialize(new XmlDescriptor()
                {
                    Element = d.Element.FirstChild
                });
            }
        }
Esempio n. 4
0
        private void BuildJoinNode(ReteBuilderContext context, RuleElement element, IEnumerable <ConditionElement> conditions = null)
        {
            var betaConditions = new List <IBetaCondition>();

            if (conditions != null)
            {
                foreach (var condition in conditions)
                {
                    var betaCondition = ExpressionCompiler.CompileBetaCondition(condition, context.Declarations);
                    betaConditions.Add(betaCondition);
                }
            }

            var node = context.BetaSource
                       .Sinks.OfType <JoinNode>()
                       .FirstOrDefault(x =>
                                       x.RightSource == context.AlphaSource &&
                                       x.LeftSource == context.BetaSource &&
                                       ConditionComparer.AreEqual(x.Conditions, betaConditions));

            if (node == null)
            {
                node = new JoinNode(context.BetaSource, context.AlphaSource, context.HasSubnet);
                foreach (var betaCondition in betaConditions)
                {
                    node.Conditions.Add(betaCondition);
                }
            }
            node.NodeInfo.Add(context.Rule, element);
            BuildBetaMemoryNode(context, node);
            context.ResetAlphaSource();
        }
Esempio n. 5
0
        protected override void FillObject(XmlDescriptor d, RuleElement element)
        {
            XmlNode valuesNode = d.Element.SelectSingleNode(RuleConstants.ValuesNodeName);

            if (valuesNode?.HasChildNodes == true)
            {
                foreach (XmlNode valueNode in valuesNode.ChildNodes)
                {
                    RuleExpression valueElement = SerializerRoot.Container <RuleExpression>()
                                                  .Deserialize(new XmlDescriptor()
                    {
                        Element = valueNode
                    });

                    (element as Case).ValuesElements.Add(valueElement);
                }
            }

            XmlNode actionNode = d.Element.SelectSingleNode(RuleConstants.ActionNodeName);

            if (actionNode != null)
            {
                (element as Case).ActionElement = SerializerRoot.Container <ExecContainer>()
                                                  .Deserialize(new XmlDescriptor()
                {
                    Element = actionNode
                });
            }
        }
Esempio n. 6
0
        //protected Type _type;
        //public CustomParameterBase(Type type)
        //{
        //    _type = type;
        //}

        public void Apply(RuleElement element)
        {
            if (element is T)
            {
                InnerApply(element as T);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Creates a new instance of the Rule using the rule defined in the policy document.
        /// </summary>
        /// <param name="rule">The rule defined in the policy document.</param>
        public Rule(RuleElement rule)
        {
            if (rule == null)
            {
                throw new ArgumentNullException("rule");
            }
            _rule = rule;
            if (_rule.SchemaVersion == XacmlVersion.Version10 || _rule.SchemaVersion == XacmlVersion.Version11)
            {
                _condition = new Condition((ConditionElement)_rule.Condition);
            }
            else if (_rule.SchemaVersion == XacmlVersion.Version20)
            {
                _condition = new Condition2((ConditionElement)_rule.Condition);
            }

            if (rule.Target != null)
            {
                _target = new Target((TargetElement)rule.Target);

                // Load all the resources for the elements within this rule.
                foreach (ResourceElement resource in rule.Target.Resources.ItemsList)
                {
                    foreach (ResourceMatchElement rmatch in resource.Match)
                    {
                        if (!_allResources.Contains(rmatch.AttributeValue.Contents))
                        {
                            _allResources.Add(rmatch.AttributeValue.Contents);
                        }
                    }
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Creates a new instance of the Rule using the rule defined in the policy document.
        /// </summary>
        /// <param name="rule">The rule defined in the policy document.</param>
        public Rule(RuleElement rule)
        {
            if (rule == null) throw new ArgumentNullException("rule");
            _rule = rule;
            if (_rule.SchemaVersion == XacmlVersion.Version10 || _rule.SchemaVersion == XacmlVersion.Version11)
            {
                _condition = new Condition((ConditionElement)_rule.Condition);
            }
            else if (_rule.SchemaVersion == XacmlVersion.Version20)
            {
                _condition = new Condition2((ConditionElement)_rule.Condition);
            }

            if (rule.Target != null)
            {
                _target = new Target((TargetElement)rule.Target);

                // Load all the resources for the elements within this rule.
                foreach (ResourceElement resource in rule.Target.Resources.ItemsList)
                {
                    foreach (ResourceMatchElement rmatch in resource.Match)
                    {
                        if (!_allResources.Contains(rmatch.AttributeValue.Contents))
                        {
                            _allResources.Add(rmatch.AttributeValue.Contents);
                        }
                    }
                }
            }
        }
        protected override void FillObject(XmlDescriptor d, RuleElement element)
        {
            if (Enum.TryParse(d.Element.Name, true, out YmnosRuleKind kind))
            {
                (element as YmnosRule).Kind = kind;
            }

            XmlAttribute attr = d.Element.Attributes[RuleConstants.YmnosRuleSourceAttrName];

            if (Enum.TryParse(attr?.Value, true, out YmnosSource source))
            {
                (element as YmnosRule).Source = source;
            }

            attr = d.Element.Attributes[RuleConstants.YmnosRulePlaceAttrName];
            if (Enum.TryParse(attr?.Value, true, out PlaceYmnosSource place))
            {
                (element as YmnosRule).Place = place;
            }

            attr = d.Element.Attributes[RuleConstants.YmnosRuleCountAttrName];
            if (int.TryParse(attr?.Value, out int intValue))
            {
                (element as YmnosRule).Count = intValue;
            }

            attr = d.Element.Attributes[RuleConstants.YmnosRuleStartFromAttrName];
            if (int.TryParse(attr?.Value, out intValue))
            {
                (element as YmnosRule).StartFrom = intValue;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Gets all rule elements out of an XElement.
        /// </summary>
        /// <param name="elements">The XElement which includes the rule elements.</param>
        /// <returns>List of rule elements.</returns>
        private IEnumerable <RuleElement> GetRuleElements(IEnumerable <XElement> elements)
        {
            List <RuleElement> ruleElements = new List <RuleElement>();

            foreach (XElement element in elements)
            {
                RuleElement ruleElement = new RuleElement();
                ruleElement.RuleType = this.GetRuleElementType(element.Name.LocalName);

                //  Any Childs?
                if (element.Descendants().Count() > 0)
                {
                    ruleElement.Childs = this.GetRuleElements(element.Descendants());
                }
                else
                {
                    ruleElement.Data = element.Value;
                }

                //  Key and value?
                if (element.HasAttributes)
                {
                    foreach (XAttribute attribute in element.Attributes())
                    {
                        ruleElement.Attributes.Add(new KeyValuePair <string, string>(attribute.Name.LocalName, attribute.Value));
                    }
                }

                var test = ruleElement.Attributes.Where(t => t.Key.Equals("")).Select(t => t.Value);

                ruleElements.Add(ruleElement);
            }

            return(ruleElements);
        }
Esempio n. 11
0
        public static string ConvertElement(RuleIndex index, RuleElement element)
        {
            var stringWriter = new StringWriter();

            element.WriteJS(new IndentedTextWriter(stringWriter, "  "));
            return(stringWriter.ToString());
        }
Esempio n. 12
0
 public void StoreRule(RuleElement rule, string path)
 {
     try
     {
         var filePath = Path.GetDirectoryName(path);
         RuleManager.SaveRule(rule, filePath);
     }
     catch (Exception ex) { }
 }
Esempio n. 13
0
        protected override void FillObject(XmlDescriptor d, RuleElement container)
        {
            base.FillObject(d, container);

            if (Enum.TryParse(d.GetElementName(), true, out WorshipSequenceKind kind))
            {
                (container as WorshipSequence).Kind = kind;
            }
        }
Esempio n. 14
0
        public void WriteGenericRulesElement(RuleElement element)
        {
            writer.Write(@"te = {0}[""{1}""] = new engine.RulesElement(", QuoteIdentifier(element.Type), QuoteString(element.Name));

            element.WriteJS(this.writer);

            writer.WriteLine(");");
            writer.WriteLine("byID[te.id] = te;");
            writer.WriteLine();
        }
        private string GetDestinationFolderPath(RuleElement rule, FileSystemEventArgs e, string outFileName)
        {
            var destinationFolderPath = rule != null ? rule.MovingDestinationFolder : _defaultFolderPath;
            var logInfoMessage        = rule != null
                                 ? string.Format(Messages.RulePassed, e.Name, rule.FilePathTemplate, rule.MovingDestinationFolder)
                                 : string.Format(Messages.RuleNotPassed, e.Name, _defaultFolderPath);

            _logger.LogInfo(logInfoMessage);

            return(Path.Combine(destinationFolderPath, outFileName));
        }
Esempio n. 16
0
        protected override void FillObject(XmlDescriptor d, RuleElement element)
        {
            base.FillObject(d, element);

            XmlAttribute attr = d.Element.Attributes[RuleConstants.KSedalenPlaceAttrName];

            if (Enum.TryParse(attr?.Value, true, out KanonasPlaceKind place))
            {
                (element as KSedalenRule).Place = place;
            }
        }
Esempio n. 17
0
 protected override void FillObject(XmlDescriptor d, RuleElement element)
 {
     foreach (XmlNode childNode in d.Element.ChildNodes)
     {
         RuleElement child = SerializerRoot.Container <RuleElement>().Deserialize(new XmlDescriptor()
         {
             Element = childNode
         });
         (element as ExecContainer).ChildElements.Add(child);
     }
 }
Esempio n. 18
0
 protected override void FillObject(XmlDescriptor d, RuleElement element)
 {
     if (d.Element.HasChildNodes)// && node.FirstChild.Name == RuleConstants.YmnosRuleNode)
     {
         (element as IsExists).ChildElement = SerializerRoot.Container <RuleExecutable, ICalcStructureElement>()
                                              .Deserialize(new XmlDescriptor()
         {
             Element = d.Element.FirstChild
         }) as ICalcStructureElement;
     }
 }
        protected override void FillObject(XmlDescriptor d, RuleElement element)
        {
            base.FillObject(d, element);

            XmlAttribute attr = d.Element.Attributes[RuleConstants.KontakionShowIkosAttrName];

            if (bool.TryParse(attr?.Value, out bool val))
            {
                (element as KontakionRule).ShowIkos = val;
            }
        }
        protected override void FillObject(XmlDescriptor d, RuleElement element)
        {
            base.FillObject(d, element);

            XmlAttribute attr = d.Element.Attributes[RuleConstants.KindAttrName];

            if (Enum.TryParse(attr?.Value, true, out KindOfReplacedDay value))
            {
                (element as ModifyReplacedDay).Kind = value;
            }
        }
Esempio n. 21
0
        protected override void FillObject(XmlDescriptor d, RuleElement container)
        {
            base.FillObject(d, container);

            XmlAttribute attr = d.Element.Attributes[RuleConstants.ShowPsalmAttribute];

            if (bool.TryParse(attr?.Value, out bool showPsalm))
            {
                (container as KekragariaRule).ShowPsalm = showPsalm;
            }
        }
Esempio n. 22
0
        protected override void FillObject(XmlDescriptor d, RuleElement element)
        {
            base.FillObject(d, element);

            var attr = d.Element.Attributes[RuleConstants.KAfterOdiNumberAttrName];

            if (int.TryParse(attr?.Value, out int intValue))
            {
                (element as KAfterRule).OdiNumber = intValue;
            }
        }
Esempio n. 23
0
        private Terminal BuildTerminal(ReteBuilderContext context, RuleElement element, IEnumerable <Declaration> ruleDeclarations)
        {
            if (context.AlphaSource != null)
            {
                BuildJoinNode(context, element);
            }
            var factMap      = IndexMap.CreateMap(ruleDeclarations, context.Declarations);
            var terminalNode = new Terminal(context.BetaSource, factMap);

            return(terminalNode);
        }
Esempio n. 24
0
 protected override void FillObject(XmlDescriptor d, RuleElement element)
 {
     if (d.Element.HasChildNodes)
     {
         (element as DateByDaysFromEaster).ChildExpression = SerializerRoot.Container <IntExpression>()
                                                             .Deserialize(new XmlDescriptor()
         {
             Element = d.Element.FirstChild
         });
     }
 }
Esempio n. 25
0
        protected override void FillObject(XmlDescriptor d, RuleElement element)
        {
            XmlAttribute attr = d.Element.Attributes[RuleConstants.ShortNameAttrName];

            (element as ModifyDay).ShortName = attr?.Value;

            attr = d.Element.Attributes[RuleConstants.IsLastNameAttrName];
            (element as ModifyDay).IsLastName = bool.TryParse(attr?.Value, out bool value) ? value : false;

            attr = d.Element.Attributes[RuleConstants.AsAdditionAttrName];
            (element as ModifyDay).AsAddition = bool.TryParse(attr?.Value, out value) ? value : false;

            attr = d.Element.Attributes[RuleConstants.UseFullNameAttrName];
            (element as ModifyDay).UseFullName = bool.TryParse(attr?.Value, out value) ? value : true;

            attr = d.Element.Attributes[RuleConstants.DayMoveAttrName];
            if (int.TryParse(attr?.Value, out int intValue))
            {
                (element as ModifyDay).DayMoveCount = intValue;
            }

            attr = d.Element.Attributes[RuleConstants.PriorityAttrName];
            (element as ModifyDay).Priority = int.TryParse(attr?.Value, out intValue) ? intValue : 0;

            attr = d.Element.Attributes[RuleConstants.SignNumberAttrName];
            if (int.TryParse(attr?.Value, out intValue))
            {
                (element as ModifyDay).SignNumber = intValue;
            }

            //filter
            DeserializeFilter(d.Element, element as ModifyDay);

            foreach (XmlNode childNode in d.Element.ChildNodes)
            {
                if (childNode.Name == RuleConstants.ModifyReplacedDayNodeName)
                {
                    (element as ModifyDay).ModifyReplacedDay = SerializerRoot.Container <ModifyReplacedDay>()
                                                               .Deserialize(new XmlDescriptor()
                    {
                        Element = childNode
                    });
                }
                else
                {
                    (element as ModifyDay).ChildDateExp = SerializerRoot.Container <DateExpression>()
                                                          .Deserialize(new XmlDescriptor()
                    {
                        Element = childNode
                    });
                }
            }
        }
Esempio n. 26
0
        /// <summary>
        /// Creates an element that represents a negative existential quantifier.
        /// </summary>
        /// <param name="source">Source element to apply the negative existential quantifier to.</param>
        /// <returns>Created element.</returns>
        public static NotElement Not(RuleElement source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source), "Source element not provided");
            }

            var element = new NotElement(source);

            ElementValidator.ValidateNot(element);
            return(element);
        }
Esempio n. 27
0
        private static void AddRule(RuleElement rule)
        {
            using (CustomConfigSectionManager customConfigManager = new CustomConfigSectionManager())
            {
                customConfigManager.AddRule(rule);
            }

            if (Rules == null)
            {
                Rules = new RuleElementCollection();
            }
            Rules.Add(rule);
        }
        public virtual RuleElement Deserialize(IDescriptor descriptor)
        {
            RuleElement element = null;

            if (descriptor is XmlDescriptor d)
            {
                element = CreateObject(d);

                FillObject(d, element);
            }

            return(element);
        }
        protected override void FillObject(XmlDescriptor d, RuleElement element)
        {
            base.FillObject(d, element);

            if (d.Element.SelectSingleNode(RuleConstants.YmnosRuleNode) is XmlNode ymnosNode)
            {
                (element as TheotokionRule).ReferenceYmnos = SerializerRoot.Container <YmnosRule>()
                                                             .Deserialize(new XmlDescriptor()
                {
                    Element = ymnosNode
                });
            }
        }
Esempio n. 30
0
        protected override void FillObject(XmlDescriptor d, RuleElement element)
        {
            foreach (XmlNode childNode in d.Element.ChildNodes)
            {
                var exp = SerializerRoot.Container <RuleExpression>()
                          .Deserialize(new XmlDescriptor()
                {
                    Element = childNode
                });

                (element as LogicalExpression).ChildElements.Add(exp);
            }
        }
Esempio n. 31
0
        private void BuildTypeNode(ReteBuilderContext context, RuleElement element, Type declarationType)
        {
            TypeNode node = context.CurrentAlphaNode
                            .ChildNodes.OfType <TypeNode>()
                            .FirstOrDefault(tn => tn.FilterType.AsType() == declarationType);

            if (node == null)
            {
                node = new TypeNode(declarationType);
                context.CurrentAlphaNode.ChildNodes.Add(node);
            }
            node.NodeInfo.Add(context.Rule, element);
            context.CurrentAlphaNode = node;
        }