Exemple #1
0
        public void ThreadFunc()
        {
            for (; ;)
            {
                try
                {
                    var sleepTime = TimeSpan.FromMinutes(1);
                    Log.Debug("Sleeping for {mins} minutes", sleepTime.TotalMinutes);
                    var ret = WaitHandle.WaitAny(new WaitHandle[] { _shutdown, _newLogFile, _recheckQueues }, sleepTime, false);
                    if (ret == 0)
                    {
                        Log.Debug("Thread shutdown");
                        return;
                    }

                    Thread.Sleep(TimeSpan.FromSeconds(1));

                    var mazakData = _readDB.LoadSchedulesAndLoadActions();
                    var logs      = LoadLog(_log.MaxForeignID());
                    var trans     = new LogTranslation(_jobDB, _log, mazakData, _settings,
                                                       le => MazakLogEvent?.Invoke(le)
                                                       );
                    var sendToExternal = new List <BlackMaple.MachineFramework.MaterialToSendToExternalQueue>();
                    foreach (var ev in logs)
                    {
                        try
                        {
                            sendToExternal.AddRange(trans.HandleEvent(ev));
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex, "Error translating log event at time " + ev.TimeUTC.ToLocalTime().ToString());
                        }
                    }

                    DeleteLog(_log.MaxForeignID());

                    _queues.CheckQueues(mazakData);

                    if (sendToExternal.Count > 0)
                    {
                        _sendToExternal.Post(sendToExternal).Wait(TimeSpan.FromSeconds(30));
                    }

                    if (logs.Count > 0)
                    {
                        NewEntries?.Invoke();
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Error during log data processing");
                }
            }
        }
Exemple #2
0
        private void HandleElapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            lock (_lock)
            {
                try
                {
                    var mazakData = _readDB.LoadSchedulesAndLoadActions();
                    var logs      = LoadLog(_log.MaxForeignID());
                    var trans     = new LogTranslation(_jobDB, _log, mazakData, FMSSettings,
                                                       le => MazakLogEvent?.Invoke(le)
                                                       );
                    var sendToExternal = new List <BlackMaple.MachineFramework.MaterialToSendToExternalQueue>();
                    foreach (var ev in logs)
                    {
                        try
                        {
                            sendToExternal.AddRange(trans.HandleEvent(ev));
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex, "Error translating log event at time " + ev.TimeUTC.ToLocalTime().ToString());
                        }
                    }

                    _queues.CheckQueues(mazakData);

                    if (sendToExternal.Count > 0)
                    {
                        _sendToExternal.Post(sendToExternal);
                    }

                    if (logs.Count > 0)
                    {
                        NewEntries?.Invoke();
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Unhandled error processing log");
                }
            }
        }