示例#1
0
        public void Remove(ILightAttachment attachment)
        {
            var targetFile = attachment.Id;
            var blockBlob  = _containerReference.GetDirectoryReference(attachment.ResourceId).GetBlockBlobReference(targetFile);

            blockBlob.DeleteIfExistsAsync();
        }
        /// <summary>
        /// Add or update the attachment
        /// Calls the base class because there may be some generic behavior in it
        /// </summary>
        /// <param name="entityId">document id</param>
        /// <param name="fileName">name of the file</param>
        /// <param name="attachment">the attachment</param>
        /// <returns></returns>
        public override async Task <ILightAttachment> AddOrUpdateAttachmentAsync <T>(string entityId, string fileName, Stream attachment)
        {
            await base.AddOrUpdateAttachmentAsync <T>(entityId, fileName, attachment); //Calls the base class because there may be some generic behavior in it

            _typeToCollectionMap.TryGetValue(typeof(T), out var collection);

            Document doc = await GetByIdAsync <Document>(entityId);

            ILightAttachment upserted     = GetLightAttachment(entityId, fileName, attachment);
            Attachment       attachmentDB = GetAttachment(upserted);

            if (_mediaStorage != null)
            {
                attachmentDB.MediaLink = null;
                await _client.UpsertAttachmentAsync(doc.SelfLink, attachmentDB, new RequestOptions()
                {
                    PartitionKey = new PartitionKey(Undefined.Value)
                });

                await _mediaStorage.InsertUpdateAsync(upserted);
            }
            else
            {
                await _client.UpsertAttachmentAsync(doc.SelfLink, attachmentDB);
            }

            return(upserted);
        }
        public AzureBlobTests()
        {
            Workbench.Instance.Reset();

            Workbench.Instance.AddToCache(WorkbenchServiceType.Repository, _fakeLightRepository);

            _sut = new AzureBlob(new MediaStorageConfiguration
            {
                ConnectionString = DefaultConnectionString,
                Container        = _fixture.Create <string>().ToLower(CultureInfo.CurrentCulture),
            });

            _expectedData = _fixture.Create <string>();

            _stream = ToMemoryStream(_expectedData);

            _lightAttachment = new LightAttachment
            {
                ContentType = ContentType,
                Id          = _fixture.Create <string>() + ".txt",
                MediaLink   = _fixture.Create <string>(),
                MediaStream = _stream,
                Name        = _fixture.Create <string>(),
                ResourceId  = _fixture.Create <string>(),
            };
        }
示例#4
0
        public async void InsertUpdateAsync(ILightAttachment attachment)
        {
            var targetFile = attachment.Id;
            var blockBlob  = _containerReference.GetDirectoryReference(attachment.ResourceId).GetBlockBlobReference(targetFile);

            blockBlob.Properties.ContentType = attachment.ContentType;
            await blockBlob.UploadFromByteArrayAsync(ReadFully(attachment.MediaStream, blockBlob.StreamWriteSizeInBytes),
                                                     0, (int)attachment.MediaStream.Length);
        }
        public void Remove(ILightAttachment attachment)
        {
            DeleteObjectRequest deleteObject = new DeleteObjectRequest
            {
                BucketName = Container,
                Key        = attachment.ResourceId + "/" + attachment.Id
            };

            _client.DeleteObjectAsync(deleteObject);
        }
示例#6
0
        /// <summary>
        /// Azure Cosmos DB allows you to store binary blobs/media
        /// either with Azure Cosmos DB or to your own remote media store.
        /// allows you to represent the metadata of a media
        /// in terms of a special document called attachment
        /// </summary>
        /// <param name="lightAttachment">attachment came from LightAttachment</param>
        /// <returns>the attachment</returns>
        private Attachment GetAttachment(ILightAttachment lightAttachment)
        {
            Attachment attachment = new Attachment()
            {
                Id          = lightAttachment.Id,
                MediaLink   = lightAttachment.MediaLink,
                ContentType = lightAttachment.ContentType,
                ResourceId  = lightAttachment.ResourceId
            };

            return(attachment);
        }
        /// <summary>
        /// Google Cloud Firestore doesn't support attachments
        /// </summary>
        /// <param name="entityId">document id</param>
        /// <param name="fileName">name of the file</param>
        /// <param name="attachment">the attachment</param>
        /// <returns></returns>
        public override async Task <ILightAttachment> AddOrUpdateAttachmentAsync <T>(string entityId, string fileName, Stream attachment)
        {
            await base.AddOrUpdateAttachmentAsync <T>(entityId, fileName, attachment); //Calls the base class because there may be some generic behavior in it

            ILightAttachment upserted = GetLightAttachment(entityId, fileName, attachment);

            if (_mediaStorage != null)
            {
                _mediaStorage.InsertUpdateAsync(upserted);
            }

            return(upserted);
        }
        /// <summary>
        /// Get Attachments
        /// But Google Cloud Firestore doesn't support attachments
        /// </summary>
        /// <param name="entityId">attachment id</param>
        /// <param name="fileName">name of the file</param>
        /// <returns>The attachment type LightAttachment</returns>
        public override async Task <ILightAttachment> GetAttachmentAsync <T>(string entityId, string fileName)
        {
            await base.GetAttachmentAsync <T>(entityId, fileName);

            ILightAttachment lightAttachment = new LightAttachment();

            if (_mediaStorage != null)
            {
                var attachment = _mediaStorage.GetAsync("", "");
                ILightAttachment lightAttachmentStorage = await _mediaStorage.GetAsync(entityId, fileName);

                lightAttachment.MediaStream = lightAttachmentStorage.MediaStream;
            }
            else
            {
                lightAttachment = null;
            }

            return(lightAttachment);
        }
