示例#1
0
        private void ReadContent()
        {
            string content;
            string filePath = System.IO.Path.Combine(Path, FileName);

            if (File.Exists(filePath) == false)
            {
                return;
            }

            using (FileStream stream =
                       new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                if (stream.Length <= _lastPosition)
                {
                    _lastPosition = 0;
                }
                stream.Position = _lastPosition;

                using (StreamReader reader = new StreamReader(stream))
                {
                    content       = reader.ReadToEnd();
                    _lastPosition = stream.Position;
                }
            }
            var lines = content.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);

            _lines.AddRange(lines);

            NewEntries?.Invoke(lines.ToList());
        }
示例#2
0
        /// <summary>
        /// Applies the correct timing to the items, according to the configuration.
        /// </summary>
        public void ApplyTiming()
        {
            // Timing is applied only to entries that do not already have a next answer date
            // and that are not in a final SRS level.
            List <SrsEntry> eligibleEntries = NewEntries.Where(e => !e.NextAnswerDate.HasValue &&
                                                               !SrsLevelStore.Instance.IsFinalLevel(e.CurrentGrade, false)).ToList();

            Timing.ApplyTiming(eligibleEntries);
        }
示例#3
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");
                }
            }
        }
        /// <summary>
        /// Applies the correct timing to the items, according to the configuration.
        /// </summary>
        public void ApplyTiming()
        {
            // Timing is applied only to entries that do not already have a next answer date
            // and that are not in a final SRS level.
            var             srsDao          = new SrsEntryDao();
            List <SrsEntry> eligibleEntries = NewEntries.Where(e => !e.NextAnswerDate.HasValue &&
                                                               !SrsLevelStore.Instance.IsFinalLevel(e.CurrentGrade, false) &&
                                                               (DuplicateOptions.DuplicateNewItemAction != ImportDuplicateNewItemAction.Ignore || srsDao.GetSimilarItem(e) == null)
                                                               ).ToList();

            Timing.ApplyTiming(eligibleEntries);
        }
示例#5
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");
                }
            }
        }
示例#6
0
            public override bool Equals(object o)
            {
                if (this == o)
                {
                    return(true);
                }
                if (o == null || this.GetType() != o.GetType())
                {
                    return(false);
                }

                NewEntries newEntries = ( NewEntries )o;

                if (PrevLogIndex != newEntries.PrevLogIndex)
                {
                    return(false);
                }
                if (PrevLogTerm != newEntries.PrevLogTerm)
                {
                    return(false);
                }
                return(Arrays.Equals(NewLogEntries, newEntries.NewLogEntries));
            }