Exemplo n.º 1
0
        public void OnEventAcquired(object sender, ParserEventArgs args)
        {
            try
            {
                //Update property window anyway
                PropertyGridViewModel.Clear();
                DataViewModel?.Clear();

                if (args == null)
                {
                    throw new NullReferenceException("Invalid arguments passed");
                }

                PropertyGridViewModel.AddData(args.TreeNode?.Properties);

                var argsType = args.ArgsType;

                if ((argsType & MessageType.ProcessAll) != 0)
                {
                    DataViewModel = MarkupManager.Resolve(args.TreeNode?.Markup) ?? new DataGridViewModel();
                    DataViewModel.ProcessNodeData(args.TreeNode);
                }

                DataViewModel?.Refresh();
                PropertyGridViewModel.Refresh();
            }
            catch (Exception ex)
            {
                MessageBoxInstance.Raise(ex.Message);
            }
        }
Exemplo n.º 2
0
 public void ConstructorThrowsOnNullArguments()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         var _ = new ParserEventArgs(0, null);
     });
 }
 void target_ProductParsed(object sender, ParserEventArgs e)
 {
     Trace.WriteLine(String.Format("Product parsed: {0}", e.Product.ToString()));
     ;
     Assert.IsNotNull(e.Product);
     Assert.IsTrue(!String.IsNullOrEmpty(e.Product.Name));
     Assert.IsTrue(!Double.IsNaN(e.Product.Price));
 }
Exemplo n.º 4
0
        void _parser_FoundProduct(object sender, ParserEventArgs e)
        {
            Trace.WriteLine(String.Format("Thread {0} Product found: {1} {2}", Thread.CurrentThread.ManagedThreadId, e.ParentCategoryId, e.ProductLink));


            var task = _factory.StartNew <HtmlDocument>(() => { return(_client.Load(e.ProductLink)); }).ContinueWith(
                (t) => _parser.ParseProductPage(t.Result, e.CategoryName));
        }
Exemplo n.º 5
0
        private void ParserStatusChanged(object sender, ParserEventArgs e)
        {
            double.TryParse(e.Value, out double status);

            // Assert
            Assert.True(status > _previousStatus);

            _previousStatus = status;
        }
Exemplo n.º 6
0
        internal void ProcessParsingError(ParserEventArgs parserEventArgs)
        {
            var e = new PortListenerEventArgs(parserEventArgs.VirtualPort, parserEventArgs.ErrorDescription);

            if (ParsingErrorEvent != null)
            {
                ParsingErrorEvent(this, e);
            }
        }
Exemplo n.º 7
0
        private void parser_FoundCategory(object sender, ParserEventArgs e)
        {
            Trace.WriteLine(String.Format("Thread {0} Category found: {1} {2}", Thread.CurrentThread.ManagedThreadId, e.CategoryName, e.CategoryLink));


            var task = _factory.StartNew <HtmlDocument>(() => { return(_client.Load(e.CategoryLink)); }).ContinueWith(
                (t) => _parser.ParseCategoryPage(t.Result, e.ParentCategoryId));


            _tasks.Add(task);
        }
Exemplo n.º 8
0
 private static void parsedResult_event(object sender, ParserEventArgs <QuotesObject> args)
 {
     // add next
     if (args.ParsedData.has_next)
     {
         int next = args.ParsedData.page + 1;
         (sender as SimpleSpider).AddPage(buildPageUri(next), args.FetchInfo.Link);
     }
     // process data (show on console)
     foreach (var q in args.ParsedData.quotes)
     {
         Console.WriteLine($"{q.author.name }: { q.text }");
     }
 }
Exemplo n.º 9
0
        public void TreeElement_Selected(ITreeNodeViewModel currentNode)
        {
            if (currentNode == null)
            {
                return;
            }

            var args = new ParserEventArgs()
            {
                ArgsType = (currentNode.IsFinalGuiNode ? MessageType.ProcessAll : MessageType.ProcessProperties),
                TreeNode = currentNode,
            };

            Messenger.RaiseEvent(this, args);
        }
