private bool TryGetLatestOperation(out Operation operation) { // TODO: We may read the values from the settings? const int maxAgeInMinutes = 800 * 60; const bool onlyNonAcknowledged = false; // For the moment, we are only interested about the latest operation (if any). const int limitAmount = 1; operation = null; try { using (var service = InternalServiceProxy.GetServiceInstance()) { IList <int> ids = service.Instance.GetOperationIds(maxAgeInMinutes, onlyNonAcknowledged, limitAmount); if (ids.Count > 0) { // Retrieve the operation with full detail to allow us to access the route image OperationItem operationItem = service.Instance.GetOperationById(ids[0], OperationItemDetailLevel.Full); operation = operationItem.ToOperation(); } return(true); } } catch (EndpointNotFoundException) { // We can ignore this exception. It usually occurs if the service is just starting up. // TODO: But we may show this information in a red label on the website, still? } return(false); }
private void Timer_Elapsed(object sender, ElapsedEventArgs e) { lock (Lock) { try { using (var service = InternalServiceProxy.GetServiceInstance()) { int maxAge = Configuration.OperationFetchingArguments.MaxAge; bool onlyNonAcknowledged = Configuration.OperationFetchingArguments.OnlyNonAcknowledged; int limitAmount = Configuration.OperationFetchingArguments.LimitAmount; var operations = service.Instance.GetOperationIds(maxAge, onlyNonAcknowledged, limitAmount); if (operations.Count == 0) { return; } foreach (int operationId in operations) { // Check if we already have this event (in this case don't retrieve it all over again) if (ContainsEvent(operationId)) { continue; } // Second parameter determines the detail level. Here, we can use "1" (full detail). OperationItem operation = service.Instance.GetOperationById(operationId, OperationItemDetailLevel.Full); // If the event is too old, do display it this time, but acknowledge it so it won't show up if (ShouldAutomaticallyAcknowledgeOperation(operation)) { service.Instance.AcknowledgeOperation(operation.Id); } else { // Push the event to the queue PushEvent(operation); } } } } catch (EndpointNotFoundException) { // This is ok, since it also occurs when the service is starting up. } catch (Exception ex) { // This could be interesting though... Logger.Instance.LogException(this, ex); } } }
protected void ResetButton_Click(object sender, EventArgs e) { try { using (WrappedService <IAlarmWorkflowServiceInternal> service = InternalServiceProxy.GetServiceInstance()) { service.Instance.AcknowledgeOperation(Int32.Parse(Request["id"])); Page page = this; ServiceConnection.Instance.RedirectToNoAlarm(ref page); } } catch (EndpointNotFoundException) { Page page = this; ServiceConnection.Instance.RedirectToErrorPage(ref page); } }
private void GetOperation(string id, out Operation operation) { operation = null; try { using (WrappedService <IAlarmWorkflowServiceInternal> service = InternalServiceProxy.GetServiceInstance()) { OperationItem operationItem = service.Instance.GetOperationById(int.Parse(id)); operation = operationItem.ToOperation(); } } catch (EndpointNotFoundException) { Page page = this; ServiceConnection.Instance.RedirectToErrorPage(ref page); } }
/// <summary> /// Acknowledges the selected (current) operation. /// </summary> /// <param name="gotoNextOperation">Whether or not to change to the next operation (recommended).</param> public void AcknowledgeCurrentOperation(bool gotoNextOperation) { // Sanity-checks if (SelectedEvent == null || SelectedEvent.Operation.IsAcknowledged) { return; } // Require confirmation of this action if (!ServiceProvider.Instance.GetService <ICredentialConfirmationDialogService>().Invoke("Einsatz zur Kenntnis nehmen", AuthorizationMode.SimpleConfirmation)) { return; } try { using (var service = InternalServiceProxy.GetServiceInstance()) { service.Instance.AcknowledgeOperation(SelectedEvent.Operation.Id); // If we get here, acknowledging was successful --> update operation SelectedEvent.Operation.IsAcknowledged = true; Logger.Instance.LogFormat(LogType.Info, this, "Operation with Id '{0}' was acknowledged.", SelectedEvent.Operation.Id); } // If we shall go to the next operation afterwards if (gotoNextOperation) { RemoveEvent(SelectedEvent); SelectedEvent = AvailableEvents.FirstOrDefault(); } OnPropertyChanged("SelectedEvent"); OnPropertyChanged("SelectedEvent.Operation"); OnPropertyChanged("SelectedEvent.Operation.IsAcknowledged"); } catch (Exception ex) { // Safety first (defensive coding) - don't throw anything here. Instead leave it as it is! Logger.Instance.LogFormat(LogType.Error, this, "Could not set operation to 'acknowledged'. Most likely a connection issue or internal error."); Logger.Instance.LogException(this, ex); } }
internal bool TryGetLatestOperation(out Operation operation, ref Page page) { int maxAgeInMinutes = WebsiteConfiguration.Instance.MaxAge; bool onlyNonAcknowledged = WebsiteConfiguration.Instance.NonAcknowledgedOnly; // For the moment, we are only interested about the latest operation (if any). const int limitAmount = 1; operation = null; try { using (WrappedService <IAlarmWorkflowServiceInternal> service = InternalServiceProxy.GetServiceInstance()) { if (service.IsFaulted) { return(false); } IList <int> ids = service.Instance.GetOperationIds(maxAgeInMinutes, onlyNonAcknowledged, limitAmount); if (ids.Count > 0) { // Retrieve the operation with full detail to allow us to access the route image OperationItem operationItem = service.Instance.GetOperationById(ids[0]); operation = operationItem.ToOperation(); } return(true); } } catch (EndpointNotFoundException) { if (page.GetType().BaseType == typeof(Default) || page.GetType().BaseType == typeof(Idle)) { RedirectToErrorPage(ref page); } } return(false); }