public ReliableSamHelper( ISamHelper samHelper, ReliableSamHelperSettings settings ) { if (samHelper == null) { throw new ArgumentNullException( MyNameof.GetLocalVarName(() => samHelper)); } if (settings == null) { throw new ArgumentNullException( MyNameof.GetLocalVarName(() => settings)); } _samHelper = samHelper; _settings = settings; var rng = new Random(DateTime.UtcNow.Millisecond); _nextOutMessageId = (uint)rng.Next(int.MaxValue); RawDatagramReceived.ObserveOn(TaskPoolScheduler.Default).Subscribe(args => _log.Trace( "{5} recv raw datagram of {0} bytes " + "from {1} id={2}, rid={3}, kind={6}, ansiS='{4}'", args.Data.Length, args.Destination.Substring(0, 20), args.MessageId, args.ReplyToMessageId, Encoding.ASCII.GetString(args.Data), _reliableSamHelperGuid.ToString().Substring(0, 5), args.MessageKind )); ReliableMessageReceived.ObserveOn(TaskPoolScheduler.Default).Subscribe(args => _log.Trace( "{4} recv reliable message of {0} bytes " + "from {1} id={2}, rid={3}, kind={5}", args.Data.Length, args.Destination.Substring(0, 20), args.MessageId, args.ReplyToMessageId, _reliableSamHelperGuid.ToString().Substring(0, 5), args.MessageKind ) ); _subscriptions.AddRange( new[] { _samHelper.DatagramDataReceived.ObserveOn(TaskPoolScheduler.Default).Subscribe( SamHelperOnDatagramDataReceived ), GetProtocolVersionReceived.ObserveOn(TaskPoolScheduler.Default).Subscribe( OnGetProtocolVersionReceived ), HandshakeStartReceived.ObserveOn(TaskPoolScheduler.Default).Subscribe( OnHandshakeStartReceived ), GetMessageStatusReceived.ObserveOn(TaskPoolScheduler.Default).Subscribe( OnGetMessageStatusReceived ), BlockSendReceived.ObserveOn(TaskPoolScheduler.Default).Subscribe( OnBlockSendReceived ), Observable.Interval(TimeSpan.FromSeconds(20.0d)).ObserveOn(TaskPoolScheduler.Default).Subscribe( IntervalCleanupAction ) } ); _stateHelper.SetInitializedState(); }
public ReliableSamHelper( ISamHelper samHelper, ReliableSamHelperSettings settings ) { if(samHelper == null) throw new ArgumentNullException( MyNameof.GetLocalVarName(() => samHelper)); if(settings == null) throw new ArgumentNullException( MyNameof.GetLocalVarName(() => settings)); _samHelper = samHelper; _settings = settings; var rng = new Random(DateTime.UtcNow.Millisecond); _nextOutMessageId = (uint) rng.Next(int.MaxValue); RawDatagramReceived.ObserveOn(TaskPoolScheduler.Default).Subscribe(args => _log.Trace( "{5} recv raw datagram of {0} bytes " + "from {1} id={2}, rid={3}, kind={6}, ansiS='{4}'", args.Data.Length, args.Destination.Substring(0, 20), args.MessageId, args.ReplyToMessageId, Encoding.ASCII.GetString(args.Data), _reliableSamHelperGuid.ToString().Substring(0,5), args.MessageKind )); ReliableMessageReceived.ObserveOn(TaskPoolScheduler.Default).Subscribe(args => _log.Trace( "{4} recv reliable message of {0} bytes " + "from {1} id={2}, rid={3}, kind={5}", args.Data.Length, args.Destination.Substring(0, 20), args.MessageId, args.ReplyToMessageId, _reliableSamHelperGuid.ToString().Substring(0, 5), args.MessageKind ) ); _subscriptions.AddRange( new[] { _samHelper.DatagramDataReceived.ObserveOn(TaskPoolScheduler.Default).Subscribe( SamHelperOnDatagramDataReceived ), GetProtocolVersionReceived.ObserveOn(TaskPoolScheduler.Default).Subscribe( OnGetProtocolVersionReceived ), HandshakeStartReceived.ObserveOn(TaskPoolScheduler.Default).Subscribe( OnHandshakeStartReceived ), GetMessageStatusReceived.ObserveOn(TaskPoolScheduler.Default).Subscribe( OnGetMessageStatusReceived ), BlockSendReceived.ObserveOn(TaskPoolScheduler.Default).Subscribe( OnBlockSendReceived ), Observable.Interval(TimeSpan.FromSeconds(20.0d)).ObserveOn(TaskPoolScheduler.Default).Subscribe( IntervalCleanupAction ) } ); _stateHelper.SetInitializedState(); }