Ejemplo n.º 1
0
        /*
         * protected override string CreateTableForMailing(bool html = true)
         * {
         *
         *  return base.CreateTableForMailing(html);
         * }
         */

        protected override bool FillListResponse()
        {
            /*
             * string myWorkAnswer = MyRequest.GetResponse;
             * if (myWorkAnswer == null)
             *  return;
             */
            if (!base.FillListResponse())
            {
                return(false);
            }

            List <Tag> SearchResult = new List <Tag>();

            List <Tag> HTMLDoc = HTMLParser.Parse(lastAnswer);

            foreach (Tag item in HTMLDoc)
            {
                if (!item.IsProto)
                {
                    SearchResult.AddRange(item.LookForChildTag("span", true, new KeyValuePair <string, string>("class", "teaser teaser-product")));
                }
            }
            //

            List <LotOnlineSales> workList = new List <LotOnlineSales>();

            foreach (Tag item in SearchResult)
            {
                workList.Add(new LotOnlineSales(item, MyRequest));
            }

            this.ListResponse = workList;

            tableHead = new string[]
            {
                "№",
                "Наименование",
                "Цена"
            };

            return(true);
        }
Ejemplo n.º 2
0
        public void TestHTMLParserSimpleEmphasis()
        {
            var res = HTMLParser.Parse("<b>Hello</b>").ToList();

            Assert.AreEqual(res.Count(), 1);
            Assert.IsTrue(CheckRun(res.First(), "Hello", FontWeights.Bold, FontStyle.Normal, TextDecorations.None));

            res = HTMLParser.Parse("<i>  Hello</i>").ToList();
            Assert.AreEqual(res.Count(), 1);
            Assert.IsTrue(CheckRun(res.First(), "  Hello", FontWeights.Normal, FontStyle.Italic, TextDecorations.None));

            res = HTMLParser.Parse("<u>Hello  </u>").ToList();
            Assert.AreEqual(res.Count(), 1);
            Assert.IsTrue(CheckRun(res.First(), "Hello  ", FontWeights.Normal, FontStyle.Normal, TextDecorations.Underline));

            res = HTMLParser.Parse("<s>  Hello World </s>").ToList();
            Assert.AreEqual(res.Count(), 1);
            Assert.IsTrue(CheckRun(res.First(), "  Hello World ", FontWeights.Normal, FontStyle.Normal, TextDecorations.Strikethrough));
        }
Ejemplo n.º 3
0
        public void TestHTMLParserMultiNode()
        {
            var res = HTMLParser.Parse("<b>Hello</b> World").ToList();

            Assert.AreEqual(res.Count(), 2);
            Assert.IsTrue(CheckRun((Run)res[0], "Hello", FontWeights.Bold, FontStyle.Normal, TextDecorations.None));
            Assert.IsTrue(CheckRun((Run)res[1], " World", FontWeights.Normal, FontStyle.Normal, TextDecorations.None));

            res = HTMLParser.Parse("<b>Hello</b> World <i>!!!</i>").ToList();
            Assert.AreEqual(res.Count(), 3);
            Assert.IsTrue(CheckRun((Run)res[0], "Hello", FontWeights.Bold, FontStyle.Normal, TextDecorations.None));
            Assert.IsTrue(CheckRun((Run)res[1], " World ", FontWeights.Normal, FontStyle.Normal, TextDecorations.None));
            Assert.IsTrue(CheckRun((Run)res[2], "!!!", FontWeights.Normal, FontStyle.Italic, TextDecorations.None));

            res = HTMLParser.Parse("Welcome <b>Hello</b> World").ToList();
            Assert.AreEqual(res.Count(), 3);
            Assert.IsTrue(CheckRun((Run)res[0], "Welcome ", FontWeights.Normal, FontStyle.Normal, TextDecorations.None));
            Assert.IsTrue(CheckRun((Run)res[1], "Hello", FontWeights.Bold, FontStyle.Normal, TextDecorations.None));
            Assert.IsTrue(CheckRun((Run)res[2], " World", FontWeights.Normal, FontStyle.Normal, TextDecorations.None));
        }
        public void Open()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                Filter = "HTML Files|*.html"
            };

            if (openFileDialog.ShowDialog() == true)
            {
                string document;
                using (StreamReader sr = new StreamReader(openFileDialog.FileName))
                {
                    document = sr.ReadToEnd();
                }
                this.Elements        = new ObservableCollection <ElementModel>(HTMLParser.Parse(document));
                this.SelectedElement = this.Elements[0];
                this.BuildDocument();
                this.FilePath = openFileDialog.FileName;
                this.OpenInBrowserAvailable = true;
            }
        }
