private void sendRequestBtn_Click(object sender, RoutedEventArgs e) { Alarmus.RequestMessage request = new Alarmus.RequestMessage(troubleDataBox.Text, troubleTypeBox.SelectedItem.ToString()); AsyncClient.SendMessage(request); sendRequestBtn.IsEnabled = false; /* * Самый простой способ подождать сеть. * Ждем, пока асинхронный клиент получит ответ от сервера */ Thread.Sleep(500); //Проверяем ответ от сервера switch (AsyncClient.GetServerResponse()) { case Alarmus.ServerResponse.SR_REQUEST_SUCCESS: MessageBox.Show("Заявка успешно отправлена"); break; case Alarmus.ServerResponse.SR_REQUEST_FAILED: MessageBox.Show("Заявка не была отправлена. Попробуйте позже"); break; case Alarmus.ServerResponse.SR_NULL: MessageBox.Show("Заявка не была отправлена. Возможны неполадки с сетью"); Alarmus.Log.Warning("Ответ на заявку не успел дойти. Возможны неполадки с сетью или сервер был отсоединен"); break; } sendRequestBtn.IsEnabled = true; }
/// <summary> /// /// </summary> /// <param name="request"></param> public static void AddRequest(Alarmus.RequestMessage request) { connection.Open(); string addCommand = "INSERT INTO Request (troubleData, troubleType) VALUES ('" + request.troubleData + "', '" + request.typeOfTrouble + "')"; SQLiteCommand command = new SQLiteCommand(addCommand, connection); command.ExecuteNonQuery(); connection.Close(); }
public MainWindow() { InitializeComponent(); Alarmus.Log.WriteToComponent component = new Alarmus.Log.WriteToComponent(AddInfoToListBox); Alarmus.Log.LinkComponentMethod(AddInfoToListBox); DatabaseMaster.Initialize(); Alarmus.RequestMessage msg = new Alarmus.RequestMessage("Test trouble Data", "Test trouble type"); // DatabaseMaster.AddRequest(msg); // DatabaseMaster.AddRequest(msg); List <Alarmus.RequestMessage> list = DatabaseMaster.GetAllRequests(); list.ForEach(x => Alarmus.Log.Debug(x.troubleData, x.typeOfTrouble)); portBox.Text = "8888"; countOfConnectionsBox.Text = "1000"; }
public static List <Alarmus.RequestMessage> GetAllRequests() { connection.Open(); string getAllRequestsCommand = "SELECT * FROM Request"; SQLiteCommand command = new SQLiteCommand(getAllRequestsCommand, connection); SQLiteDataReader dataReader = command.ExecuteReader(); List <Alarmus.RequestMessage> requestList = new List <Alarmus.RequestMessage>(); while (dataReader.Read()) { Alarmus.RequestMessage request = new Alarmus.RequestMessage(dataReader["troubleData"].ToString(), dataReader["troubleType"].ToString()); requestList.Add(request); } connection.Close(); return(requestList); }