private int SaveToDB(string moduleID, IList <StoreValue> values) { if (dbs.ContainsKey(moduleID)) { ModuleDBs moduleDBs = dbs[moduleID]; if (moduleDBs.Workers.Length == 1) { return(moduleDBs.Workers[0].Worker.Append(values)); } else { foreach (StoreValue v in values) { string varName = v.Value.Variable.Name; if (moduleDBs.Variable2Worker.ContainsKey(varName)) { moduleDBs.Variable2Worker[varName].Buffer.Add(v); } else { if (moduleDBs.DefaultWorker != null) { moduleDBs.DefaultWorker.Buffer.Add(v); } else { logger.Warn("Failed to store value because of missing default DB worker: " + v.Value.Variable); } } } int maxBufferCount = 0; foreach (WorkerWithBuffer wb in moduleDBs.Workers) { if (wb.Buffer.Count > 0) { int count = wb.Worker.Append(wb.Buffer.ToArray()); maxBufferCount = Math.Max(maxBufferCount, count); wb.Buffer.Clear(); } } return(maxBufferCount); } } else { logger.Warn("No DB worker for modules " + moduleID); return(0); } }
private HistoryDBWorker?WorkerByVarRef(VariableRef variable) { string moduleID = variable.Object.ModuleID; if (dbs.ContainsKey(moduleID)) { ModuleDBs moduleDBs = dbs[moduleID]; if (moduleDBs.Workers.Length == 1) { return(moduleDBs.Workers[0].Worker); } else { string varName = variable.Name; if (moduleDBs.Variable2Worker.ContainsKey(varName)) { return(moduleDBs.Variable2Worker[varName].Worker); } else { if (moduleDBs.DefaultWorker != null) { return(moduleDBs.DefaultWorker.Worker); } else { return(null); } } } } else { return(null); } }