Пример #1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _logger.LogInformation("Writing Currencies...");

            var currencies = new []
            {
                new Currency {
                    Name = "Euro"
                },
                new Currency {
                    Name = "Dollar"
                }
            }.AsEnumerable();

            await _dataWriter.LockAsync(async() =>
            {
                await _dataWriter.WriteAsync(currencies);
            });

            _logger.LogInformation("Reading Currencies...");

            currencies = await _dataRetriever.GetAsync();

            _logger.LogInformation("Currencies: {@currencies}", currencies);
        }
Пример #2
0
        public async Task WriteAsync(T obj, IDataWriter writer, CancellationToken token)
        {
            var byteArr = _codec.Encode(obj);
            await writer.WriteInt32Async(byteArr.Length, token);

            await writer.WriteAsync(byteArr, 0, byteArr.Length, token);
        }
Пример #3
0
        /// <summary>
        /// Writes the class fields.
        /// </summary>
        /// <param name="obj">The message to write</param>
        /// <param name="writer">The writer to which to write</param>
        /// <param name="token">The cancellation token</param>
        public async System.Threading.Tasks.Task WriteAsync(GroupCommunicationMessage <T> obj, IDataWriter writer, CancellationToken token)
        {
            byte[] encodedMetadata = GenerateMetaDataEncoding(obj);
            byte[] encodedInt      = BitConverter.GetBytes(encodedMetadata.Length);
            byte[] totalEncoding   = encodedInt.Concat(encodedMetadata).ToArray();
            await writer.WriteAsync(totalEncoding, 0, totalEncoding.Length, token);

            foreach (var data in obj.Data)
            {
                await _codec.WriteAsync(data, writer, token);
            }
        }
Пример #4
0
        /// <summary>
        /// Writes the integer array to the writer.
        /// </summary>
        /// <param name="obj">The integer array to be encoded</param>
        /// <param name="writer">The writer to which to write</param>
        /// <param name="token">Cancellation token</param>
        public async Task WriteAsync(int[] obj, IDataWriter writer, CancellationToken token)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj", "integer array is null");
            }

            await writer.WriteInt32Async(obj.Length, token);

            byte[] buffer = new byte[sizeof(int) * obj.Length];
            Buffer.BlockCopy(obj, 0, buffer, 0, sizeof(int) * obj.Length);
            await writer.WriteAsync(buffer, 0, buffer.Length, token);
        }
        /// <summary>
        /// Writes message asynchronously to the writer
        /// </summary>
        /// <param name="obj">Message to write</param>
        /// <param name="writer">Writer used to write the message</param>
        /// <param name="token">Cancellation token</param>
        async Task IStreamingCodec <MapInputWithControlMessage <TMapInput> > .WriteAsync(
            MapInputWithControlMessage <TMapInput> obj, IDataWriter writer, CancellationToken token)
        {
            switch (obj.ControlMessage)
            {
            case MapControlMessage.AnotherRound:
                await writer.WriteAsync(new byte[] { 0 }, 0, 1, token);

                await _baseCodec.WriteAsync(obj.Message, writer, token);

                break;

            case MapControlMessage.Stop:
                writer.Write(new byte[] { 1 }, 0, 1);
                break;
            }
        }
Пример #6
0
        /// <summary>
        /// Writes the class fields to the writer.
        /// </summary>
        /// <param name="obj">The object of type NsMessage<T> to be encoded</param>
        /// <param name="writer">The writer to which to write</param>
        /// <param name="token">Cancellation token</param>
        public async Task WriteAsync(NsMessage <T> obj, IDataWriter writer, CancellationToken token)
        {
            byte[] encodedMetadata = GenerateMetaDataEncoding(obj);
            byte[] encodedInt      = BitConverter.GetBytes(encodedMetadata.Length);
            byte[] totalEncoding   = encodedInt.Concat(encodedMetadata).ToArray();
            await writer.WriteAsync(totalEncoding, 0, totalEncoding.Length, token);

            Type messageType = obj.Data[0].GetType();

            var codecWriteFunc = _codecFunctionsCache.WriteAsyncFunction(messageType);

            foreach (var data in obj.Data)
            {
                var asyncResult = codecWriteFunc.BeginInvoke(data, writer, token, null, null);
                await codecWriteFunc.EndInvoke(asyncResult);
            }
        }