Пример #1
0
        private void InitializeUnicodeCharset()
        {
            char ch = '\0';

            charactersToUse.BeginUpdate();
            string[] charsets = UnicodeCharset.Split(comma, StringSplitOptions.RemoveEmptyEntries);
            foreach (string charset in charsets)
            {
                if (charset.IndexOfAny(dash) > 0)
                {
                    int[] charsetRange =
                        charset.Split(dash).Select(str => int.Parse(str, NumberStyles.HexNumber)).OrderBy(i => i).ToArray();

                    for (int idx = charsetRange[0]; idx <= charsetRange[1]; idx++)
                    {
                        ch = Convert.ToChar(idx);
                        if (!charactersToUse.Any(c => c.CharValue == ch))
                        {
                            charactersToUse.Add(new CharExt(ch));
                        }
                    }
                }
                else
                {
                    ch = Convert.ToChar(int.Parse(charset, NumberStyles.HexNumber));
                    if (!charactersToUse.Any(c => c.CharValue == ch))
                    {
                        charactersToUse.Add(new CharExt(ch));
                    }
                }
            }
            charactersToUse.EndUpdate();
        }
        private void PreviewWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            List <string> regExList = new List <string>();
            const int     maxCount  = 100;

            object[]          args             = (object[])e.Argument;
            RegularExpression passwordIterator = (RegularExpression)args[0];
            int maxRows = (int)args[1];

            string currentPassword = passwordIterator.GetNextPassword();

            while (!string.IsNullOrEmpty(currentPassword) &&
                   !previewBackgroundWorker.CancellationPending &&
                   passwordIterator.Progress < maxRows)
            {
                regExList.Add(currentPassword);
                currentPassword = passwordIterator.GetNextPassword();

                if (string.IsNullOrEmpty(currentPassword) ||
                    regExList.Count > maxCount ||
                    passwordIterator.Progress >= maxRows)
                {
                    App.Current.Dispatcher.Invoke(delegate
                    {
                        RegExMatches.BeginUpdate();
                        foreach (string regEx in regExList)
                        {
                            RegExMatches.Add(regEx);
                        }
                        RegExMatches.EndUpdate();
                    });

                    regExList.Clear();
                }
            }

            if (previewBackgroundWorker.CancellationPending)
            {
                e.Cancel = true;
            }
            else
            {
                e.Result = passwordIterator.Progress;
            }
        }