private void agent_OnNewPacketReceived(AgentRelay.Packet packet, AgentRelay agentRelay) { try { switch (packet.Command) { case (byte)TcpCommands.ServerGetDataMarkResponse: byte mark = packet.Content[0]; Dispatcher.BeginInvoke(new Action(() => { switch (mark) { case (byte)CurrentMemoirField.MEMOIR_TEXT: user.CurrentField = CurrentMemoirField.MEMOIR_TEXT; break; case (byte)CurrentMemoirField.MEMOIR_DATE_CHANGE: user.CurrentField = CurrentMemoirField.MEMOIR_DATE_CHANGE; break; case (byte)CurrentMemoirField.MEMOIR_ID: user.CurrentField = CurrentMemoirField.MEMOIR_ID; break; case (byte)CurrentMemoirField.MEMOIR_TITLE: user.CurrentField = CurrentMemoirField.MEMOIR_TITLE; break; } })); break; case (byte)TcpCommands.ServerGetDataMarkMemoirResponse: int curMemoir = Convert.ToInt32(AgentRelay.MakeStringFromPacketContents(packet)); Dispatcher.BeginInvoke(new Action(() => { if (user.TotalMemoir < curMemoir) { user.Memoirs.Add(new Memoir()); user.TotalMemoir++; } })); break; case (byte)TcpCommands.ServerGetDataResponse: string content = AgentRelay.MakeStringFromPacketContents(packet); Dispatcher.BeginInvoke(new Action(() => { switch (user.CurrentField) { case CurrentMemoirField.MEMOIR_TEXT: user.Memoirs[user.Memoirs.Count - 1].MEMOIR_TEXT = content; break; case CurrentMemoirField.MEMOIR_DATE_CHANGE: user.Memoirs[user.Memoirs.Count - 1].MEMOIR_DATE_CHANGE = content; break; case CurrentMemoirField.MEMOIR_ID: user.Memoirs[user.Memoirs.Count - 1].MEMOIR_ID = content; break; case CurrentMemoirField.MEMOIR_TITLE: user.Memoirs[user.Memoirs.Count - 1].MEMOIR_TITLE = content; break; } })); break; case (byte)TcpCommands.ServerFailed: Dispatcher.BeginInvoke(new Action(() => { if (message != null) { message.Close(); var mes = new Message("Ошибка", AgentRelay.MakeStringFromPacketContents(packet)); mes.CreateMessageDialog(new DialogManager(this, Dispatcher)); buttonRecord.IsEnabled = true; } })); break; case (byte)TcpCommands.ServerOK: Dispatcher.BeginInvoke(new Action(() => { if (message != null) { message.Close(); var mes = new Message("Успешно", AgentRelay.MakeStringFromPacketContents(packet)); mes.CreateMessageDialog(new DialogManager(this, Dispatcher)); buttonRecord.IsEnabled = true; } })); break; } } catch (Exception ex) { var mes = new Message("Ошибка", ex.Message); mes.CreateMessageDialog(new DialogManager(this, Dispatcher)); } }
private void Agent_OnNewPacketReceived(AgentRelay.Packet packet, AgentRelay agentRelay) { switch (packet.Command) { case (byte)TcpCommands.ServerLoginFailed: serverResponseTimeout.Abort(); Dispatcher.BeginInvoke(new Action(() => { message.Close(); var mes = new Message("Ошибка", AgentRelay.MakeStringFromPacketContents(packet)); mes.CreateMessageDialog(new DialogManager(this, Dispatcher)); buttonEnter.IsEnabled = true; })); break; case (byte)TcpCommands.ServerLoginOK: serverResponseTimeout.Abort(); Dispatcher.BeginInvoke(new Action(() => { var mainWindow = new MainWindow(agent, textBoxLogin1.Text); message.Close(); disconnect = false; Close(); mainWindow.Show(); })); break; case (byte)TcpCommands.ServerRegistrationFailed: serverResponseTimeout.Abort(); Dispatcher.BeginInvoke(new Action(() => { message.Close(); var mes = new Message("Ошибка", AgentRelay.MakeStringFromPacketContents(packet)); mes.CreateMessageDialog(new DialogManager(this, Dispatcher)); buttonRegistrationOK.IsEnabled = true; textBoxLogin2.Text = ""; textBoxPassword2.Password = ""; textBoxPassword3.Password = ""; })); break; case (byte)TcpCommands.ServerRegistrationOK: serverResponseTimeout.Abort(); Dispatcher.BeginInvoke(new Action(() => { message.Close(); var mes = new Message("Успешно", "Ваша регистрация прошла успешно," + Environment.NewLine + " теперь можете войти."); mes.CreateMessageDialog(new DialogManager(this, Dispatcher)); StackPanelRegistration.Visibility = Visibility.Hidden; buttonRegistrationOK.IsEnabled = true; textBoxLogin1.Text = textBoxLogin2.Text; textBoxPassword1.Password = textBoxPassword3.Password; textBoxLogin2.Text = ""; textBoxPassword2.Password = ""; textBoxPassword3.Password = ""; StackPanelMain.Visibility = Visibility.Visible; textBoxLogin1.Focus(); })); break; case (byte)TcpCommands.ServerHello: serverResponseTimeout.Abort(); break; } }