public static async Task <AttachmentContent> UpdateAssetById(this ISquidexAttachmentClient that, string application, string id, string fileName, string mimeType, Stream stream)
 {
     return(await that.UpdateAsset(application, id, new[]
     {
         new StreamPart(stream, fileName, mimeType)
     }));
 }
        public static async Task <AttachmentContent> GetAssetByNameOrThrow(this ISquidexAttachmentClient that, string application, string fileName)
        {
            var item = await that.GetAssetByNameOrDefault(application, fileName);

            if (item == null)
            {
                throw new ArgumentNullException("fileName", $"An 'Attachment' with the fileName '{fileName}' was not found on the application '{application}'");
            }

            return(item);
        }
示例#3
0
        public static async Task AssertAttachmentMustNotExist(this ISquidexAttachmentClient that, string application, string name, TimeSpan?delay = null)
        {
            // because of eventual consistency
            if (delay.HasValue)
            {
                await Task.Delay(delay.Value);
            }

            var exists = await that.AttachmentExists(application, name);

            exists.Should().BeFalse();
        }
        public static async Task <AttachmentContent> GetAssetByNameOrDefault(this ISquidexAttachmentClient that, string application, string fileName)
        {
            // todo : pagination, caching ??

            var data = await that.GetAllAssets(application, new ListRequest()
            {
                Skip = 0, Top = 200
            });

            var count = data.Total;

            if (count == 0)
            {
                return(default(AttachmentContent));
            }

            var item = data.Items.SingleOrDefault(d => CheckEquality(d, fileName));

            return(item);
        }
        public static async Task <bool> AttachmentExists(this ISquidexAttachmentClient that, string application, string fileName = null)
        {
            var item = await that.GetAssetByNameOrDefault(application, fileName);

            return(item != null);
        }
        public static async Task DeleteAssetByName(this ISquidexAttachmentClient that, string application, string fileName)
        {
            var item = await that.GetAssetByNameOrThrow(application, fileName);

            await that.DeleteAsset(application, item.Id);
        }
        public static async Task <AttachmentContent> UpdateAssetContentByName(this ISquidexAttachmentClient that, string application, string fileName, string mimeType, Stream stream)
        {
            var item = await that.GetAssetByNameOrThrow(application, fileName);

            return(await that.UpdateAssetById(application, item.Id, fileName, mimeType, stream));
        }