Ejemplo n.º 1
0
        private void StartWork()
        {
            done             = false;
            done1            = false;
            done2            = false;
            done3            = false;
            done4            = false;
            LastWrittenPost1 = new JsonTemplate1();
            LastWrittenPost2 = new JsonTemplate2();
            LastWrittenPost3 = new JsonTemplate3();
            List <IWebElement> webElements = chromeDriver.FindElements(By.CssSelector("div[class='feed_row '")).ToList();
            List <IWebElement> posts1      = (from t in webElements where (t.FindElements(By.CssSelector("div[class='wall_post_text']")).Count != 0 || (t.FindElements(By.CssSelector("div[class='wall_post_text zoom_text']")).Count != 0)) && (t.FindElements(By.CssSelector("div[class='_post post page_block post--with-likes deep_active']")).Count != 0) select t).ToList();
            List <IWebElement> posts2      = (from t in webElements where (t.FindElements(By.CssSelector("a[aria-label='фотография']")).Count != 0) && (t.FindElements(By.CssSelector("div[class='_post post page_block post--with-likes deep_active']")).Count != 0) select t).ToList();
            List <IWebElement> posts3      = (from t in webElements where (t.FindElements(By.CssSelector("a[aria-label='фотография']")).Count != 0) && (t.FindElements(By.CssSelector("div[class='_post post page_block post--with-likes deep_active']")).Count != 0) select t).ToList();

            thread1           = new Thread(new ParameterizedThreadStart(WriteIdAndText));
            thread1.Name      = "Writer1";
            thread2           = new Thread(new ParameterizedThreadStart(WriteIdPostAndPicture));
            thread2.Name      = "Writer2";
            thread3           = new Thread(new ParameterizedThreadStart(WriteIdAndHrefPicture));
            thread3.Name      = "Writer3";
            readerThread      = new Thread(Read);
            readerThread.Name = "Reader";
            thread1.Start(posts1);
            thread2.Start(posts2);
            thread3.Start(posts3);
            readerThread.Start();
        }
Ejemplo n.º 2
0
        private void WriteIdAndHrefPicture(object webElements)
        {
            if (thirdFileIsUsed)
            {
                return;
            }
            thirdFileIsUsed = true;
            using (StreamWriter streamWriter = new StreamWriter(@"C:\Users\Warmi\Desktop\ОС\text3.txt", true))
            {
                JsonTemplate3 jsonTemplate = new JsonTemplate3();
                foreach (IWebElement item in (List <IWebElement>)webElements)
                {
                    jsonTemplate.id = item.FindElement(By.CssSelector("div[class='_post post page_block post--with-likes deep_active']")).GetAttribute("id").ToString();

                    foreach (IWebElement picture in item.FindElement(By.CssSelector("div[class='page_post_sized_thumbs  clear_fix']")).FindElements(By.CssSelector("a[aria-label='фотография']")).ToList())
                    {
                        jsonTemplate.hrefPicture.Add(picture.GetAttribute("data-photo-id").ToString());
                    }

                    jsonTemplate.hrefPicture.Add(CutString(item.FindElement(By.CssSelector("a[aria-label='фотография']")).GetAttribute("style").ToString()));

                    streamWriter.Write(JsonConvert.SerializeObject(jsonTemplate));
                    jsonTemplate.hrefPicture.Clear();
                }
                streamWriter.Flush();
                streamWriter.Dispose();
                streamWriter.Close();
            }
            thirdFileIsUsed = false;
            done3           = true;
            done            = done1 && done2 && done3 && done4;
            readerThread.Resume();
        }
Ejemplo n.º 3
0
        private void Read()
        {
            if (thread1.IsAlive)
            {
                Thread.CurrentThread.Suspend();
            }

            firstFileIsUsed = true;
            using (StreamReader streamReader = new StreamReader(@"C:\Users\Warmi\Desktop\ОС\text1.txt"))
            {
                string s = @"";
                s += streamReader.Read();
                while (s[s.Length - 1] != '}')
                {
                    s += streamReader.Read();
                }
                LastWrittenPost1 = JsonConvert.DeserializeObject <JsonTemplate1>(s);
                streamReader.Dispose();
                streamReader.Close();
            }
            firstFileIsUsed = false;

            if (thread2.IsAlive)
            {
                Thread.CurrentThread.Suspend();
            }
            secondFileIsUsed = true;
            using (StreamReader streamReader = new StreamReader(@"C:\Users\Warmi\Desktop\ОС\text2.txt"))
            {
                string s = @"";
                s += streamReader.Read();
                while (s[s.Length - 1] != '}')
                {
                    s += streamReader.Read();
                }
                LastWrittenPost2 = JsonConvert.DeserializeObject <JsonTemplate2>(s);

                streamReader.Dispose();
                streamReader.Close();
            }
            secondFileIsUsed = false;

            if (thread3.IsAlive)
            {
                Thread.CurrentThread.Suspend();
            }
            thirdFileIsUsed = true;
            using (StreamReader streamReader = new StreamReader(@"C:\Users\Warmi\Desktop\ОС\text3.txt"))
            {
                string s = @"";
                s += streamReader.Read();
                while (s[s.Length - 1] != '}')
                {
                    s += streamReader.Read();
                }
                LastWrittenPost3 = JsonConvert.DeserializeObject <JsonTemplate3>(s);

                streamReader.Dispose();
                streamReader.Close();
            }
            thirdFileIsUsed = false;
            done4           = true;
            done            = done1 && done2 && done3 && done4;
        }