コード例 #1
0
      /// <summary>
      /// Calculates an MD5 hash of a blob. Comparing to <see cref="Blob.MD5"/> field, it always returns
      /// a hash, even if the underlying storage doesn't support it natively.
      /// </summary>
      public static async Task<string> GetMD5HashAsync(this IBlobStorage blobStorage, Blob blob, CancellationToken cancellationToken = default)
      {
         if(blob == null)
            throw new ArgumentNullException(nameof(blob));

         if(blob.MD5 != null)
            return blob.MD5;

         blob = await blobStorage.GetBlobAsync(blob.FullPath, cancellationToken).ConfigureAwait(false);

         if(blob.MD5 != null)
            return blob.MD5;

         //hash definitely not supported, calculate it manually

         using(Stream s = await blobStorage.OpenReadAsync(blob.FullPath, cancellationToken).ConfigureAwait(false))
         {
            if(s == null)
               return null;

            string hash = s.GetHash(HashType.Md5);

            return hash;
         }
      }
コード例 #2
0
        private async Task LoadFullBlobAsync()
        {
            if (_blob == null || _blobStorage == null)
            {
                return;
            }

            IsLoading = true;
            EditableMetadata.Clear();
            try
            {
                FullBlob = await _blobStorage.GetBlobAsync(_blob);

                if (FullBlob != null)
                {
                    EditableMetadata.AddRange(FullBlob.Metadata.Select(p => new EditableKeyValue {
                        Key = p.Key, Value = p.Value
                    }));
                }
            }
            catch (Exception ex)
            {
                await DialogService.ShowMessageAsync("Failed to load", ex.Message);
            }
            finally
            {
                IsDirty   = false;
                IsLoading = false;
            }
        }
コード例 #3
0
        public async Task Save(Snapshot snapshot, CancellationToken cancellationToken = default)
        {
            var json = JsonConvert.SerializeObject(snapshot, JsonSettings);
            await _storage.WriteTextAsync(_path.GetSnapshotPath(snapshot.Id), json, null, cancellationToken);

            Blob b = await _storage.GetBlobAsync(_path.GetSnapshotPath(snapshot.Id), cancellationToken);

            b.Properties["Version"] = snapshot.Version.ToString();
            b.Properties["Id"]      = snapshot.Id.ToString();
            await _storage.SetBlobAsync(b, cancellationToken);
        }
コード例 #4
0
        public override async ValueTask SaveAsync(WorkflowStorageContext context, string key, object?value, CancellationToken cancellationToken = default)
        {
            if (value == null)
            {
                return;
            }

            var path = GetFullPath(context, key);

            if (value is Stream stream)
            {
                await _blobStorage.WriteAsync(path, stream, cancellationToken : cancellationToken);

                var blob = await _blobStorage.GetBlobAsync(path, cancellationToken);

                blob.Metadata["ContentType"] = "Binary";
                await _blobStorage.SetBlobAsync(blob, cancellationToken);
            }
            else if (value is byte[] bytes)
            {
                await _blobStorage.WriteAsync(path, bytes, cancellationToken : cancellationToken);

                var blob = await _blobStorage.GetBlobAsync(path, cancellationToken);

                blob.Metadata["ContentType"] = "Binary";
                await _blobStorage.SetBlobAsync(blob, cancellationToken);
            }
            else
            {
                var json      = JsonConvert.SerializeObject(value, _serializerSettings);
                var jsonBytes = Encoding.UTF8.GetBytes(json);
                await _blobStorage.WriteAsync(path, jsonBytes, cancellationToken : cancellationToken);

                var blob = await _blobStorage.GetBlobAsync(path, cancellationToken);

                blob.Metadata["ContentType"] = "Json";
                await _blobStorage.SetBlobAsync(blob, cancellationToken);
            }
        }
コード例 #5
0
        /// <inheritdoc/>
        public async Task <IImageResolver> GetAsync(HttpContext context)
        {
            var path = context.Request.Path.Value;

            if (!await _blobStorage.ExistsAsync(path))
            {
                return(await Task.FromResult <IImageResolver>(null));
            }

            var blob = await _blobStorage.GetBlobAsync(path);


            var metadata = new ImageMetadata(blob.LastModificationTime.Value.UtcDateTime, blob.Size.Value);

            return(await Task.FromResult <IImageResolver>(new StorageNetImageResolver(_blobStorage, blob, metadata)));
        }
コード例 #6
0
ファイル: BlobEventStore.cs プロジェクト: 628426/CQRSlite
        public async Task Save(IEnumerable <IEvent> events, CancellationToken cancellationToken = default)
        {
            List <Task> tasksStore      = new List <Task>();
            List <Task> tasksAttributes = new List <Task>();
            List <Task> tasksPublishers = new List <Task>();

            foreach (IEvent e in events)
            {
                var json = JsonConvert.SerializeObject(e, JsonSettings);
                await _storage.WriteTextAsync(_path.GetEventPath(e.Id, e.Version), json, null, cancellationToken);

                Blob blob = await _storage.GetBlobAsync(_path.GetEventPath(e.Id, e.Version), cancellationToken);

                blob.Properties["Version"] = e.Version.ToString();
                blob.Properties["Id"]      = e.Id.ToString();
                blob.Properties["Type"]    = e.GetType().ToString();
                await _storage.SetBlobAsync(blob, cancellationToken);

                await _publisher.Publish <IEvent>(e, cancellationToken);
            }
        }