private void ReportQueuedErrors(InetUploader inetUploader) { lock ( _errorsQueue ) { while (_errorsQueue.Count > 0) { Log.Debug("ReportQueuedErrors: uploading error"); DockingStationError dsError = _errorsQueue.Peek(); Log.Debug(dsError.ToString()); inetUploader.UploadError(dsError, Configuration.DockingStation.TimeZoneInfo); _errorsQueue.Dequeue(); } _errorsQueue.TrimExcess(); } }
/// <summary> /// For certain 'actions' that the VDS decides to do, iNet needs to be /// notified of. e.g. failed Leak check, Unavailable Gas, etc. /// </summary> /// <param name="dsAction"></param> /// <param name="inetUploader">May be null. /// If null is passed, the method will instantiate an Inet object to use.</param> private void ProcessNotificationAction(DockingStationAction dsAction, InetUploader inetUploader) { // _lastNotificationError is the last CONSECUTIVE NotificationAction. // This the passed-in action is not a NotificationAction, then that // breaks the current series of consecutive NotificationActions. // So, we set it to null to denote that. if (!(dsAction is INotificationAction)) { _lastNotificationError = null; return; } const string funcMsg = "ProcessNotificationAction: "; StringBuilder errMsg = new StringBuilder(dsAction.Name); foreach (string m in dsAction.Messages) { errMsg.AppendFormat("\r\n{0}", m); } if (dsAction is UnsupportedCylinderAction) { errMsg.AppendFormat("\r\non Port {0}", ((UnsupportedCylinderAction)dsAction).GasEndPoint.Position); } // If it's an UnavailableAction, then the content of the error should // be the Exception's error (if there is an Exception). if ((dsAction is UnavailableAction) && (((UnavailableAction)dsAction).Exception != null)) { errMsg.AppendFormat("\r\n{0}", ((UnavailableAction)dsAction).Exception.ToString()); } DockingStationError dsError; //Suresh 02-Feb-2012 INS-2392 if (Master.SwitchService.Instrument == null) { dsError = new DockingStationError(errMsg.ToString()); } else { dsError = new DockingStationError(errMsg.ToString(), Master.SwitchService.Instrument.SerialNumber); } // If this NotificationError's detail is the exact same as the last NotificationError's // detail, then we assume it's a duplicate. We don't want to upload duplicates. if (_lastNotificationError != null && _lastNotificationError.Description == dsError.Description) { Log.Debug(string.Format("{0}Ignoring duplicate: {1}", funcMsg, dsAction.ToString())); return; } _lastNotificationError = dsError; // We upload the error immediately (don't just queue it to our "Errors" List). if (inetUploader != null) { Log.Debug(string.Format("{0}Uploading ", funcMsg, dsAction.Name)); inetUploader.UploadError(dsError, Configuration.DockingStation.TimeZoneInfo); } else { // if an uploader wasn't passed in to us to be re-used, then we need to create our own local one. using (InetUploader localUploader = new InetUploader()) { Log.Debug(string.Format("{0}Uploading {1}", funcMsg, dsAction.Name)); localUploader.UploadError(dsError, Configuration.DockingStation.TimeZoneInfo); } } }