Esempio n. 1
0
        private void SaveToJson(List <FollowModel> findResultModel, TextBox resultTextBox)
        {
            SetMessage("Set all paths to JSON file ...", true, resultTextBox);

            string        fileName = "resultList.json";
            ConstantPaths cp       = new ConstantPaths();
            string        fullPath = cp.GetFullPath(fileName);

            // Create JSON file if not exists
            if (!File.Exists(fullPath))
            {
                var file = File.Create(fullPath);
                file.Close();
            }
            else
            {
                File.Delete(fullPath);

                var file = File.Create(fullPath);
                file.Close();
            }

            SetMessage("Start serializing to JSON format ...", true, resultTextBox);

            UniversalSerializeDataClass <List <FollowModel> > serializeData = new UniversalSerializeDataClass <List <FollowModel> >();

            serializeData.SerializeData(findResultModel, fullPath);

            SetMessage("Save JSON file action complete! Well done!", true, resultTextBox);
        }
 public Settings()
 {
     InitializeComponent();
     _cp       = new ConstantPaths();
     _fullPath = _cp.GetFullPath(_fileName);
     _am       = new AccountModel();
 }
Esempio n. 3
0
        private static List <FollowModel> GetDataFromJson(TextBox resultTextBox)
        {
            ConstantPaths cp = new ConstantPaths();

            string fileName = "resultList.json";
            string fullPath = cp.GetFullPath(fileName);

            UniversalSerializeDataClass <List <FollowModel> > deserializer = new UniversalSerializeDataClass <List <FollowModel> >();
            var result = deserializer.DeserializeData(fullPath);

            if (result != null)
            {
                SetMessage("Load data from JSON complete.", false, resultTextBox);
                return(result);
            }
            else
            {
                SetMessage("Load data from JSON failed. Please, parse the data and push Show result button first.", false, resultTextBox);
                return(null);
            }
        }
Esempio n. 4
0
        // Save result to JSON
        private void SaveDataToJson(IWebDriver driver, TextBox resultTextBox)
        {
            ConstantPaths paths = new ConstantPaths();

            SetMessage($"Start to serialize data to JSON file ...", true, resultTextBox);

            // Create paths
            string jsonFileName = "parsedFollowersList.json";
            string fullPath     = paths.GetFullPath(jsonFileName);

            // Check, if directory not exists, create directory
            if (!Directory.Exists(paths.PathToJsonFolder))
            {
                Directory.CreateDirectory(paths.PathToJsonFolder);
            }

            // Create JSON file if not exists
            if (!File.Exists(fullPath))
            {
                var file = File.Create(fullPath);
                file.Close();
            }
            else
            {
                File.Delete(fullPath);

                var file = File.Create(fullPath);
                file.Close();
            }


            UniversalSerializeDataClass <List <FollowModel> > serializeData = new UniversalSerializeDataClass <List <FollowModel> >();

            serializeData.SerializeData(FollowsList.Follows, fullPath);

            driver.Quit();

            SetMessage($"All data saved!\nWell done!\nPeople count: {FollowsList.Follows.Count}\nNow you can convert to all same addresses to XML", true, resultTextBox);
        }
Esempio n. 5
0
        private void LoginPasperTask(IWebDriver driver)
        {
            // Go to user page
            ConstantPaths paths = new ConstantPaths();

            driver.Navigate().GoToUrl(paths.StartAddress);

            /* LOGIN PAGE */

            // Find element by name
            var formElement     = driver.FindElement(By.TagName("form"));
            var usernameElement = formElement.FindElement(By.Name("username"));
            var passwordElement = formElement.FindElement(By.Name("password"));
            var loginButton     = formElement.FindElement(By.TagName("button"));

            // Set username
            usernameElement.SendKeys(TempUserData.UserName);
            passwordElement.SendKeys(TempUserData.UserPassword);

            // Wait 4 seconds
            Thread.Sleep(4000);

            // Click login button
            loginButton.Click();

            // Wait 4 seconds and check login success
            while (true)
            {
                // Wait 4 seconds
                Thread.Sleep(4000);

                // Get current URL
                string checkUrl = driver.Url;

                // Check urls
                if (paths.StartAddress == checkUrl)
                {
                    // Click login button
                    loginButton.Click();
                }
                else
                {
                    break;
                }
            }


            /**************/

            /* Find element to applay save */

            // Wait 4 seconds and click the button
            Thread.Sleep(4000);

            // Find section element and button
            var saveFormElement = driver.FindElement(By.TagName("section"));
            var saveButton      = saveFormElement.FindElement(By.TagName("button"));

            saveButton.Click();

            /*******************************/

            DoneActionList.LoginIsDone = true;
        }
