Example #1
0
        internal JobContext(IAlarmSource source, AlarmSourceEventArgs args)
        {
            Assertions.AssertNotNull(source, "source");
            Assertions.AssertNotNull(args, "args");

            AlarmSourceName = source.GetType().Name;
            Parameters      = args.Parameters;
        }
Example #2
0
        internal JobContext(IAlarmSource source, AlarmSourceEventArgs args)
        {
            Assertions.AssertNotNull(source, "source");
            Assertions.AssertNotNull(args, "args");

            AlarmSourceName = source.GetType().Name;
            Parameters = args.Parameters;
        }
        private void InitializeAlarmSources()
        {
            foreach (var export in ExportedTypeLibrary.GetExports(typeof(IAlarmSource)).Where(j => _configuration.EnabledAlarmSources.Contains(j.Attribute.Alias)))
            {
                Logger.Instance.LogFormat(LogType.Info, this, Resources.AlarmSourceEnabling, export.Type.Name);

                IAlarmSource alarmSource = export.CreateInstance <IAlarmSource>();
                _alarmSources.Add(alarmSource);

                Logger.Instance.LogFormat(LogType.Info, this, Resources.AlarmSourceEnabled, export.Type.Name);
            }
        }
        private void AlarmSource_NewAlarm(object sender, AlarmSourceEventArgs e)
        {
            IAlarmSource source = (IAlarmSource)sender;

            Operation operation = e.Operation;

            if (operation == null)
            {
                Logger.Instance.LogFormat(LogType.Warning, this, Resources.AlarmSourceNoOperation, source.GetType().FullName);
                return;
            }

            Logger.Instance.LogFormat(LogType.Info, this, Resources.AlarmSourceReceivedOperation, operation.ToString(), sender.GetType().Name);
            try
            {
                if (!ShouldStoreOperation(operation))
                {
                    Logger.Instance.LogFormat(LogType.Info, this, Resources.NewAlarmIgnoringAlreadyPresentOperation, operation.OperationNumber);
                    return;
                }

                // If there is no timestamp, use the current time.
                if (operation.Timestamp.Year == 1)
                {
                    Logger.Instance.LogFormat(LogType.Warning, this, Resources.NewAlarmInvalidTimestamp);
                    operation.Timestamp = DateTime.Now;
                }

                JobContext context = new JobContext(source, e);
                context.Phase = JobPhase.OnOperationSurfaced;
                _jobManager.ExecuteJobs(context, operation);

                operation = StoreOperation(operation);
                if (operation == null)
                {
                    return;
                }

                Logger.Instance.LogFormat(LogType.Info, this, Resources.NewAlarmStored, operation.Id);

                context.Phase = JobPhase.AfterOperationStored;
                _jobManager.ExecuteJobs(context, operation);

                Logger.Instance.LogFormat(LogType.Info, this, Resources.NewAlarmHandlingFinished, operation.Id);
            }
            catch (Exception ex)
            {
                Logger.Instance.LogFormat(LogType.Warning, this, Resources.NewAlarmHandlingException);
                Logger.Instance.LogException(this, ex);
            }
        }
Example #5
0
        private void AlarmSource_NewAlarm(object sender, AlarmSourceEventArgs e)
        {
            IAlarmSource source = (IAlarmSource)sender;

            // Sanity-checks
            if (e.Operation == null)
            {
                Logger.Instance.LogFormat(LogType.Warning, this, "Alarm Source '{0}' did not return an operation! This may indicate that parsing an operation has failed. Please check the log!", source.GetType().FullName);
                return;
            }

            try
            {
                // If there is no timestamp, use the current time. Not too good but better than MinValue :-/
                if (e.Operation.Timestamp.Year == 1)
                {
                    Logger.Instance.LogFormat(LogType.Warning, this, "Could not parse timestamp from the fax. Using the current time as the timestamp.");
                    e.Operation.Timestamp = DateTime.Now;
                }

                // Download the route plan information (if data is meaningful)
                DownloadRoutePlan(e.Operation);

                // Grant the operation a new Id
                e.Operation.Id = _operationStore.GetNextOperationId();

                foreach (IJob job in _jobs)
                {
                    // Run the job. If the job fails, ignore that exception as well but log it too!
                    try
                    {
                        job.DoJob(e.Operation);
                    }
                    catch (Exception ex)
                    {
                        // Be careful when processing the jobs, we don't want a malicious job to terminate the process!
                        Logger.Instance.LogFormat(LogType.Warning, this, string.Format("An error occurred while processing job '{0}'!", job.GetType().Name));
                        Logger.Instance.LogException(this, ex);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Instance.LogFormat(LogType.Warning, this, "An exception occurred while processing the operation!");
                Logger.Instance.LogException(this, ex);
            }
        }
        /// <summary>
        /// Wraps execution of an <see cref="IAlarmSource"/>-plugin to avoid terminating the whole process.
        /// </summary>
        /// <param name="parameter">The parameter (of type <see cref="IAlarmSource"/>).</param>
        private void AlarmSourceThreadWrapper(object parameter)
        {
            IAlarmSource source = (IAlarmSource)parameter;

            try
            {
                source.RunThread();
            }
            catch (ThreadAbortException)
            {
                // Ignore this exception. It is caused by calling Stop().
            }
            catch (Exception ex)
            {
                Logger.Instance.LogFormat(LogType.Error, this, Resources.AlarmSourceThreadException, source.GetType().FullName);
                Logger.Instance.LogException(this, ex);
            }
        }
Example #7
0
        /// <summary>
        /// Wraps execution of an <see cref="IAlarmSource"/>-plugin to avoid terminating the whole process.
        /// </summary>
        /// <param name="parameter">The parameter (of type <see cref="IAlarmSource"/>).</param>
        private void AlarmSourceThreadWrapper(object parameter)
        {
            IAlarmSource source = (IAlarmSource)parameter;

            try
            {
                source.RunThread();
            }
            catch (ThreadAbortException)
            {
                // Ignore this exception. It is caused by calling Stop().
            }
            catch (Exception ex)
            {
                // Log any exception (the thread will end afterwards).
                Logger.Instance.LogFormat(LogType.Error, this, "An unhandled exception occurred while running the thread for alarm source '{0}'. The thread is being terminated. Please check the log.", source.GetType().FullName);
                Logger.Instance.LogException(this, ex);
            }
        }