void StartSetView() { try { string[] allFoundFiles = Directory.GetFiles($"{AppDomain.CurrentDomain.BaseDirectory}\\data", "*.txt", SearchOption.TopDirectoryOnly); if (allFoundFiles.Length != 0) { foreach (var item in allFoundFiles) { computers.Add(new Computer(new StreamReader(item).ReadToEnd())); } mainWindow.act.sp_act.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate() { foreach (var computer in computers) { ComputerTile tile = new ComputerTile(computer); tile.pressed += SelectedComuterTile; tile.text_NameComputer.Content = computer.ComputerName; mainWindow.act.sp_act.Children.Add(tile); } }); } } catch (Exception) { } }
public void ConnectingComputer(string str) { Computer ccc = new Computer(str); bool isInComputerList = false; for (int i = 0; i < computers.Count; i++) { if (computers[i].ComputerName == ccc.ComputerName) { isInComputerList = true; /*computers[i] = ccc; * if (selectComputer.ComputerName == computers[i]?.ComputerName) * { * SelectedComuterTile(computers[i]); * }*/ break; } } if (!isInComputerList) { mainWindow.act.sp_act.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate() { computers.Add(ccc); var c = new ComputerTile(ccc); c.pressed += SelectedComuterTile; c.text_NameComputer.Content = ccc.ComputerName; mainWindow.act.sp_act.Children.Add(c); }); } FileStream fs = new FileStream($"{ AppDomain.CurrentDomain.BaseDirectory }\\data\\{ccc.ComputerName}.txt", FileMode.OpenOrCreate); StreamWriter sw = new StreamWriter(fs); sw.Write(ccc.MessegeFromClient); sw.Close(); fs.Close(); }