49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.IO;
|
|
|
|
using System.Runtime.Serialization.Formatters.Binary;
|
|
|
|
namespace BCG
|
|
{
|
|
[DataStreamUserRespresentation("loader")]
|
|
public class LoaderStream : ViewStream, ISideEffectStream
|
|
{
|
|
public class Exception : System.Exception
|
|
{public Exception(string msg) : base(msg) { }}
|
|
|
|
public LoaderStream(string fileName, int secondsBetweenPolls)
|
|
{
|
|
mySetRealSource(
|
|
new PollStream(() => new LoaderStream(fileName).rows, secondsBetweenPolls,
|
|
ViewStreamDatabase.instance));
|
|
}
|
|
|
|
public LoaderStream(string fileName)
|
|
{
|
|
if (fileName == null)
|
|
throw new LoaderStream.Exception("File name cannot be null");
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
try
|
|
{
|
|
using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
|
|
{
|
|
#pragma warning disable SYSLIB0011
|
|
BinaryFormatter bf = new BinaryFormatter();
|
|
BlueTable bt = (BlueTable)bf.Deserialize(fs);
|
|
#pragma warning restore SYSLIB0011
|
|
mySetRealSource(new BlueRowCollectionStaticStream(bt));
|
|
}
|
|
break;
|
|
}
|
|
catch (IOException)
|
|
{
|
|
System.Threading.Thread.Sleep(50);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|