private async Task DeleteVariablesOfWorker(HistoryDBWorker worker, VariableRef[] variables) { foreach (VariableRef variable in variables) { await worker.Delete(variable); NotifyChange(variable, Timestamp.Empty, Timestamp.Max, HistoryChangeType.Delete); } }
public async Task <long> HistorianCount(VariableRef variable, Timestamp startInclusive, Timestamp endInclusive) { HistoryDBWorker worker = WorkerByVarRef(variable); if (worker == null) { throw new Exception("Failed to find DB worker for variable " + variable); } CheckExistingVariable(variable); return(await worker.Count(variable, startInclusive, endInclusive)); }
public async Task <IList <VTTQ> > HistorianReadRaw(VariableRef variable, Timestamp startInclusive, Timestamp endInclusive, int maxValues, BoundingMethod bounding) { HistoryDBWorker worker = WorkerByVarRef(variable); if (worker == null) { throw new Exception("Failed to find DB worker for variable " + variable); } CheckExistingVariable(variable); return(await worker.ReadRaw(variable, startInclusive, endInclusive, maxValues, bounding)); }
public async Task <long> HistorianDeleteInterval(VariableRef variable, Timestamp startInclusive, Timestamp endInclusive) { HistoryDBWorker worker = WorkerByVarRef(variable); if (worker == null) { throw new Exception("Failed to find DB worker for variable " + variable); } CheckExistingVariable(variable); long res = await worker.DeleteInterval(variable, startInclusive, endInclusive); NotifyChange(variable, startInclusive, endInclusive, HistoryChangeType.Delete); return(res); }
public async Task HistorianModify(VariableRef variable, VTQ[] data, ModifyMode mode) { HistoryDBWorker worker = WorkerByVarRef(variable); if (worker == null) { throw new Exception("Failed to find DB worker for variable " + variable); } Variable varDesc = CheckExistingVariable(variable); await worker.Modify(variable, varDesc, data, mode); if (data.Length > 0) { Timestamp start = data.Min(x => x.T); Timestamp end = data.Max(x => x.T); NotifyChange(variable, start, end, MapMode(mode)); } }
public async Task DeleteVariables(IList <VariableRef> variables) { var groups = variables.Select(v => Tuple.Create(WorkerByVarRef(v), v)).GroupBy(x => x.Item1).ToArray(); Task[] tasks = groups.Select(group => { HistoryDBWorker worker = group.Key; VariableRef[] variablesForWorker = group.Select(tp => tp.Item2).ToArray(); if (worker == null) { if (variablesForWorker.Length == 1) { logger.Warn("Failed to find DB worker for variable: {0}", variablesForWorker[0]); } else { logger.Warn("Failed to find DB worker for {0} variables: {1}, ...", variablesForWorker.Length, variablesForWorker[0]); } return(Task.FromResult(true)); } return(DeleteVariablesOfWorker(worker, variablesForWorker)); }).ToArray(); await Task.WhenAll(tasks); }
public WorkerWithBuffer(HistoryDBWorker worker) { Worker = worker; Buffer = new List <StoreValue>(); }
public async Task Start(Module[] modules, Func <VariableRef, Variable?> fVarResolver, Action <IList <HistoryChange> > fNotifyChanges, bool emptyDBs) { this.syncContext = SynchronizationContext.Current; this.fVarResolver = fVarResolver; this.fNotifyChanges = fNotifyChanges; foreach (Module m in modules) { var workers = new List <WorkerWithBuffer>(); WorkerWithBuffer?defaultWorker = null; var variable2Worker = new Dictionary <string, WorkerWithBuffer>(); foreach (HistoryDB db in m.HistoryDBs) { string dbt = db.Type.ToLowerInvariant(); if (dbt != "sqlite" && dbt != "postgres" && dbt != "postgresflat") { throw new Exception($"Unknown DB type '{db.Type}' in configuration of module " + m.ID); } Func <Timeseries.TimeSeriesDB> fCreateDB = () => throw new Exception($"Unknown DB type '{db.Type}' in configuration of module " + m.ID); if (dbt == "sqlite") { fCreateDB = () => new Timeseries.SQLite.SQLiteTimeseriesDB(); } else if (dbt == "postgres") { fCreateDB = () => new Timeseries.Postgres.PostgresTimeseriesDB(); } else if (dbt == "postgresflat") { fCreateDB = () => new Timeseries.PostgresFlat.PostgresFlatTimeseriesDB(); } if (emptyDBs) { var d = fCreateDB(); d.ClearDatabase(db.Name, db.ConnectionString, db.Settings); } var worker = new HistoryDBWorker(db.Name, db.ConnectionString, db.Settings, db.PrioritizeReadRequests, fCreateDB, Notify_Append); var wb = new WorkerWithBuffer(worker); workers.Add(wb); if (db.Variables != null && db.Variables.Length > 0) { foreach (string varName in db.Variables) { variable2Worker[varName] = wb; } } else { if (defaultWorker == null) { defaultWorker = wb; } else { logger.Warn("More than one default DB worker for module " + m.ID); } } await worker.Start(); } if (defaultWorker == null && m.HistoryDBs.Count > 0) { logger.Warn("No default DB worker for module " + m.ID); } dbs[m.ID] = new ModuleDBs(m.ID, workers.ToArray(), variable2Worker, defaultWorker); } }