public IDownloadInfo GetDownloadInfo(IContentIdentifier contentIdentifier) { var contentID = ContentIdentifierSerializer.Serialize(contentIdentifier); var requestURL = ContentStorageServiceURLProvider.GetURLForGetContentDownloadInfo(ContentStorageServiceURL, ContainerName, contentID, AuthenticationToken); using (var httpClient = GetHttpClient()) { var downloadinfoJson = httpClient.CheckedGetStringAsync(requestURL).Result; return(Serializer.Deserialize <IDownloadInfo>(downloadinfoJson)); } }
private IEnumerable <IContentIdentifier> GetContentIdentifiers(DateTimeOffset afterMoment) { afterMoment = new[] { afterMoment, new DateTimeOffset(1900, 1, 1, 0, 0, 0, TimeSpan.FromTicks(0)) }.Max(); using (var httpClient = GetHttpClient()) { IContentIdentifier lastContentIdentifier = null; while (true) { var afterContentID = (lastContentIdentifier == null) ? null : ContentIdentifierSerializer.Serialize(lastContentIdentifier); var moment = (lastContentIdentifier == null) ? (DateTimeOffset?)afterMoment : null; var requestURL = ContentStorageServiceURLProvider.GetURLForGetContentIdentifiers(ContentStorageServiceURL, ContainerName, moment, null, afterContentID, AuthenticationToken); using (var stream = httpClient.CheckedGetStreamAsync(requestURL).Result) { var contentIdentifiers = stream .ReadAllLines(Encoding.UTF8) .Select(x => ContentIdentifierSerializer.Deserialize(x)) .ToList(); var hasContentIdentifiers = false; foreach (var contentIdentifier in contentIdentifiers) { yield return(contentIdentifier); lastContentIdentifier = contentIdentifier; hasContentIdentifiers = true; } if (!hasContentIdentifiers) { break; } } } } }
private IHttpRequestInfo GetUrlContentUploadInfo(IContentIdentifier contentIdentifier, IDownloadInfo downloadInfo) { var contentID = ContentIdentifierSerializer.Serialize(contentIdentifier); var urlForGetUrlContentUploadInfo = ContentStorageServiceURLProvider.GetURLForGetUrlContentUploadInfo( ContentStorageServiceURL, ContainerName, contentID, downloadInfo.Size, AuthenticationToken); using (var httpClient = GetHttpClient()) { var headers = new[] { new KeyValuePair <string, string>("ContentUrl", downloadInfo.Url), new KeyValuePair <string, string>("ContentStorageServiceUrl", ContentStorageServiceURL) }; using (var response = httpClient.GetAsync(urlForGetUrlContentUploadInfo, headers: headers).Result) { if (response.IsSuccessStatusCode) { var stringResult = response.Content.ReadAsStringAsync().Result; return(Serializer.Deserialize <IHttpRequestInfo>(stringResult)); } else if (response.StatusCode == HttpStatusCode.NotFound) { return(null); } else { response.CheckSuccessAsync().Wait(); return(null); } } } }