private void Save_Click(object sender, RoutedEventArgs e) { // Check null values if (string.IsNullOrWhiteSpace(UserNameBox.Text) && string.IsNullOrWhiteSpace(PasswordBox.Password)) { ErrorLabel.Content = "User name of password cannot be empty!"; return; } // Set values to model _am.UserName = UserNameBox.Text; _am.UserPassword = PasswordBox.Password; // Set data to static model TempUserData.UserName = _am.UserName; TempUserData.UserPassword = _am.UserPassword; if (IsSaved.IsChecked ?? false) { // Check, if directory not exists, create directory if (!Directory.Exists(_cp.PathToJsonFolder)) { Directory.CreateDirectory(_cp.PathToJsonFolder); } // Create JSON file if not exists if (!File.Exists(_fullPath)) { var file = File.Create(_fullPath); file.Close(); } UniversalSerializeDataClass <AccountModel> serializeData = new UniversalSerializeDataClass <AccountModel>(); serializeData.SerializeData(_am, _fullPath); // Print success message ErrorLabel.Foreground = new SolidColorBrush(Colors.Green); ErrorLabel.Content = "\nSave data success!"; // Set save button to disable SaveButton.IsEnabled = false; } else { TempUserData.UserName = _am.UserName; TempUserData.UserPassword = _am.UserPassword; // Print success message ErrorLabel.Foreground = new SolidColorBrush(Colors.Green); ErrorLabel.Content = "Data temporary saved! \nRemember set new data next time!"; } }
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!"; } } }