private void InitAccountData(object sender, RoutedEventArgs e)
        {
            string pathToFile = _cp.GetFullPath(_pageLinkFileName);

            // Check Address List existing
            if (File.Exists(pathToFile))
            {
                //var serializer = new JsonSerializer();

                // Deserialize name and pass
                UniversalSerializeDataClass <List <string> > deserilazeData = new UniversalSerializeDataClass <List <string> >();
                PageLinkArray.PageListLink = deserilazeData.DeserializeData(pathToFile);

                // Check null
                if (PageLinkArray.PageListLink != null)
                {
                    // Change color and set successful message
                    ErrorLabel.Foreground = new SolidColorBrush(Colors.Green);
                    ErrorLabel.Content   += $"Page link list load success!\nList count: {PageLinkArray.PageListLink.Count}";

                    // Add dresses to text block
                    foreach (var item in PageLinkArray.PageListLink)
                    {
                        PageLinkBlock.Text += item;
                        PageLinkBlock.Text += "\r\n";
                    }
                }
                else
                {
                    // Change color and set failed message
                    ErrorLabel.Foreground = new SolidColorBrush(Colors.Red);
                    ErrorLabel.Content   += "Page link list load FAILED!\nPlease, add links to list!";
                }
            }
            else
            {
                // Change color and set failed message
                ErrorLabel.Foreground = new SolidColorBrush(Colors.Red);
                ErrorLabel.Content   += "Page link list NOT EXISTS!\nPlease, add links to list!";
            }

            if (File.Exists(_fullPath))
            {
                // Save button disable
                SaveButton.IsEnabled = false;

                // Deserialize name and pass
                UniversalSerializeDataClass <AccountModel> deSerializeData = new UniversalSerializeDataClass <AccountModel>();
                _am = deSerializeData.DeserializeData(_fullPath);

                // Check for null
                if (_am == null)
                {
                    ErrorLabel.Foreground = new SolidColorBrush(Colors.Red);
                    ErrorLabel.Content   += "\nAccount Data load failed!";
                    File.Delete(_fullPath);
                    return;
                }

                // Set values to textboxes
                UserNameBox.Text     = _am.UserName;
                PasswordBox.Password = _am.UserPassword;

                // Change color and set successful message
                ErrorLabel.Foreground = new SolidColorBrush(Colors.Green);
                ErrorLabel.Content   += "\nAccount Data load success!";
            }
            else
            {
                // Set save button to enable
                SaveButton.IsEnabled = true;
            }
        }
Пример #2
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!";
            }
        }
        private void SaveListButton_Click(object sender, RoutedEventArgs e)
        {
            if (PageLinkBlock != null)
            {
                string        pathToFile = _cp.GetFullPath(_pageLinkFileName);
                List <string> listDeserialize;

                string        tempString     = PageLinkBlock.Text;
                List <string> tempArrayLinks = tempString.Replace("\r\n", ",")
                                               .Split(',')
                                               .ToList();

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

                UniversalSerializeDataClass <List <string> > deserializeData = new UniversalSerializeDataClass <List <string> >();
                listDeserialize = deserializeData.DeserializeData(pathToFile);

                // Check deserialize list for null
                if (listDeserialize != null)
                {
                    // Clear List
                    listDeserialize.Clear();

                    // Add all data to list
                    listDeserialize.AddRange(tempArrayLinks);

                    // Add values to static list
                    PageLinkArray.PageListLink.Clear();
                    PageLinkArray.PageListLink.AddRange(listDeserialize);
                }
                else
                {
                    listDeserialize = new List <string>();
                    listDeserialize.AddRange(tempArrayLinks);

                    // Add values to static list
                    PageLinkArray.PageListLink = new List <string>();
                    PageLinkArray.PageListLink.AddRange(listDeserialize);
                }

                // Check for empty items in array
                for (int i = 0; i < PageLinkArray.PageListLink.Count; i++)
                {
                    if (string.IsNullOrWhiteSpace(PageLinkArray.PageListLink[i]))
                    {
                        PageLinkArray.PageListLink.Remove(PageLinkArray.PageListLink[i]);
                    }
                }

                // Save values to JSON file
                UniversalSerializeDataClass <List <string> > serializeData = new UniversalSerializeDataClass <List <string> >();
                serializeData.SerializeData(PageLinkArray.PageListLink, pathToFile);

                ErrorLabel.Foreground = new SolidColorBrush(Colors.Green);
                ErrorLabel.Content    = "\nPage address link data Saved!";
            }
            else
            {
                // Path to file
                string        pathToFile = _cp.GetFullPath(_pageLinkFileName);
                List <string> listDeserialize;

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

                // Deserialize name and pass
                UniversalSerializeDataClass <List <string> > deserializeData = new UniversalSerializeDataClass <List <string> >();
                listDeserialize = deserializeData.DeserializeData(pathToFile);

                if (listDeserialize == null)
                {
                    ErrorLabel.Foreground = new SolidColorBrush(Colors.Red);
                    ErrorLabel.Content   += "\nPage adress link is empty!\nPlease, add addresses to list";
                }
                else
                {
                    ErrorLabel.Foreground = new SolidColorBrush(Colors.Green);
                    ErrorLabel.Content   += "\nPage adress link data loaded!";
                }
            }
        }