Esempio n. 1
0
        /// <summary>
        /// Loads new events from a file if the file has changed.
        /// </summary>
        private void RefreshEvents(EventTable eventTable)
        {
            if (string.IsNullOrEmpty(eventTable.FileName))
            {
                eventTable.FileName = Path.Combine(archivePath,
                                                   EventTableAdapter.GetTableFileName(Code, eventTable.TableDate));
            }

            DateTime fileAge = File.Exists(eventTable.FileName) ?
                               File.GetLastWriteTimeUtc(eventTable.FileName) : DateTime.MinValue;

            if (fileAge > DateTime.MinValue && fileAge != eventTable.FileAge)
            {
                stopwatch.Restart();
                adapter.FileName = eventTable.FileName;
                adapter.Fill(eventTable);
                eventTable.FileAge = fileAge;

                stopwatch.Stop();
                arcLog?.WriteAction(Locale.IsRussian ?
                                    "Чтение таблицы событий длины {0} успешно завершено за {1} мс" :
                                    "Reading an event table of length {0} completed successfully in {1} ms",
                                    eventTable.Events.Count, stopwatch.ElapsedMilliseconds);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Deletes the outdated data from the archive.
        /// </summary>
        public override void DeleteOutdatedData()
        {
            DirectoryInfo arcDirInfo = new DirectoryInfo(archivePath);

            if (arcDirInfo.Exists)
            {
                DateTime minDT       = DateTime.UtcNow.AddDays(-options.StoragePeriod);
                string   minFileName = EventTableAdapter.GetTableFileName(Code, minDT);
                appLog.WriteAction(ServerPhrases.DeleteOutdatedData, Code, minDT.ToLocalizedDateString());

                foreach (FileInfo fileInfo in
                         arcDirInfo.EnumerateFiles(Code + "*", SearchOption.TopDirectoryOnly))
                {
                    if (string.CompareOrdinal(fileInfo.Name, minFileName) < 0)
                    {
                        fileInfo.Delete();
                    }
                }
            }
        }