public AnimationViewModel() { this.Timer = new DispatcherTimer(TimeSpan.FromMilliseconds(50), DispatcherPriority.Background, (o, e) => OnTimerTick(), Application.Current.Dispatcher) { IsEnabled = false }; this.Frames = new ObservableCollection <WriteableBitmap>(); this.CurrentFrameIndex = Cell.Create(0); this.CurrentFrame = Cell.Derived(this.CurrentFrameIndex, DeriveCurrentFrame); this.IsDoneRendering = Cell.Create(false); this.MaximumFrameIndex = Cell.Derived(() => this.Frames.Count - 1); this.Messages = new TextDocument(); this.Frames.CollectionChanged += (sender, e) => OnFrameCollectionChanged(); this.ToggleAnimation = EnabledCommand.FromDelegate(OnToggleAnimation); this.ScaleToFill = Cell.Create(true); this.ToggleScale = EnabledCommand.CreateTogglingCommand(ScaleToFill); this.FullScreen = Cell.Create(false); this.ToggleFullScreen = EnabledCommand.CreateTogglingCommand(FullScreen); this.ExportFrame = EnabledCommand.FromDelegate(OnExportFrame); this.ExportMovie = CellCommand.FromDelegate(this.IsDoneRendering, OnExportMovie); this.CopyFrame = EnabledCommand.FromDelegate(OnCopyFrame); this.PreviousFrame = EnabledCommand.FromDelegate(OnPreviousFrame); this.NextFrame = EnabledCommand.FromDelegate(OnNextFrame); }
internal Cell ReceiveCell() { Cell cell = new Cell(); do { StreamWrapper socket_buffer = new StreamWrapper(_socket, Endianness.big_endian); // get circuit id based on the current protocol version. uint circuit_id; byte[] buffer = new byte[sizeof(uint)]; if (_protocol_version < 4) { if (socket_buffer.Read(buffer, sizeof(ushort)) != sizeof(ushort)) { break; } circuit_id = buffer.ToUInt16(); } else { if (socket_buffer.Read(buffer) != sizeof(uint)) { break; } circuit_id = buffer.ToUInt32(); } // get the cell command. if (socket_buffer.Read(buffer, sizeof(CellCommand)) != sizeof(CellCommand)) { break; } CellCommand command = (CellCommand)(buffer[0]); // get payload size for variable-length cell types. ushort payload_size = 509; if (CellCommand.versions == command || (uint)command >= 128) { if (socket_buffer.Read(buffer, sizeof(ushort)) != sizeof(ushort)) { break; } payload_size = buffer.ToUInt16(); } // get the content of the payload. byte[] payload = new byte[payload_size]; if (socket_buffer.Read(payload, payload_size) != payload_size) { break; } // build the cell cell.CircuitId = circuit_id; cell.Command = command; cell.Payload = payload; cell.MarkAsValid(); } while (false); return(cell); }
public RelayCell(uint circuit_id, CellCommand command, CircuitNode node, CellCommand relay_command, ushort stream_id, byte[] relay_payload) : base(circuit_id, command) { // : cell(circuit_id, command) _circuit_node = node; _relay_command = relay_command; _stream_id = stream_id; this.RelayPayload = relay_payload; }
public RelayCell(CircuitNode node, Cell cell) : base(ref cell) { _circuit_node = node; MemoryStream payload_stream = new MemoryStream(cell.Payload); StreamWrapper payload_buffer = new StreamWrapper(payload_stream, Endianness.big_endian); CellCommand relay_command = (CellCommand)payload_buffer.ReadByte(); ushort dummy = payload_buffer.ReadUInt16(); ushort stream_id = payload_buffer.ReadUInt16(); uint digest = payload_buffer.ReadUInt32(); ushort payload_size = payload_buffer.ReadUInt16(); byte[] payload = new byte[payload_size]; payload_buffer.Read(payload); _relay_command = relay_command; _stream_id = stream_id; this.RelayPayload = payload; }
private void SendRelayCell(ushort stream_id, CellCommand relay_command, byte[] payload = null, CellCommand cell_command = CellCommand.relay, CircuitNode node = null) { node = node ?? FinalCircuitNode; if ((null == GetStreamById(stream_id)) && (0 != stream_id)) { Logger.Warning("circuit::send_relay_cell() attempt to send cell to non-existent stream-id: {0}", stream_id); return; } Logger.Debug("tor_socket::send_cell() [circuit: %i%s, stream: %u, command: %i, relay_command: %i]", _circuit_id & 0x7FFFFFFF, ((0 != (_circuit_id & 0x80000000)) ? " (MSB set)" : ""), stream_id, cell_command, relay_command); SendCell( Encrypt( new RelayCell(_circuit_id, cell_command, node, relay_command, stream_id, payload))); }
internal Cell(uint circuit_id, CellCommand command, byte[] payload = null) { this._circuit_id = circuit_id; this._command = command; this._payload = payload; }