Exemplo n.º 1
0
            private void NormalSyntaxHighlight(Utoken utoken, UnparsableAst target, IDecoration decoration)
            {
                if (target.AstValue is D.Color && SpecialSyntaxHighlightForColorLiterals)
                {
                    Color color;

                    if (Enum.TryParse <Color>(target.AstValue.ToString(), out color))
                    {
                        decoration
                        .Add(DecorationKey.Background, color)
                        ;

                        if (color.EqualToAny(Color.Black, Color.Blue, Color.Green, Color.Red))
                        {
                            decoration
                            .Add(DecorationKey.Foreground, Color.White)
                            ;
                        }
                        else
                        {
                            decoration
                            .Add(DecorationKey.Foreground, Color.Black)
                            ;
                        }
                    }
                }
                else if (utoken.Discriminator.EqualToAny(CommentContent, CommentStartSymbol, CommentEndSymbol))
                {
                    decoration
                    .Add(DecorationKey.Foreground, ForeColorOfComment)
                    ;
                }
                else if (target.BnfTerm is KeyTerm)
                {
                    if (target.BnfTerm.IsOperator() || target.BnfTerm.IsBrace())
                    {
                        decoration
                        .Add(DecorationKey.Foreground, ForeColorOfOperator)
                        ;
                    }
                    else
                    {
                        decoration
                        .Add(DecorationKey.Foreground, ForeColorOfKeyword)
                        ;
                    }
                }
                else if (target.AstValue is D.Type)
                {
                    decoration
                    .Add(DecorationKey.Foreground, ForeColorOfType)
                    ;
                }
                else if (target.BnfTerm.IsLiteral() || target.BnfTerm.IsConstant())
                {
                    decoration
                    .Add(DecorationKey.Foreground, ForeColorOfLiteral)
                    ;
                }
            }
Exemplo n.º 2
0
        public IActionResult PostLogin([FromBody()] Login loginInfo)
        {
            LoginOutput output = new LoginOutput();

            if (!ModelState.IsValid)
            {
                output.result = "驗證失敗!";
                return(Ok(output));
            }

            var user = _context.User.FirstOrDefault(x => x.UserId == loginInfo.userId && x.Password == loginInfo.password);

            if (user == null)
            {
                output.result = "帳號或密碼輸入錯誤!";
                return(Ok(output));
            }

            // 取得ClientIP
            string ClientIP = HttpContext.Connection.RemoteIpAddress.ToString();

            // 產生Token
            var UToken = Guid.NewGuid().ToString().ToUpper();

            // 設定token逾時分鐘數
            int TimeoutMinute = 20;

            // 計算逾時時間
            DateTime UtokenTime = DateTime.Now.AddMinutes(TimeoutMinute);

            // 刪除所有逾時Token資料
            var timeoutToken = _context.Utoken.Where(x => x.UTokenTimeOut < DateTime.Now && x.UserId == user.UserId).ToList();

            if (timeoutToken.Count > 0)
            {
                _context.Utoken.RemoveRange(timeoutToken);
            }

            // 新增本次登入token資料
            Utoken newToken = new Utoken()
            {
                UserId        = user.UserId,
                User          = user,
                IP            = ClientIP,
                UtokenId      = UToken,
                LastInTime    = DateTime.Now,
                UTokenTimeOut = UtokenTime
            };

            _context.Utoken.Add(newToken);
            _context.SaveChanges();

            output = new LoginOutput
            {
                result = "登入成功!",
                uToken = newToken.UtokenId
            };

            return(Ok(output));
        }
Exemplo n.º 3
0
        internal IDecoration GetDecoration(Utoken utoken)
        {
            UnparsableAst target = utoken is UtokenText
                ? ((UtokenText)utoken).Reference
                : null;

            return(GetDecoration(utoken, target));
        }
Exemplo n.º 4
0
 private void NormalSyntaxHighlight(Utoken utoken, UnparsableAst target, IDecoration decoration)
 {
     if (target.BnfTerm is KeyTerm)
     {
         decoration
         .Add(DecorationKey.Foreground, ForeColorOfOperator)
         ;
     }
     else if (target.BnfTerm.IsLiteral() || target.BnfTerm.IsConstant())
     {
         decoration
         .Add(DecorationKey.Foreground, ForeColorOfLiteral)
         ;
     }
 }
Exemplo n.º 5
0
            public override IDecoration GetDecoration(Utoken utoken, UnparsableAst target)
            {
                var decoration = base.GetDecoration(utoken, target);

                decoration.Add(DecorationKey.FontFamily, FontFamily.GenericMonospace);

                if (target != null)
                {
                    if (SyntaxHighlight == GrammarPrefix.SyntaxHighlight.Color)
                    {
                        NormalSyntaxHighlight(utoken, target, decoration);
                    }
                }

                return(decoration);
            }
