Beispiel #1
0
        public PriceRule(RuleName ruleName, RuleType ruleType, string frienldyName, int value, int priority, bool applyNextRules)
        {
            RuleName = ruleName;
            RuleType = ruleType;

            if (string.IsNullOrEmpty(frienldyName) || string.IsNullOrWhiteSpace(frienldyName))
            {
                throw new MissingValueException("Nazwa reguły jest wymagana.");
            }

            if (ruleType.ToString().Contains("Percentage"))
            {
                if (value < 0 || value > 100)
                {
                    throw new HotelException("Nieprawidłowa wartość procentowa reguły.");
                }
            }

            if (priority <= 0)
            {
                throw new HotelException("Priorytet musi być większy od zera.");
            }

            Value          = value;
            Priority       = priority;
            FriendlyName   = frienldyName;
            ApplyNextRules = applyNextRules;
        }
Beispiel #2
0
        public void Add()
        {
            if (RuleName == null)
            {
                RuleName = propInfo.Name;
            }

            if (_service.HasRule(RuleName))
            {
                throw new Exception($"Duplicate rule name: {{{RuleName}}}");
            }

            _service.AddRule(
                new Rule <T, TValue>
            {
                PropertyExpression            = PropertyExpression,
                PropertyInfo                  = propInfo,
                RuleName                      = RuleName,
                RuleNameLowerCase             = RuleName.ToLower(),
                RuleNameLowerCaseWithBrackets = '{' + RuleName + '}',
                Setup   = Setup,
                Stencil = Stencil
            }
                );
        }
Beispiel #3
0
        public Token TokenizeFile(String filePath)
        {
            Token _Ret = new Token();

            if (!File.Exists(filePath))
            {
                return(_Ret);
            }

            string ext = Path.GetExtension(filePath).ToLower();

            if (string.IsNullOrEmpty(ext) || !ext.Equals(".seq"))    //only .seq files are parsed
            {
                return(_Ret);
            }

            /* TODO
             * if (ResourceManager.getProjectRelativePath().segment(0).equalsIgnoreCase("SOURCE")) {
             *  m_IsClassDef = true;  //Version 1   its in //SOURCE//...
             * }
             * if (ResourceManager.getProjectRelativePath().segment(0).equalsIgnoreCase("APP")) {
             *  m_IsClassDef = true;   //Version 2    its in //APP//PLUGINS//...
             * }*/
            String _content = File.ReadAllText(filePath);

            _Ret = Tokenize(_content, filePath);
            Rule Root = new RuleName(null);

            _Ret.SetValue(filePath, _Ret.GetPosStart(), Root, Root);
            return(_Ret);
        }
Beispiel #4
0
        public decimal GetCalculatedPrice(RuleName ruleName, decimal inputPrice)
        {
            var priceRule       = GetRuleByName(ruleName);
            var calculatedPrice = priceRule.GetCalculatedPrice(inputPrice);

            return(calculatedPrice);
        }
Beispiel #5
0
        public SlotModel(ParserRule rule, string baseRule, string baseNamespace, GrammarInfo grammarInfo)
            : base(rule: rule, baseNamespace: baseNamespace)
        {
            if (rule.Alternatives.Count != 1)
            {
                throw new ArgumentException();
            }

            BaseRuleName = baseRule?.ToPascalcase();
            SyntaxKind   = $"{rule.Name.ToPascalcase()}Syntax";

            int index = 0;

            if (IsSection)
            {
                // Überprüfen, ob es sich um eine benannte Sektion handelt
                var expectedSectionName = RuleName.Replace("Section", "Identifier");

                // Die Begin-/End Sektionen muss es geben, andernfalls ist die Grammatik falsch formuliert
                var sb     = grammarInfo.Rules.Single(r => r.Name?.ToPascalcase() == SectionBeginName);
                var sbName = sb.Alternatives.Single().Elements.FirstOrDefault(e => e.Name.ToPascalcase() == expectedSectionName);

                var se     = grammarInfo.Rules.Single(r => r.Name?.ToPascalcase() == SectionEndName);
                var seName = se.Alternatives.Single().Elements.FirstOrDefault(e => e.Name.ToPascalcase() == expectedSectionName);

                if (sbName != null && seName != null)
                {
                    IsNamedSection             = true;
                    NamedSectionIdentifierName = expectedSectionName;
                }
            }

            foreach (var element in rule.Alternatives.Single().Elements)
            {
                var name = element.Name.ToPascalcase();
                if (name == "EOF")
                {
                    name = "Eof";
                }

                var syntaxKind = element.SyntaxKind;
                if (syntaxKind == "EOF")
                {
                    syntaxKind = "Eof";
                }

                Slots.Add(new SlotMemberModel {
                    Name        = name,
                    IsToken     = element is TokenElement,
                    IsLabeled   = element.IsLabeled,
                    SyntaxKind  = syntaxKind,
                    Cardinality = element.Cardinality,
                    SlotIndex   = index++
                });
            }
        }