Ejemplo n.º 5
0
        protected override bool FillListResponse()
        {
            /*
             * string myWorkAnswer = MyRequest.GetResponse;
             * if (myWorkAnswer == null)
             *  return;
             */

            if (!base.FillListResponse())
            {
                return(false);
            }

            //
            List <Tag> SearchResult = new List <Tag>();

            List <Tag> HTMLDoc = HTMLParser.Parse(lastAnswer);

            foreach (Tag item in HTMLDoc)
            {
                if (!item.IsProto)
                {
                    //SearchResult.AddRange(item.LookForChildTag("ul", true, new KeyValuePair<string, string>("class", "component-list lot-catalog__list")));
                    SearchResult.AddRange(item.LookForChildTag("li", true, new KeyValuePair <string, string>("class", "component-list__item lot-catalog__list-item")));
                }
            }
            //

            List <TorgASV> workList = new List <TorgASV>();

            foreach (Tag item in SearchResult)
            {
                workList.Add(new TorgASV(item, MyRequest));
            }

            this.ListResponse = workList;

            return(true);
        }
Ejemplo n.º 6
0
        protected override bool FillListResponse()
        {
            /*
             * string myWorkAnswer = MyRequest.GetResponse;
             * if (myWorkAnswer == null)
             *  return;
             */
            if (!base.FillListResponse())
            {
                return(false);
            }

            //
            List <Tag> SearchResult = new List <Tag>();

            List <Tag> HTMLDoc = HTMLParser.Parse(lastAnswer);

            foreach (Tag item in HTMLDoc)
            {
                if (!item.IsProto)
                {
                    SearchResult.AddRange(item.LookForChildTag("div", true, new KeyValuePair <string, string>("class", "row no-gutters registry-entry__form mr-0")));
                }
            }
            //

            List <ZakupkiGov> workList = new List <ZakupkiGov>();

            foreach (Tag item in SearchResult)
            {
                workList.Add(new ZakupkiGov(item, MyRequest));
            }

            this.ListResponse = workList;

            return(true);
        }
        protected override bool FillListResponse()
        {
            /*
             * string myWorkAnswer = MyRequest.GetResponse;
             * if (myWorkAnswer == null)
             *  return;
             */

            if (!base.FillListResponse())
            {
                return(false);
            }
            //
            List <Tag> SearchResult = new List <Tag>();

            List <Tag> HTMLDoc = HTMLParser.Parse(lastAnswer);

            foreach (Tag item in HTMLDoc)
            {
                if (!item.IsProto)
                {
                    SearchResult.AddRange(item.LookForChildTag("tr", true, new KeyValuePair <string, string>("class", "gridRow")));
                }
            }

            List <Centerr> workList = new List <Centerr>();

            if (SearchResult.Count < 1)
            {
                Exception e = new Exception("Nothing found!");
                this.ListResponse = workList;
                return(false);
            }

            foreach (Tag item in SearchResult)
            {
                workList.Add(new Centerr(item, MyRequest));
            }

            this.ListResponse = workList;
            freshResponse     = true;
            return(true);

            //return;
            //

            // Старый парсер

            /*
             * //  Разбор результатов
             * //myWorkAnswer = myHTMLParser.NormalizeString(myWorkAnswer);
             * //myHTMLParser myHtmlParser = new myHTMLParser();
             * List<_Tag> myTagRes = myHtmlParser.getTags(myWorkAnswer, "table");
             * List<List<StringUri>> myTable = new List<List<StringUri>>();
             * foreach (var item in myTagRes)
             * myTable = myHtmlParser.getOutTable(item);
             * // LAST myTable - is RIGHT table!
             * this.ListResponse = GetResultTableAsListOfMyObjects(GetResultTableAsList(myTable));
             *
             * freshResponse = true;
             */
            //
        }
        /*
         * static void Test6()
         * {
         *  string fileName = "ETP_GPB.txt";
         *  string testStr = "";
         *  if (!File.Exists(fileName))
         *  {
         *      GPBRequest myReq = new GPBRequest("техническая жидкость");
         *
         *      //testStr = myReq.GetResponse;
         *      File.WriteAllText(fileName, myReq.GetResponse);
         *  }
         *  testStr = File.ReadAllText(fileName);
         *
         *  myHTMLParser myhp = new myHTMLParser();
         *  //dynamic tmp = myhp.getTags(testStr, "html");
         *  int startParsingFrom = 0;
         *  int endParsingTo = 0;
         *  //startParsingFrom = testStr.IndexOf("<div class=\"proceduresList proceduresList--big proceduresList--with-block-links\"");
         *  startParsingFrom = testStr.IndexOf("<div class=\"proceduresList proceduresList--big proceduresList--with-block-links\" data-selector=\"proceduresList\"");
         *  if (startParsingFrom < 0)
         *      startParsingFrom = testStr.IndexOf("<div class=\"proceduresList hidden proceduresList--big proceduresList--with-block-links\" data-selector=\"proceduresList\"");
         *  endParsingTo = testStr.IndexOf("<div class=\"hiddenPagination hiddenPagination--mb\" data-selector=\"paginationWithKeybordControls\"");
         *  dynamic tmp = myhp.getTags(testStr.Substring(startParsingFrom, endParsingTo - startParsingFrom), "div");
         *  // Попробуем отслеживать доп содержание тега
         *  tmp = myhp.getTags(testStr.Substring(startParsingFrom, endParsingTo-startParsingFrom), "div class=\"procedure\"");
         * }
         */

        static void Test65()
        {
            string fileName = "ETP_GPB_20200727.txt";
            string testStr  = "";

            if (!File.Exists(fileName))
            {
                GPBRequest myReq = new GPBRequest("техническая жидкость");

                //testStr = myReq.GetResponse;
                File.WriteAllText(fileName, myReq.GetResponse);
            }
            testStr = File.ReadAllText(fileName);


            List <Tag> HTMLDoc = new List <Tag>();

            /*
             * Tag myTag;
             * string workStr = testStr;
             *
             * workStr = workStr.Substring(workStr.IndexOf("<div class=\"proceduresList"));
             *
             * while (workStr.Length > 0)
             * {
             *  myTag = new Tag(workStr, null);
             *  if (myTag.IsProto)
             *      HTMLDoc.Add((ProtoTag)myTag);
             *  else
             *      HTMLDoc.Add(myTag);
             *  workStr = myTag.CutOffAfter;
             *
             *  while (workStr.StartsWith("</"))
             *  {
             *      workStr = workStr.Substring(workStr.IndexOf(">")+1);
             *      //continue;
             *  }
             * }
             */

            string workStr = testStr;

            workStr = workStr.Substring(workStr.IndexOf("<div class=\"proceduresList"));

            HTMLDoc = HTMLParser.Parse(testStr);

            List <Tag>      SearchResult      = new List <Tag>();
            List <ProtoTag> SearchProtoResult = new List <ProtoTag>();

            foreach (ProtoTag item in HTMLDoc)
            {
                if (!item.IsProto)
                {
                    SearchResult.AddRange((IEnumerable <Tag>)((Tag)item).LookForChildTag("div", true, new KeyValuePair <string, string>("class", "procedure")));
                    SearchProtoResult.AddRange((IEnumerable <Tag>)((Tag)item).LookForChildTag(null, true));
                }
                else
                {
                    SearchProtoResult.Add(item);
                }
            }

            List <GPB> GPBList = new List <GPB>();

            foreach (Tag item in SearchResult)
            {
                GPBList.Add(new GPB(item, new GPBRequest()));
            }


            HTMLDoc = HTMLParser.Parse(workStr);
        }
 static void Test55()
 {
     // <img src="/images/desc_order.gif" width=7 height=7 border=0 alt="Отсортировано по убыванию">
     string     testStr = "<img src=\"/images/desc_order.gif\" width=7 height=7 border=0 alt=\"Отсортировано по убыванию\">";
     List <Tag> testDoc = HTMLParser.Parse(testStr);
 }
