public static bool LoadClients() { try { ClientsList.Clear(); using (var sr = new StreamReader(FilePath)) { var deSerializer = new XmlSerializer(typeof(ObservableCollection <Client>)); var tmpCollection = (ObservableCollection <Client>)deSerializer.Deserialize(sr); foreach (var item in tmpCollection) { ClientsList.Add(item); } return(true); } } catch (Exception ex) { if (ex is FileNotFoundException) { var sw = new StreamWriter(FilePath); } MessageBox.Show(ex.Message); return(false); } }
public void FindClientFunc(object obj) { try { if (_searchText != "") { string task; if (radio2 == true) { task = $"findClientByProject#{_searchText}"; } else { task = $"findClientByClient#{_searchText}"; } client = new TcpClient(); client.Connect(ep); NetworkStream ns = client.GetStream(); StreamWriter sw = new StreamWriter(ns); sw.WriteLine(task); sw.Flush(); byte[] data = new byte[50000]; int bytes = ns.Read(data, 0, data.Length); ObservableCollection <ClassesLibaryBilling.Client> cl = new ObservableCollection <ClassesLibaryBilling.Client>(); cl = FromByteArray <ObservableCollection <ClassesLibaryBilling.Client> >(data); ClientsList.Clear(); foreach (var item in cl) { ClientsList.Add(item); } sw.Close(); ns.Close(); client.Close(); } else { MessageBox.Show("Введите текст для поиска"); } } catch (Exception error) { MessageBox.Show(error.Message); } }
public ClientsList GetClients() { ClientsList result = new ClientsList(); MySqlCommand cmd = new MySqlCommand("SELECT c_id,c_org,c_address FROM clients;", sql); MySqlDataReader rd = cmd.ExecuteReader(); while (rd.Read()) { result.Add(new Client(rd.GetInt32("c_id"), rd.GetString("c_org"), rd.GetString("c_address"))); } rd.Close(); return(result); }
public MainWindowViewModel() { ClientsList.Add(new Client { Id = 1, LastName = "Иванов", Name = "Иван", Patronymic = "Иванович" }); //Инициализация команда (задаем поведение при вызове команды) //Можно задать с помощью анонимной функции ClickCommand = ReactiveCommand.Create(() => { Data++; }); //А можно задать из метода AddCommand = ReactiveCommand.Create(AddImp); EditCommand = ReactiveCommand.Create(EditImp); RemoveCommand = ReactiveCommand.Create(RemoveImp); }
public override Task OnConnected() { Logger.Info($"Client {this.Context.ConnectionId} connected!"); tokenSource = new CancellationTokenSource(); cancellationToken = tokenSource.Token; if (!ClientsList.Any()) { ClientsList.Add(this.Context.ConnectionId); Logger.Info($"Client first!"); First = true; } else { return(Task); } return(base.OnConnected()); }
public void LoadClients() { try { ClientsList.Clear(); string task = "loadClients"; client = new TcpClient(); client.Connect(ep); NetworkStream ns = client.GetStream(); StreamWriter sw = new StreamWriter(ns); sw.WriteLine(task); sw.Flush(); byte[] data = new byte[50000]; int bytes = ns.Read(data, 0, data.Length); ObservableCollection <ClassesLibaryBilling.Client> cl = new ObservableCollection <ClassesLibaryBilling.Client>(); cl = FromByteArray <ObservableCollection <ClassesLibaryBilling.Client> >(data); foreach (var item in cl) { ClientsList.Add(item); } sw.Close(); ns.Close(); client.Close(); } catch (Exception) { MessageBox.Show("Сервер выключен либо отсутствует соидинение с интеренетом"); } }
/// <summary> /// Реализация метода добавления сотрудника (тут мы работаем только со списоком, об вьюхе и списке на ней мы ничего не знаем) /// </summary> private void AddImp() { ClientsList.Add(new Client { Id = 1, LastName = "Иванов", Name = "Иван", Patronymic = "Иванович" }); }
public static void AddClient(Client newClient) { ClientsList.Add(newClient); SaveClients(); SetNumberOfClients(); }
/// <summary> /// Listen for new messages of individual clients /// </summary> /// <param name="client"></param> protected void ListenClient(TCPServerClient client) { if (Logging) { Logger.Write("REGION", "Method [ListenClient]"); } using (Stream ns = GetStream(client)) { client.Stream = ns; client.Writer = new TCPWriter(ns); client.Reader = new TCPReader(ns); if (Logging) { Logger.Write("INFO", "Created stream, writer and reader for client: " + client.UID); } lock (ClientsList) ClientsList.Add(client); lock (ClientsDict) ClientsDict.Add(client.UID, client); OnConnected?.Invoke(client); if (RequireHandshake) { TCPMessage message = client.Reader.Read(client); if (message.Code != TCPMessageCode.Init || message.Content.Length > 10) { RemoveClient(client, TCPDisconnectType.NoHandshake); return; } if (Logging) { Logger.Write("SUCCESS", "Handshake: " + client.UID); } client.DoneHandshake = true; client.Send(new TCPMessage() { Code = TCPMessageCode.Init, Content = new byte[] { 0, 1, 0 } }); } while (Running && ClientsDict.ContainsKey(client.UID)) { TCPMessage message = client.Reader.Read(client); if (message == null) { RemoveClient(client, TCPDisconnectType.Timeout); return; } if (Logging) { Logger.Write("INFO", "New message " + Enum.GetName(typeof(TCPMessageCode), message.Code) + " from user: " + client.UID); } if (message.Code == TCPMessageCode.Message) { OnMessage?.Invoke(client, message); } } } }