Exemplo n.º 1
0
 /// <summary>
 /// Получить класс реализующего работу с журналом событий Windows
 /// </summary>
 /// <returns>Класс реализующего работу с журналом событий Windows</returns>
 public static Journal CreateInstance()
 {
     try
     {
         if (journal == null)
         {
             journal = new Journal();
         }
         return journal;
     }
     catch
     {
         return null;
     }
 }
Exemplo n.º 2
0
        private Mutex t_mutex = null; // синхронизатор таймера

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Инициализирует новый экземпляр класса
        /// </summary>
        protected Application()
        {
            signals = new Float[size];
            results = new Float[size];

            repository = new Repository();
            repository.onError += new ApplicationErrorHandler(ErrorHandler);

            for (int i = 0; i < size; i++)
            {
                signals[i] = new Float();
                results[i] = new Float();
            }

            journal = Journal.CreateInstance();

            p_locker = new ReaderWriterLock();

            crc = TypeCRC.Cycled;
            mode = ApplicationMode.Active;

            serial = new Serial(repository);
            serial.Secondary = new SecondaryPort(repository);

            stock = new Stock(signals);

            display = new DisplayUnit(repository);
            converter = new Converter(stock, results);

            devTcpOld = new TcpDevManager();

            t_mutex = new Mutex();
            timer = new Timer(TimerElapsed, null, Timeout.Infinite, period);

            devTcpOld.Place = repository.InstancePlace();

            saver = new Saver();
            service = new Service();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Осуществляет обработку ошибок
        /// </summary>
        /// <param name="sender">Источник события</param>
        /// <param name="args">Параметры события</param>
        private void ErrorHandler(object sender, ErrorArgs args)
        {
            try
            {
                if (journal != null)
                {
                    switch (args.ErrorType)
                    {
                        case ErrorType.Information:

                            journal.Write(args.Message, EventLogEntryType.Information);
                            break;

                        case ErrorType.Warning:

                            journal.Write(args.Message, EventLogEntryType.Warning);
                            break;

                        case ErrorType.NotFatal:

                            journal.Write(args.Message, EventLogEntryType.Error);
                            break;

                        case ErrorType.Fatal:

                            journal.Write(args.Message, EventLogEntryType.Error);
                            if (OnExit != null)
                            {
                                OnExit(this, new EventArgs());
                            }
                            break;

                        case ErrorType.Unknown:

                            journal.Write(args.Message, EventLogEntryType.Error);
                            break;

                        case ErrorType.Default:

                            journal.Write(args.Message, EventLogEntryType.Information);
                            break;
                    }
                }
                else
                {
                    journal = Journal.CreateInstance();
                    if (journal != null)
                    {
                        string message = string.Format("{0}{1}{2}", "Не был создан экземпляр класса Joirnal",
                            Constants.vbCrLf, "Сообщение приложения будет сохранено как Error!");

                        journal.Write(message, EventLogEntryType.Error);
                        journal.Write(args.Message, EventLogEntryType.Error);
                    }
                }
            }
            catch
            {
                // ...
            }
        }