protected override void OnOpened() { EncodedVia via = new EncodedVia(base.Via.AbsoluteUri); EncodedContentType contentType = EncodedContentType.Create(this.settings.MessageEncoderFactory.Encoder.ContentType); int size = ClientSingletonEncoder.ModeBytes.Length + ClientSingletonEncoder.CalcStartSize(via, contentType); int dstOffset = 0; if (this.upgrade == null) { dstOffset = size; size += SessionEncoder.PreambleEndBytes.Length; } this.startBytes = DiagnosticUtility.Utility.AllocateByteArray(size); Buffer.BlockCopy(ClientSingletonEncoder.ModeBytes, 0, this.startBytes, 0, ClientSingletonEncoder.ModeBytes.Length); ClientSingletonEncoder.EncodeStart(this.startBytes, ClientSingletonEncoder.ModeBytes.Length, via, contentType); if (dstOffset > 0) { Buffer.BlockCopy(ClientSingletonEncoder.PreambleEndBytes, 0, this.startBytes, dstOffset, ClientSingletonEncoder.PreambleEndBytes.Length); } base.OnOpened(); }
protected override void OnOpened() { // setup our preamble which we'll use for all connections we establish EncodedVia encodedVia = new EncodedVia(this.Via.AbsoluteUri); EncodedContentType encodedContentType = EncodedContentType.Create(_settings.MessageEncoderFactory.Encoder.ContentType); int startSize = ClientSingletonEncoder.ModeBytes.Length + ClientSingletonEncoder.CalcStartSize(encodedVia, encodedContentType); int preambleEndOffset = 0; if (_upgrade == null) { preambleEndOffset = startSize; startSize += ClientDuplexEncoder.PreambleEndBytes.Length; } _startBytes = Fx.AllocateByteArray(startSize); Buffer.BlockCopy(ClientSingletonEncoder.ModeBytes, 0, _startBytes, 0, ClientSingletonEncoder.ModeBytes.Length); ClientSingletonEncoder.EncodeStart(_startBytes, ClientSingletonEncoder.ModeBytes.Length, encodedVia, encodedContentType); if (preambleEndOffset > 0) { Buffer.BlockCopy(ClientSingletonEncoder.PreambleEndBytes, 0, _startBytes, preambleEndOffset, ClientSingletonEncoder.PreambleEndBytes.Length); } // and then transition to the Opened state base.OnOpened(); }