public async Task <ImmutableDictionary <string, ICandle> > TryGetAsync()
        {
            if (!await _storage.HasBlobAsync(Constants.SnapshotsContainer, Key))
            {
                return(null);
            }

            try
            {
                using (var stream = await _storage.GetAsync(Constants.SnapshotsContainer, Key))
                {
                    var model = MessagePackSerializer.Deserialize <Dictionary <string, CandleEntity> >(stream);

                    return(model.ToImmutableDictionary(i => i.Key, i => (ICandle)i.Value));
                }
            }
            catch (InvalidOperationException)
            {
                await _log.WriteWarningAsync(
                    nameof(CandlesGeneratorSnapshotRepository),
                    nameof(TryGetAsync),
                    "Failed to deserialize the candles generator snapshot, trying to deserialize it as the legacy format");

                return(await DeserializeLegacyFormat());
            }
        }
Exemplo n.º 2
0
        public T Read <T>(string blobContainer, string key)
        {
            if (_blobStorage.HasBlobAsync(blobContainer, key).Result)
            {
                var data = _blobStorage.GetAsync(blobContainer, key).Result.ToBytes();
                var str  = Encoding.UTF8.GetString(data);

                return(JsonConvert.DeserializeObject <T>(str));
            }

            return(default(T));
        }
Exemplo n.º 3
0
        public async Task <byte[]> GetAsync(string id)
        {
            using (var stream = await _storage.GetAsync(ContainerName, id))
            {
                byte[] buffer = new byte[stream.Length];
                await stream.ReadAsync(buffer, 0, (int)stream.Length);

                return(buffer);
            }
        }
        public T Read <T>(string container, string key) where T : class
        {
            if (_blobStorage.HasBlobAsync(container, key).Result)
            {
                var data = _blobStorage.GetAsync(container, key).GetAwaiter().GetResult().ToBytes();
                return(JsonConvert.DeserializeObject <T>(Encoding.UTF8.GetString(data)));
            }

            return(null);
        }
Exemplo n.º 5
0
        protected async Task <byte[]> GetBlobAsync(string blobKey)
        {
            var stream = await Storage.GetAsync(_container, blobKey);

            using (var ms = new MemoryStream())
            {
                stream.CopyTo(ms);
                return(ms.ToArray());
            }
        }
Exemplo n.º 6
0
        public SettingsRoot Read()
        {
            if (_blobStorage.HasBlobAsync(BlobContainer, Key).Result)
            {
                var data = _blobStorage.GetAsync(BlobContainer, Key).GetAwaiter().GetResult().ToBytes();
                var str  = Encoding.UTF8.GetString(data);
                return(Convert(JsonConvert.DeserializeObject <SettingsRootStorageModel>(str)));
            }

            return(null);
        }
 private async Task <ConcurrentChain> GetFromPersistentCacheAsync()
 {
     try
     {
         return(new ConcurrentChain((await _blobStorage.GetAsync(BlobContainerName, _appSettings.BcnExploler.UsedNetwork().ToString())).ReadToEnd()));
     }
     catch
     {
         return(null);
     }
 }
        public async Task <T> ReadAsync <T>(string blobContainer, string key)
        {
            if (!_blobStorage.HasBlobAsync(blobContainer, key).Result)
            {
                return(default(T));
            }

            var data = (await _blobStorage.GetAsync(blobContainer, key)).ToBytes();
            var str  = Encoding.UTF8.GetString(data);

            return(JsonConvert.DeserializeObject <T>(str));
        }
        public async Task <byte[]> GetAsync(string fileName)
        {
            await _storage.CreateContainerIfNotExistsAsync(ContainerName);

            using (var stream = await _storage.GetAsync(ContainerName, fileName))
            {
                byte[] buffer = new byte[stream.Length];
                await stream.ReadAsync(buffer, 0, (int)stream.Length);

                return(buffer);
            }
        }
        public async Task <IEnumerable <IAssetPair> > Read()
        {
            if (_storage.HasBlobAsync(_container, _key).Result)
            {
                var data = await _storage.GetAsync(_container, _key);

                var content = Encoding.UTF8.GetString(data.ToBytes());

                return(JsonConvert.DeserializeObject <AssetPair[]>(content));
            }

            return(Enumerable.Empty <IAssetPair>());
        }
        public async Task <IEthereumContract> GetAsync(string contractAddress)
        {
            var stream = await _blobStorage.GetAsync(_blobName, contractAddress);

            using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
            {
                string result = await reader.ReadToEndAsync();

                IEthereumContract contract = Newtonsoft.Json.JsonConvert.DeserializeObject <IEthereumContract>(result);

                return(contract);
            }
        }
        public async Task <IImmutableList <ICandle> > TryGetAsync()
        {
            if (!await _storage.HasBlobAsync(Constants.SnapshotsContainer, Key))
            {
                return(null);
            }

            using (var stream = await _storage.GetAsync(Constants.SnapshotsContainer, Key))
            {
                var model = MessagePackSerializer.Deserialize <IEnumerable <SnapshotCandleEntity> >(stream);

                return(model.ToImmutableList <ICandle>());
            }
        }