Beispiel #6
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (RuleName != null ? RuleName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (RuleExpression != null ? RuleExpression.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)Status;
         return(hashCode);
     }
 }
Beispiel #7
0
 /// <summary>
 /// Gets a hash value for the current instance.
 /// </summary>
 /// <returns>The hash value.</returns>
 public override int GetHashCode()
 {
     unchecked
     {
         var hash = 17;
         hash = hash * 23 + ManifestValue.GetHashCode();
         hash = hash * 23 + RuleType.GetHashCode();
         hash = hash * 23 + (RuleName?.GetHashCode() ?? 0);
         return(hash);
     }
 }
Beispiel #8
0
 public override int GetHashCode()
 {
     unchecked {
         var hashCode = Id.GetHashCode();
         hashCode = (hashCode * 397) ^ (SchemaName != null ? SchemaName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (SearchSchemaName != null ? SearchSchemaName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (RuleName != null ? RuleName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ IsActive.GetHashCode();
         hashCode = (hashCode * 397) ^ UseAtSave.GetHashCode();
         hashCode = (hashCode * 397) ^ (RuleBody != null ? RuleBody.GetHashCode() : 0);
         return(hashCode);
     }
 }
Beispiel #9
0
 internal static RuleFunction RuleFunc(RuleName rule)
 {
     switch(rule)
     {
         case RuleName.CanAccessZone:
             return Rule_CanAccessZone;
         case RuleName.CanAccessObject:
             return Rule_CanAccessObject;
         case RuleName.CanManipulateObject:
             return Rule_CanManipulateObject;
         default: 
             return null;
     }
 }
Beispiel #10
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = _operatorName?.GetHashCode() ?? 0;
         hashCode = (hashCode * 397) ^ _operatorValue;
         hashCode = (hashCode * 397) ^ (RuleName?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (Notes?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ Order.GetHashCode();
         hashCode = (hashCode * 397) ^ (int)Field;
         hashCode = (hashCode * 397) ^ (int)Status;
         return(hashCode);
     }
 }
 /// <summary>
 /// Get hash code.
 /// </summary>
 /// <returns></returns>
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (ProjectName != null ? ProjectName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (RuleName != null ? RuleName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)Severity;
         hashCode = (hashCode * 397) ^ (FilePath != null ? FilePath.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)Line;
         hashCode = (hashCode * 397) ^ (DeepLink != null ? DeepLink.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (int)Status;
         hashCode = (hashCode * 397) ^ FalsePositive.GetHashCode();
         return(hashCode);
     }
 }
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (WorkCell != null ? WorkCell.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (WorkUnit != null ? WorkUnit.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ Actual.GetHashCode();
         hashCode = (hashCode * 397) ^ Remaining.GetHashCode();
         hashCode = (hashCode * 397) ^ Set.GetHashCode();
         hashCode = (hashCode * 397) ^ OverflowRemaining.GetHashCode();
         hashCode = (hashCode * 397) ^ OverflowSet.GetHashCode();
         hashCode = (hashCode * 397) ^ (RuleName != null ? RuleName.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (RuleType != null ? RuleType.GetHashCode() : 0);
         return(hashCode);
     }
 }
Beispiel #13
0
        /// <summary>
        /// This created a new entry for our DictOfErrors and then adds it to it.
        /// </summary>
        /// <param name="target">Target that broke the rule</param>
        /// <param name="errorName">Name of the rule broken</param>
        /// <param name="errorMessage">the errorMessage associated with that error</param>
        public void addError(object target, RuleName errorName, string errorMessage)
        {
            List <Tuple <RuleName, string> > temp = new List <Tuple <RuleName, string> >();

            if (DictOfErrors.TryGetValue(target, out temp))
            {
                temp.Add(new Tuple <RuleName, string>(errorName, errorMessage));
                DictOfErrors.Remove(target);
            }
            else
            {
                temp = new List <Tuple <RuleName, string> >();
                temp.Add(new Tuple <RuleName, string>(errorName, errorMessage));
            }
            DictOfErrors.Add(target, temp);
        }
        public string JavaScript()
        {
            System.Text.StringBuilder bldr = new System.Text.StringBuilder();

            bldr.Append("function(value) {if (");
            bldr.Append(RuleName.Replace(" ", "_"));
            bldr.Append("(value");

            if (AllowedValue != null)
            {
                bldr.Append(string.Format(", {0}))", AllowedValueString()));
            }
            else
            {
                bldr.Append("))");
            }
            bldr.Append(" return ");
            bldr.Append(Description.Surround("'"));

            bldr.Append("; }");
            return(bldr.ToString());
        }
Beispiel #15
0
        private void RenameRule( )
        {
            string newName = RuleName;

            if (InputDialog.ShowDialog("Rename Rule", "New Name", ref newName) != DialogResult.OK)
            {
                return;
            }

            if (RuleName.ToLowerInvariant() == newName.ToLowerInvariant())
            {
                return;
            }

            DbCmd.RenameRule(_cp, _owner, _ruleName, newName);
            RuleName     = newName;
            txtName.Text = RuleName;

            if (_afterRuleRenamed != null)
            {
                _afterRuleRenamed(this, EventArgs.Empty);
            }
        }
Beispiel #16
0
        public Token Tokenize(String stream, String filePath)
        {
            int   Pos = 0;
            Token Result;
            Token FileNode = new Token();
            Rule  Root     = new RuleName(null);

            FileNode.SetValue("", 0, Root, Root);
            DateTime _start = DateTime.Now;

            Log.getInstance().Add("Tokenize " + filePath, Log.EnuSeverity.Info, "");
            while (Pos < stream.Length)
            {
                Result = Rules.Evaluate(stream, ref Pos);
                if (Result != null && Result.IsValid())
                {
                    FileNode.AddLast(Result);
                }
                else
                {
                    RuleAnyLine x = new RuleAnyLine(null);
                    Result = x.Evaluate(stream, ref Pos);
                    Result.SetError("invalid:" + Rules.GetError() + " at " + Pos.ToString());
                    FileNode.AddLast(Result);
                    Log.getInstance().Add("invalid:" + Rules.GetError() + " at " + Pos.ToString(),
                                          Log.EnuSeverity.Warn,
                                          filePath + "@" + Pos.ToString());
                    break;
                }
            }
            DateTime _end = DateTime.Now;
            TimeSpan dt   = _end - _start;

            Log.getInstance().Add("Tokenized " + filePath + " in " + dt.TotalMilliseconds.ToString() + " ms", Log.EnuSeverity.Info, "");
            return(FileNode);
        }
Beispiel #17
0
        protected Sequence ReadSequence()
        {
            Sequence seq = null;

            if (!Eof)
            {
                SkipWhite();

                if (IsLetter)
                {
                    seq = new RuleName()
                    {
                        Name = ReadRuleName()
                    }
                }
                ;
                else
                {
                    switch (Current)
                    {
                    case '\'':
                    case '"':
                        seq = new Terminal()
                        {
                            Value = ReadTerminal()
                        };
                        break;

                    case '[':
                        Next();
                        seq = new Optional()
                        {
                            Sequence = ReadSequence()
                        };
                        Match("]");
                        break;

                    case '{':
                        Next();
                        seq = new Repetition()
                        {
                            Sequence = ReadSequence()
                        };
                        Match("}");
                        break;

                    case '(':
                        Next();
                        seq = new Grouping()
                        {
                            Sequence = ReadSequence()
                        };
                        Match(")");
                        break;
                    }
                }

                SkipWhite();

                if (!Eof)
                {
                    switch (Current)
                    {
                    case ',':
                        Next();

                        if (seq == null)
                        {
                            seq = new Empty();
                        }

                        seq.Next = ReadSequence();
                        break;

                    case '|':
                        Next();

                        if (seq == null)
                        {
                            seq = new Empty();
                        }

                        seq.Alternative = ReadSequence();
                        break;
                    }
                }
            }

            if (seq == null)
            {
                seq = new Empty();
            }

            return(seq);
        }
Beispiel #18
0
        public int CompareTo(object rule)
        {
            Rule r = (Rule)rule;

            return(RuleName.CompareTo(r.RuleName));
        }
 public IActionResult Validate([FromBody] RuleName trade)
 {
     // TODO: check data valid and save to db, after saving return RuleName list
     return(View("ruleName/add"));
 }
 public IActionResult updateRuleName(int id, [FromBody] RuleName rating)
 {
     // TODO: check required fields, if valid call service to update RuleName and return RuleName list
     return(Redirect("/ruleName/list"));
 }
Beispiel #21
0
 private static bool? CheckCache(RuleName name, IHasState x, IHasState y)
 {
     RuleCache cache;
     if (cacheRules == null)
         return null;
     if (cacheRules.TryGetValue(name, out cache) == false)
         return null;
     return cache.Get(x, y);
 }
 public IActionResult AddRuleName([FromBody] RuleName trade)
 {
     return(View("ruleName/add"));
 }
Beispiel #23
0
        public PsiUnresolvedRuleReferenceHighlighting(RuleName element)
        {
            myElement = element;

            myReference = element.RuleNameReference;
        }
Beispiel #24
0
 private static IEnumerable<IHasState> GetLHSSatisfiers(
     IEnumerable<IHasState> scope,
     RuleName rule,
     IHasState Y)
 {
     Variable X = new Variable();
     foreach (bool l2 in RuleDefs.RuleFunc(rule)(scope, X, Y))
         yield return X.GetValue<IHasState>();
 }
Beispiel #25
0
 public Result(List <Card> cards, RuleName rule)
 {
     Cards = cards;
     Rule  = rule;
 }
Beispiel #26
0
    public static bool IsRuleSatisfied(
        IEnumerable<IHasState> scope,
        RuleName rule,
        IHasState X,
        IHasState Y)
    {
        int checksum = GetScopeCheckSum(scope);
        if (DEBUG_scopeChecksum.HasValue == true)
            if (checksum != DEBUG_scopeChecksum.Value)
                Debug.LogError("Scope checksum mismatch with cached checksum");
        DEBUG_scopeChecksum = checksum;

        bool? cached = CheckCache(rule, X, Y);
        if (cached.HasValue == true)
            return cached.Value;

        bool evaluated = EvaluateRule(scope, rule, X, Y);
        StoreCache(rule, X, Y, evaluated);
        return evaluated;
    }
Beispiel #27
0
 private static IEnumerable<Tuple<IHasState, IHasState>> GetRuleSatisfiers(
     IEnumerable<IHasState> scope,
     RuleName rule)
 {
     Variable X = new Variable();
     Variable Y = new Variable();
     foreach (bool l2 in RuleDefs.RuleFunc(rule)(scope, X, Y))
         yield return new Tuple<IHasState, IHasState>(
             X.GetValue<IHasState>(),
             Y.GetValue<IHasState>());
 }
 internal bool IsDefault()
 {
     return(RuleName.Equals(Default));
 }
Beispiel #29
0
 private static bool EvaluateRule(
     IEnumerable<IHasState> scope,
     RuleName rule,
     IHasState X,
     IHasState Y)
 {
     foreach (bool l2 in RuleDefs.RuleFunc(rule)(scope, X, Y))
         return true;
     return false;
 }
Beispiel #30
0
 private static void StoreCache(
     RuleName rule,
     IHasState x,
     IHasState y,
     bool value)
 {
     if (cacheRules == null)
         cacheRules = new Dictionary<RuleName, RuleCache>();
     if (cacheRules.ContainsKey(rule) == false)
         cacheRules[rule] = new RuleCache();
     cacheRules[rule].Store(x, y, value);
 }
Beispiel #31
0
 public PriceRule GetRuleByName(RuleName ruleName) => _priceRules.FirstOrDefault(x => x.RuleName == ruleName);