public CaptureForm(ShotType shotType) { InitializeComponent(); //this code must be here, you must set beckground before form takes focus ScreenCapture _sc = new ScreenCapture(); BackgroundImageLayout = ImageLayout.None; BackgroundImage = _sc.CaptureRectangle(GetScreenSize()); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.OptimizedDoubleBuffer, true); switch (shotType) { case ShotType.General: m_state = new GeneralState(this); break; case ShotType.Region: m_state = new RegionState(this); break; case ShotType.Window: m_state = new WindowState(this); break; case ShotType.Screen: m_state = new ScreenState(this); break; } }
public void Write(ICaptureState state) { if (!this.StateResolver.IsAllocated(state.Guid)) { throw new Exception("Cannot resolve GUID in state allocation table"); } //validate the given timestamp var binaryTimestamp = state.Timestamp.ToBinary(); if (state.Timestamp < this.Timestamp) { binaryTimestamp = this.Timestamp.ToBinary(); } //write data using this format: //stateId (2 bytes) timestamp (8 bytes) lengthOfState (4 bytes) state (<lengthOfState> bytes) byte[] stateId = BitConverter.GetBytes(this.StateResolver.GetAllocatedId(state.Guid)); byte[] timestamp = BitConverter.GetBytes(binaryTimestamp); byte[] bytes = state.Data; byte[] lengthBytes = BitConverter.GetBytes(bytes.Length); this.BaseStream.Write(stateId, 0, stateId.Length); this.BaseStream.Write(timestamp, 0, timestamp.Length); this.BaseStream.Write(lengthBytes, 0, lengthBytes.Length); this.BaseStream.Write(bytes, 0, bytes.Length); this.Length = state.Timestamp.Subtract(this.Timestamp); this.Position++; this.Count++; //update the count in the header of the stream var currentPosition = this.BaseStream.Position; this.BaseStream.Position = _CountPosition; this.BaseStream.Write(BitConverter.GetBytes(this.Count), 0, 8); this.BaseStream.Position = currentPosition; //update the length in the header of the stream currentPosition = this.BaseStream.Position; this.BaseStream.Position = _LengthPosition; this.BaseStream.Write(BitConverter.GetBytes(this.Length.Ticks), 0, 8); this.BaseStream.Position = currentPosition; }
public void Next(Capture capture, ICaptureState captureState) { capture.NextState(captureState); }
public ITask Create(ICaptureState captureState) { return new Task(this.StateResolver, captureState, TimeSpan.FromMilliseconds(captureState.Offset)); }
public bool Filter(ICaptureState captureState) { return Predicate(captureState); }
public void Write(ICaptureState state) { lock (_Lock) { if (!this.CanWrite) { throw new Exception("Cannot write to underlying stream"); } //put the stream at the correct write position, a reader may have been reading from somewhere else in the stream _CaptureWriter.BaseStream.Position = _WritePointer; _CaptureWriter.Write(state); _WritePointer = _CaptureWriter.BaseStream.Position; } }
public Task(IStateResolver stateResolver, ICaptureState captureState, TimeSpan desiredExecution) { this.StateResolver = stateResolver; this.CaptureState = captureState; this.DesiredExecution = desiredExecution; }
public void Execute(ICaptureState captureState) { throw new NotImplementedException(); }
public Capture(IRecord record, IDisplay display) { state = new GameFrontEndState(record, display); }
public void NextState(ICaptureState captureState) { state = captureState; }
public void Execute(ICaptureState captureState) { Console.WriteLine("Executed capture state"); }
public void Execute(ICaptureState captureState) { //write the temperature out to the console and raise an event StateExecuted.Raise(this, captureState); Console.WriteLine(string.Format("At {0} the temperature was: {1} degrees celcius", captureState.Timestamp.ToString(), (captureState as WeatherCaptureState).Temperature)); }