Esempio n. 6
0
        public void ConvertToExcel(TextBox resultTextBox)
        {
            ConstantPaths cp = new ConstantPaths();

            ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

            var dataListToConvert = GetDataFromJson(resultTextBox);

            if (dataListToConvert == null)
            {
                SetMessage("List is empty! Please, press to Show Data button first!", false, resultTextBox);
                return;
            }

            SetMessage("Create the paths ...", false, resultTextBox);

            // Check, if directory not exists, create directory
            if (!Directory.Exists(cp.PathToExcelFolder))
            {
                Directory.CreateDirectory(cp.PathToExcelFolder);
            }

            var fullPath = new FileInfo(cp.GetFullPathToResult("Result.xlsx"));

            if (fullPath.Exists)
            {
                fullPath.Delete();
            }

            using (ExcelPackage excelPackage = new ExcelPackage(fullPath))
            {
                // Get handle to the existing worksheet
                ExcelWorksheet worksheet  = excelPackage.Workbook.Worksheets.Add("Follows");
                var            namedStyle = excelPackage.Workbook.Styles.CreateNamedStyle("HyperLink"); //This one is language dependent
                namedStyle.Style.Font.UnderLine = true;
                namedStyle.Style.Font.Color.SetColor(Color.Blue);

                SetMessage("Create the table object, Please, Wait ...", true, resultTextBox);

                if (worksheet != null)
                {
                    const int startRow = 5;
                    int       row      = startRow;

                    //Create Headers and format them
                    worksheet.Cells["A1"].Value = "Demonick Games";
                    using (ExcelRange r = worksheet.Cells["A1:D1"])
                    {
                        r.Merge = true;
                        r.Style.Font.SetFromFont(new Font("Britannic Bold", 22, FontStyle.Italic));
                        r.Style.Font.Color.SetColor(Color.White);
                        r.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.CenterContinuous;
                        r.Style.Fill.PatternType    = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                        r.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(23, 55, 93));
                    }

                    worksheet.Cells["A2"].Value = "Same follows report";

                    using (ExcelRange r = worksheet.Cells["A2:D2"])
                    {
                        r.Merge = true;
                        r.Style.Font.SetFromFont(new Font("Britannic Bold", 18, FontStyle.Italic));
                        r.Style.Font.Color.SetColor(Color.Black);
                        r.Style.HorizontalAlignment = ExcelHorizontalAlignment.CenterContinuous;
                        r.Style.Fill.PatternType    = ExcelFillStyle.Solid;
                        r.Style.Fill.BackgroundColor.SetColor(Color.FromArgb(184, 204, 228));
                    }

                    worksheet.Cells["A4"].Value = cp.ColumNames[0];
                    worksheet.Cells["B4"].Value = cp.ColumNames[1];
                    worksheet.Cells["C4"].Value = cp.ColumNames[2];
                    worksheet.Cells["D4"].Value = cp.ColumNames[3];

                    worksheet.Cells["A4:D4"].Style.Fill.PatternType = ExcelFillStyle.Solid;
                    worksheet.Cells["A4:D4"].Style.Fill.BackgroundColor.SetColor(Color.FromArgb(184, 204, 228));
                    worksheet.Cells["A4:D4"].Style.Font.Bold = true;

                    List <FollowData> rowData = new List <FollowData>();

                    foreach (var item in dataListToConvert)
                    {
                        rowData.AddRange(item.FollowsData);
                    }

                    rowData = rowData.OrderByDescending(x => x.SameFollowCount).ToList();

                    while ((row - 5) < rowData.Count)
                    {
                        // our query has the columns in the right order, so simply
                        // iterate through the columns
                        for (int i = 1; i <= cp.ColumNames.Length; i++)
                        {
                            // use the email address as a hyperlink for column 1
                            if (i == 2)
                            {
                                // insert the email address as a hyperlink for the name
                                string hyperlink = rowData[row - 5].FollowPageAddress;
                                worksheet.Cells[row, i].Hyperlink = new Uri(hyperlink, UriKind.Absolute);
                            }
                            else
                            {
                                // do not bother filling cell with blank data (also useful if we have a formula in a cell)
                                worksheet.Cells[row, i].Value = GetRowData(rowData[row - 5], i);
                                //col++;
                            }
                        }
                        row++;
                    }

                    worksheet.Cells[startRow, 2, row - 1, 2].StyleName = "HyperLink";

                    //Set column width
                    worksheet.Column(1).Width = 34;
                    worksheet.Column(2).Width = 45;
                    worksheet.Column(3).Width = 6;
                    worksheet.Column(4).Width = 40;

                    // lets set the header text
                    worksheet.HeaderFooter.OddHeader.CenteredText = "Demonick Games. Twitter Following Page Report";
                    // add the page number to the footer plus the total number of pages
                    worksheet.HeaderFooter.OddFooter.RightAlignedText =
                        string.Format("Page {0} of {1}", ExcelHeaderFooter.PageNumber, ExcelHeaderFooter.NumberOfPages);
                    // add the sheet name to the footer
                    worksheet.HeaderFooter.OddFooter.CenteredText = ExcelHeaderFooter.SheetName;
                    // add the file path to the footer
                    worksheet.HeaderFooter.OddFooter.LeftAlignedText = ExcelHeaderFooter.FilePath + ExcelHeaderFooter.FileName;

                    excelPackage.Save();

                    SetMessage("Save in file ...", true, resultTextBox);
                }
            }

            SetMessage($"Convert and Save data to Excel file seccessful!\nFile path is: {fullPath}", true, resultTextBox);
        }
