private Dictionary <int, CnlData> updatedCnlData; // holds recently updated channel data /// <summary> /// Initializes a new instance of the class. /// </summary> public PostgreHAL(IArchiveContext archiveContext, ArchiveConfig archiveConfig, int[] cnlNums, ModuleConfig moduleConfig) : base(archiveContext, archiveConfig, cnlNums) { this.moduleConfig = moduleConfig ?? throw new ArgumentNullException(nameof(moduleConfig)); archiveOptions = new PostgreHAO(archiveConfig.CustomOptions); appLog = archiveContext.Log; arcLog = archiveOptions.LogEnabled ? CreateLog(ModuleUtils.ModuleCode) : null; stopwatch = new Stopwatch(); queryBuilder = new QueryBuilder(Code); pointQueue = new PointQueue(FixQueueSize(), queryBuilder.InsertHistoricalDataQuery) { ReturnOnError = true, ArchiveCode = Code, AppLog = appLog, ArcLog = arcLog }; writingPeriod = GetPeriodInSec(archiveOptions.WritingPeriod, archiveOptions.WritingUnit); hasError = false; conn = null; thread = null; terminated = false; nextWriteTime = DateTime.MinValue; cnlIndexes = null; prevCnlData = null; updateTime = DateTime.MinValue; updatedCnlData = null; }
public void SaveTo(SaveEntryFolder parentFolder, IArchiveContext archiveContext) { int entryCount = this._containerType == ContainerType.Dictionary ? this._elementCount * 2 : this._elementCount; SaveEntryFolder folder = archiveContext.CreateFolder(parentFolder, new FolderId(this.ObjectId, SaveFolderExtension.Container), entryCount); for (int id = 0; id < this._elementCount; ++id) { ElementSaveData elementSaveData = this._values[id]; BinaryWriter binaryWriter1 = BinaryWriterFactory.GetBinaryWriter(); BinaryWriter binaryWriter2 = binaryWriter1; elementSaveData.SaveTo((IWriter)binaryWriter2); folder.CreateEntry(new EntryId(id, SaveEntryExtension.Value)).FillFrom(binaryWriter1); BinaryWriterFactory.ReleaseBinaryWriter(binaryWriter1); if (this._containerType == ContainerType.Dictionary) { ElementSaveData key = this._keys[id]; BinaryWriter binaryWriter3 = BinaryWriterFactory.GetBinaryWriter(); BinaryWriter binaryWriter4 = binaryWriter3; key.SaveTo((IWriter)binaryWriter4); folder.CreateEntry(new EntryId(id, SaveEntryExtension.Key)).FillFrom(binaryWriter3); BinaryWriterFactory.ReleaseBinaryWriter(binaryWriter3); } } foreach (ObjectSaveData childStruct in this._childStructs) { childStruct.SaveTo(folder, archiveContext); } }
public static string ArchivePath(this IArchiveContext context, int year, int?month) { if (context.Archives != null && !string.IsNullOrWhiteSpace(context.Archives.Directory)) { if (month.HasValue) { return($"{context.Path}{context.Archives.Directory}/{year}/{month:d2}/"); } else { return($"{context.Path}{context.Archives.Directory}/{year}/"); } } else { if (month.HasValue) { return($"{context.Path}{year}/{month:d2}/"); } else { return($"{context.Path}{year}/"); } } }
/// <summary> /// Initializes a new instance of the class. /// </summary> protected ArchiveLogic(IArchiveContext archiveContext, ArchiveConfig archiveConfig, int[] cnlNums) { ArchiveContext = archiveContext ?? throw new ArgumentNullException(nameof(archiveContext)); ArchiveConfig = archiveConfig ?? throw new ArgumentNullException(nameof(archiveConfig)); CnlNums = cnlNums ?? throw new ArgumentNullException(nameof(cnlNums)); Code = archiveConfig.Code; Title = ServerUtils.GetArchiveTitle(Code, archiveConfig.Name); IsReady = false; LastWriteTime = DateTime.MinValue; LastCleanupTime = DateTime.MinValue; CleanupPeriod = TimeSpan.FromDays(1); }
public void SaveHeaderTo(SaveEntryFolder parentFolder, IArchiveContext archiveContext) { SaveEntryFolder folder = archiveContext.CreateFolder(parentFolder, new FolderId(this.ObjectId, SaveFolderExtension.Container), 1); BinaryWriter binaryWriter = BinaryWriterFactory.GetBinaryWriter(); this._typeDefinition.SaveId.WriteTo((IWriter)binaryWriter); binaryWriter.WriteByte((byte)this._containerType); binaryWriter.WriteInt(this.GetElementCount()); EntryId entryId = new EntryId(-1, SaveEntryExtension.Object); folder.CreateEntry(entryId).FillFrom(binaryWriter); BinaryWriterFactory.ReleaseBinaryWriter(binaryWriter); }
private int[] cnlIndexes; // the channel mapping indexes /// <summary> /// Initializes a new instance of the class. /// </summary> public BasicCAL(IArchiveContext archiveContext, ArchiveConfig archiveConfig, int[] cnlNums, ModuleConfig moduleConfig) : base(archiveContext, archiveConfig, cnlNums) { this.moduleConfig = moduleConfig ?? throw new ArgumentNullException(nameof(moduleConfig)); options = new BasicCAO(archiveConfig.CustomOptions); arcLog = options.LogEnabled ? CreateLog(ModuleUtils.ModuleCode) : null; stopwatch = new Stopwatch(); adapter = new SliceTableAdapter(); slice = new Slice(DateTime.MinValue, cnlNums); nextWriteTime = DateTime.MinValue; cnlIndexes = null; }
private EventTable lastTable; // the last accessed event table /// <summary> /// Initializes a new instance of the class. /// </summary> public BasicEAL(IArchiveContext archiveContext, ArchiveConfig archiveConfig, int[] cnlNums) : base(archiveContext, archiveConfig, cnlNums) { options = new BasicEAO(archiveConfig.CustomOptions); appLog = archiveContext.Log; arcLog = options.LogEnabled ? CreateLog(ModuleUtils.ModuleCode) : null; stopwatch = new Stopwatch(); adapter = new EventTableAdapter(); archivePath = Path.Combine(archiveContext.AppConfig.PathOptions.GetArcDir(options.IsCopy), Code); tableCache = new MemoryCache <DateTime, EventTable>(ModuleUtils.CacheExpiration, ModuleUtils.CacheCapacity); currentTable = null; lastTable = null; }
private int[] cnlIndexes; // the indexes that map the input channels /// <summary> /// Initializes a new instance of the class. /// </summary> public BasicCAL(IArchiveContext archiveContext, ArchiveConfig archiveConfig, int[] cnlNums) : base(archiveContext, archiveConfig, cnlNums) { options = new BasicCAO(archiveConfig.CustomOptions); arcLog = options.LogEnabled ? CreateLog(ModuleUtils.ModuleCode) : null; stopwatch = new Stopwatch(); adapter = new SliceTableAdapter { FileName = GetCurDataPath(archiveContext.AppConfig.PathOptions) }; slice = new Slice(DateTime.MinValue, cnlNums); nextWriteTime = DateTime.MinValue; cnlIndexes = null; }
public static ArchivesSummary GetArchivesSummary(this IArchiveContext context, Site site) { var children = site.Pages.ChildrenOf(context); return(new ArchivesSummary { Archives = children.GroupBy(p => new { p.Published.Year, p.Published.Month }).Select(g => new ArchiveSummary { Year = g.Key.Year, Month = g.Key.Month, PageCount = g.Count() }).OrderByDescending(a => a.Year).ThenByDescending(a => a.Month).ToArray() }); }
private EventTable lastTable; // the last accessed event table /// <summary> /// Initializes a new instance of the class. /// </summary> public BasicEAL(IArchiveContext archiveContext, ArchiveConfig archiveConfig, int[] cnlNums, ModuleConfig moduleConfig) : base(archiveContext, archiveConfig, cnlNums) { this.moduleConfig = moduleConfig ?? throw new ArgumentNullException(nameof(moduleConfig)); options = new BasicEAO(archiveConfig.CustomOptions); appLog = archiveContext.Log; arcLog = options.LogEnabled ? CreateLog(ModuleUtils.ModuleCode) : null; stopwatch = new Stopwatch(); adapter = new EventTableAdapter(); tableCache = new MemoryCache <DateTime, EventTable>(ModuleUtils.CacheExpiration, ModuleUtils.CacheCapacity); archivePath = ""; currentTable = null; lastTable = null; }
public static bool TryResolveArchivePath(this IArchiveContext context, string relativePath, Site site, out object result) { var hasArchiveDir = context.Archives != null && !string.IsNullOrWhiteSpace(context.Archives.Directory); var parts = relativePath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (hasArchiveDir && !parts[0].Equals(context.Archives.Directory, StringComparison.CurrentCultureIgnoreCase)) { result = null; return(false); } var yearIndex = hasArchiveDir ? 1 : 0; var monthIndex = hasArchiveDir ? 2 : 1; int year, month; if (parts.Length > yearIndex && int.TryParse(parts[yearIndex], out year)) { var archivePage = new ArchivePage { Year = year }; if (parts.Length > monthIndex && int.TryParse(parts[monthIndex], out month)) { archivePage.Month = month; archivePage.Results = site.Pages.ChildrenOf(context).Where(p => p.Published.Year == year && p.Published.Month == month).ToArray(); } else { archivePage.Results = site.Pages.ChildrenOf(context).Where(p => p.Published.Year == year).ToArray(); } result = archivePage; return(true); } else if (hasArchiveDir) { result = context.GetArchivesSummary(site); return(true); } else { result = null; return(false); } }
/// <summary> /// Creates a new archive logic. /// </summary> public override ArchiveLogic CreateArchive(IArchiveContext archiveContext, ArchiveConfig archiveConfig, int[] cnlNums) { switch (archiveConfig.Kind) { case ArchiveKind.Current: return(new BasicCAL(archiveContext, archiveConfig, cnlNums)); case ArchiveKind.Historical: return(new BasicHAL(archiveContext, archiveConfig, cnlNums)); case ArchiveKind.Events: return(new BasicEAL(archiveContext, archiveConfig, cnlNums)); default: return(null); } }
private volatile bool terminated; // necessary to stop the thread /// <summary> /// Initializes a new instance of the class. /// </summary> public PostgreEAL(IArchiveContext archiveContext, ArchiveConfig archiveConfig, int[] cnlNums, ModuleConfig moduleConfig) : base(archiveContext, archiveConfig, cnlNums) { this.moduleConfig = moduleConfig ?? throw new ArgumentNullException(nameof(moduleConfig)); archiveOptions = new PostgreEAO(archiveConfig.CustomOptions); appLog = archiveContext.Log; arcLog = archiveOptions.LogEnabled ? CreateLog(ModuleUtils.ModuleCode) : null; stopwatch = new Stopwatch(); queryBuilder = new QueryBuilder(Code); eventQueue = new EventQueue(FixQueueSize(), queryBuilder.InsertEventQuery) { ArchiveCode = Code, AppLog = appLog, ArcLog = arcLog }; hasError = false; conn = null; thread = null; terminated = false; }
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> /// Creates a new archive logic. /// </summary> public virtual ArchiveLogic CreateArchive(IArchiveContext archiveContext, ArchiveConfig archiveConfig, int[] cnlNums) { return(null); }
/// <summary> /// Initializes a new instance of the class. /// </summary> public EventArchiveLogic(IArchiveContext archiveContext, ArchiveConfig archiveConfig, int[] cnlNums) : base(archiveContext, archiveConfig, cnlNums) { }
/// <summary> /// Initializes a new instance of the class. /// </summary> public HistoricalArchiveLogic(IArchiveContext archiveContext, ArchiveConfig archiveConfig, int[] cnlNums) : base(archiveContext, archiveConfig, cnlNums) { }