Ejemplo n.º 1
0
 protected override OperatorHandler MakeHandler(int priority,
                                                Func <Expression, Expression, Expression> binaryOperator)
 {
     // An unintelligable but very slick operator priority algorithm.
     if (this.priority < priority)
     {
         return((priorPriority, priorOperator) =>
         {
             if (this.priority < priorPriority)
             {
                 return priorOperand => previous_handler(this.priority, operand => operand)(
                     priorOperator(binaryOperator(Expression, priorOperand)));
             }
             else
             {
                 return priorOperand => previous_handler(
                     priorPriority, operand => priorOperator(operand))(
                     binaryOperator(Expression, priorOperand));
             }
         });
     }
     else
     {
         return((priorPriority, priorOperator) => priorOperand => priorOperator(previous_handler(
                                                                                    priorPriority, operand => binaryOperator(operand, priorOperand))(Expression)));
     }
 }
 public override void BuildAst(LanguageData language, ParseTree parseTree) {
   var opHandler = new OperatorHandler(language.Grammar.CaseSensitive);
   Util.Check(!parseTree.HasErrors(), "ParseTree has errors, cannot build AST.");
   var astContext = new InterpreterAstContext(language, opHandler);
   var astBuilder = new AstBuilder(astContext);
   astBuilder.BuildAst(parseTree);
 }