Ejemplo n.º 10
0
        protected override bool FillListResponse()
        {
            /*
             * string myWorkAnswer = MyRequest.GetResponse;
             * if (myWorkAnswer == null)
             *  return;
             */
            if (!base.FillListResponse())
            {
                return(false);
            }

            //
            // /*
            List <Tag> SearchResult = new List <Tag>();

            List <Tag> HTMLDoc = HTMLParser.Parse(lastAnswer);

            foreach (Tag item in HTMLDoc)
            {
                if (!item.IsProto)
                {
                    //SearchResult.AddRange(item.LookForChildTag("table", true));
                    SearchResult.AddRange(item.LookForChildTag("tbody", true));
                }
            }

            List <B2B> workList = new List <B2B>();

            if (SearchResult.Count < 1)
            {
                if (lastAnswer.Contains("search-results empty_results"))
                {
                    lastError         = new Exception("Поиск не дал результатов");
                    this.ListResponse = workList;
                    return(false);
                }
                lastError         = new Exception("Ответ сервера не содержит данных (ожидалась 1 таблица с тегом \"tbody\"):" + Environment.NewLine + lastAnswer);
                this.ListResponse = workList;
                return(false);
            }
            else if (SearchResult.Count > 1)
            {
                lastError         = new Exception("Ответ сервера содержит неожиданную структуру (ожидалась 1 таблица с тегом \"tbody\"):" + Environment.NewLine + lastAnswer);
                this.ListResponse = workList;
                return(false);
            }

            foreach (Tag item in SearchResult[0].ChildTags)
            {
                workList.Add(new B2B(item, MyRequest));
            }

            this.ListResponse = workList;
            return(true);
            // */
            //

            /*
             * // По старому парсеру
             *
             * List<B2B> curList = new List<B2B>();
             *
             * myHTMLParser myParser = new myHTMLParser();
             *
             * List<_Tag> myListCaption = myParser.getTags(myWorkAnswer, "table");
             *
             * //
             * //List<Tag> myList = myParser.getTags(myWorkAnswer, "ol");
             * //List<Tag> resList = new List<Tag>();
             * //
             *
             * if (myListCaption.Count < 1)
             * {
             *  if (myWorkAnswer.Contains("search-results empty_results"))
             *  {
             *      lastError = new Exception("Поиск не дал результатов");
             *      this.ListResponse = curList;
             *      return;
             *  }
             *
             *  lastError = new Exception("Ответ сервера не содержит данных (ожидалась 1 таблица с тегом \"table\"):" + Environment.NewLine + myWorkAnswer);
             *  return;
             * }
             * else if (myListCaption.Count != 1)   // какой-то неожиданный ответ
             * {
             *  lastError = new Exception("Ответ сервера содержит неожиданную структуру (ожидалась 1 таблица с тегом \"table\"):" + Environment.NewLine + myWorkAnswer);
             *  return;
             * }
             *
             * if (myListCaption[0].InnerTags.Count < 1)
             * {
             *  lastError = new Exception("Таблица не содержит данных (ожидалось 2 раздела - заголовки и данные):" + Environment.NewLine + myWorkAnswer);
             *  return;
             * }
             * else if (myListCaption[0].InnerTags.Count != 2)
             * {
             *  lastError = new Exception("Таблица содержит неожиданную структуру (ожидалось 2 раздела - заголовки и данные):" + Environment.NewLine + myWorkAnswer);
             *  return;
             * }
             *
             * if (!myListCaption[0].InnerTags[1].HasInnerTags)
             * {
             *  lastError = new Exception("Похоже, что не нашлось результатов поиска:" + Environment.NewLine + myWorkAnswer);
             *  return;
             * }
             *
             * foreach (_Tag item in myListCaption[0].InnerTags[1].InnerTags)
             * {
             *  if (item.InnerTags.Count == 4)
             *      if ((item.InnerTags[0].InnerTags.Count == 1) & (item.InnerTags[1].InnerTags.Count == 1))
             *          curList.Add(new B2B(item));
             * }
             *
             * this.ListResponse = curList;
             * //
             */
        }
