public void TestInitialize() { stubStateResolver = MockRepository.GenerateStub <IStateResolver>(); stubOperationsFactory = MockRepository.GenerateStub <IOperationsFactory>(); stubStateFactory = MockRepository.GenerateStub <IStateFactory>(); stubCurrentState = MockRepository.GenerateStub <IState>(); stubStateFactory.Stub(x => x.GetStartState()).Return(stubCurrentState); }
/// <summary> /// Initializes a new instance of the <see cref="PlaybackService"/> class. /// </summary> /// <param name="stateResolver">The state resolver.</param> public PlaybackService(IStateResolver stateResolver) { _Captures = new List<ICaptureStream>(); _Filters = new List<IStreamFilter>(); this.Scheduler = new Scheduler(); this.StateResolver = stateResolver; this.TaskFactory = new TaskFactory(stateResolver); }
/// <summary> /// Creates a new instance of the CaptureStream with the specified base stream and mode /// </summary> /// <param name="stream"></param> public CaptureStream(IStream baseStream, System.IO.FileAccess fileAccess, IStateResolver stateResolver) { switch (fileAccess) { case System.IO.FileAccess.Read: { _CaptureReader = new CaptureReader(baseStream, stateResolver); this.Timestamp = _CaptureReader.Timestamp; break; } case System.IO.FileAccess.Write: { _CaptureWriter = new CaptureWriter(baseStream, stateResolver); this.Timestamp = _CaptureWriter.Timestamp; break; } default: { var streamPosition = baseStream.Position; //important to create writer first, it will create the header the reader expects (if required) _CaptureWriter = new CaptureWriter(baseStream, stateResolver); //put the position back to the original position baseStream.Position = streamPosition; //reader now has a valid continuum file to play _CaptureReader = new CaptureReader(baseStream, stateResolver); this.Timestamp = _CaptureWriter.Timestamp; break; } } this.StateResolver = stateResolver; //store the read/write pointers _ReadPointer = baseStream.Position; _WritePointer = baseStream.Position; _Lock = new object(); }
public Calculator(IStateResolver stateResolver, IOperationsFactory operationFactory, IStateFactory stateFactory) { this.stateResolver = stateResolver; this.operationFactory = operationFactory; this.stateFactory = stateFactory; this.operationDic = new Dictionary <string, IOperation>() { { "+", operationFactory.GetAddOperation() }, { "C", operationFactory.GetClearOperation() }, { "-", operationFactory.GetSubtractOperation() }, { "=", operationFactory.GetNoOperation() }, { "/", operationFactory.GetDivideOperation() }, { "+/-", operationFactory.GetChangeSignOperation() }, { "*", operationFactory.GetMultiplyOperation() }, { "sqrt", operationFactory.GetSqrtOperation() }, { "%", operationFactory.GetPercentageOperation() }, }; Reset(); }
public CaptureWriter(IStream baseStream, IStateResolver stateResolver) : base(baseStream) { this.StateResolver = stateResolver; this.Timestamp = DateTime.UtcNow; this.Version = new Version((int)Constants.CONTINUUM_VERSION[0], (int)Constants.CONTINUUM_VERSION[1], (int)Constants.CONTINUUM_VERSION[2], (int)Constants.CONTINUUM_VERSION[3]); try { //write the header this.BaseStream.Write(Constants.CONTINUUM_HEADER_SIGNATURE, 0, Constants.CONTINUUM_HEADER_SIGNATURE.Length); this.BaseStream.Write(Constants.CONTINUUM_VERSION, 0, Constants.CONTINUUM_VERSION.Length); this.BaseStream.Write(BitConverter.GetBytes(this.Timestamp.ToBinary()), 0, 8); _CountPosition = this.BaseStream.Position; //write a place holder for the count property this.BaseStream.Write(BitConverter.GetBytes(this.Count), 0, 8); _LengthPosition = this.BaseStream.Position; //write a place holder for the length property this.BaseStream.Write(BitConverter.GetBytes(this.Length.TotalMilliseconds), 0, 8); //write the state allocation table this.BaseStream.Write(BitConverter.GetBytes(this.StateResolver.AllocationTable.Count), 0, 4); foreach (var allocation in this.StateResolver.AllocationTable) { var idBytes = BitConverter.GetBytes(allocation.Value); var guidBytes = allocation.Key.ToByteArray(); this.BaseStream.Write(idBytes, 0, idBytes.Length); this.BaseStream.Write(guidBytes, 0, guidBytes.Length); } } catch { } }
public TaskFactory(IStateResolver stateResolver) { this.StateResolver = stateResolver; }
public SolidMachine(object context, IStateResolver stateResolver) : this(context) { _context = context; _stateResolver = stateResolver; }
/// <summary> /// Initializes a new instance of the <see cref="PlaybackService"/> class. /// </summary> /// <param name="stateResolver">The state resolver.</param> /// <param name="scheduler">The scheduler.</param> /// <param name="taskFactory">The task factory.</param> public PlaybackService(IStateResolver stateResolver, IScheduler scheduler, ITaskFactory taskFactory) : this(stateResolver) { this.Scheduler = scheduler; this.TaskFactory = taskFactory; }
public Task(IStateResolver stateResolver, ICaptureState captureState, TimeSpan desiredExecution) { this.StateResolver = stateResolver; this.CaptureState = captureState; this.DesiredExecution = desiredExecution; }
/// <summary> /// Creates a new instance of a CaptureReader for the specified baseStream instance using the specified state resolver /// </summary> /// <param name="baseStream">Base stream to read data from</param> /// <param name="stateResolver">IStateResolver instance to use when resolving ICaptureStates from the stream</param> public CaptureReader(IStream baseStream, IStateResolver stateResolver) : base(baseStream) { this.StateResolver = stateResolver; this.StateAllocationTable = new Dictionary<short, Guid>(); //test if the stream contains a valid continuum stream by looking for the header signature try { byte[] header = new byte[Constants.CONTINUUM_HEADER_SIGNATURE.Length]; this.BaseStream.Read(header, 0, header.Length); for (int i = 0; i < Constants.CONTINUUM_HEADER_SIGNATURE.Length; i++) { if (header[i] != Constants.CONTINUUM_HEADER_SIGNATURE[i]) throw new Exception("Stream does not contain a valid continuum header"); } //read the version byte[] version = new byte[4]; this.BaseStream.Read(version, 0, version.Length); this.Version = new Version((int)version[0], (int)version[1], (int)version[2], (int)version[3]); //read the timestamp byte[] timestamp = new byte[8]; this.BaseStream.Read(timestamp, 0, timestamp.Length); this.Timestamp = DateTime.FromBinary(BitConverter.ToInt64(timestamp, 0)); //read the count var count = new byte[8]; this.BaseStream.Read(count, 0, count.Length); this.Count = BitConverter.ToInt64(count, 0); //read the length var length = new byte[8]; this.BaseStream.Read(length, 0, length.Length); this.Length = TimeSpan.FromTicks(BitConverter.ToInt64(length, 0)); //read the SAT, there should be at least one entry for it to be valid //the SAT looks like this: //<lengthOfSac><firstId of type short><delimiter> var lengthOfSatBuffer = new byte[4]; this.BaseStream.Read(lengthOfSatBuffer, 0, lengthOfSatBuffer.Length); var lengthOfSat = BitConverter.ToInt32(lengthOfSatBuffer, 0); if (lengthOfSat <= 0) { throw new Exception("Stream does not contain a valid State Allocation Table"); } //build out the SAT for (int i = 0; i < lengthOfSat; i++) { var idBuffer = new byte[2]; this.BaseStream.Read(idBuffer, 0, idBuffer.Length); var guid = new byte[16]; //guids are 16-bytes this.BaseStream.Read(guid, 0, guid.Length); this.StateAllocationTable.Add(BitConverter.ToInt16(idBuffer, 0), new Guid(guid)); } _PositionOfFirstState = this.BaseStream.Position; } catch { this.BaseStream.Close(); throw new Exception("Stream does not contain a valid continuum header"); } }