コード例 #1
0
        public void ExtraerTexto()
        {
            Tokens.Clear();


            //Texto = Area.Lines; /// cada linea del texto sera una posicion en el arreglo
            string palabras = seleccionado().GetNextControl(seleccionado(), true).Text;

            Texto = palabras.Split('\n');

            if (Texto.Length == 0)
            {
                MessageBox.Show($"No se ha escrito nada en el cuadro de texto", "ERROR",
                                MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                Analizador(Texto);
            }
        }
コード例 #2
0
ファイル: TokenView.cs プロジェクト: heniu75/Imagin.NET
        /// <summary>
        ///
        /// </summary>
        void IntersectTokens()
        {
            var ActualTokens = new List <object>();

            Enumerate <TokenButton>((b) =>
            {
                ActualTokens.Add(b.Content);
                return(true);
            });

            var Result = Tokens.Intersect(ActualTokens).ToList();

            Tokens.Clear();
            while (Result.Any <object>())
            {
                foreach (var i in Result)
                {
                    Result.Remove(i);
                    Tokens.Add(i);
                    break;
                }
            }
        }
コード例 #3
0
 public void Reset()
 {
     Tokens.Clear();
     Content         = null;
     IsPushCompleted = false;
 }
コード例 #4
0
 /// <summary>
 /// Remove all settings
 /// </summary>
 public static void Clear()
 {
     Tokens.Clear();
 }
コード例 #5
0
 public void Reset()
 {
     Tokens.Clear();
     Content = null;
     Newlines.Clear();
 }
コード例 #6
0
        /// <summary>
        /// Load actual address token state from neblio explorer
        /// </summary>
        /// <returns></returns>
        public async Task LoadTokensStates()
        {
            try
            {
                var tokens = new Dictionary <string, IToken>();

                string url      = "https://explorer.nebl.io/address/" + Address; //loading actual state of tokens from explorer
                var    webGet   = new HtmlWeb();
                var    document = webGet.Load(url);

                HtmlNodeCollection tl = document.DocumentNode.SelectNodes("//a");
                if (tl != null)
                {
                    foreach (HtmlNode node in tl)
                    {
                        //Console.WriteLine(node.InnerText.Trim());
                        var href = node.Attributes["href"].Value;

                        if (!string.IsNullOrEmpty(href))
                        {
                            if (href.Contains("/token/"))
                            {
                                var tabletr = node.ParentNode.ParentNode.ParentNode;
                                if (tabletr != null)
                                {
                                    var symbol      = node.InnerText;
                                    var tokid       = href.Remove(0, 7);
                                    var balanceLine = tabletr.LastChild;

                                    if (balanceLine != null)
                                    {
                                        var bal = Convert.ToDouble(balanceLine.InnerText);

                                        try
                                        {
                                            var tdetails = await NeblioTransactionHelpers.TokenMetadataAsync(TokenTypes.NTP1, tokid, string.Empty);

                                            tdetails.ActualBalance = bal;
                                            tokens.Add(tokid, tdetails);
                                        }
                                        catch (Exception ex)
                                        {
                                            // todo
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                Tokens.Clear();
                foreach (var t in tokens)
                {
                    Tokens.Add(t.Key, t.Value);
                }

                //cleanup
                webGet   = null;
                document = null;
                tl       = null;
                tokens   = null;
            }
            catch (Exception ex)
            {
                // todo
            }
        }
コード例 #7
0
ファイル: Figure.cs プロジェクト: Alex-Malik/VeDraw
        public void Parse(string markup)
        {
            // Prepare markup for parsing.
            // Replace multiply spaces and commas with a single space.
            markup = Regex.Replace(markup, "[ ]{2,}", " ", RegexOptions.None);
            markup = Regex.Replace(markup, "[,]", " ", RegexOptions.None);
            markup = markup.Trim();

            // We will change current tokens collection only
            // after the parsing process finishes successful.
            var newTokens = new List <Token>();

            // Markup is ready for parsing. Now we can
            // analyse the syntax and get tokens.
            try
            {
                for (int i = 0; i < markup.Length; i++)
                {
                    // Parse markup and create token. Also we can get
                    // start (s) and end (e) points of the token in given markup.
                    char symbol = markup[i];
                    int  s = 0, e = 0;

                    if (symbol == 'M' || symbol == 'm')
                    {
                        // Create token and save it to the tokens collection.
                        newTokens.Add(Move.Parse(markup.Substring(i), out s, out e));
                    }
                    else if (symbol == 'L' || symbol == 'l')
                    {
                        newTokens.Add(Line.Parse(markup.Substring(i), out s, out e));
                        i += e;
                    }
                    else if (symbol == 'H' || symbol == 'h')
                    {
                        newTokens.Add(HLine.Parse(markup.Substring(i), out s, out e));
                        i += e;
                    }
                    else if (symbol == 'V' || symbol == 'v')
                    {
                        newTokens.Add(VLine.Parse(markup.Substring(i), out s, out e));
                    }
                    else if (symbol == 'C' || symbol == 'c')
                    {
                        newTokens.Add(CubicBezierCurve.Parse(markup.Substring(i), out s, out e));
                    }
                    else if (symbol == 'Q' || symbol == 'q')
                    {
                        newTokens.Add(QuadraticBezierCurve.Parse(markup.Substring(i), out s, out e));
                    }
                    else if (symbol == 'S' || symbol == 's')
                    {
                        newTokens.Add(SmoothCubicBezierCurve.Parse(markup.Substring(i), out s, out e));
                    }
                    else if (symbol == 'T' || symbol == 't')
                    {
                        newTokens.Add(SmoothQuadraticBezierCurve.Parse(markup.Substring(i), out s, out e));
                    }
                    else if (symbol == 'A' || symbol == 'a')
                    {
                        newTokens.Add(EllipticalArc.Parse(markup.Substring(i), out s, out e));
                    }
                    else if (symbol == 'Z' || symbol == 'z')
                    {
                        newTokens.Add(Close.Parse(markup.Substring(i), out s, out e));
                    }
                    else if (symbol == ' ')
                    {
                        continue;
                    }
                    else
                    {
                        // TODO: Throw an exception or log error and finish parsing.
                    }

                    // Continue loop from the end point of the token.
                    i += e;
                }

                // Parsing process finshed successful so we can update tokens collection.
                if (Tokens.Any())
                {
                    Tokens.Clear();
                }

                foreach (var token in newTokens)
                {
                    Tokens.Add(token);
                }
            }
            catch (Exception e)
            {
                // TODO: Log exception.
                // Left collection not changed.
            }
        }
コード例 #8
0
        private void serverPick_SelectedIndexChanged(object sender, EventArgs e)
        {
            Tokens.Clear();
            actionText.Text = "Loading info...";

            try
            {
                ButtonLogin.Enabled    = true;
                ButtonRegister.Enabled = true;

                SelectedServerName  = ServerDropDownList.Text.ToString().ToUpper();
                SelectedServerIP    = new Uri(ServerDropDownList.SelectedValue.ToString()).Host;
                SelectedServerIPRaw = ServerDropDownList.SelectedValue.ToString();

                WebClientWithTimeout serverval = new WebClientWithTimeout();
                var    stringToUri             = new Uri(ServerDropDownList.SelectedValue.ToString() + "/GetServerInformation");
                String serverdata = serverval.DownloadString(stringToUri);

                result = JSON.Parse(serverdata);

                actionText.Text = "Players on server: " + result["onlineNumber"];

                try
                {
                    if (string.IsNullOrEmpty(result["modernAuthSupport"]))
                    {
                        _modernAuthSupport = false;
                    }
                    else if (result["modernAuthSupport"])
                    {
                        if (stringToUri.Scheme == "https")
                        {
                            _modernAuthSupport = true;
                        }
                        else
                        {
                            _modernAuthSupport = false;
                        }
                    }
                    else
                    {
                        _modernAuthSupport = false;
                    }
                }
                catch
                {
                    _modernAuthSupport = false;
                }

                try
                {
                    _ticketRequired = (bool)result["requireTicket"];
                }
                catch
                {
                    _ticketRequired = true; //lets assume yes, we gonna check later if ticket is empty or not.
                }
            }
            catch
            {
                ButtonLogin.Enabled    = false;
                ButtonRegister.Enabled = false;

                SelectedServerName = "Offline";
                SelectedServerIP   = "http://localhost";

                actionText.Text = "Server is offline.";
            }

            ticketBox.Enabled = _ticketRequired;
        }
コード例 #9
0
        private void RegisterButton_Click(object sender, EventArgs e)
        {
            Refresh();

            List <string> registerErrors = new List <string>();

            if (string.IsNullOrWhiteSpace(RegisterEmail.Text))
            {
                registerErrors.Add("Please enter your e-mail.");
                RegisterEmailBorder.Image = Theming.BorderEmailError;
            }
            else if (!IsEmailValid.Validate(RegisterEmail.Text))
            {
                registerErrors.Add("Please enter a valid e-mail address.");
                RegisterEmailBorder.Image = Theming.BorderEmailError;
            }

            if (string.IsNullOrWhiteSpace(RegisterTicket.Text) && _ticketRequired)
            {
                registerErrors.Add("Please enter your ticket.");
                RegisterTicketBorder.Image = Theming.BorderTicketError;
            }

            if (string.IsNullOrWhiteSpace(RegisterPassword.Text))
            {
                registerErrors.Add("Please enter your password.");
                RegisterPasswordBorder.Image = Theming.BorderPasswordError;
            }

            if (string.IsNullOrWhiteSpace(RegisterConfirmPassword.Text))
            {
                registerErrors.Add("Please confirm your password.");
                RegisterConfirmPasswordBorder.Image = Theming.BorderPasswordError;
            }

            if (RegisterConfirmPassword.Text != RegisterPassword.Text)
            {
                registerErrors.Add("Passwords don't match.");
                RegisterConfirmPasswordBorder.Image = Theming.BorderPasswordError;
            }

            if (!RegisterAgree.Checked)
            {
                registerErrors.Add("You have not agreed to the Terms of Service.");
                RegisterAgree.ForeColor = Theming.Error;
            }

            if (registerErrors.Count == 0)
            {
                bool allowReg = false;

                String Email;
                String Password;

                switch (Authentication.HashType(InformationCache.SelectedServerJSON.authHash ?? string.Empty))
                {
                case AuthHash.H10:
                    Email    = RegisterEmail.Text.ToString();
                    Password = RegisterPassword.Text.ToString();
                    break;

                case AuthHash.H11:
                    Email    = RegisterEmail.Text.ToString();
                    Password = MDFive.Hashes(RegisterPassword.Text.ToString()).ToLower();
                    break;

                case AuthHash.H12:
                    Email    = RegisterEmail.Text.ToString();
                    Password = SHA.Hashes(RegisterPassword.Text.ToString()).ToLower();
                    break;

                case AuthHash.H13:
                    Email    = RegisterEmail.Text.ToString();
                    Password = SHATwoFiveSix.Hashes(RegisterPassword.Text.ToString()).ToLower();
                    break;

                case AuthHash.H20:
                    Email    = MDFive.Hashes(RegisterEmail.Text.ToString()).ToLower();
                    Password = MDFive.Hashes(RegisterPassword.Text.ToString()).ToLower();
                    break;

                case AuthHash.H21:
                    Email    = SHA.Hashes(RegisterEmail.Text.ToString()).ToLower();
                    Password = SHA.Hashes(RegisterPassword.Text.ToString()).ToLower();
                    break;

                case AuthHash.H22:
                    Email    = SHATwoFiveSix.Hashes(RegisterEmail.Text.ToString()).ToLower();
                    Password = SHATwoFiveSix.Hashes(RegisterPassword.Text.ToString()).ToLower();
                    break;

                default:
                    Log.Error("HASH TYPE: Unknown Hash Standard was Provided");
                    return;
                }

                try
                {
                    string[] regex = new Regex(@"([0-9A-Z]{5})([0-9A-Z]{35})").Split(Password.ToUpper());

                    Uri URLCall = new Uri("https://api.pwnedpasswords.com/range/" + regex[1]);
                    ServicePointManager.FindServicePoint(URLCall).ConnectionLeaseTimeout = (int)TimeSpan.FromMinutes(1).TotalMilliseconds;
                    var Client = new WebClient
                    {
                        Encoding = Encoding.UTF8
                    };
                    if (!WebCalls.Alternative())
                    {
                        Client = new WebClientWithTimeout {
                            Encoding = Encoding.UTF8
                        };
                    }
                    else
                    {
                        Client.Headers.Add("user-agent", "SBRW Launcher " +
                                           Application.ProductVersion + " (+https://github.com/SoapBoxRaceWorld/GameLauncher_NFSW)");
                    }

                    String serverReply = null;
                    try
                    {
                        serverReply = Client.DownloadString(URLCall);
                    }
                    catch (WebException Error)
                    {
                        APIChecker.StatusCodes(URLCall.GetComponents(UriComponents.HttpRequestUrl, UriFormat.SafeUnescaped),
                                               Error, (HttpWebResponse)Error.Response);
                    }
                    catch (Exception Error)
                    {
                        LogToFileAddons.OpenLog("Register", null, Error, null, true);
                    }
                    finally
                    {
                        if (Client != null)
                        {
                            Client.Dispose();
                        }
                    }

                    if (!string.IsNullOrWhiteSpace(serverReply))
                    {
                        String verify = regex[2];

                        string[] hashes = serverReply.Split('\n');
                        foreach (string hash in hashes)
                        {
                            var splitChecks = hash.Split(':');
                            if (splitChecks[0] == verify)
                            {
                                var passwordCheckReply = MessageBox.Show(null, "Password used for registration has been breached " + Convert.ToInt32(splitChecks[1]) +
                                                                         " times, you should consider using a different one.\n\nAlternatively you can use the unsafe password anyway." +
                                                                         "\nWould you like to continue to use it?", "GameLauncher", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                                if (passwordCheckReply == DialogResult.Yes)
                                {
                                    allowReg = true;
                                }
                                else
                                {
                                    allowReg = false;
                                }
                            }
                            else
                            {
                                allowReg = true;
                            }
                        }
                    }
                    else
                    {
                        allowReg = true;
                    }
                }
                catch
                {
                    allowReg = true;
                }

                if (allowReg)
                {
                    Tokens.Clear();

                    Tokens.IPAddress  = InformationCache.SelectedServerData.IPAddress;
                    Tokens.ServerName = ServerListUpdater.ServerName("Register");

                    Authentication.Client("Register", InformationCache.SelectedServerJSON.modernAuthSupport, Email, Password, _ticketRequired ? RegisterTicket.Text : null);

                    if (!String.IsNullOrWhiteSpace(Tokens.Success))
                    {
                        DialogResult Success = MessageBox.Show(null, Tokens.Success, "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                        if (Success == DialogResult.OK)
                        {
                            Close();
                        }
                    }
                    else
                    {
                        MessageBox.Show(null, Tokens.Error, "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    var message = "There were some errors while registering. Please fix them:\n\n";

                    foreach (var error in registerErrors)
                    {
                        message += "• " + error + "\n";
                    }

                    MessageBox.Show(null, message, "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #10
0
        private double Calculate(Tokens tokens)
        {
            int                curPriority = 0;
            Stack <double>     opNumbers   = new Stack <double>();
            Stack <PriorityOp> opOperators = new Stack <PriorityOp>();

            for (int i = 0; i < tokens.Count; i++)
            {
                switch (tokens[i].Type)
                {
                case TokenType.Number:
                    opNumbers.Push(double.Parse(tokens[i].Value));    //TODO 检测正确性
                    break;

                case TokenType.Operator:
                    int priority = curPriority;
                    if ("*".Equals(tokens[i].Value) || "//".Equals(tokens[i].Value))
                    {
                        priority++;
                    }
                    while (opOperators.Count > 0 && opOperators.Peek().priority >= priority)
                    {
                        opNumbers.Push(Calculate(opNumbers.Pop(), opNumbers.Pop(), opOperators.Pop().op));
                    }
                    opOperators.Push(new PriorityOp(priority, tokens[i].Value.ToCharArray()[0]));
                    break;

                case TokenType.End:
                    while (opOperators.Count > 0)
                    {
                        opNumbers.Push(Calculate(opNumbers.Pop(), opNumbers.Pop(), opOperators.Pop().op));
                    }
                    break;

                case TokenType.Identifier:
                    Function function = mFunctions.GetFunction(tokens[i].Value);
                    if (function != null)
                    {
                        int paraCount = function.Parameters.Count;
                        if (tokens[i + 1].Type == TokenType.ParenthesesLeft)
                        {
                            //List<double> paras = new List<double>();
                            //for (int j = i + 2; j < i + 1 + paraCount * 2; j+=2)
                            //{
                            //    paras.Add(double.Parse(tokens[j].Value));
                            //}
                            //double? funcResult = GetFunctionResult(function, paras);
                            //if (funcResult.HasValue) {
                            //    opNumbers.Push(funcResult.Value);
                            //    i += function.Parameters.Count * 2 + 1;
                            //}
                            //else
                            //    break;
                            List <double> paras      = new List <double>();
                            int           lPriority  = 0;
                            int           paraStart  = i + 2;
                            Tokens        paraTokens = new Tokens();
                            int           j          = paraStart;
                            for (; j < tokens.Count; j++)
                            {
                                if (tokens[j].Type == TokenType.Comma && lPriority == 0)
                                {
                                    paraTokens.Add(new Token()
                                    {
                                        Type = TokenType.End
                                    });
                                    paras.Add(Calculate(paraTokens));
                                    paraTokens.Clear();
                                    paraStart = j + 1;
                                    continue;
                                }
                                else if (tokens[j].Type == TokenType.ParenthesesLeft)
                                {
                                    lPriority += 10;
                                }
                                else if (tokens[j].Type == TokenType.ParenthesesRight)
                                {
                                    if (lPriority == 0)
                                    {
                                        if (paraTokens.Count > 0)
                                        {
                                            paraTokens.Add(new Token()
                                            {
                                                Type = TokenType.End
                                            });
                                            paras.Add(Calculate(paraTokens));
                                        }
                                        break;
                                    }
                                    lPriority -= 10;
                                }
                                paraTokens.Add(tokens[j]);
                            }
                            double?funcResult = GetFunctionResult(function, paras);
                            if (funcResult.HasValue)
                            {
                                opNumbers.Push(funcResult.Value);
                                i = j;
                            }
                            else
                            {
                                break;
                            }
                        }
                        else
                        {
                            MessageBox.Show("函数 " + tokens[i].Value + " 参数个数不合适。", "计算表达式", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                            break;
                        }
                    }
                    else
                    {
                        MessageBox.Show("无法识别函数 " + tokens[i].Value + " 。", "计算表达式", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                        break;
                    }
                    break;

                case TokenType.ParenthesesLeft:
                    curPriority += 10;
                    break;

                case TokenType.ParenthesesRight:
                    curPriority -= 10;
                    break;
                }
            }
            return(opNumbers.Pop());
        }
コード例 #11
0
ファイル: AccountTokens.cs プロジェクト: toro-ponz/TweetGazer
        public static async Task <bool> LoadTokensAsync()
        {
            //ファイルの存在確認
            if (!File.Exists(SecretParameters.TokensFilePath))
            {
                return(false);
            }

            IsVerifying = true;

            if (Tokens == null)
            {
                Tokens = new List <Tokens>();
            }

            var loadedText = "";
            //ファイルから読み込み
            FileStream fileStream = null;

            try
            {
                fileStream = new FileStream(SecretParameters.TokensFilePath, FileMode.Open, FileAccess.Read);
                using (var streamReader = new StreamReader(fileStream))
                {
                    fileStream = null;
                    loadedText = CommonMethods.DecryptString(streamReader.ReadToEnd(), SecretParameters.TokensEncryptionKey);
                }
            }
            catch (Exception e)
            {
                DebugConsole.Write(e);
                IsVerifying = false;
                return(false);
            }
            finally
            {
                if (fileStream != null)
                {
                    fileStream.Dispose();
                }
            }

            var regex = new Regex(@"AccessData\[(?<token>.+?), (?<secret>.+?)\]", RegexOptions.IgnoreCase | RegexOptions.Singleline);
            var match = regex.Match(loadedText);

            while (match.Success)
            {
                Tokens.Add(
                    CoreTweet.Tokens.Create(
                        SecretParameters.ConsumerKey,
                        SecretParameters.ConsumerSecret,
                        match.Groups["token"].Value,
                        match.Groups["secret"].Value
                        )
                    );
                match = match.NextMatch();
            }

            if (Tokens.Count < 1)
            {
                IsVerifying = false;
                return(false);
            }

            //ユーザー情報の取得
            if (!await TokenVerifyAsync(Tokens))
            {
                Tokens.Clear();
                CommonMethods.Notify("トークンの認証失敗", NotificationType.Error);
                IsVerifying = false;
                return(false);
            }

            CommonMethods.Notify("トークン読み込み完了", NotificationType.Success);

            IsVerifying = false;
            return(true);
        }
コード例 #12
0
ファイル: TuneLexer.cs プロジェクト: ModernMAK/ABCSharp
 private void Clear()
 {
     Tokens.Clear();
     //TODO clear rest
 }