Esempio n. 7
0
        private void InitData(object sender, EventArgs e)
        {
            var           messageBox = GeTextBox();
            ConstantPaths cp         = new ConstantPaths();

            // JSON file paths
            const string fileName = "settings.json";
            string       fullPath = cp.GetFullPath(fileName);

            const string pageLinkFileName = "pageLinks.json";
            string       pathToList       = cp.GetFullPath(pageLinkFileName);

            const string parsedFileName   = "parsedFollowersList.json";
            string       pathToParsedFile = cp.GetFullPath(parsedFileName);

            // Init Account Model

            if (File.Exists(fullPath))
            {
                AccountModel am = new AccountModel();

                UniversalSerializeDataClass <AccountModel> accountData = new UniversalSerializeDataClass <AccountModel>();
                am = accountData.DeserializeData(fullPath);

                // Check, if file exists
                if (File.Exists(pathToList))
                {
                    // Deserialize Page link list
                    UniversalSerializeDataClass <List <string> > followsData = new UniversalSerializeDataClass <List <string> >();
                    PageLinkArray.PageListLink = followsData.DeserializeData(pathToList);

                    // Check for null
                    if (PageLinkArray.PageListLink == null)
                    {
                        // Set warning message to Text box
                        messageBox.Text =
                            "List link data load failed!\nPlease, add links to list!";
                        return;
                    }
                    else
                    {
                        // Set successful message to Text box
                        messageBox.Text = $"Page Link Data load successful!\nLink count: {PageLinkArray.PageListLink.Count}";
                    }
                }
                else
                {
                    // Set warning message to Text box
                    messageBox.Text += "List link data file not found!\nPlease, add links to list!";
                }

                // Check, if file exists
                if (File.Exists(pathToParsedFile))
                {
                    // Deserialize Parsed File list
                    UniversalSerializeDataClass <List <FollowModel> > folloData = new UniversalSerializeDataClass <List <FollowModel> >();
                    FollowsList.Follows = folloData.DeserializeData(pathToParsedFile);

                    // Check for null
                    if (FollowsList.Follows == null)
                    {
                        // Set warning message to Text box
                        messageBox.Text +=
                            "\nFollows people list data load failed!\nPlease, start to parse!";
                        return;
                    }
                    else
                    {
                        // Set successful message to Text box
                        messageBox.Text += $"\nFollows people list data load successful!\nPeople count: {FollowsList.Follows.Count}";
                    }
                }
                else
                {
                    // Set warning message to Text box
                    messageBox.Text += "\nFollows people list data file not found!\nPlease, start to parse!";
                }

                // Set values to static model
                if (am != null)
                {
                    TempUserData.UserName     = am.UserName;
                    TempUserData.UserPassword = am.UserPassword;
                }

                // Set successful message to Text box
                messageBox.Text += "\nUser Data load successful!";
            }
            else
            {
                // Set warning message to Text box
                messageBox.Text += "\nPlease, set user data to Settings!";
            }
        }