Exemplo n.º 10
0
        public void OnEventAcquiredProcessAllRegularTest()
        {
            var args = new ParserEventArgs()
            {
                TreeNode = Utilities.FormNodeFromStorage(Tools.GetMockStorage(Tools.MockType.IsGuiNode)),
                ArgsType = MessageType.ProcessAll
            };

            mainViewModel.OnEventAcquired(null, args);

            propertyGridViewModelMock.Verify(model => model.Clear(), Times.AtLeastOnce());
            dataGridViewModelMock.Verify(model => model.Clear(), Times.AtLeastOnce());

            propertyGridViewModelMock.Verify(model => model.AddData(It.IsAny <List <DataTuple> >()), Times.AtLeastOnce());
            dataGridViewModelMock.Verify(model => model.ProcessNodeData(It.IsAny <ITreeNodeViewModel>()), Times.AtLeastOnce());

            propertyGridViewModelMock.Verify(model => model.Refresh(), Times.AtLeastOnce());
            dataGridViewModelMock.Verify(model => model.Refresh(), Times.AtLeastOnce());
        }
        private void CommandRouter(Object Sender, ParserEventArgs e)
        {
            switch (e.Action)
            {
                case Actions.Print:
                    this.PrintChar(e.CurChar);
                    ////Console.Write ("{0}", e.CurChar);
                    break;

                case Actions.Execute:
                    this.ExecuteChar(e.CurChar);
                    break;

                case Actions.Dispatch:
                    break;

                default:
                    break;
            }

            Int32 Param = 0;
            Int32 Inc = 1; // increment

            switch (e.CurSequence)
            {
                case "":
                    break;

                case "\x1b" + "7": // DECSC Save Cursor position and attributes
                    this.SavedCarets.Add(new uc_CaretAttribs(
                                             this.Caret.Pos,
                                             this.G0.Set,
                                             this.G1.Set,
                                             this.G2.Set,
                                             this.G3.Set,
                                             this.CharAttribs));

                    break;

                case "\x1b" + "8": // DECRC Restore Cursor position and attributes
                    this.Caret.Pos = ((uc_CaretAttribs) this.SavedCarets[this.SavedCarets.Count - 1]).Pos;
                    this.CharAttribs = ((uc_CaretAttribs) this.SavedCarets[this.SavedCarets.Count - 1]).Attribs;

                    this.G0.Set = ((uc_CaretAttribs) this.SavedCarets[this.SavedCarets.Count - 1]).G0Set;
                    this.G1.Set = ((uc_CaretAttribs) this.SavedCarets[this.SavedCarets.Count - 1]).G1Set;
                    this.G2.Set = ((uc_CaretAttribs) this.SavedCarets[this.SavedCarets.Count - 1]).G2Set;
                    this.G3.Set = ((uc_CaretAttribs) this.SavedCarets[this.SavedCarets.Count - 1]).G3Set;

                    this.SavedCarets.RemoveAt(this.SavedCarets.Count - 1);

                    break;

                case "\x1b~": //LS1R Locking Shift G1 -> GR
                    this.CharAttribs.GR = this.G1;
                    break;

                case "\x1bn": //LS2 Locking Shift G2 -> GL
                    this.CharAttribs.GL = this.G2;
                    break;

                case "\x1b}": //LS2R Locking Shift G2 -> GR
                    this.CharAttribs.GR = this.G2;
                    break;

                case "\x1bo": //LS3 Locking Shift G3 -> GL
                    this.CharAttribs.GL = this.G3;
                    break;

                case "\x1b|": //LS3R Locking Shift G3 -> GR
                    this.CharAttribs.GR = this.G3;
                    break;

                case "\x1b#8": //DECALN
                    e.CurParams.Elements.Add("1");
                    e.CurParams.Elements.Add(this._rows.ToString());
                    this.SetScrollRegion(e.CurParams);

                    // put E's on the entire screen
                    for (int y = 0; y < this._rows; y++)
                    {
                        this.CaretToAbs(y, 0);
                        for (int x = 0; x < this._cols; x++)
                        {
                            this.PrintChar('E');
                        }
                    }

                    break;

                case "\x1b=": // Keypad to Application mode
                    this.Modes.Flags = this.Modes.Flags | uc_Mode.KeypadAppln;
                    break;

                case "\x1b>": // Keypad to Numeric mode
                    this.Modes.Flags = this.Modes.Flags ^ uc_Mode.KeypadAppln;
                    break;

                case "\x1b[B": // CUD

                    if (e.CurParams.Count() > 0)
                    {
                        Inc = Convert.ToInt32(e.CurParams.Elements[0]);
                    }

                    if (Inc == 0)
                        Inc = 1;

                    this.CaretToAbs(this.Caret.Pos.Y + Inc, this.Caret.Pos.X);
                    break;

                case "\x1b[A": // CUU

                    if (e.CurParams.Count() > 0)
                    {
                        Inc = Convert.ToInt32(e.CurParams.Elements[0]);
                    }

                    if (Inc == 0)
                        Inc = 1;

                    this.CaretToAbs(this.Caret.Pos.Y - Inc, this.Caret.Pos.X);
                    break;

                case "\x1b[C": // CUF

                    if (e.CurParams.Count() > 0)
                    {
                        Inc = Convert.ToInt32(e.CurParams.Elements[0]);
                    }

                    if (Inc == 0)
                        Inc = 1;

                    this.CaretToAbs(this.Caret.Pos.Y, this.Caret.Pos.X + Inc);
                    break;

                case "\x1b[D": // CUB

                    if (e.CurParams.Count() > 0)
                    {
                        Inc = Convert.ToInt32(e.CurParams.Elements[0]);
                    }

                    if (Inc == 0)
                        Inc = 1;

                    this.CaretToAbs(this.Caret.Pos.Y, this.Caret.Pos.X - Inc);
                    break;

                case "\x1b[H": // CUP
                case "\x1b[f": // HVP

                    Int32 X = 0;
                    Int32 Y = 0;

                    if (e.CurParams.Count() > 0)
                    {
                        Y = Convert.ToInt32(e.CurParams.Elements[0]) - 1;
                    }

                    if (e.CurParams.Count() > 1)
                    {
                        X = Convert.ToInt32(e.CurParams.Elements[1]) - 1;
                    }

                    this.CaretToRel(Y, X);
                    break;

                case "\x1b[J":

                    if (e.CurParams.Count() > 0)
                    {
                        Param = Convert.ToInt32(e.CurParams.Elements[0]);
                    }

                    this.ClearDown(Param);
                    break;

                case "\x1b[K":

                    if (e.CurParams.Count() > 0)
                    {
                        Param = Convert.ToInt32(e.CurParams.Elements[0]);
                    }

                    this.ClearRight(Param);
                    break;

                case "\x1b[L": // INSERT LINE
                    this.InsertLine(e.CurParams);
                    break;

                case "\x1b[M": // DELETE LINE
                    this.DeleteLine(e.CurParams);
                    break;

                case "\x1bN": // SS2 Single Shift (G2 -> GL)
                    this.CharAttribs.GS = this.G2;
                    break;

                case "\x1bO": // SS3 Single Shift (G3 -> GL)
                    this.CharAttribs.GS = this.G3;
                    // Console.WriteLine ("SS3: GS = {0}", this.CharAttribs.GS);
                    break;

                case "\x1b[m":
                    this.SetCharAttribs(e.CurParams);
                    break;

                case "\x1b[?h":
                    this.SetqmhMode(e.CurParams);
                    break;

                case "\x1b[?l":
                    this.SetqmlMode(e.CurParams);
                    break;

                case "\x1b[c": // DA Device Attributes
                    //                    this.DispatchMessage (this, "\x1b[?64;1;2;6;7;8;9c");
                    this.DispatchMessage(this, "\x1b[?6c");
                    break;

                case "\x1b[g":
                    this.ClearTabs(e.CurParams);
                    break;

                case "\x1b[h":
                    this.SethMode(e.CurParams);
                    break;

                case "\x1b[l":
                    this.SetlMode(e.CurParams);
                    break;

                case "\x1b[r": // DECSTBM Set Top and Bottom Margins
                    this.SetScrollRegion(e.CurParams);
                    break;

                case "\x1b[t": // DECSLPP Set Lines Per Page
                    if (e.CurParams.Count() > 0)
                    {
                        Param = Convert.ToInt32(e.CurParams.Elements[0]);
                    }

                    if (Param > 0)
                        this.SetSize(Param, this._cols);
                    break;

                case "\x1b" + "D": // IND

                    if (e.CurParams.Count() > 0)
                    {
                        Param = Convert.ToInt32(e.CurParams.Elements[0]);
                    }

                    this.Index(Param);
                    break;

                case "\x1b" + "E": // NEL
                    this.LineFeed();
                    this.CarriageReturn();
                    break;

                case "\x1bH": // HTS
                    this.TabSet();
                    break;

                case "\x1bM": // RI
                    if (e.CurParams.Count() > 0)
                    {
                        Param = Convert.ToInt32(e.CurParams.Elements[0]);
                    }

                    this.ReverseIndex(Param);
                    break;

                default:
                    // Console.Write ("unsupported VT sequence {0} happened\n", e.CurSequence);
                    break;
            }

            if (e.CurSequence.StartsWith("\x1b("))
            {
                this.SelectCharSet(ref this.G0.Set, e.CurSequence.Substring(2));
            }
            else if (e.CurSequence.StartsWith("\x1b-") ||
                     e.CurSequence.StartsWith("\x1b)"))
            {
                this.SelectCharSet(ref this.G1.Set, e.CurSequence.Substring(2));
            }
            else if (e.CurSequence.StartsWith("\x1b.") ||
                     e.CurSequence.StartsWith("\x1b*"))
            {
                this.SelectCharSet(ref this.G2.Set, e.CurSequence.Substring(2));
            }
            else if (e.CurSequence.StartsWith("\x1b/") ||
                     e.CurSequence.StartsWith("\x1b+"))
            {
                this.SelectCharSet(ref this.G3.Set, e.CurSequence.Substring(2));
            }
        }
