/// <summary> /// Delegates <paramref name="message"/> handling to remote WEB server. /// </summary> public async Task <TResponse> DelegateHandling <TResponse>(IMessage <TResponse> message, CancellationToken token) { var messageType = message.GetType(); var requestSerializer = factory.Create(messageType); var requestStream = new MemoryStream(); await requestSerializer.SerializeObject(requestStream, message, token); requestStream.Position = 0; var messageName = typeEncoder.Encode(messageType); var response = await client.SendAsync(new HttpRequestMessage(HttpMethod.Post, "") { Headers = { { HeaderNames.MessageName, messageName } }, Content = new StreamContent(requestStream) }, token); var responseSerializer = factory.Create(typeof(TResponse)); var responseStream = await response.Content.ReadAsStreamAsync(token); var responseObject = (TResponse)await responseSerializer.DeserializeObject(responseStream, token); return(responseObject !); }
public async Task Write <T>(IEnumerable <T> items, CancellationToken token) { var serializer = _serializerFactory.Create <T>(); using (var fs = new FileStream(_path, FileMode.Append, FileAccess.Write, FileShare.None, bufferSize: 4096, useAsync: true)) { foreach (var item in items) { serializer.Serialize(fs, item); } await fs.FlushAsync(token); } }
/// <inheritdoc /> public object Connect(Type type, string objectId) { var contractDescription = _contractDescriptionFactory.Create(type); //Send ConnectObjectMessage to ensure that object is hosted var connectObjectMessage = new ConnectMessage(_clientHostAddress, objectId); _outputChannel.SendWithAck(connectObjectMessage); var knownTypes = contractDescription.GetTypes(); var serializer = _serializerFactory.Create(typeof(object), knownTypes); var interceptor = new ClientInterceptor(contractDescription); var proxy = _proxyGenerator.CreateInterfaceProxyWithoutTarget(type, interceptor); var connection = new Connection(objectId, proxy, _eventHandlersRepository, contractDescription, serializer, this, _outputChannel, _clientHostAddress); interceptor.Subscribe(connection); lock (_objectIds) { RemoveDeadObjectIds(); _objectIds.Add(new Tuple <string, WeakReference>(objectId, new WeakReference(proxy))); } return(proxy); }
public async Task AddAsync <T>(ItemKey itemKey, T value, CancellationToken cancellationToken = default(CancellationToken), bool enableTraces = true) { if (value == null) { return; } if (itemKey == null) { throw new ArgumentNullException(nameof(itemKey)); } var serializer = _serializerFactory.Create(typeof(T)); var compressedData = await SerializeWithCompression <T>(value, serializer, cancellationToken, enableTraces); await Push(itemKey.Category, itemKey.Key, compressedData, cancellationToken, enableTraces); }
public async Task ExecuteAsync(ReceivePipelineContext ctx, Func <Task> next) { var transportMessage = ctx.Load <TransportMessage>(); var serializer = _serializerFactory.Create(transportMessage); ctx.Save <Message>(await serializer.DeserializeAsync(transportMessage)); await FuncInvoker.Invoke(next); }
public IEnumerable <WorkspacePath> Load(string source) { if (string.IsNullOrEmpty(source)) { return(new List <WorkspacePath>()); } var deserializer = _serializerFactory.Create(typeof(List <WorkspacePath>)); List <WorkspacePath> deserializedItems; using (var fs = new StringReader(source)) { using (var reader = XmlDictionaryReader.CreateTextReader(Encoding.UTF8.GetBytes(fs.ReadToEnd()), new XmlDictionaryReaderQuotas())) { deserializedItems = (List <WorkspacePath>)deserializer.ReadObject(reader, false); } } return(deserializedItems); }
protected ISerializer <T> GetSerializer(Type aliasType) { if (aliasType == null) { return(_serializerFactory.Create <T>()); } var method = AliasCreateMethodInfo.MakeGenericMethod(typeof(T), aliasType); return((ISerializer <T>)method.Invoke(_serializerFactory, null)); }
private ISerializer <T> GetSerializer(Type aliasType) { if (aliasType == null) { return(_serializerFactory.Create <T>()); } var method = ReflectionHelper.AliasGenericCreateMethod.MakeGenericMethod(typeof(T), aliasType); return((ISerializer <T>)method.Invoke(_serializerFactory, null)); }
private async Task <byte[]> Serialize <T>(T value) { byte[] serializedValue; if (value is byte[]) { return(serializedValue = value as byte[]); } var serializer = _serializerFactory.Create(typeof(T)); using (new ProfileContext("State serialization")) using (var outputStream = await _memoryStreamPool.GetMemoryStream()) { serializer.Serialize(outputStream, value); serializedValue = outputStream.ToArray(); } return(serializedValue); }
/// <inheritdoc /> public IObjectHost <T> Add <T>(string objectId, T obj, SynchronizationContext synchronizationContext = null) where T : class { //TODO: check arguments var contractDescription = _contractDescriptionFactory.Create(typeof(T)); var knownTypes = contractDescription.GetTypes(); var serializer = _serializerFactory.Create(typeof(object), knownTypes); var objectHost = _objectsRepository.Add(objectId, new ObjectAdapter(objectId, contractDescription, serializer, synchronizationContext, obj, _objectsRepository)); return(new ServerEloquentObject <T>(obj, objectId, null, objectHost)); }
public Workspace Load(string path) { var fileData = this._fileSystem.File.ReadAllText(path); var deserializer = _serializerFactory.Create(typeof(Workspace)); Workspace workspace; using (var fs = new StringReader(fileData)) { using (var reader = XmlDictionaryReader.CreateTextReader(Encoding.UTF8.GetBytes(fs.ReadToEnd()), new XmlDictionaryReaderQuotas())) { workspace = (Workspace)deserializer.ReadObject(reader, false); } } workspace.LastRecentlyUsed = DateTime.Now; return(workspace); }
public Investigation Load(string path) { var fileData = this._fileSystem.File.ReadAllText(path); var deserializer = _serializerFactory.Create(typeof(Investigation)); Investigation investigation; using (var fs = new StringReader(fileData)) { using (var reader = XmlDictionaryReader.CreateTextReader(Encoding.UTF8.GetBytes(fs.ReadToEnd()), new XmlDictionaryReaderQuotas())) { investigation = (Investigation)deserializer.ReadObject(reader, false); } } return(investigation); }
#pragma warning restore CS0618 // Type or member is obsolete public ConnectionSettings(IConnectionPool connectionPool, IConnection connection, ISerializerFactory serializerFactory) : base(connectionPool, connection, serializerFactory, s => serializerFactory.Create(s)) { }
public BaseClient(HttpClient httpClient, ISerializerFactory serializerFactory) { _httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); _deserilzer = serializerFactory.Create <T>() ?? throw new ArgumentNullException(nameof(httpClient)); }
private ObjectSerializer Create(Type objectType, ISerializationContext context) => _serializerFactory.Create(objectType, context);
protected ISerializer ResolveSerializer(string fileName) { var fileType = userInputParser.GetFileType(fileName); return(serializerFactory.Create(fileType)); }
public void Create_returnsSerializer_unregistered() => factory.Create(typeof(object)).Should().NotBeNull();