Beispiel #1
0
        private async Task <CopyResult> CopyInternal(string source, bool?makePublic, string pattern, bool?store, string target)
        {
            using (var request = new HttpRequestMessage(HttpMethod.Post, UrlHelper.ApiFiles()))
            {
                var contentSB = new StringBuilder($"source={source}");

                if (makePublic.HasValue)
                {
                    contentSB.Append("&makePublic=").Append(makePublic.Value);
                }

                if (!string.IsNullOrEmpty(pattern))
                {
                    contentSB.Append("&pattern=").Append(pattern);
                }

                if (store.HasValue)
                {
                    contentSB.Append("&store=").Append(store.Value);
                }

                if (!string.IsNullOrEmpty(target))
                {
                    contentSB.Append("&target=").Append(target);
                }

                request.Content = new StringContent(contentSB.ToString(), Encoding.UTF8, "application/x-www-form-urlencoded");

                return(await ExecuteRequestAsync <CopyResult>(this._httpClient, request).ConfigureAwait(false));
            }
        }
Beispiel #2
0
 public async Task <File> GetAsync(Guid fileId)
 {
     using (var request = new HttpRequestMessage(HttpMethod.Get, UrlHelper.ApiFiles(fileId)))
     {
         return(await ExecuteRequestAsync <File>(this._httpClient, request).ConfigureAwait(false));
     }
 }
Beispiel #3
0
        /// <summary>
        /// Get a paginated file list.
        /// </summary>
        /// <param name="filter"></param>
        public async Task <PaginatedResult <File> > GetListAsync(GetFilesFilter filter)
        {
            var pathSB = new StringBuilder("?ordering=");

            if (filter.SortDirection.Equals(GetFilesFilter.Direction.Descending))
            {
                pathSB.Append("-");
            }

            pathSB.Append(filter.Sort);

            if (filter.OnlyRemoved)
            {
                pathSB.Append("&removed=true");
            }

            if (filter.Stored.HasValue)
            {
                pathSB.Append("&stored=").Append(filter.Stored.Value ? "true" : "false");
            }

            if (filter.Limit > 0)
            {
                pathSB.Append("&limit=").Append(filter.Limit);
            }

            if (filter.Sort.Equals(GetFilesFilter.SortProperty.datetime_uploaded) &&
                filter.FromDatetimeUploaded.HasValue)
            {
                pathSB.Append("&from=").Append(filter.FromDatetimeUploaded.Value.ToString("yyyy-MM-ddTHH:mm:ss"));
            }
            else if (filter.Sort.Equals(GetFilesFilter.SortProperty.size) &&
                     filter.FromSize > 0)
            {
                pathSB.Append("&from=").Append(filter.FromSize);
            }

            var uri = new Uri(UrlHelper.ApiFiles(), pathSB.ToString());

            using (var request = new HttpRequestMessage(HttpMethod.Get, uri))
            {
                return(await ExecuteRequestAsync <PaginatedResult <File> >(this._httpClient, request).ConfigureAwait(false));
            }
        }