Merging changes

This commit is contained in:
Taha committed 2023-09-04 16:25:40 -04:00
1 parent c4216d2272
commit 797816be7e
437 files changed
+54228 -28

No files matched your search

@@ -0,0 +1,99 @@
using System;
using BCG.Utilities.General;
namespace BCG
{
public abstract class TimeUnitStream : ViewStream, IWorker
{
protected TimeSpan myOffset;
protected DateTime myConstructionTime;
protected int mySizeOfStream;
protected DateTime myZeroTime;
protected CircularRowCollection myCollection;
protected ViewStreamDatabase myDb;
protected int myId = 0;
public TimeUnitStream (DateTime zeroTime, TimeSpan offSet, int sizeOfStream, ViewStreamDatabase db)
{
myConstructionTime = DateTime.Now;
myZeroTime = zeroTime;
myOffset = offSet;
mySizeOfStream = sizeOfStream;
myDb = db;
myCollection = new CircularRowCollection (
new BlueTableSchema ("Time",
new ColumnInfo ("id", 0, typeof(Int32)), new ColumnInfo ("time", 1, typeof(DateTime))),
mySizeOfStream);
}
#region ViewStream overriden methods
protected override void myOnFirstSubscriber()
{
myDb.addWorker (this);
myInit ();
}
protected override void myOnLastSubscriber()
{
myDb.removeWorker (this);
}
#endregion
protected virtual void myInit ()
{
int periods = (int)
(DateTime.Now - myConstructionTime).TotalMilliseconds / (int) myOffset.TotalMilliseconds;
DateTime dt = myGetLatestRow() == null ? myRoundTime(myZeroTime) :
myRoundTime (myZeroTime + new TimeSpan(myOffset.Ticks * periods));
if (myGetLatestRow() == null ||
!myGetLatestRow()["time"].Equals(dt))
{
IBlueRow ar = new BlueRow (myCollection.schema,
myId++, dt);
IBlueRow dr = myCollection.addRowWithReturn (ar);
myFireEvent (new DataPacket (myCollection,
myConvertToCollection (ar),
myConvertToCollection (dr)));
}
}
#region IWorker methods
public void doWork ()
{
myInit ();
}
#endregion
protected abstract DateTime myRoundTime (DateTime dt);
#region Private Helper methods
private IBlueRow myGetLatestRow ()
{
return myCollection.Count == 0 ?
null :
BlueDataUtility.extractRow (myCollection, myCollection.Count - 1);
}
private IBlueRowCollection myConvertToCollection (IBlueRow r)
{
BlueTable retVal = new BlueTable (myCollection.schema);
if (r != null)
retVal.addRow (r);
return retVal;
}
#endregion
}
}