Ejemplo n.º 11
0
        private void SendEmails()
        {
            App app = Application.Current as App;

            if (app.SqlManager.IsConnected)
            {
                // Getting the entries where prealert is 0 / false
                ISqlResultSet result = app.SqlManager.ExecuteQuerryFromFile("Sql/GetPreAlertFalse.sql");
                if (result.GetRowCount() == 0)
                {
                    Console.WriteLine("No entries with PreAlert = false found!");
                    return;
                }

                string           json              = File.ReadAllText(App.TRANSFORM_DIR + "PurchaseOrder.json");
                TableTransformer tableTransformer  = TableTransformer.FromJson(json);
                ISqlResultSet    transformedResult = tableTransformer.TransformSqlResultSet(result);

                json             = File.ReadAllText(App.TRANSFORM_DIR + "Items.json");
                tableTransformer = TableTransformer.FromJson(json);

                HashSet <int> ids = new HashSet <int>();
                for (int i = 0; i < result.GetRowCount(); i++)
                {
                    int?nid = result.GetValue(0, i).AsInt();
                    if (nid.HasValue)
                    {
                        ids.Add(nid.Value);
                    }
                }

                List <EmailWrapper> emails = new List <EmailWrapper>();

                for (int i = 0; i < result.GetRowCount(); i++)
                {
                    int           idcol                 = result.ColumnIndexOf("ID");
                    int           colid                 = result.GetValue(idcol, i).AsInt().Value;
                    int           inboundcol            = result.ColumnIndexOf("INBOUNDID");
                    int           inboundid             = result.GetValue(inboundcol, i).AsInt().Value;
                    ISqlResultSet itemResult            = app.SqlManager.ExectuteParameterizedQuerryFromFile("Sql/ItemLevel.sql", new string[] { inboundid.ToString() });
                    ISqlResultSet transformedItemResult = tableTransformer.TransformSqlResultSet(itemResult);

                    EmailDataContext context = new EmailDataContext
                    {
                        ShipmentTable = SimpleHTMLTable.FromSqlResult(transformedResult, i, 1),
                        ItemTable     = SimpleHTMLTable.FromSqlResult(transformedItemResult)
                    };

                    string     htmlSource = File.ReadAllText("Html/EmailTemplate.html");
                    HTMLParser parser     = new HTMLParser(htmlSource)
                    {
                        DataContext = context
                    };
                    string parsedSource = parser.Parse();

                    EmailWrapper emailData = new EmailWrapper
                    {
                        ID         = colid,
                        ShouldSend = true,
                        Receiver   = app.Settings.EmailAdress,
                        Subject    = ("PREALERT - OrderID=" + inboundid),
                        HTMLBody   = parsedSource
                    };

                    emails.Add(emailData);
                }

                if (app.Settings.ShowEmailsBeforeSending)
                {
                    EmailPreviewWindow emailPreviewWindow = new EmailPreviewWindow(emails);
                    emailPreviewWindow.ShowDialog();
                }

                HashSet <int> sendIds = new HashSet <int>();

                OutlookApplication application = OutlookApplication.CreateApplication();
                foreach (EmailWrapper data in emails)
                {
                    if (data.ShouldSend)
                    {
                        //Console.WriteLine("EmailData: ID:{0}, TO:{1}, SUBJECT:{2}, SHOULD_SEND:{3}", data.ID, data.Receiver, data.Subject, data.ShouldSend);
                        bool sent = SendEmail(application, data);
                        if (sent)
                        {
                            sendIds.Add(data.ID);
                        }
                    }
                }

                if (sendIds.Count > 0)
                {
                    // updating the prealert to 1 / true
                    StringBuilder conditionBuilder = new StringBuilder();

                    int j = 0;
                    foreach (int id in sendIds)
                    {
                        conditionBuilder.Append("ID = " + id);
                        j++;
                        if (j < sendIds.Count)
                        {
                            conditionBuilder.Append(" OR ");
                        }
                    }

                    string updateQuerry = "UPDATE TRITPurchaseOrder SET PREALERT = 1 WHERE " + conditionBuilder.ToString();
                    int    rowsAffected = app.SqlManager.ExecuteWithoutResult(updateQuerry);
                    Console.WriteLine("Rows affected: {0}", rowsAffected);
                }
            }
        }
        /*
         * protected void _FillListResponse()
         * {
         *  string myWorkAnswer = MyRequest.GetResponse;
         *  if (myWorkAnswer == null)
         *      return;
         *
         *  List<ASVorg> curList = new List<ASVorg>();
         *
         *  myHTMLParser myParser = new myHTMLParser();
         *  List<_Tag> myListCaption = myParser.getTags(myWorkAnswer, "h3");
         *
         *  List<_Tag> myList = myParser.getTags(myWorkAnswer, "ol");
         *  List<_Tag> resList = new List<_Tag>();
         *
         *  int k = 0;
         *  string sectionName;
         *  foreach (_Tag itemSection in myList) // первый уровень - разделы (страхование, ликвидация и т.п.)
         *  {
         *      sectionName = "";
         *      if (k < myListCaption.Count)
         *          sectionName = myListCaption[k].Value;
         *
         *      foreach (_Tag item in itemSection.InnerTags) // второй уровень - записи
         *          curList.Add(new ASVorg(item, sectionName));
         *      k++;
         *  }
         *
         *  this.ListResponse = curList;
         *
         * }
         */

        protected override bool FillListResponse()
        {
            /*
             * string myWorkAnswer = MyRequest.GetResponse;
             * if (myWorkAnswer == null)
             *  return;
             */

            if (!base.FillListResponse())
            {
                return(false);
            }

            //
            List <Tag>    SearchResultTmp = new List <Tag>();
            List <ASVorg> workList        = new List <ASVorg>();

            List <Tag> HTMLDoc = HTMLParser.Parse(lastAnswer);

            foreach (Tag item in HTMLDoc)
            {
                if (!item.IsProto)
                {
                    SearchResultTmp.AddRange(item.LookForChildTag("ol", true));
                }
            }
            List <Tag> SearchResult = new List <Tag>();

            foreach (Tag item in SearchResultTmp)
            {
                SearchResult.AddRange(item.LookForChildTag("li", true));
            }

            if (SearchResult.Count < 1)
            {
                if (lastAnswer.Contains("emptyResultsBlock"))
                {
                    lastError         = new Exception("Поиск не дал результатов");
                    this.ListResponse = workList;
                    return(false);
                }
                lastError         = new Exception("Ответ сервера не содержит данных (ожидались результаты с тегом \"div\" и классом \"procedure__data\"):" + Environment.NewLine + lastAnswer);
                this.ListResponse = workList;
                return(false);
            }

            foreach (Tag item in SearchResult)
            {
                workList.Add(new ASVorg(item, MyRequest));
            }

            this.ListResponse = workList;
            return(true);

            //

            /*
             * List<ASVorg> curList = new List<ASVorg>();
             *
             * myHTMLParser myParser = new myHTMLParser();
             * List<_Tag> myListCaption = myParser.getTags(myWorkAnswer, "h3");
             *
             * List<_Tag> myList = myParser.getTags(myWorkAnswer, "ol");
             * List<_Tag> resList = new List<_Tag>();
             *
             * int k = 0;
             * string sectionName;
             * foreach (_Tag itemSection in myList) // первый уровень - разделы (страхование, ликвидация и т.п.)
             * {
             *  sectionName = "";
             *  if (k < myListCaption.Count)
             *      sectionName = myListCaption[k].Value;
             *
             *  foreach (_Tag item in itemSection.InnerTags) // второй уровень - записи
             *      curList.Add(new ASVorg(item, sectionName));
             *  k++;
             * }
             *
             * this.ListResponse = curList;
             */
        }