Exemplo n.º 13
0
        public async Task AzureBlob_CheckInsert()
        {
            var data = new byte[] { 0x0, 0xff };

            await _testBlob.SaveBlobAsync(BlobContainer, BlobName, new MemoryStream(data));

            using (var result = await _testBlob.GetAsync(BlobContainer, BlobName))
                using (var ms = new MemoryStream())
                {
                    result.CopyTo(ms);

                    CollectionAssert.AreEquivalent(data, ms.ToArray());
                }
        }
        public async Task <IImmutableDictionary <string, IMarketState> > TryGetAsync()
        {
            if (!await _storage.HasBlobAsync(Constants.SnapshotsContainer, Key))
            {
                return(null);
            }

            using (var stream = await _storage.GetAsync(Constants.SnapshotsContainer, Key))
            {
                var model = MessagePackSerializer.Deserialize <Dictionary <string, MarketStateEntity> >(stream);

                return(model.ToImmutableDictionary(i => i.Key, i => (IMarketState)i.Value));
            }
        }
Exemplo n.º 15
0
        public async Task <Contract.AssetPairPrice[]> ReadAsync()
        {
            if (!await _storage.HasBlobAsync(_container, _key))
            {
                return(Array.Empty <Contract.AssetPairPrice>());
            }

            var data = await _storage.GetAsync(_container, _key);

            var content = Encoding.UTF8.GetString(data.ToBytes());

            return(JsonConvert.DeserializeObject <AssetPairPrice[]>(content)
                   .Select(x => x.ToAssetPairPrice())
                   .ToArray());
        }
        public async Task <Tuple <string, string> > GetDataWithMetaAsync(string file = null)
        {
            var fileName = GetFileName(file);

            try
            {
                var result = await _blobStorage.GetAsync(_container, fileName);

                return(new Tuple <string, string>(result.AsString(), result.ETag));
            }
            catch (Exception)
            {
                return(new Tuple <string, string>(string.Empty, string.Empty));
            }
        }
Exemplo n.º 17
0
        public async Task <string> GetDataAsync(string file = null)
        {
            var fileName = GetFileName(file);

            try
            {
                var result = await _blobStorage.GetAsync(_container, fileName);

                return(result.AsString());
            }
            catch (Exception)
            {
                return(string.Empty);
            }
        }
 public async Task <BlockchainIndexationState> GetOrCreateAsync()
 {
     if (await _blobStorage.HasBlobAsync(Container, DataKey))
     {
         using (var stream = await _blobStorage.GetAsync(Container, DataKey))
         {
             return(BlockchainIndexationState.Restore
                    (
                        await MessagePackSerializer.DeserializeAsync <IEnumerable <BlocksIntervalIndexationState> >(stream)
                    ));
         }
     }
     else
     {
         return(BlockchainIndexationState.Create());
     }
 }
