/* * Method to handle errors in client/ server. * Operate accordingly to the problem. * Input string is a short description of the problem's type. */ private void HandleError(string error) { string message, time; // Postfix of current Hour time = " at " + DateTime.Now.ToString("T", CultureInfo.CreateSpecificCulture("de-DE")); if (error == "NaN") { message = "Got a NaN from server"; } else if (error == "10 seconds") { message = "More than 10 sec for an answer"; } else if (error == "NIE") { message = "Invalid Plane position"; } else if (error == "ERR") { message = "Server returned ERR"; } else if (error == "CNC") { message = "Error while talking to server"; } else { message = "Unknown error happened"; } ErrorsQueue.Insert(message + time); }
protected override void DisposeInternal(bool disposing) { if (Disposed) { return; } if (disposing) { _queue?.Dispose(); _connection?.Dispose(); ErrorsQueue?.Dispose(); (ExceptionHandler as IDisposable)?.Dispose(); } Disposed = true; }
protected override void OnStart(string[] args) { try { _recieveRequestTimer = new Timer(Settings.Default.RECIEVE_REQUEST_TIMER * 1000); _recieveRequestTimer.Elapsed += RecieveRequestTimerOnElapsed; _recieveRequestTimer.Enabled = true; eventLog.WriteEntry($"Сервис запущен, периодичность проверки наличия запросов: {Settings.Default.RECIEVE_REQUEST_TIMER} сек", EventLogEntryType.Information); _recieveResponseTimer = new Timer(Settings.Default.RECIEVE_RESPONSE_TIMER * 1000); _recieveResponseTimer.Elapsed += RecieveResponseTimerOnElapsed; _recieveResponseTimer.Enabled = true; eventLog.WriteEntry($"Сервис запущен, периодичность проверки наличия ответов: {Settings.Default.RECIEVE_RESPONSE_TIMER} сек", EventLogEntryType.Information); _sendTimer = new Timer(Settings.Default.SEND_TIMER * 1000); _sendTimer.Elapsed += SendTimerOnElapsed; _sendTimer.Enabled = true; eventLog.WriteEntry($"Сервис запущен, периодичность проверки очереди для отправки: {Settings.Default.SEND_TIMER} сек", EventLogEntryType.Information); _errorsQueue = new ErrorsQueue(Settings.Default.RABBIT_SERVER, Settings.Default.RABBIT_USER, Settings.Default.RABBIT_PASS); _ackQueue = new AckQueue(Settings.Default.RABBIT_SERVER, Settings.Default.RABBIT_USER, Settings.Default.RABBIT_PASS); _ackQueue.LogEvent += QueueOnLogEvent; _ackQueue.Subscribe(OnReceivedAck, OnErrorAck, true, Settings.Default.WAITING_MIN, Settings.Default.MAX_ITERATIONS); _rejectQueue = new RejectQueue(Settings.Default.RABBIT_SERVER, Settings.Default.RABBIT_USER, Settings.Default.RABBIT_PASS); _rejectQueue.LogEvent += QueueOnLogEvent; _rejectQueue.Subscribe(OnReceivedReject, OnErrorReject, true, Settings.Default.WAITING_MIN, Settings.Default.MAX_ITERATIONS); } catch (Exception ex) { eventLog.WriteEntry(ex.Message, EventLogEntryType.Error); Stop(); } }
public void QueueError(IError error) => ErrorsQueue.Enqueue(error);