Ejemplo n.º 3
0
        public override void DoDelete()
        {
            if (_current == null)
            {
                return;
            }


            try
            {
                if (XtraMessageBox.Show("L'elemento sarà eliminato solamente se nel sistema non ci sono altri riferimenti all'elemento oppure se non è un elemento predefinito. Sicuro di voler procedere? ", "Elimina elemento", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Nested_CheckSecurityForDeletion();

                    OperatorHandler h = new OperatorHandler();
                    h.Delete(_current);

                    _mainForm.NavigatorUtility.NavigateToPrevious();
                }
            }
            catch (AccessDeniedException)
            {
                XtraMessageBox.Show("Impossibile accedere alla funzionalità richiesta. Accesso negato", "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                ErrorHandler.Show(ex);
            }
        }
Ejemplo n.º 4
0
        private void LoadGrid()
        {
            OperatorHandler h = new OperatorHandler();

            IList l = h.GetAll();

            gridControl1.DataSource = l;
        }
Ejemplo n.º 5
0
 public AstContext(string fileName, LanguageData language, OperatorHandler operationHandler = null) : base(language)
 {
     OperationHandler          = operationHandler ?? new OperatorHandler();
     DefaultIdentifierNodeType = typeof(IdentifierNode);
     DefaultLiteralNodeType    = typeof(LiteralValueNode);
     DefaultNodeType           = typeof(AstNode);
     FileName = fileName;
 }
Ejemplo n.º 6
0
        private void SaveOrUpdate()
        {
            _current.Descrizione = txtDescrizione.Text;
            _current.Color       = cboColor.Color.ToArgb();

            OperatorHandler h = new OperatorHandler();

            h.SaveOrUpdate(_current);
        }
Ejemplo n.º 7
0
 public JoinedExpressionParser(Expression expression,
                               int parentheses,
                               int priority,
                               OperatorHandler previousHandler)
     : base(expression, parentheses)
 {
     this.previous_handler = previousHandler;
     this.priority         = priority;
 }
Ejemplo n.º 8
0
 public JunctionParser(string junction,
                       int parentheses,
                       int priority,
                       OperatorHandler previousHandler)
 {
     this.junction         = junction;
     this.parentheses      = parentheses;
     this.priority         = priority;
     this.previous_handler = previousHandler;
 }
Ejemplo n.º 9
0
        public override void BuildAst(LanguageData language, ParseTree parseTree)
        {
            var opHandler = new OperatorHandler(language.Grammar.CaseSensitive);

            Util.Ensure(!parseTree.HasErrors, "ParseTree has errors, cannot build AST.");
            var astContext = new InterpreterAstContext(language, opHandler);
            var astBuilder = new AstBuilder(astContext);

            astBuilder.BuildAst(parseTree);
        }
Ejemplo n.º 10
0
        protected override void Nested_LoadDataFromDataSource()
        {
            OperatorHandler h = new OperatorHandler();

            _current = h.GetElementById(m_IdShowedObject.ToString()) as WIN.SCHEDULING_APPLICATION.DOMAIN.ComboElements.Operator;;

            if (_current == null)
            {
                throw new Exception("Elemento non trovato");
            }
        }
Ejemplo n.º 11
0
        private static void RegisteOperator(char op, int priority, int paramCount, OperatorHandler handler)
        {
            Operator o = new Operator();

            o.op               = op;
            o.priority         = priority;
            o.desiredParaCount = paramCount;
            o.handler          = handler;

            operators[op] = o;
        }
Ejemplo n.º 12
0
        private void LoadListaOperatori()
        {
            lstOp.Items.Clear();

            OperatorHandler h = new OperatorHandler();

            foreach (Operator item in h.GetAll())
            {
                lstOp.Items.Add(item);
            }
        }
Ejemplo n.º 13
0
        public override void BuildAst(LanguageData language, ParseTree parseTree)
        {
            //return;
            var opHandler = new OperatorHandler();

            Util.Check(!parseTree.HasErrors(), "ParseTree has errors, cannot build AST.");
            var astContext = new AstContext(parseTree.FileName, language, opHandler);
            var astBuilder = new Irony.Ast.AstBuilder(astContext);

            astBuilder.BuildAst(parseTree);
        }
Ejemplo n.º 14
0
        private void LoadComboOperatori()
        {
            //preparo la combo delle zone
            cboOp.Properties.Items.Clear();

            OperatorHandler h = new OperatorHandler();

            //la riempio
            cboOp.Properties.Items.Add("");
            cboOp.Properties.Items.AddRange(h.GetAll());

            //seleziono quella iniziale
            cboOp.SelectedIndex = 0;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Evaluates the given (simple) expression
        ///
        /// TODO: Use Polish Notation to allow more efficiency and complexity
        /// TODO: Add operator priority
        /// </summary>
        public static bool Eval(Type valType, ref long val, string expr, ref object error, bool startsWithOperator)
        {
            // syntax: <val> <op> <value> [<op> <value> [<op> <value>...]]
            var args = expr.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var isOp = startsWithOperator;
            OperatorHandler <long> op = null;

            foreach (var argument in args)
            {
                var arg = argument.Trim();
                if (isOp)
                {
                    if (!IntOperators.TryGetValue(arg, out op))
                    {
                        error = "Invalid operator: " + arg;
                        return(false);
                    }
                }
                else
                {
                    object argVal = null;
                    if (!Parse(arg, valType, ref argVal))
                    {
                        error = "Could not convert value \"" + arg + "\" to Type \"" + valType + "\"";
                        return(false);
                    }

                    var longVal = (long)Convert.ChangeType(argVal, typeof(long));
                    if (op != null)
                    {
                        val = op(val, longVal);
                    }
                    else
                    {
                        val = longVal;
                    }
                }
                isOp = !isOp;
            }
            return(true);
        }
Ejemplo n.º 16
0
        //public CustomPrincipal(string firstName, string lastName, string badge, string cardNumber, string sessionId) : base(new GenericIdentity(badge))
        //{
        //    Logger.WriteDebug("SessionId:" + sessionId);
        //    var hasAccess = false;
        //    var key = $"{firstName}_{lastName}_{badge}_{cardNumber}_{sessionId}";
        //    if (Cache.Get(key) is bool cacheFound)
        //        hasAccess = cacheFound;
        //    else
        //    {
        //        hasAccess = AsyncHelpers.RunSync(async () =>
        //        {
        //            using (var service = new OperatorHandler())
        //            {
        //                return await service.IsValidSessionAsync(firstName, lastName, badge, sessionId);
        //            }
        //        });
        //        Cache.Add(key, hasAccess, null, DateTime.Now.AddMinutes(5), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
        //    }



        //    if (!hasAccess)
        //        throw new UnauthorizedAccessException();

        //}
        public CustomPrincipal(string badge, string deviceGuid, string sessionId) : base(new GenericIdentity(badge))
        {
            Logger.WriteDebug($"Badge: {badge}, SessionId: {sessionId}, deviceGuid: {deviceGuid}");
            var hasAccess = false;
            var jobTitle  = "";
            var user      = "";
            var key       = $"{badge}_{sessionId}";

            if (Cache.Get(key) is Tuple <bool, string, string> cacheFound)
            {
                hasAccess = cacheFound.Item1;
                jobTitle  = cacheFound.Item2;
                user      = cacheFound.Item3;
            }
            else
            {
                hasAccess = AsyncHelpers.RunSync(async() =>
                {
                    using (var service = new OperatorHandler())
                    {
                        var result = await service.IsValidSessionAsync(badge, deviceGuid, sessionId);
                        jobTitle   = result.Item2;
                        user       = result.Item3;
                        return(result.Item1);
                    }
                });
                Cache.Add(key, new Tuple <bool, string, string>(hasAccess, jobTitle, user), null, DateTime.Now.AddMinutes(5), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
            }


            if (!hasAccess)
            {
                throw new UnauthorizedAccessException();
            }


            var claims = new List <Claim>();

            Identity.AddClaim(new Claim("JobTitle", jobTitle));
            Identity.AddClaim(new Claim("User", user));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Evaluates the given (simple) expression
        ///
        /// TODO: Use Polish Notation to allow more efficiency and complexity
        /// TODO: Add operator priority
        /// </summary>
        public static bool Eval(Type valType, ref long val, string expr, ref object error, bool startsWithOperator)
        {
            string[] strArray = expr.Split(new char[1] {
                ' '
            }, StringSplitOptions.RemoveEmptyEntries);
            bool flag = startsWithOperator;
            OperatorHandler <long> operatorHandler = null;

            foreach (string str1 in strArray)
            {
                string str2 = str1.Trim();
                if (flag)
                {
                    if (!IntOperators.TryGetValue(str2, out operatorHandler))
                    {
                        error = "Invalid operator: " + str2;
                        return(false);
                    }
                }
                else
                {
                    object obj = null;
                    if (!Parse(str2, valType, ref obj))
                    {
                        error = "Could not convert value \"" + str2 + "\" to Type \"" + valType +
                                "\"";
                        return(false);
                    }

                    long y = (long)Convert.ChangeType(obj, typeof(long));
                    val = operatorHandler == null ? y : operatorHandler(val, y);
                }

                flag = !flag;
            }

            return(true);
        }
Ejemplo n.º 18
0
        /// <summary>Creates a new instance of the <see cref="CqlGrammar" /> class.</summary>
        public CqlGrammar() :
            base(true)
        {
            GrammarComments = "OGC Common Catalogue Query Language grammar as defined in [OGC 07-006r1 §6.2.2]";

            // Terminals
            var identifier = new IdentifierTerminal("identifier", ":", "");

            identifier.StartCharCategories.AddRange(
                new UnicodeCategory[] {
                UnicodeCategory.UppercaseLetter,     //Ul
                UnicodeCategory.LowercaseLetter      //Ll
            }
                );
            identifier.CharCategories.AddRange(
                new UnicodeCategory[] {
                UnicodeCategory.UppercaseLetter,     //Ul
                UnicodeCategory.LowercaseLetter,     //Ll
                UnicodeCategory.DecimalDigitNumber   //Nd
            }
                );
            //var digit_literal=new FixedLengthLiteral("digit", 1, TypeCode.Byte);
            var numeric_literal          = new NumberLiteral("numeric literal", NumberOptions.AllowSign, typeof(Ast.DefaultLiteralNode));
            var unsigned_numeric_literal = new NumberLiteral("unsigned numeric literal", NumberOptions.None, typeof(Ast.DefaultLiteralNode));
            //var integer_literal=new NumberLiteral("integer literal", NumberOptions.IntOnly | NumberOptions.NoDotAfterInt);
            //var character_literal=new StringLiteral("character literal", "'", StringOptions.IsChar | StringOptions.AllowsDoubledQuote);
            var string_literal = new StringLiteral("string literal", "'", StringOptions.AllowsDoubledQuote, typeof(Ast.DefaultLiteralNode));
            var period         = ToTerm(".", "period");
            var comma          = ToTerm(",", "comma");
            var left_paren     = ToTerm("(", "left paren");
            var right_paren    = ToTerm(")", "right paren");

            left_paren.SetFlag(TermFlags.IsOpenBrace);
            left_paren.IsPairFor = right_paren;
            right_paren.SetFlag(TermFlags.IsCloseBrace);
            right_paren.IsPairFor = left_paren;

            var TRUE    = ToTerm("TRUE");
            var FALSE   = ToTerm("FALSE");
            var UNKNOWN = ToTerm("UNKNOWN");
            var NULL    = ToTerm("NULL");

            var AFTER        = ToTerm("AFTER");
            var AND          = ToTerm("AND");
            var BEFORE       = ToTerm("BEFORE");
            var BEYOND       = ToTerm("BEYOND");
            var CONTAINS     = ToTerm("CONTAINS");
            var CROSSES      = ToTerm("CROSSES");
            var DISJOINT     = ToTerm("DISJOINT");
            var DOESNOTEXIST = ToTerm("DOESNOTEXIST");
            var DURING       = ToTerm("DURING");
            var DWITHIN      = ToTerm("DWITHIN");
            var EQUALS       = ToTerm("EQUALS", "Equal");
            var EXISTS       = ToTerm("EXISTS");
            var INTERSECTS   = ToTerm("INTERSECTS");
            var LIKE         = ToTerm("LIKE");
            var NOT          = ToTerm("NOT");
            var OR           = ToTerm("OR");
            var OVERLAPS     = ToTerm("OVERLAPS");
            var RELATE       = ToTerm("RELATE");
            var TOUCHES      = ToTerm("TOUCHES");
            var WITHIN       = ToTerm("WITHIN");

            var equals_operator                 = ToTerm("=", "equals operator");
            var greater_than_operator           = ToTerm(">", "greater than operator");
            var less_than_operator              = ToTerm("<", "less than operator");
            var not_equals_operator             = ToTerm("<>", "not equals operator");
            var greater_than_or_equals_operator = ToTerm(">=", "greater than or equals operator");
            var less_than_or_equals_operator    = ToTerm("<=", "less than or equals operator");
            var date_time = new RegexBasedTerminal(name: "date-time", pattern: @"(?<fulldate>(?<dateyear>\d{4})-(?<datemonth>\d{2})-(?<dateday>\d{2}))T(?<UTCtime>(?<timehour>\d{2}):(?<timeminute>\d{2}):(?<timesecond>\d{2}(\.\d+)?)Z)");
            var duration  = new RegexBasedTerminal(name: "duration", pattern: @"P((?<duryear>\d+)Y)?((?<durmonth>\d+)M)?((?<durday>\d+)D)?(T((?<durhour>\d+)H)?((?<durminute>\d+)M)?((?<dursecond>\d+)S)?)?");

            AFTER.AstConfig.NodeType        = typeof(Ast.OperatorNameNode);
            AND.AstConfig.NodeType          = typeof(Ast.OperatorNameNode);
            BEFORE.AstConfig.NodeType       = typeof(Ast.OperatorNameNode);
            BEYOND.AstConfig.NodeType       = typeof(Ast.OperatorNameNode);
            CONTAINS.AstConfig.NodeType     = typeof(Ast.OperatorNameNode);
            CROSSES.AstConfig.NodeType      = typeof(Ast.OperatorNameNode);
            DISJOINT.AstConfig.NodeType     = typeof(Ast.OperatorNameNode);
            DURING.AstConfig.NodeType       = typeof(Ast.OperatorNameNode);
            DOESNOTEXIST.AstConfig.NodeType = typeof(Ast.OperatorNameNode);
            DURING.AstConfig.NodeType       = typeof(Ast.OperatorNameNode);
            DWITHIN.AstConfig.NodeType      = typeof(Ast.OperatorNameNode);
            EQUALS.AstConfig.NodeType       = typeof(Ast.OperatorNameNode);
            EXISTS.AstConfig.NodeType       = typeof(Ast.OperatorNameNode);
            INTERSECTS.AstConfig.NodeType   = typeof(Ast.OperatorNameNode);
            LIKE.AstConfig.NodeType         = typeof(Ast.OperatorNameNode);
            NOT.AstConfig.NodeType          = typeof(Ast.NotKeywordNode);
            OR.AstConfig.NodeType           = typeof(Ast.OperatorNameNode);
            OVERLAPS.AstConfig.NodeType     = typeof(Ast.OperatorNameNode);
            //RELATE.AstConfig.NodeType=typeof(Ast.OperatorNameNode);
            TOUCHES.AstConfig.NodeType = typeof(Ast.OperatorNameNode);
            WITHIN.AstConfig.NodeType  = typeof(Ast.OperatorNameNode);

            date_time.AstConfig.NodeType = typeof(Ast.DateTimeLiteralNode);
            duration.AstConfig.NodeType  = typeof(Ast.DurationLiteralNode);

            // Non terminals
            var optional_not = new NonTerminal("optional not", Empty | NOT);

            var attribute_name           = new NonTerminal("attribute name", typeof(Ast.AttributeNameNode));
            var search_condition         = new NonTerminal("search condition");
            var boolean_value_expression = new NonTerminal("boolean value expression", typeof(Ast.BooleanValueExpressionNode));
            var boolean_term             = new NonTerminal("boolean term", typeof(Ast.BooleanTermNode));
            var boolean_factor           = new NonTerminal("boolean factor", typeof(Ast.BooleanFactorNode));
            var boolean_primary          = new NonTerminal("boolean primary");
            var predicate            = new NonTerminal("predicate");
            var temporal_predicate   = new NonTerminal("temporal predicate", typeof(Ast.TemporalPredicateNode));
            var date_time_expression = new NonTerminal("date-time expression");
            var existence_predicate  = new NonTerminal("existence predicate", typeof(Ast.ExistencePredicateNode));
            var comparison_predicate = new NonTerminal("comparison predicate", typeof(Ast.ComparisonPredicateNode));
            var text_predicate       = new NonTerminal("text predicate", typeof(Ast.TextPredicateNode));
            var null_predicate       = new NonTerminal("null predicate", typeof(Ast.NullPredicateNode));
            var comp_op         = new NonTerminal("comp op", equals_operator | not_equals_operator | less_than_operator | greater_than_operator | less_than_or_equals_operator | greater_than_or_equals_operator);
            var general_literal = new NonTerminal("general literal");
            var literal         = new NonTerminal("literal");
            var boolean_literal = new NonTerminal("boolean literal", TRUE | FALSE | UNKNOWN);

            boolean_literal.AstConfig.NodeType = typeof(Ast.BooleanLiteralNode);
            var routine_invocation   = new NonTerminal("routine invocation");
            var geoop_routine        = new NonTerminal("geoop routine", typeof(Ast.GeoOperatorRoutineNode));
            var relgeoop_routine     = new NonTerminal("relgeoop routine", typeof(Ast.RelativeGeoOperatorRoutineNode));
            var routine              = new NonTerminal("routine");
            var geoop_name           = new NonTerminal("geoop name");
            var relgeoop_name        = new NonTerminal("relgeoop name");
            var argument             = new NonTerminal("argument");
            var positional_arguments = new NonTerminal("positional arguments");
            var tolerance            = new NonTerminal("tolerance", typeof(Ast.ToleranceNode));
            var distance_units       = new NonTerminal("distance units");

            var geometry_literal               = new NonTerminal("geometry literal", typeof(Ast.GeometryLiteralNode));
            var geometry_literal_series        = new NonTerminal("geometry literal series");
            var point_tagged_text              = new NonTerminal("Point Tagged Text");
            var linestring_tagged_text         = new NonTerminal("LineString Tagged Text");
            var polygon_tagged_text            = new NonTerminal("Polygon Tagged Text");
            var multipoint_tagged_text         = new NonTerminal("MultiPoint Tagged Text");
            var multilinestring_tagged_text    = new NonTerminal("MultiLineString Tagged Text");
            var multipolygon_tagged_text       = new NonTerminal("MultiPolygon Tagged Text");
            var geometrycollection_tagged_text = new NonTerminal("GeometryCollection Tagged Text");
            var point_text        = new NonTerminal("Point Text");
            var point_text_series = new NonTerminal("Point Text series");
            var point             = new NonTerminal("Point");
            var point_series      = new NonTerminal("Point series");
            var x = new NonTerminal("x");
            var y = new NonTerminal("y");
            var linestring_text         = new NonTerminal("LineString Text");
            var linestring_text_series  = new NonTerminal("LineString Text series");
            var polygon_text            = new NonTerminal("Polygon Text");
            var polygon_text_series     = new NonTerminal("Polygon Text series");
            var multipoint_text         = new NonTerminal("MultiPoint Text");
            var multilinestring_text    = new NonTerminal("MultiLineString Text");
            var multipolygon_text       = new NonTerminal("MultiPolygon Text");
            var geometrycollection_text = new NonTerminal("GeometryCollection Text");
            var envelope_tagged_text    = new NonTerminal("Envelope Tagged Text");
            var envelope_text           = new NonTerminal("Envelope Text");
            var westboundlongitude      = new NonTerminal("WestBoundLongitude", numeric_literal);
            var eastboundlongitude      = new NonTerminal("EastBoundLongitude", numeric_literal);
            var northboundlongitude     = new NonTerminal("NorthBoundLongitude", numeric_literal);
            var southboundlongitude     = new NonTerminal("SouthBoundLongitude", numeric_literal);

            var date_time_period = new NonTerminal("date-time period", typeof(Ast.DateTimePeriodNode));

            identifier.AstConfig.NodeType = typeof(IdentifierNode);
            attribute_name.Rule           = MakePlusRule(attribute_name, period, identifier);

            search_condition.Rule         = boolean_value_expression;
            boolean_value_expression.Rule = MakePlusRule(boolean_value_expression, OR, boolean_term);
            boolean_term.Rule             = MakePlusRule(boolean_term, AND, boolean_factor);
            boolean_factor.Rule           = optional_not + boolean_primary;
            boolean_primary.Rule          = predicate | routine_invocation | (left_paren + search_condition + right_paren);
            predicate.Rule            = comparison_predicate | text_predicate | null_predicate | temporal_predicate | existence_predicate;
            temporal_predicate.Rule   = (attribute_name + BEFORE + date_time_expression) | (attribute_name + BEFORE + OR + DURING + date_time_period) | (attribute_name + DURING + date_time_period) | (attribute_name + DURING + OR + AFTER + date_time_period) | (attribute_name + AFTER + date_time_expression);
            date_time_expression.Rule = date_time | date_time_period;
            existence_predicate.Rule  = (attribute_name + EXISTS) | (attribute_name + DOESNOTEXIST);
            comparison_predicate.Rule = attribute_name + comp_op + literal;
            text_predicate.Rule       = attribute_name + optional_not + LIKE + string_literal;
            null_predicate.Rule       = attribute_name + "IS" + optional_not + NULL;
            general_literal.Rule      = string_literal | boolean_literal | date_time_expression | geometry_literal;
            literal.Rule              = numeric_literal | general_literal;
            routine_invocation.Rule   = geoop_routine | relgeoop_routine | routine;
            geoop_name.Rule           = EQUALS | DISJOINT | INTERSECTS | TOUCHES | CROSSES | WITHIN | CONTAINS | OVERLAPS | RELATE;
            relgeoop_name.Rule        = DWITHIN | BEYOND;
            argument.Rule             = literal | attribute_name;
            positional_arguments.Rule = MakePlusRule(positional_arguments, comma, argument);
            geoop_routine.Rule        = geoop_name + left_paren + attribute_name + comma + geometry_literal + right_paren;
            relgeoop_routine.Rule     = relgeoop_name + left_paren + attribute_name + comma + geometry_literal + comma + tolerance + right_paren;
            routine.Rule              = attribute_name + left_paren + positional_arguments + right_paren;
            tolerance.Rule            = unsigned_numeric_literal + comma + distance_units;
            distance_units.Rule       = ToTerm("feet") | "meters" | ("statute" + "miles") | ("nautical" + "miles") | "kilometers";

            geometry_literal.Rule               = point_tagged_text | linestring_tagged_text | polygon_tagged_text | multipoint_tagged_text | multilinestring_tagged_text | multipolygon_tagged_text | geometrycollection_tagged_text | envelope_tagged_text;
            geometry_literal_series.Rule        = MakePlusRule(geometry_literal_series, comma, geometry_literal);
            point_tagged_text.Rule              = ToTerm("POINT") + point_text;
            linestring_tagged_text.Rule         = ToTerm("LINESTRING") + linestring_text;
            polygon_tagged_text.Rule            = ToTerm("POLYGON") + polygon_text;
            multipoint_tagged_text.Rule         = ToTerm("MULTIPOINT") + multipoint_text;
            multilinestring_tagged_text.Rule    = ToTerm("MULTILINESTRING") + multilinestring_text;
            multipolygon_tagged_text.Rule       = ToTerm("MULTIPOLYGON") + multipolygon_text;
            geometrycollection_tagged_text.Rule = ToTerm("GEOMETRYCOLLECTION") + geometrycollection_text;
            point_text.Rule        = Empty | (left_paren + point + right_paren);
            point_text_series.Rule = MakePlusRule(point_text_series, comma, point_text);
            point.Rule             = x + y;
            x.Rule                       = numeric_literal;
            y.Rule                       = numeric_literal;
            point_series.Rule            = MakePlusRule(point_series, comma, point);
            linestring_text.Rule         = Empty | (left_paren + point_series + right_paren);
            linestring_text_series.Rule  = MakePlusRule(linestring_text_series, comma, linestring_text);
            polygon_text.Rule            = Empty | (left_paren + linestring_text_series + right_paren);
            polygon_text_series.Rule     = MakePlusRule(polygon_text_series, comma, polygon_text);
            multipoint_text.Rule         = Empty | (left_paren + point_text_series + right_paren);
            multilinestring_text.Rule    = Empty | (left_paren + linestring_text_series + right_paren);
            multipolygon_text.Rule       = Empty | (left_paren + polygon_text_series + right_paren);
            geometrycollection_text.Rule = Empty | (left_paren + geometry_literal_series + right_paren);
            envelope_tagged_text.Rule    = ToTerm("ENVELOPE") + envelope_text;
            envelope_text.Rule           = Empty | left_paren + westboundlongitude + comma + eastboundlongitude + comma + northboundlongitude + comma + southboundlongitude + right_paren;

            date_time_period.Rule     = (date_time + "/" + date_time) | (date_time + "/" + duration) | (duration + "/" + date_time);
            date_time_expression.Rule = date_time | date_time_period;

            // Operators
            RegisterOperators(10, equals_operator, not_equals_operator, greater_than_operator, greater_than_or_equals_operator, less_than_operator, less_than_or_equals_operator);
            RegisterOperators(3, NOT);
            RegisterOperators(2, OR);
            RegisterOperators(1, AND);
            RegisterOperators(0, BEYOND, WITHIN);

            _OperatorHandler = new OperatorHandler(true);
            var oid = _OperatorHandler.BuildDefaultOperatorMappings();

            oid.Clear();
            oid.Add(equals_operator.Text, ExpressionType.Equal, 10);
            oid.Add(not_equals_operator.Text, ExpressionType.NotEqual, 10);
            oid.Add(greater_than_operator.Text, ExpressionType.GreaterThan, 10);
            oid.Add(greater_than_or_equals_operator.Text, ExpressionType.GreaterThanOrEqual, 10);
            oid.Add(less_than_operator.Text, ExpressionType.LessThan, 10);
            oid.Add(less_than_or_equals_operator.Text, ExpressionType.LessThanOrEqual, 10);
            oid.Add(NOT.Text, ExpressionType.Not, 3);
            oid.Add(OR.Text, ExpressionType.OrElse, 2);
            oid.Add(AND.Text, ExpressionType.AndAlso, 1);

            oid.Add(BEYOND.Text, ExpressionType.GreaterThanOrEqual, 0);
            oid.Add(DWITHIN.Text, ExpressionType.LessThanOrEqual, 0);

            // Grammar
            MarkMemberSelect(":");
            MarkPunctuation(left_paren, right_paren, period, comma);
            MarkTransient(argument, boolean_primary, comp_op, date_time_expression, general_literal, geometry_literal, geoop_name, literal, optional_not, predicate, relgeoop_name, search_condition);

            Root          = search_condition;
            LanguageFlags = LanguageFlags.CreateAst;
        }
Ejemplo n.º 19
0
        /// <summary>Creates a new instance of the <see cref="CqlGrammar" /> class.</summary>
        public CqlGrammar():
            base(true)
        {
            GrammarComments="OGC Common Catalogue Query Language grammar as defined in [OGC 07-006r1 §6.2.2]";

            // Terminals
            var identifier=new IdentifierTerminal("identifier", ":", "");
            identifier.StartCharCategories.AddRange(
                new UnicodeCategory[] {
                    UnicodeCategory.UppercaseLetter, //Ul
                    UnicodeCategory.LowercaseLetter  //Ll
                }
            );
            identifier.CharCategories.AddRange(
                new UnicodeCategory[] {
                    UnicodeCategory.UppercaseLetter, //Ul
                    UnicodeCategory.LowercaseLetter, //Ll
                    UnicodeCategory.DecimalDigitNumber //Nd
                }
            );
            //var digit_literal=new FixedLengthLiteral("digit", 1, TypeCode.Byte);
            var numeric_literal=new NumberLiteral("numeric literal", NumberOptions.AllowSign, typeof(Ast.DefaultLiteralNode));
            var unsigned_numeric_literal=new NumberLiteral("unsigned numeric literal", NumberOptions.None, typeof(Ast.DefaultLiteralNode));
            //var integer_literal=new NumberLiteral("integer literal", NumberOptions.IntOnly | NumberOptions.NoDotAfterInt);
            //var character_literal=new StringLiteral("character literal", "'", StringOptions.IsChar | StringOptions.AllowsDoubledQuote);
            var string_literal=new StringLiteral("string literal", "'", StringOptions.AllowsDoubledQuote, typeof(Ast.DefaultLiteralNode));
            var period=ToTerm(".", "period");
            var comma=ToTerm(",", "comma");
            var left_paren=ToTerm("(", "left paren");
            var right_paren=ToTerm(")", "right paren");
            left_paren.SetFlag(TermFlags.IsOpenBrace);
            left_paren.IsPairFor=right_paren;
            right_paren.SetFlag(TermFlags.IsCloseBrace);
            right_paren.IsPairFor=left_paren;

            var TRUE=ToTerm("TRUE");
            var FALSE=ToTerm("FALSE");
            var UNKNOWN=ToTerm("UNKNOWN");
            var NULL=ToTerm("NULL");

            var AFTER=ToTerm("AFTER");
            var AND=ToTerm("AND");
            var BEFORE=ToTerm("BEFORE");
            var BEYOND=ToTerm("BEYOND");
            var CONTAINS=ToTerm("CONTAINS");
            var CROSSES=ToTerm("CROSSES");
            var DISJOINT=ToTerm("DISJOINT");
            var DOESNOTEXIST=ToTerm("DOESNOTEXIST");
            var DURING=ToTerm("DURING");
            var DWITHIN=ToTerm("DWITHIN");
            var EQUALS=ToTerm("EQUALS", "Equal");
            var EXISTS=ToTerm("EXISTS");
            var INTERSECTS=ToTerm("INTERSECTS");
            var LIKE=ToTerm("LIKE");
            var NOT=ToTerm("NOT");
            var OR=ToTerm("OR");
            var OVERLAPS=ToTerm("OVERLAPS");
            var RELATE=ToTerm("RELATE");
            var TOUCHES=ToTerm("TOUCHES");
            var WITHIN=ToTerm("WITHIN");

            var equals_operator=ToTerm("=", "equals operator");
            var greater_than_operator=ToTerm(">", "greater than operator");
            var less_than_operator=ToTerm("<", "less than operator");
            var not_equals_operator=ToTerm("<>", "not equals operator");
            var greater_than_or_equals_operator=ToTerm(">=", "greater than or equals operator");
            var less_than_or_equals_operator=ToTerm("<=", "less than or equals operator");
            var date_time=new RegexBasedTerminal(name: "date-time", pattern: @"(?<fulldate>(?<dateyear>\d{4})-(?<datemonth>\d{2})-(?<dateday>\d{2}))T(?<UTCtime>(?<timehour>\d{2}):(?<timeminute>\d{2}):(?<timesecond>\d{2}(\.\d+)?)Z)");
            var duration=new RegexBasedTerminal(name: "duration", pattern: @"P((?<duryear>\d+)Y)?((?<durmonth>\d+)M)?((?<durday>\d+)D)?(T((?<durhour>\d+)H)?((?<durminute>\d+)M)?((?<dursecond>\d+)S)?)?");

            AFTER.AstConfig.NodeType=typeof(Ast.OperatorNameNode);
            AND.AstConfig.NodeType=typeof(Ast.OperatorNameNode);
            BEFORE.AstConfig.NodeType=typeof(Ast.OperatorNameNode);
            BEYOND.AstConfig.NodeType=typeof(Ast.OperatorNameNode);
            CONTAINS.AstConfig.NodeType=typeof(Ast.OperatorNameNode);
            CROSSES.AstConfig.NodeType=typeof(Ast.OperatorNameNode);
            DISJOINT.AstConfig.NodeType=typeof(Ast.OperatorNameNode);
            DURING.AstConfig.NodeType=typeof(Ast.OperatorNameNode);
            DOESNOTEXIST.AstConfig.NodeType=typeof(Ast.OperatorNameNode);
            DURING.AstConfig.NodeType=typeof(Ast.OperatorNameNode);
            DWITHIN.AstConfig.NodeType=typeof(Ast.OperatorNameNode);
            EQUALS.AstConfig.NodeType=typeof(Ast.OperatorNameNode);
            EXISTS.AstConfig.NodeType=typeof(Ast.OperatorNameNode);
            INTERSECTS.AstConfig.NodeType=typeof(Ast.OperatorNameNode);
            LIKE.AstConfig.NodeType=typeof(Ast.OperatorNameNode);
            NOT.AstConfig.NodeType=typeof(Ast.NotKeywordNode);
            OR.AstConfig.NodeType=typeof(Ast.OperatorNameNode);
            OVERLAPS.AstConfig.NodeType=typeof(Ast.OperatorNameNode);
            //RELATE.AstConfig.NodeType=typeof(Ast.OperatorNameNode);
            TOUCHES.AstConfig.NodeType=typeof(Ast.OperatorNameNode);
            WITHIN.AstConfig.NodeType=typeof(Ast.OperatorNameNode);

            date_time.AstConfig.NodeType=typeof(Ast.DateTimeLiteralNode);
            duration.AstConfig.NodeType=typeof(Ast.DurationLiteralNode);

            // Non terminals
            var optional_not=new NonTerminal("optional not", Empty | NOT);

            var attribute_name=new NonTerminal("attribute name", typeof(Ast.AttributeNameNode));
            var search_condition=new NonTerminal("search condition");
            var boolean_value_expression=new NonTerminal("boolean value expression", typeof(Ast.BooleanValueExpressionNode));
            var boolean_term=new NonTerminal("boolean term", typeof(Ast.BooleanTermNode));
            var boolean_factor=new NonTerminal("boolean factor", typeof(Ast.BooleanFactorNode));
            var boolean_primary=new NonTerminal("boolean primary");
            var predicate=new NonTerminal("predicate");
            var temporal_predicate=new NonTerminal("temporal predicate", typeof(Ast.TemporalPredicateNode));
            var date_time_expression=new NonTerminal("date-time expression");
            var existence_predicate=new NonTerminal("existence predicate", typeof(Ast.ExistencePredicateNode));
            var comparison_predicate=new NonTerminal("comparison predicate", typeof(Ast.ComparisonPredicateNode));
            var text_predicate=new NonTerminal("text predicate", typeof(Ast.TextPredicateNode));
            var null_predicate=new NonTerminal("null predicate", typeof(Ast.NullPredicateNode));
            var comp_op=new NonTerminal("comp op", equals_operator | not_equals_operator | less_than_operator | greater_than_operator | less_than_or_equals_operator | greater_than_or_equals_operator);
            var general_literal=new NonTerminal("general literal");
            var literal=new NonTerminal("literal");
            var boolean_literal=new NonTerminal("boolean literal", TRUE | FALSE | UNKNOWN);
            boolean_literal.AstConfig.NodeType=typeof(Ast.BooleanLiteralNode);
            var routine_invocation=new NonTerminal("routine invocation");
            var geoop_routine=new NonTerminal("geoop routine", typeof(Ast.GeoOperatorRoutineNode));
            var relgeoop_routine=new NonTerminal("relgeoop routine", typeof(Ast.RelativeGeoOperatorRoutineNode));
            var routine=new NonTerminal("routine");
            var geoop_name=new NonTerminal("geoop name");
            var relgeoop_name=new NonTerminal("relgeoop name");
            var argument=new NonTerminal("argument");
            var positional_arguments=new NonTerminal("positional arguments");
            var tolerance=new NonTerminal("tolerance", typeof(Ast.ToleranceNode));
            var distance_units=new NonTerminal("distance units");

            var geometry_literal=new NonTerminal("geometry literal", typeof(Ast.GeometryLiteralNode));
            var geometry_literal_series=new NonTerminal("geometry literal series");
            var point_tagged_text=new NonTerminal("Point Tagged Text");
            var linestring_tagged_text=new NonTerminal("LineString Tagged Text");
            var polygon_tagged_text=new NonTerminal("Polygon Tagged Text");
            var multipoint_tagged_text=new NonTerminal("MultiPoint Tagged Text");
            var multilinestring_tagged_text=new NonTerminal("MultiLineString Tagged Text");
            var multipolygon_tagged_text=new NonTerminal("MultiPolygon Tagged Text");
            var geometrycollection_tagged_text=new NonTerminal("GeometryCollection Tagged Text");
            var point_text=new NonTerminal("Point Text");
            var point_text_series=new NonTerminal("Point Text series");
            var point=new NonTerminal("Point");
            var point_series=new NonTerminal("Point series");
            var x=new NonTerminal("x");
            var y=new NonTerminal("y");
            var linestring_text=new NonTerminal("LineString Text");
            var linestring_text_series=new NonTerminal("LineString Text series");
            var polygon_text=new NonTerminal("Polygon Text");
            var polygon_text_series=new NonTerminal("Polygon Text series");
            var multipoint_text=new NonTerminal("MultiPoint Text");
            var multilinestring_text=new NonTerminal("MultiLineString Text");
            var multipolygon_text=new NonTerminal("MultiPolygon Text");
            var geometrycollection_text=new NonTerminal("GeometryCollection Text");
            var envelope_tagged_text=new NonTerminal("Envelope Tagged Text");
            var envelope_text=new NonTerminal("Envelope Text");
            var westboundlongitude=new NonTerminal("WestBoundLongitude", numeric_literal);
            var eastboundlongitude=new NonTerminal("EastBoundLongitude", numeric_literal);
            var northboundlongitude=new NonTerminal("NorthBoundLongitude", numeric_literal);
            var southboundlongitude=new NonTerminal("SouthBoundLongitude", numeric_literal);

            var date_time_period=new NonTerminal("date-time period", typeof(Ast.DateTimePeriodNode));

            identifier.AstConfig.NodeType=typeof(IdentifierNode);
            attribute_name.Rule=MakePlusRule(attribute_name, period, identifier);

            search_condition.Rule=boolean_value_expression;
            boolean_value_expression.Rule=MakePlusRule(boolean_value_expression, OR, boolean_term);
            boolean_term.Rule=MakePlusRule(boolean_term, AND, boolean_factor);
            boolean_factor.Rule=optional_not + boolean_primary;
            boolean_primary.Rule=predicate | routine_invocation | (left_paren + search_condition + right_paren);
            predicate.Rule=comparison_predicate | text_predicate | null_predicate | temporal_predicate | existence_predicate;
            temporal_predicate.Rule=(attribute_name + BEFORE + date_time_expression) | (attribute_name + BEFORE + OR + DURING + date_time_period) | (attribute_name + DURING + date_time_period) | (attribute_name + DURING + OR + AFTER + date_time_period) | (attribute_name + AFTER + date_time_expression);
            date_time_expression.Rule=date_time | date_time_period;
            existence_predicate.Rule=(attribute_name + EXISTS) | (attribute_name + DOESNOTEXIST);
            comparison_predicate.Rule=attribute_name + comp_op + literal;
            text_predicate.Rule=attribute_name + optional_not + LIKE + string_literal;
            null_predicate.Rule=attribute_name + "IS" + optional_not + NULL;
            general_literal.Rule=string_literal | boolean_literal | date_time_expression | geometry_literal;
            literal.Rule=numeric_literal | general_literal;
            routine_invocation.Rule=geoop_routine | relgeoop_routine | routine;
            geoop_name.Rule=EQUALS | DISJOINT | INTERSECTS | TOUCHES | CROSSES | WITHIN | CONTAINS | OVERLAPS | RELATE;
            relgeoop_name.Rule=DWITHIN | BEYOND;
            argument.Rule=literal | attribute_name;
            positional_arguments.Rule=MakePlusRule(positional_arguments, comma, argument);
            geoop_routine.Rule=geoop_name + left_paren + attribute_name + comma + geometry_literal + right_paren;
            relgeoop_routine.Rule=relgeoop_name + left_paren + attribute_name + comma + geometry_literal + comma + tolerance + right_paren;
            routine.Rule=attribute_name + left_paren + positional_arguments + right_paren;
            tolerance.Rule=unsigned_numeric_literal + comma + distance_units;
            distance_units.Rule=ToTerm("feet") | "meters" | ("statute" + "miles") | ("nautical" + "miles") | "kilometers";

            geometry_literal.Rule=point_tagged_text | linestring_tagged_text | polygon_tagged_text | multipoint_tagged_text | multilinestring_tagged_text | multipolygon_tagged_text | geometrycollection_tagged_text | envelope_tagged_text;
            geometry_literal_series.Rule=MakePlusRule(geometry_literal_series, comma, geometry_literal);
            point_tagged_text.Rule=ToTerm("POINT") + point_text;
            linestring_tagged_text.Rule=ToTerm("LINESTRING") + linestring_text;
            polygon_tagged_text.Rule=ToTerm("POLYGON") + polygon_text;
            multipoint_tagged_text.Rule=ToTerm("MULTIPOINT") + multipoint_text;
            multilinestring_tagged_text.Rule=ToTerm("MULTILINESTRING") + multilinestring_text;
            multipolygon_tagged_text.Rule=ToTerm("MULTIPOLYGON") + multipolygon_text;
            geometrycollection_tagged_text.Rule=ToTerm("GEOMETRYCOLLECTION") + geometrycollection_text;
            point_text.Rule=Empty | (left_paren + point + right_paren);
            point_text_series.Rule=MakePlusRule(point_text_series, comma, point_text);
            point.Rule=x + y;
            x.Rule=numeric_literal;
            y.Rule=numeric_literal;
            point_series.Rule=MakePlusRule(point_series, comma, point);
            linestring_text.Rule=Empty | (left_paren + point_series + right_paren);
            linestring_text_series.Rule=MakePlusRule(linestring_text_series, comma, linestring_text);
            polygon_text.Rule=Empty | (left_paren + linestring_text_series + right_paren);
            polygon_text_series.Rule=MakePlusRule(polygon_text_series, comma, polygon_text);
            multipoint_text.Rule=Empty | (left_paren + point_text_series + right_paren);
            multilinestring_text.Rule=Empty | (left_paren + linestring_text_series + right_paren);
            multipolygon_text.Rule=Empty | (left_paren + polygon_text_series + right_paren);
            geometrycollection_text.Rule=Empty | (left_paren + geometry_literal_series + right_paren);
            envelope_tagged_text.Rule=ToTerm("ENVELOPE") + envelope_text;
            envelope_text.Rule=Empty | left_paren + westboundlongitude + comma + eastboundlongitude + comma + northboundlongitude + comma + southboundlongitude + right_paren;

            date_time_period.Rule=(date_time + "/" + date_time) | (date_time + "/" + duration) | (duration + "/" + date_time);
            date_time_expression.Rule=date_time | date_time_period;

            // Operators
            RegisterOperators(10, equals_operator, not_equals_operator, greater_than_operator, greater_than_or_equals_operator, less_than_operator, less_than_or_equals_operator);
            RegisterOperators(3, NOT);
            RegisterOperators(2, OR);
            RegisterOperators(1, AND);
            RegisterOperators(0, BEYOND, WITHIN);

            _OperatorHandler=new OperatorHandler(true);
            var oid=_OperatorHandler.BuildDefaultOperatorMappings();
            oid.Clear();
            oid.Add(equals_operator.Text, ExpressionType.Equal, 10);
            oid.Add(not_equals_operator.Text, ExpressionType.NotEqual, 10);
            oid.Add(greater_than_operator.Text, ExpressionType.GreaterThan, 10);
            oid.Add(greater_than_or_equals_operator.Text, ExpressionType.GreaterThanOrEqual, 10);
            oid.Add(less_than_operator.Text, ExpressionType.LessThan, 10);
            oid.Add(less_than_or_equals_operator.Text, ExpressionType.LessThanOrEqual, 10);
            oid.Add(NOT.Text, ExpressionType.Not, 3);
            oid.Add(OR.Text, ExpressionType.OrElse, 2);
            oid.Add(AND.Text, ExpressionType.AndAlso, 1);

            oid.Add(BEYOND.Text, ExpressionType.GreaterThanOrEqual, 0);
            oid.Add(DWITHIN.Text, ExpressionType.LessThanOrEqual, 0);

            // Grammar
            MarkMemberSelect(":");
            MarkPunctuation(left_paren, right_paren, period, comma);
            MarkTransient(argument, boolean_primary, comp_op, date_time_expression, general_literal, geometry_literal, geoop_name, literal, optional_not, predicate, relgeoop_name, search_condition);

            Root=search_condition;
            LanguageFlags=LanguageFlags.CreateAst;
        }
Ejemplo n.º 20
0
 public bool IsValueTrue(double externalValue, double compareValue, OperatorHandler operation)
 {
     return(operation(externalValue, compareValue));
 }
Ejemplo n.º 21
0
 public InterpreterAstContext(LanguageData language, OperatorHandler operatorHandler = null) : base(language) {
   OperatorHandler = operatorHandler ?? new OperatorHandler(language.Grammar.CaseSensitive);
   base.DefaultIdentifierNodeType = typeof(IdentifierNode);
   base.DefaultLiteralNodeType = typeof(LiteralValueNode);
   base.DefaultNodeType = null; 
 }
        public override void OnAuthorization(HttpActionContext filterContext)
        {
            if (SkipAuthorization(filterContext))
            {
                return;
            }


            const string key1 = "sessionId";
            const string key2 = "badge";
            const string key3 = "deviceGuid";
            bool         hasAccess;
            string       sessionId  = GetHeaderValue(filterContext, key1);
            string       badge      = GetHeaderValue(filterContext, key2);
            string       deviceGuid = GetHeaderValue(filterContext, key3);

            hasAccess = AsyncHelpers.RunSync(async() =>
            {
                using (var service = new OperatorHandler())
                {
                    var result = await service.IsValidSessionAsync(badge, deviceGuid, sessionId);
                    return(result?.Item1 ?? false);
                }
            });



            //_logger.Debug("SessionId:" + sessionId);
            //if (!string.IsNullOrEmpty(sessionId))
            //{
            //    try
            //    {
            //        var ticket = FormsAuthentication.Decrypt(sessionId);
            //        if (ticket != null)
            //        {
            //            _logger.Debug("tikcet is not null! " + ticket.UserData);
            //            var userData = ticket.UserData;
            //            if (!string.IsNullOrWhiteSpace(userData))
            //            {
            //                _logger.Debug("User data object is created.");
            //                var user = JsonConvert.DeserializeObject<SecurityUserInfo>(userData);
            //                _logger.Debug("User data DeserializeObject successfull!");
            //                if (user != null)
            //                {
            //                    _logger.Debug("User data user is not null!");
            //                    using (var service = new OperatorHandler())
            //                    {
            //                        hasAccess = service.IsValidSession(user.Badge, ticket.Name,sessionId);
            //                        _logger.Debug("has Access:" + hasAccess);
            //                    }
            //                }
            //            }
            //        }

            //    }
            //    catch (Exception ex)
            //    {
            //        _logger.Error("Error on OnAuthorization", ex);

            //        throw new FriendlyException(FriendlyExceptionType.AccessDenied);
            //    }
            //}


            //if (!string.IsNullOrEmpty(Token) || (Tokens != null && Tokens.Length > 0))
            //{
            //    if (Tokens == null || Tokens.Length == 0)
            //        hasAccess = AuthorizeHelper.HasAccess(Token);
            //    else
            //    {
            //        var arr = new List<string>();
            //        if (Tokens != null)
            //            arr.AddRange(Tokens);
            //        if (!string.IsNullOrEmpty(Token))
            //            arr.Add(Token);
            //        foreach (var token in arr)
            //        {
            //            hasAccess = AuthorizeHelper.HasAccess(token);
            //            if (hasAccess)
            //                break;
            //        }
            //    }
            //}

            //if (!string.IsNullOrEmpty(Tokens))
            //{
            //    string[] tokens;
            //    if (Tokens.Contains(';'))
            //        tokens = Tokens.Split(';');
            //    else
            //        tokens = Tokens.Split(',');
            //    foreach (var token in tokens)
            //    {
            //        hasAccess = AuthorizeHelper.HasAccess(token);
            //        if (hasAccess)
            //            break;
            //    }
            //}
            if (!hasAccess)
            {
                throw new FriendlyException(FriendlyExceptionType.AccessDenied);
            }
        }
Ejemplo n.º 23
0
        public static void connectionServer()
        {
            log("初始化连接集群服务器完成,获取认证服务器线程开启...", Constant.info, Constant.infoColor);
            while (runing)
            {
                String message = null;

                try
                {
                    message = reader.ReadLine();
                }
                catch (System.Exception ex)
                {
                    //Close();
                    break;
                }
                if (message == null)
                {
                    // Close();
                    break;
                }

                if (message.Length < 3)
                {
                    continue;
                }

                log(message, Constant.info, Constant.infoColor);

                if (SERVER_AES_KEY != null)
                {
                    message = AESCryptos.Decrypt(message, SERVER_AES_KEY);
                }

                //log(SERVER_AES_KEY, Constant.info, Constant.infoColor);

                log(message, Constant.info, Constant.infoColor);
                TransferProtocol tp = null;
                try
                {
                    tp = LitJson.JsonMapper.ToObject <TransferProtocol>(message);
                }
                catch (LitJson.JsonException)
                {
                }
                if (tp == null)
                {
                    continue;
                }
                String code = tp.protocolCode;
                if (code == null || "".Equals(code))
                {
                    continue;
                }
                if (SERVER_RESPONSED.ContainsKey(code))
                {
                    OperatorHandler handler = (OperatorHandler)SERVER_RESPONSED[code];
                    handler.execute(tp);
                }
            }
        }