示例#9
0
        /// <summary>
        /// Calls the base class because there may be some generic behavior in it
        /// Get the attatchment by id and filename
        /// </summary>
        /// <param name="entityId">attachment id</param>
        /// <param name="fileName">name of the file</param>
        /// <returns>The attachment type LightAttachment</returns>
        public override async Task <ILightAttachment> GetAttachmentAsync <T>(string entityId, string fileName)
        {
            await base.GetAttachmentAsync <T>(entityId, fileName);

            ILightAttachment lightAttachment;

            if (_mediaStorage != null)
            {
                Attachment attachment = (Attachment)await _client.ReadAttachmentAsync(GetAttachmentUri(entityId, fileName));

                lightAttachment = ConvertLightAttachment(attachment);
                ILightAttachment lightAttachmentStorage = await _mediaStorage.GetAsync(entityId, fileName);

                lightAttachment.MediaStream = lightAttachmentStorage.MediaStream;
            }
            else
            {
                lightAttachment = await _client.ReadAttachmentAsync(((await _collection).SelfLink + "/" + fileName)) as ILightAttachment;
            }

            return(lightAttachment);
        }
示例#10
0
        /// <summary>
        /// Add or update the attachment
        /// Calls the base class because there may be some generic behavior in it
        /// </summary>
        /// <param name="entityId">document id</param>
        /// <param name="fileName">name of the file</param>
        /// <param name="attachment">the attachment</param>
        /// <returns></returns>
        public override async Task <ILightAttachment> AddOrUpdateAttachmentAsync <T>(string entityId, string fileName, Stream attachment)
        {
            await base.AddOrUpdateAttachmentAsync <T>(entityId, fileName, attachment); //Calls the base class because there may be some generic behavior in it

            Document doc = await GetByIdAsync <Document>(entityId);

            ILightAttachment upserted     = GetLightAttachment(entityId, fileName, attachment);
            Attachment       attachmentDB = GetAttachment(upserted);

            if (_mediaStorage != null)
            {
                attachmentDB.MediaLink = null;
                await _client.UpsertAttachmentAsync(doc.SelfLink, attachmentDB);

                _mediaStorage.InsertUpdateAsync(upserted);
            }
            else
            {
                await _client.UpsertAttachmentAsync(doc.SelfLink, attachmentDB);
            }
            return(upserted);
        }
示例#11
0
 public async void InsertUpdateAsync(ILightAttachment attachment)
 {
     await _fileTransferUtility.UploadAsync(attachment.MediaStream, Container, attachment.ResourceId + "/" + attachment.Id);
 }
        public Task Remove(ILightAttachment attachment)
        {
            _client.DeleteObject(this.Container, attachment.ResourceId + "/" + attachment.Id);

            return(Task.CompletedTask);
        }
 public Task InsertUpdateAsync(ILightAttachment attachment)
 {
     return(_client.UploadObjectAsync(this.Container, attachment.ResourceId + "/" + attachment.Name, attachment.ContentType, attachment.MediaStream));
 }
示例#14
0
 /// <summary>
 /// Azure File allows you to store binary blobs/media
 /// either with Azure File or to your own remote media store.
 /// allows you to represent the metadata of a media
 /// in terms of a special document called attachment
 /// </summary>
 /// <param name="lightAttachment">attachment came from LightAttachment</param>
 /// <returns>the attachment</returns>
 private dynamic GetAttachment(ILightAttachment lightAttachment)
 {
     throw new NotImplementedException();
 }
示例#15
0
 public Task InsertUpdateAsync(ILightAttachment attachment)
 {
     return(_fileTransferUtility.UploadAsync(attachment.MediaStream, Container, attachment.ResourceId + "/" + attachment.Id));
 }
示例#16
0
 public async void InsertUpdateAsync(ILightAttachment attachment)
 {
     await _client.UploadObjectAsync(this.Container, attachment.ResourceId + "/" + attachment.Name, attachment.ContentType, attachment.MediaStream);
 }
示例#17
0
 public void Remove(ILightAttachment attachment)
 {
     _client.DeleteObject(this.Container, attachment.ResourceId + "/" + attachment.Id);
 }