Пример #1
0
        public IHttpRequestInfo GetUrlContentUploadInfo(string contentUrl, string contentStorageServiceUrl, string containerName, string contentID, long size, string authenticationToken)
        {
            var uploaderServiceUrl = _configurationSettings.GetAppSetting(UploaderServiceUrlSettingName);

            if (string.IsNullOrEmpty(uploaderServiceUrl))
            {
                return(null);
            }

            var uploaderAwsApiGatewayKey = _configurationSettings.GetAppSetting(UploaderAwsApiGatewayKeySettingName);

            var uploadMethodUrl = uploaderServiceUrl.TrimEnd('/') + "/upload";

            var headers =
                new[] {
                new KeyValuePair <string, string>("Uploader-ContentUrl", contentUrl),
                new KeyValuePair <string, string>("Uploader-ContentStorageServiceUrl", contentStorageServiceUrl),
                new KeyValuePair <string, string>("Uploader-ContainerName", containerName),
                new KeyValuePair <string, string>("Uploader-ContentID", contentID),
                new KeyValuePair <string, string>("Uploader-Size", size.ToString()),
                new KeyValuePair <string, string>("Uploader-AuthenticationToken", authenticationToken),
                new KeyValuePair <string, string>("x-api-key", uploaderAwsApiGatewayKey)
            };

            return(_httpRequestInfoFactory(uploadMethodUrl, "POST", headers));
        }
        public string GetURL(string containerName)
        {
            if (string.IsNullOrEmpty(containerName))
            {
                return(null);
            }

            var containerNameParts = containerName.Split('@');

            if (containerNameParts.Count() == 2)
            {
                return(containerNameParts[1]);
            }

            var locatorURLs = _configurationSettings.GetAppSetting(ContentStorageLocatorSettingName);

            if (string.IsNullOrEmpty(locatorURLs))
            {
                throw new UserException(string.Format("App setting not found: {0}", ContentStorageLocatorSettingName));
            }

            locatorURLs = locatorURLs.Replace("{ContainerName}", containerName);

            using (var httpClient = new System.Net.Http.HttpClient())
            {
                var errorMsg = string.Empty;

                var RetryCount = 2;
                for (var i = 0; i < RetryCount; i++)
                {
                    foreach (var url in locatorURLs.Split(';'))
                    {
                        try
                        {
                            return(httpClient.GetStringAsync(url).Result);
                        }
                        catch (AggregateException e)
                        {
                            if (string.IsNullOrEmpty(errorMsg))
                            {
                                errorMsg = string.Join("\n", e.Flatten().InnerExceptions.Select(x => x.Message));
                            }
                        }
                        catch (Exception e)
                        {
                            if (string.IsNullOrEmpty(errorMsg))
                            {
                                errorMsg = e.Message;
                            }
                        }
                    }

                    Task.Delay(3000).Wait();
                }

                throw new UserException(string.Format("Could not obtain content storage service for container \"{0}\":\r\n{1}", containerName, errorMsg));
            }
        }
Пример #3
0
        private string GetTransferServiceBaseURL()
        {
            var transferServiceURL = _configurationSettings.GetAppSetting(TransferServiceURLSettingName);

            if (string.IsNullOrEmpty(transferServiceURL))
            {
                throw new UserException("Transfer service address not configured");
            }

            return(transferServiceURL.TrimEnd('/'));
        }
 private int GetExpiryMinutes()
 {
     return(int.Parse(_configurationSettings.GetAppSetting(SCompleteMomentExpiryMinutesAppSetting)));
 }
Пример #5
0
 public string GetRoot()
 {
     return(_configurationSettings.GetAppSetting(StorageRootAppSettingName));
 }