Exemplo n.º 19
0
        public async Task <Dictionary <string, byte[]> > GetAllBlobAsync()
        {
            var keys = await _blobStorage.GetListOfBlobsAsync(_container);

            var result = new Dictionary <string, byte[]>();

            foreach (var k in keys)
            {
                var ks = k.Split(@"/\".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                if (ks.Length == 0)
                {
                    continue;
                }
                result.Add(ks[ks.Length - 1], (await _blobStorage.GetAsync(_container, ks[ks.Length - 1])).AsBytes());
            }

            return(result);
        }
        public async Task <Base64String> GetOrDefaultAsync(RawObjectType objectType, string objectId)
        {
            var containerName = RawObjectRepositoryTools.GetContainerName(_integrationName, objectType);
            var blobName      = RawObjectRepositoryTools.GetBlobName(objectId);

            if (!await _blob.HasBlobAsync(containerName, blobName))
            {
                return(null);
            }

            using (var stream = await _blob.GetAsync(containerName, blobName))
                using (var textReader = new StreamReader(stream))
                {
                    stream.Position = 0;

                    return(new Base64String(await textReader.ReadToEndAsync()));
                }
        }
Exemplo n.º 21
0
        private async Task <TransactionExecutionBlobEntity> TryGetBlobEntityAsync(
            Guid operationId)
        {
            var containerName = TransactionExecutionBlobEntity.GetContainerName();
            var blobName      = TransactionExecutionBlobEntity.GetBlobName(operationId);

            if (!await _blob.HasBlobAsync(containerName, blobName))
            {
                return(null);
            }

            using (var stream = await _blob.GetAsync(containerName, blobName))
                using (var textReader = new StreamReader(stream))
                    using (var jsonReader = new JsonTextReader(textReader))
                    {
                        stream.Position = 0;

                        return(_blobJsonSerializer.Deserialize <TransactionExecutionBlobEntity>(jsonReader));
                    }
        }
 public Task <BlobElement> GetAsync(string path, CancellationToken cancellationToken)
 {
     return(_storage.GetAsync(_containerName + "/" + path, cancellationToken));
 }
Exemplo n.º 23
0
 public async Task <Stream> GetAsync(string container, string key)
 => await WrapAsync(async() => await _impl.GetAsync(container, key), container);
Exemplo n.º 24
0
 public async Task <Stream> GetAttachment(string fileId)
 {
     return(await _blobStorage.GetAsync(ContainerName, fileId));
 }
Exemplo n.º 25
0
        public async Task <Tuple <string, string> > GetDataWithMetaAsync()
        {
            var result = await _blobStorage.GetAsync(_container, _file);

            return(new Tuple <string, string>(result.AsString(), result.ETag));
        }
Exemplo n.º 26
0
 public virtual Task <BlobElement> GetAsync(string path, CancellationToken cancellationToken = default)
 {
     return(_blobStorage.GetAsync(path, cancellationToken));
 }
Exemplo n.º 27
0
 public async Task <Stream> GetBlogPicture(string blogId)
 {
     return(await _blobStorage.GetAsync(ContainerName, blogId));
 }
Exemplo n.º 28
0
        public async Task <byte[]> GetDocument(string id)
        {
            var stream = await _blobStorage.GetAsync(ContainerName, id);

            return(await stream.ToBytesAsync());
        }
Exemplo n.º 29
0
 public async Task <Stream> GetAsync(string container, string key)
 => await _retryService.RetryAsync(async() => await _impl.GetAsync(container, key), _onGettingRetryCount);
 public async Task <Stream> GetProjectFile(string projectId)
 {
     return(await _blobStorage.GetAsync(ContainerName, projectId));
 }