public IPayloadPackage Wrap(PackageKind packageKind, object payload, Guid?packageId = null) { object package = payload; if (packageId.HasValue) { Type payloadType = package.GetType(); package = new InterlinkedPackage { Id = packageId.Value, PayloadType = payloadType.AssemblyQualifiedName, Payload = _modelSerializer.Serialize(payloadType, package) }; } Type packageType = package.GetType(); return(new PayloadPackage { PackageKind = packageKind, PayloadType = packageType.AssemblyQualifiedName, Payload = _modelSerializer.Serialize(packageType, package) }); }
void Connect() { Guid clientId = Guid.NewGuid(); Socket introduceConnection = new Socket(_endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); introduceConnection.Connect(_endPoint); var initStream = new NetworkStream(introduceConnection); var wrapper = new TelemetryPackageWrapper(_contractSerializer); BytePackageUtil.WritePackage(initStream, _contractSerializer.Serialize(typeof(PayloadPackage), wrapper.Wrap(PackageKind.Request, new ConnectionRequest { ConnectionId = clientId, ResourceCount = Environment.ProcessorCount }))); channelResources.RegisterResource(initStream); var resourceCount = Environment.ProcessorCount * 2; for (int i = 1; i < resourceCount; i++) { Socket clientSocket = new Socket(_endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); clientSocket.Connect(_endPoint); var stream = new NetworkStream(clientSocket); BytePackageUtil.WritePackage(stream, _contractSerializer.Serialize(typeof(PayloadPackage), wrapper.Wrap(PackageKind.Request, new ResourceConnectionRequest() { ConnectionId = clientId }))); channelResources.RegisterResource(stream); } }
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context) { contractSerializer.Serialize(stream, data, false); return(Task.CompletedTask); }