2 using System.Collections;
3 using System.Collections.Generic;
5 using System.Threading;
28 _logQueue =
new Queue<LogInfo>();
29 _currValsQueue =
new Queue<CurrValInfo>();
31 _dbWriterThread =
new Thread(_dbWriter.ThreadRun);
32 _dbWriterThread.Start();
41 public static void AddLogValue(String time, String blockname, String value)
47 if (value == Definitions.BlockInfo.ErrorString)
49 info =
new LogInfo(time, blockname,
"NAN");
52 lock (((ICollection)_logQueue).SyncRoot)
54 _logQueue.Enqueue(info);
61 Seci.Helpers.ErrorLogger.SeciError(
"AddLogValue", err);
71 public static void AddCurrentValue(String blockname, String value, String setpoint)
82 lock (((ICollection)_currValsQueue).SyncRoot)
84 _currValsQueue.Enqueue(info);
91 Seci.Helpers.ErrorLogger.SeciError(
"AddCurrentValue", err);
100 _dbWriter.RequestThreadExit();
109 _dbWriter.WriteConfigName(config);
116 for (
int i = 0; i < blocks.Count; ++i)
121 if (blocks[i].BlockEnabled) options += 1;
122 if (blocks[i].UnderRunControl) options += 2;
123 if (blocks[i].LogChangesOnly || blocks[i].LogChangesTolerance) options += 12;
129 String nexusname =
"";
134 if (blocks[i].ReadControl != null && blocks[i].ReadControl.EndsWith(
")")) read = blocks[i].ReadControl.Substring(0, blocks[i].ReadControl.LastIndexOf(
'(') - 1);
135 if (blocks[i].WriteControl != null && blocks[i].WriteControl.EndsWith(
")")) write = blocks[i].WriteControl.Substring(0, blocks[i].WriteControl.LastIndexOf(
'(') - 1);
136 if (blocks[i].GoButton != null && blocks[i].GoButton.EndsWith(
")")) go = blocks[i].GoButton.Substring(0, blocks[i].GoButton.LastIndexOf(
'(') - 1);
137 if (blocks[i].NexusName != null) nexusname = blocks[i].NexusName;
138 if (blocks[i].BlockUnits != null) units = blocks[i].BlockUnits;
139 if (blocks[i].CurrentValue != null) curr = blocks[i].CurrentValue;
140 if (blocks[i].SetPointValue != null) set = blocks[i].SetPointValue;
142 _dbWriter.WriteBlockDetails(blocks[i].BlockName, set, blocks[i].ParentVI, read,
143 write, go, options, nexusname, blocks[i].LowerLimit, blocks[i].UpperLimit, units, curr);
157 lock (((ICollection)_currValsQueue).SyncRoot)
159 _currValsQueue.Clear();
162 lock (((ICollection)_logQueue).SyncRoot)
177 _dbWriter.CloseDatabase();
186 private Boolean _inError =
false;
188 private selogcomLib.selog _dbCom =
new selogcomLib.selog();
192 private List<String> _logTimes =
new List<string>();
193 private List<String> _logNames =
new List<string>();
194 private List<String> _logValues =
new List<string>();
197 private List<String> _currValsNames =
new List<string>();
198 private List<String> _currValsValues =
new List<string>();
199 private List<String> _currValsSetpoints =
new List<string>();
208 _logQueue = logqueue;
209 _currValsQueue = currvalsqueue;
236 _currValsNames.Clear();
237 _currValsValues.Clear();
238 _currValsSetpoints.Clear();
241 lock (((ICollection)_logQueue).SyncRoot)
244 while (_logQueue.Count > 0)
246 LogInfo temp = _logQueue.Dequeue();
248 if (temp != null && !String.IsNullOrEmpty(temp.
Time) && !String.IsNullOrEmpty(temp.Name) && !String.IsNullOrEmpty(temp.
Value))
250 _logTimes.Add(temp.Time);
251 _logNames.Add(temp.Name);
252 _logValues.Add(temp.Value);
259 if (_logTimes.Count > 0 &&
int.TryParse(Seci.Standard.Dae.RunNumber, out runNumber))
263 _dbCom.SELogValues(runNumber,
"SECI", _logTimes.ToArray(), _logNames.ToArray(), _logValues.ToArray());
268 lock (((ICollection)_currValsQueue).SyncRoot)
271 while (_currValsQueue.Count > 0)
274 _currValsNames.Add(temp.Name);
275 _currValsValues.Add(temp.Value);
276 _currValsSetpoints.Add(temp.Setpoint);
283 if (_currValsNames.Count > 0)
285 _dbCom.SESetBlockValues(_currValsNames.ToArray(), _currValsValues.ToArray());
286 _dbCom.SESetBlockSetpoints(_currValsNames.ToArray(), _currValsSetpoints.ToArray());
293 catch (Exception err)
299 _firstErrorTime = DateTime.UtcNow;
300 Helpers.ErrorLogger.SeciError(
"DatabaseWriter ThreadRun", err);
304 TimeSpan diff = DateTime.UtcNow - _firstErrorTime;
305 if (diff >= TimeSpan.FromMinutes(10))
307 Helpers.ErrorLogger.SeciError(
"DatabaseWriter ThreadRun - still in error", err);
308 _firstErrorTime = DateTime.UtcNow;
325 _dbCom.SENewSECIConfig(name);
328 catch (Exception err)
331 Helpers.ErrorLogger.SeciError(
"WriteConfigName", err);
350 public void WriteBlockDetails(String name, String setpoint, String vi, String readcontrol, String setcontrol, String buttoncontrol,
351 int options, String nexusname, Double lowlimit, Double highlimit, String units, String currentvalue)
358 Single low = correctLimit((Single)lowlimit);
359 Single high = correctLimit((Single)highlimit);
361 _dbCom.SESetBlockDetails(name, setpoint, vi, readcontrol, setcontrol, buttoncontrol, options, nexusname, low, high, units, currentvalue);
364 catch (Exception err)
366 Seci.Helpers.ErrorLogger.SeciError(
"WriteBlockDetails", err);
372 if (Single.IsNegativeInfinity(value))
374 value = Single.MinValue;
376 else if (Single.IsPositiveInfinity(value))
378 value = Single.MaxValue;
407 public String Name {
get;
private set; }
408 public String Time {
get;
private set; }
409 public String Value {
get;
private set; }
417 public LogInfo(String time, String name, String value)
430 public String Name {
get;
private set; }
431 public String Value {
get;
private set; }
432 public String Setpoint {
get;
private set; }
static void CloseDatabase()
Close the database connection
static void ClearQueues()
LogInfo(String time, String name, String value)
Constructor
CurrValInfo(String name, String value, String setpoint)
Constructor
static Queue< CurrValInfo > _currValsQueue
static void AddLogValue(String time, String blockname, String value)
Add a log value to the queue
static DatabaseWriter _dbWriter
void RequestThreadExit()
Request that the thread should exit
void CloseDatabase()
Close the database connection
void WriteConfigName(String name)
Write the configuration name to the database
static void StopDatabaseLoggerThread()
Stop the logging thread
static void AddCurrentValue(String blockname, String value, String setpoint)
Add a current value to the queue
A small class for storing current value information
A small class for storing log information
static void LogConfigName(String config)
Log the configuration name
This class is used performs the following tasks:
static Queue< LogInfo > _logQueue
Queue< LogInfo > _logQueue
static Single correctLimit(Single value)
Specialised version of the Dictionary class which can be converted to XML. Also has some additional s...
static void StartLogger()
Starts the logger thread.
This class does the actual logging to the database
static Thread _dbWriterThread
static void WriteBlockDetails()
void ThreadRun()
This is the method that is run on a separate thread
void WriteBlockDetails(String name, String setpoint, String vi, String readcontrol, String setcontrol, String buttoncontrol, int options, String nexusname, Double lowlimit, Double highlimit, String units, String currentvalue)
This method is used to write the details about the block to the database.
Queue< CurrValInfo > _currValsQueue
DatabaseWriter(Queue< LogInfo > logqueue, Queue< CurrValInfo > currvalsqueue)
The constructor