/// <summary> /// Adds the channel number to the list and set. /// </summary> protected void AddCnlNum(int cnlNum) { if (cnlNum > 0 && CnlNumSet.Add(cnlNum)) { int index = CnlNumList.BinarySearch(cnlNum); if (index < 0) { CnlNumList.Insert(~index, cnlNum); } } }
private TrendTable updatedTable; // the trend table that is currently being updated /// <summary> /// Initializes a new instance of the class. /// </summary> public BasicHAL(IArchiveContext archiveContext, ArchiveConfig archiveConfig, int[] cnlNums, ModuleConfig moduleConfig) : base(archiveContext, archiveConfig, cnlNums) { this.moduleConfig = moduleConfig ?? throw new ArgumentNullException(nameof(moduleConfig)); options = new BasicHAO(archiveConfig.CustomOptions); appLog = archiveContext.Log; arcLog = options.LogEnabled ? CreateLog(ModuleUtils.ModuleCode) : null; stopwatch = new Stopwatch(); adapter = new TrendTableAdapter { ArchiveCode = Code, CnlNumCache = new MemoryCache <long, CnlNumList>(ModuleUtils.CacheExpiration, ModuleUtils.CacheCapacity) }; tableCache = new MemoryCache <DateTime, TrendTable>(ModuleUtils.CacheExpiration, ModuleUtils.CacheCapacity); slice = new Slice(DateTime.MinValue, cnlNums); writingPeriod = GetPeriodInSec(options.WritingPeriod, options.WritingUnit); nextWriteTime = DateTime.MinValue; cnlIndexes = null; cnlNumList = new CnlNumList(cnlNums); currentTable = null; updatedTable = null; }
private TrendTable updatedTable; // the trend table that is currently being updated /// <summary> /// Initializes a new instance of the class. /// </summary> public BasicHAL(IArchiveContext archiveContext, ArchiveConfig archiveConfig, int[] cnlNums) : base(archiveContext, archiveConfig, cnlNums) { options = new BasicHAO(archiveConfig.CustomOptions); appLog = archiveContext.Log; arcLog = options.LogEnabled ? CreateLog(ModuleUtils.ModuleCode) : null; stopwatch = new Stopwatch(); adapter = new TrendTableAdapter { ParentDirectory = Path.Combine(archiveContext.AppConfig.PathOptions.GetArcDir(options.IsCopy), Code), ArchiveCode = Code, CnlNumCache = new MemoryCache <long, CnlNumList>(ModuleUtils.CacheExpiration, ModuleUtils.CacheCapacity) }; tableCache = new MemoryCache <DateTime, TrendTable>(ModuleUtils.CacheExpiration, ModuleUtils.CacheCapacity); slice = new Slice(DateTime.MinValue, cnlNums); writingPeriod = GetPeriodInSec(options.WritingPeriod, options.WritingUnit); nextWriteTime = DateTime.MinValue; cnlIndexes = null; cnlNumList = new CnlNumList(cnlNums); currentTable = null; updatedTable = null; }
/// <summary> /// Checks and updates the today's trend table. /// </summary> private void CheckCurrentTrendTable(DateTime nowDT) { currentTable = GetCurrentTrendTable(nowDT); string tableDir = adapter.GetTablePath(currentTable); string metaFileName = adapter.GetMetaPath(currentTable); if (Directory.Exists(tableDir)) { TrendTableMeta srcTableMeta = adapter.ReadMetadata(metaFileName); if (srcTableMeta == null) { // the existing table is invalid and should be deleted Directory.Delete(tableDir, true); } else if (srcTableMeta.Equals(currentTable.Metadata)) { if (currentTable.GetDataPosition(nowDT, PositionKind.Ceiling, out TrendTablePage page, out _)) { string pageFileName = adapter.GetPagePath(page); CnlNumList srcCnlNums = adapter.ReadCnlNums(pageFileName); if (srcCnlNums == null) { // make sure that there is no page file File.Delete(pageFileName); } else if (srcCnlNums.Equals(cnlNumList)) { // re-create the channel list to use the existing list ID cnlNumList = new CnlNumList(srcCnlNums.ListID, cnlNumList); } else { // update the current page string msg = string.Format(Locale.IsRussian ? "Обновление номеров каналов страницы {0}" : "Update channel numbers of the page {0}", pageFileName); appLog.WriteAction(ServerPhrases.ArchiveMessage, Code, msg); arcLog?.WriteAction(msg); adapter.UpdatePageChannels(page, srcCnlNums); } } } else { // updating the entire table structure would take too long, so just backup the table string msg = string.Format(Locale.IsRussian ? "Резервное копирование таблицы {0}" : "Backup the table {0}", tableDir); appLog.WriteAction(ServerPhrases.ArchiveMessage, Code, msg); arcLog?.WriteAction(msg); adapter.BackupTable(currentTable); } } // create an empty table if it does not exist if (!Directory.Exists(tableDir)) { adapter.WriteMetadata(metaFileName, currentTable.Metadata); currentTable.IsReady = true; } // add the archive channel list to the cache adapter.CnlNumCache.Add(cnlNumList.ListID, cnlNumList); }