Exemplo n.º 6
0
            public override IDecoration GetDecoration(Utoken utoken, UnparsableAst target)
            {
                var decoration = base.GetDecoration(utoken, target);

                decoration.Add(DecorationKey.FontFamily, FontFamily.GenericMonospace);

                if (utoken.Discriminator.EqualToAny(CommentContent, CommentStartSymbol, CommentEndSymbol))
                {
                    decoration
                    .Add(DecorationKey.Foreground, ForeColorOfComment)
                    ;

                    return(decoration);
                }

                if (target != null)
                {
                    if (target.BnfTerm.EqualToAny(B.BOOLEAN, B.NULL) || target.BnfTerm is NumberLiteral)
                    {
                        decoration.Add(DecorationKey.Foreground, ForeColorOfLiteral);
                    }
                    else if (target.AstParentMember != null && target.AstParentMember.BnfTerm == B.Key)
                    {
                        if (target.AstValue is string && ((string)target.AstValue).EqualToAny(TYPE_KEYWORD, COLLECTION_VALUES_KEYWORD, PRIMITIVE_VALUE_KEYWORD))
                        {
                            decoration.Add(DecorationKey.Foreground, ForeColorOfKeyword);
                        }
                        else
                        {
                            decoration.Add(DecorationKey.Foreground, ForeColorOfKey);
                        }
                    }
                    else if (target.AstParentMember != null && target.AstParentMember.BnfTerm == B.Value)
                    {
                        if (target.AstParent != null && target.AstParent.AstValue is KeyValuePair <string, object> && ((KeyValuePair <string, object>)target.AstParent.AstValue).IsTypeInfo)
                        {
                            decoration.Add(DecorationKey.Foreground, ForeColorOfType);
                        }
                        else
                        {
                            decoration.Add(DecorationKey.Foreground, ForeColorOfValue);
                        }
                    }
                }

                return(decoration);
            }
Exemplo n.º 7
0
            private void CrazySyntaxHighlight(Utoken utoken, UnparsableAst target, IDecoration decoration)
            {
                if (target.AstValue is D.Color)
                {
                    Color color;

                    if (Enum.TryParse <Color>(target.AstValue.ToString(), out color))
                    {
                        decoration
                        .Add(DecorationKey.Background, color)
                        ;

                        if (color.EqualToAny(Color.Black, Color.Blue, Color.Green, Color.Red))
                        {
                            decoration
                            .Add(DecorationKey.Foreground, Color.White)
                            ;
                        }
                        else
                        {
                            decoration
                            .Add(DecorationKey.Foreground, Color.Black)
                            ;
                        }
                    }
                }
                else if (utoken.Discriminator == CommentContent)
                {
                    decoration
                    .Add(DecorationKey.Foreground, Color.Pink)
                    .Add(DecorationKey.TextDecoration, TextDecoration.Strikethrough)
                    .Add(DecorationKey.FontStyle, FontStyle.Italic)
                    ;
                }
                else if (utoken.Discriminator == CommentStartSymbol)
                {
                    decoration
                    .Add(DecorationKey.Foreground, Color.Yellow)
                    .Add(DecorationKey.Background, Color.Violet)
                    ;
                }
                else if (utoken.Discriminator == CommentEndSymbol)
                {
                    decoration
                    .Add(DecorationKey.Foreground, Color.Blue)
                    .Add(DecorationKey.Background, Color.Yellow)
                    ;
                }
                else if (utoken.Discriminator == StringLiteralStartSymbol)
                {
                    decoration
                    .Add(DecorationKey.FontSizeRelativePercent, 2)
                    .Add(DecorationKey.Foreground, Color.Red)
                    .Add(DecorationKey.Background, Color.Blue)
                    ;
                }
                else if (target.AstValue is D.If)
                {
                    if (target.BnfTerm == B.LEFT_PAREN)
                    {
                        decoration
                        .Add(DecorationKey.FontWeight, FontWeight.Bold)
                        .Add(DecorationKey.FontSizeRelativePercent, 2)
                        .Add(DecorationKey.Foreground, Color.Blue)
                        ;
                    }
                    else
                    {
                        decoration
                        .Add(DecorationKey.FontWeight, FontWeight.Bold)
                        .Add(DecorationKey.TextDecoration, TextDecoration.Underline)
                        ;
                    }
                }
                else if (target.BnfTerm == B.PROGRAM)
                {
                    decoration
                    .Add(DecorationKey.FontStyle, FontStyle.Italic)
                    .Add(DecorationKey.Foreground, Color.Red)
                    .Add(DecorationKey.Background, Color.Yellow)
                    .Add(DecorationKey.FontSize, 30);
                }
                else if (target.AstValue is D.Type)
                {
                    decoration
                    .Add(DecorationKey.BaselineAlignment, BaselineAlignment.Subscript)
                    .Add(DecorationKey.FontSizeRelativePercent, 0.75);
                }
                else if (target.AstValue is INumberLiteral)
                {
                    INumberLiteral number = (INumberLiteral)target.AstValue;

                    if (number.Value is int)
                    {
                        if (((int)number.Value) % 2 == 0)
                        {
                            decoration
                            .Add(DecorationKey.Foreground, Color.Red)
                            ;
                        }
                        else
                        {
                            decoration
                            .Add(DecorationKey.Foreground, Color.Green)
                            .Add(DecorationKey.Background, Color.Yellow)
                            ;
                        }
                    }
                }
            }
Exemplo n.º 8
0
 public virtual IDecoration GetDecoration(Utoken utoken, UnparsableAst target)
 {
     return Decoration.None;
 }
Exemplo n.º 9
0
        internal IDecoration GetDecoration(Utoken utoken)
        {
            UnparsableAst target = utoken is UtokenText
                ? ((UtokenText)utoken).Reference
                : null;

            return GetDecoration(utoken, target);
        }
Exemplo n.º 10
0
 public static bool IsTab(this Utoken utoken)
 {
     return(utoken is UtokenWhitespace && ((UtokenWhitespace)utoken).kind == UtokenWhitespace.Kind.Tab);
 }
Exemplo n.º 11
0
 public static bool IsEmptyLine(this Utoken utoken)
 {
     return(utoken is UtokenWhitespace && ((UtokenWhitespace)utoken).kind == UtokenWhitespace.Kind.EmptyLine);
 }
Exemplo n.º 12
0
 public static bool IsIndent(this Utoken utoken)
 {
     return(utoken is UtokenIndent);
 }
Exemplo n.º 13
0
 public virtual IDecoration GetDecoration(Utoken utoken, UnparsableAst target)
 {
     return(Decoration.None);
 }