Exemplo n.º 12
0
 void _parser_ProductParsed(object sender, ParserEventArgs e)
 {
     Products.Add(e.Product);
 }
Exemplo n.º 13
0
 private void target_FoundCategory(object sender, ParserEventArgs e)
 {
     Trace.WriteLine(String.Format("Category found: {0} {1}", e.CategoryName, e.CategoryLink));
     categoryCount++;
 }
Exemplo n.º 14
0
 void target_FoundProductLink(object sender, ParserEventArgs e)
 {
     Trace.WriteLine(String.Format("Product link found: {0}", e.ProductLink));
     productCount++;
 }
Exemplo n.º 15
0
 protected override void OnFoundCategory(ParserEventArgs args)
 {
     base.OnFoundCategory(args);
 }
Exemplo n.º 16
0
 protected override void OnFoundProductLink(ParserEventArgs args)
 {
     base.OnFoundProductLink(args);
 }
Exemplo n.º 17
0
        private void CommandRouter(object Sender, ParserEventArgs e)
        {
            //prntSome.printSome("CommandRouter");
            switch (e.Action)
            {
            case Actions.Print:
                this.PrintChar(e.CurChar);
                //System.Console.Write ("{0}", e.CurChar);
                break;

            case Actions.Execute:
                this.ExecuteChar(e.CurChar);
                break;

            case Actions.Dispatch:
                break;

            default:
                break;
            }

            System.Int32 Param = 0;

            System.Int32 Inc = 1; // increment

            //rdbsb.AppendLine("cmdrotr: " + e.CurSequence + " params: "+e.CurParams.Elements.Count);

            //for(int rr=0; rr < e.CurParams.Elements.Count; rr++)
            //    rdbsb.AppendLine("cmdrotr params: " + e.CurParams.Elements[rr]);

            switch (e.CurSequence)
            {
            case "":
                break;

            case "\x1b" + "7":     //DECSC Save Cursor position and attributes
                this.SavedCarets.Add(new uc_CaretAttribs(
                                         this.Caret.Pos,
                                         this.G0.Set,
                                         this.G1.Set,
                                         this.G2.Set,
                                         this.G3.Set,
                                         this.CharAttribs));

                break;

            case "\x1b" + "8":     //DECRC Restore Cursor position and attributes
                this.Caret.Pos   = this.SavedCarets[this.SavedCarets.Count - 1].Pos;
                this.CharAttribs = this.SavedCarets[this.SavedCarets.Count - 1].Attribs;

                this.G0.Set = this.SavedCarets[this.SavedCarets.Count - 1].G0Set;
                this.G1.Set = this.SavedCarets[this.SavedCarets.Count - 1].G1Set;
                this.G2.Set = this.SavedCarets[this.SavedCarets.Count - 1].G2Set;
                this.G3.Set = this.SavedCarets[this.SavedCarets.Count - 1].G3Set;

                this.SavedCarets.RemoveAt(this.SavedCarets.Count - 1);

                break;

            case "\x1b~":     //LS1R Locking Shift G1 -> GR
                this.CharAttribs.GR = G1;
                break;

            case "\x1bn":     //LS2 Locking Shift G2 -> GL
                this.CharAttribs.GL = G2;
                break;

            case "\x1b}":     //LS2R Locking Shift G2 -> GR
                this.CharAttribs.GR = G2;
                break;

            case "\x1bo":     //LS3 Locking Shift G3 -> GL
                this.CharAttribs.GL = G3;
                break;

            case "\x1b|":     //LS3R Locking Shift G3 -> GR
                this.CharAttribs.GR = G3;
                break;

            case "\x1b#8":     //DECALN
                e.CurParams.Elements.Add("1");
                e.CurParams.Elements.Add(this.Rows.ToString());
                this.SetScrollRegion(e.CurParams);

                // put E's on the entire screen
                for (int y = 0; y < this.Rows; y++)
                {
                    this.CaretToAbs(y, 0);

                    for (int x = 0; x < this.Columns; x++)
                    {
                        this.PrintChar('E');
                    }
                }
                break;

            case "\x1b=":     // Keypad to Application mode
                this.Modes.Flags = this.Modes.Flags | uc_Mode.KeypadAppln;
                break;

            case "\x1b>":     // Keypad to Numeric mode
                this.Modes.Flags = this.Modes.Flags ^ uc_Mode.KeypadAppln;
                break;

            case "\x1b[B":     // CUD

                if (e.CurParams.Count() > 0)
                {
                    Inc = System.Convert.ToInt32(e.CurParams.Elements[0]);
                }

                if (Inc == 0)
                {
                    Inc = 1;
                }

                this.CaretToAbs(this.Caret.Pos.Y + Inc, this.Caret.Pos.X);
                break;

            case "\x1b[A":     // CUU

                if (e.CurParams.Count() > 0)
                {
                    Inc = System.Convert.ToInt32(e.CurParams.Elements[0]);
                }

                if (Inc == 0)
                {
                    Inc = 1;
                }

                this.CaretToAbs(this.Caret.Pos.Y - Inc, this.Caret.Pos.X);
                break;

            case "\x1b[C":     // CUF

                if (e.CurParams.Count() > 0)
                {
                    Inc = System.Convert.ToInt32(e.CurParams.Elements[0]);
                }

                if (Inc == 0)
                {
                    Inc = 1;
                }

                this.CaretToAbs(this.Caret.Pos.Y, this.Caret.Pos.X + Inc);
                break;

            case "\x1b[D":     // CUB

                if (e.CurParams.Count() > 0)
                {
                    Inc = System.Convert.ToInt32(e.CurParams.Elements[0]);
                }

                if (Inc == 0)
                {
                    Inc = 1;
                }

                this.CaretToAbs(this.Caret.Pos.Y, this.Caret.Pos.X - Inc);
                break;

            case "\x1b[H":     // CUP

                System.Int32 X = 0;
                System.Int32 Y = 0;

                if (e.CurParams.Count() > 0)
                {
                    Y = System.Convert.ToInt32(e.CurParams.Elements[0]) - 1;
                }

                if (e.CurParams.Count() > 1)
                {
                    X = System.Convert.ToInt32(e.CurParams.Elements[1]) - 1;
                }

                this.CaretToRel(Y, X);
                break;

            case "\x1b[f":     // HVP

                System.Int32 Xf = 0;
                System.Int32 Yf = 0;

                if (e.CurParams.Count() > 0)
                {
                    Yf = System.Convert.ToInt32(e.CurParams.Elements[0]) - 1;
                }

                if (e.CurParams.Count() > 1)
                {
                    Xf = System.Convert.ToInt32(e.CurParams.Elements[1]) - 1;
                }

                this.CaretToRel(Yf, Xf);
                break;

            case "\x1b[J":

                if (e.CurParams.Count() > 0)
                {
                    Param = System.Convert.ToInt32(e.CurParams.Elements[0]);
                }

                this.ClearDown(Param);
                break;

            case "\x1b[K":

                if (e.CurParams.Count() > 0)
                {
                    Param = System.Convert.ToInt32(e.CurParams.Elements[0]);
                }

                this.ClearRight(Param);
                break;

            case "\x1b[L":     // INSERT LINE
                this.InsertLine(e.CurParams);
                break;

            case "\x1b[M":     // DELETE LINE
                this.DeleteLine(e.CurParams);
                break;

            case "\x1bN":     // SS2 Single Shift (G2 -> GL)
                this.CharAttribs.GS = this.G2;
                break;

            case "\x1bO":     // SS3 Single Shift (G3 -> GL)
                this.CharAttribs.GS = this.G3;
                //System.Console.WriteLine ("SS3: GS = {0}", this.CharAttribs.GS);
                break;

            case "\x1b[m":
                this.SetCharAttribs(e.CurParams);
                break;

            case "\x1b[?h":
                this.SetqmhMode(e.CurParams);
                break;

            case "\x1b[?l":
                this.SetqmlMode(e.CurParams);
                break;

            case "\x1b[c":     // DA Device Attributes
//                    this.DispatchMessage (this, "\x1b[?64;1;2;6;7;8;9c");
                this.DispatchMessage(this, "\x1b[?6c");
                //prntSome.printSome(" DA Device Attributes", "montdis", countmontdisrdb);
                //countmontdisrdb++;
                break;

            case "\x1b[g":
                this.ClearTabs(e.CurParams);
                break;

            case "\x1b[h":
                this.SethMode(e.CurParams);
                break;

            case "\x1b[l":
                this.SetlMode(e.CurParams);
                break;

            case "\x1b[r":     // DECSTBM Set Top and Bottom Margins
                this.SetScrollRegion(e.CurParams);
                break;

            case "\x1b[t":     // DECSLPP Set Lines Per Page

                if (e.CurParams.Count() > 0)
                {
                    Param = System.Convert.ToInt32(e.CurParams.Elements[0]);
                }

                if (Param > 0)
                {
                    this.SetSize(Param, this.Columns);
                }

                break;

            case "\x1b" + "D":     // IND

                if (e.CurParams.Count() > 0)
                {
                    Param = System.Convert.ToInt32(e.CurParams.Elements[0]);
                }

                this.Index(Param);
                break;

            case "\x1b" + "E":     // NEL
                this.LineFeed();
                this.CarriageReturn();
                break;

            case "\x1bH":     // HTS
                this.TabSet();
                break;

            case "\x1bM":     // RI
                if (e.CurParams.Count() > 0)
                {
                    Param = System.Convert.ToInt32(e.CurParams.Elements[0]);
                }

                this.ReverseIndex(Param);
                break;

            default:
                //System.Console.Write ("unsupported VT sequence {0} happened\n", e.CurSequence);
                break;
            }

            if (e.CurSequence.StartsWith("\x1b("))
            {
                this.SelectCharSet(ref this.G0.Set, e.CurSequence.Substring(2));
            }
            else if (e.CurSequence.StartsWith("\x1b-") ||
                     e.CurSequence.StartsWith("\x1b)"))
            {
                this.SelectCharSet(ref this.G1.Set, e.CurSequence.Substring(2));
            }
            else if (e.CurSequence.StartsWith("\x1b.") ||
                     e.CurSequence.StartsWith("\x1b*"))
            {
                this.SelectCharSet(ref this.G2.Set, e.CurSequence.Substring(2));
            }
            else if (e.CurSequence.StartsWith("\x1b/") ||
                     e.CurSequence.StartsWith("\x1b+"))
            {
                this.SelectCharSet(ref this.G3.Set, e.CurSequence.Substring(2));
            }
        }