Ejemplo n.º 1
0
        private async void Worker()
        {
            loader = new HtmlLoader(parserSettings);
            for (int i = parserSettings.StartPoint; i <= parserSettings.EndPoint; i++)
            {
                if (!Program.ParserActive)
                {
                    return;
                }

                var source = await loader.GetSourceByPageId(i);

                var domParser = new HtmlParser();

                var document = await domParser.ParseDocumentAsync(source);

                Parser.Parse(document);
                lock (locker)
                    OnParseOneLink?.Invoke();
            }

            if (Program.ParserActive)
            {
                ParseComplete?.Invoke();
            }
        }
        private static async void Worker()
        {
            CefSourceLoader.BrowsersInit();
            var filesArr = Directory.GetFiles(@"Games Struct");

            var linesList = new List <string>();

            foreach (var fileName in filesArr)
            {
                using (StreamReader sr = new StreamReader(fileName))
                    lines = sr.ReadToEnd().Split('\n').Select((item) => item.Replace("\r", "")).Where(x => x != "")
                            .ToArray();

                foreach (var line in lines)
                {
                    linesList.Add(line);
                }
            }

            lines = linesList.ToArray();

            countOfParsedLines = 0;
            parseIsDone        = false;

            var taskCount = (lines.Length > beginTasksCount) ? beginTasksCount : lines.Length;

            tasks = Enumerable.Range(0, taskCount).Select(RunParsePage).ToArray();

            await WaitForParseAllLines();

            if (Program.ParserActive)
            {
                ParseComplete?.Invoke();
            }
        }
        public void Parse()
        {
            var Tokens = Tokenize(InputString);

            Console.WriteLine("Input:{0}", InputString);
            var Tokenstream = new TokenStream(Tokens);
            var parsedNode  = parse_expression(Tokenstream);

            PolynomialList = AddFromTree(parsedNode);
            bool[] ExistingVariables = new bool[Variables.Count];
            for (int i = 0; i < PolynomialList.Count; i++)
            {
                Console.Write(PolynomialList[i].Scalar.ToString());
                for (int j = 0; j < PolynomialList[i].Variables.Count; j++)
                {
                    int varid = PolynomialList[i].Variables.ElementAt(j).Key;
                    Console.Write(" {0}^{1}", Variables[varid].ToString(), PolynomialList[i].Variables.ElementAt(j).Value.ToString());
                    ExistingVariables[varid] = true;
                }
                Console.WriteLine();
            }

            for (int i = Variables.Count - 1; i >= 0; i--)
            {
                if (!ExistingVariables[i])
                {
                    Variables.RemoveAt(i);
                }
            }
            for (int i = 0; i < Variables.Count; i++)
            {
                Console.Write(Variables[i].ToString() + " ");
            }

            Console.WriteLine();
            if (Success)
            {
                parseEvent?.Invoke();
            }
        }
Ejemplo n.º 4
0
 internal void OnParseComplete()
 {
     ParseComplete?.Invoke(this, EventArgs.Empty);
 }
Ejemplo n.º 5
0
        public EditorState(IWin32Window window, string name, object tag, int tabIndex)
        {
            FilePath     = null;
            Name         = name;
            Tag          = tag;
            IsChanged    = false;
            FileEncoding = Encoding.UTF8;

            _styleNeededState = new StyleNeededState();

            _window  = window;
            TabIndex = tabIndex;

            _editor = new Scintilla();
            SetupEditor(_editor);

            _containerPanel      = new Panel();
            _containerPanel.Dock = DockStyle.Fill;
            _containerPanel.Controls.Add(_editor);

            _searchControl      = new SearchReplaceControl();
            _searchControl.Dock = DockStyle.Top;
            _containerPanel.Controls.Add(_searchControl);

            _searchControl.Search += (s, direction) =>
            {
                SearchText(_window, _searchControl.SearchText, direction, _searchControl.MatchCase, _searchControl.MatchWords, _searchControl.IsRegex, _searchControl.IsWrap);
            };
            _searchControl.Replace += (s, mode) =>
            {
                ReplaceText(_window, _searchControl.SearchText, _searchControl.ReplaceText, mode, _searchControl.MatchCase, _searchControl.MatchWords, _searchControl.IsRegex, _searchControl.IsWrap);
            };
            _searchControl.FocusChanged += (s, focused) =>
            {
                FocusChanged?.Invoke(this, focused);
            };
            _searchControl.Hide();

            _maxLineNumberCharLength = 0;
            _textChangedTimer        = new System.Windows.Forms.Timer()
            {
                Enabled = false, Interval = 250
            };
            _textChangedTimer.Tick += (s, e) =>
            {
                if (!_parseWorker.IsBusy)
                {
                    _textChangedTimer.Enabled = false;
                    ParseStarting?.Invoke(this);
                    _parseWorker.RunWorkerAsync(_editor.Text);
                }
            };
            _parseWorker = new BackgroundWorker();
            _parseWorker.WorkerSupportsCancellation = true;
            _parseWorker.DoWork += (s, e) =>
            {
                // @TODO(final): Support for incremental parsing, so only changes are applied
                string text = (string)e.Argument;
                Tokenize(text);
                Parse(text);
            };
            _parseWorker.RunWorkerCompleted += (s, e) =>
            {
                // @TODO(final): Dont colorize everything, just re-colorize the changes -> See "Support for continuous tokenization"
                if (_styleNeededState.Has > 0)
                {
                    _editor.Colorize(_styleNeededState.StartPos, _styleNeededState.EndPos);
                }
                else
                {
                    int firstLine = _editor.FirstVisibleLine;
                    int lastLine  = firstLine + _editor.LinesOnScreen;
                    int start     = _editor.Lines[firstLine].Index;
                    int end       = _editor.Lines[lastLine].Index;
                    _editor.Colorize(start, end);
                }
                ParseComplete?.Invoke(this);
            };
        }