private void UpdateChainInfo() { var files = Directory.GetFiles(folderUsersData); foreach (var file in files) { using (CustomJsonSerializer <Chain> serializer = new CustomJsonSerializer <Chain>()) { serializer.SerializeToFile(Chain, file); } } }
private void Registration() { if (loginBox.Text == "" || passwordBox.Text == "") { MessageBox.Show("Input login and password"); return; } if (!File.Exists(usersFile)) { File.Create(usersFile).Close(); } List <Person> persons; using (CustomJsonSerializer <List <Person> > serializer = new CustomJsonSerializer <List <Person> >()) { persons = serializer.DeserializeFromFile(usersFile) ?? new List <Person>(); if (persons.Any(p => p.AccountNumber == loginBox.Text)) { MessageBox.Show("This login currently exist!"); return; } persons.Add(new Person() { AccountNumber = loginBox.Text, Password = passwordBox.Text, Name = "", Surname = "" }); serializer.SerializeToFile(persons, usersFile); } var dataPath = Path.Combine(folderUsersData, $"{loginBox.Text}_chain.json"); if (!Directory.Exists(folderUsersData)) { Directory.CreateDirectory(folderUsersData); } var files = Directory.GetFiles(folderUsersData); File.Create(dataPath).Close(); if (files.Length > 0) { string chainInfo; using (StreamReader sr = new StreamReader(files.First())) { chainInfo = sr.ReadToEnd(); } using (StreamWriter sw = new StreamWriter(dataPath, false)) { sw.Write(chainInfo); } } LogIn(); }