public static async Task <string> SerializeToStringAsync(
            this ISerializable serializable,
            CancellationToken cancellationToken = default)
        {
            using var stream = new MemoryStream();
            await serializable.SerializeAsync(stream, cancellationToken).ConfigureAwait(false);

            return(Encoding.UTF8.GetString(stream.ToArray()));
        }
示例#2
0
        public static async Task <string> SerializeToStringAsync(
            this ISerializable serializable,
            CancellationToken cancellationToken = default)
        {
            var stream = new MemoryStream();

#if NET461 || NETSTANDARD2_0
            using (stream)
#else
            await using (stream.ConfigureAwait(false))
#endif
            {
                await serializable.SerializeAsync(stream, cancellationToken).ConfigureAwait(false);

                return(Encoding.UTF8.GetString(stream.ToArray()));
            }
        }
示例#3
0
        public async Task <T> UpdateAsync <T>(string key, ISerializable value) where T : class
        {
            // Get or create setting
            var existingSetting = await GetByKeyAsync(key)
                                  ?? new DictionaryEntry()
            {
                Key = key
            };

            // Serilize value
            existingSetting.Value = await value.SerializeAsync();

            // update setting & return updated typed settings
            var updatedSetting = await _dictionaryRepository.InsertUpdateAsync(existingSetting);

            if (updatedSetting != null)
            {
                return(await GetAsync <T>(updatedSetting.Key));
            }

            return(default(T));
        }
示例#4
0
        public async Task <T> UpdateAsync <T>(int userId, string key, ISerializable value) where T : class
        {
            // Get or create setting
            var data = await GetByUserIdAndKeyAsync(userId, key)
                       ?? new UserData()
            {
                UserId = userId,
                Key    = key
            };

            // Serialize value
            data.Value = await value.SerializeAsync();

            var updatedData = await _userDataRepository.InsertUpdateAsync(data);

            if (updatedData != null)
            {
                return(await GetAsync <T>(userId, updatedData.Key));
            }

            return(default(T));
        }
示例#5
0
        public async Task <T> UpdateAsync(int entityId, string key, ISerializable value)
        {
            // Get or create setting
            var data = await GetByEntityIdAndKeyAsync(entityId, key)
                       ?? new EntityData()
            {
                EntityId = entityId,
                Key      = key
            };

            // Serilize value
            data.Value = await value.SerializeAsync();

            var updatedData = await _entityDataRepository.InsertUpdateAsync(data);

            if (updatedData != null)
            {
                return(await GetAsync(entityId, updatedData.Key));
            }

            return(default(T));
        }
 protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
 {
     await _envelope.SerializeAsync(stream).ConfigureAwait(false);
 }