public static void CheckMediaOptionsOrThrow(IDownloadMediaOptions options, string source) { if (!MediaOptionsValidator.IsValidMediaOptions(options)) { throw new ArgumentException(source + " : is not valid"); } }
private string AppendUrlStringWithDownloadOptions(string path, IDownloadMediaOptions options) { string paramsString = this.SerializeOptions(options); if (this.itemSource.Database != null) { paramsString = this.AddOptionValueToPath(paramsString, MediaItemUrlBuilder.DATABASE_KEY, this.itemSource.Database); } if (this.itemSource.Language != null) { paramsString = this.AddOptionValueToPath(paramsString, MediaItemUrlBuilder.LANGUAGE_KEY, this.itemSource.Language); } if (null != this.itemSource.VersionNumber) { string strVersionNumber = this.itemSource.VersionNumber.Value.ToString(CultureInfo.InvariantCulture); paramsString = this.AddOptionValueToPath(paramsString, MediaItemUrlBuilder.VERSION_KEY, strVersionNumber); } if (!String.IsNullOrEmpty(paramsString)) { paramsString = paramsString.Remove(paramsString.Length - this.restGrammar.FieldSeparator.Length); path += this.restGrammar.HostAndArgsSeparator; path += paramsString; } return(path); }
// https://test.host/~/media/1.png.ashx?w=640&h=480 public string BuildUrlStringForPath(string path, IDownloadMediaOptions options) { MediaPathValidator mediaPathValidator = new MediaPathValidator(this.mediaSettings); mediaPathValidator.ValidateMediaPath(path, this.GetType().Name + ".Path"); string relativePath = path; string result = SessionConfigValidator.AutocompleteInstanceUrlForcingHttps(this.sessionConfig.InstanceUrl); string lowerCasePathForComparisonNeeds = path.ToLowerInvariant(); string lowerCaseMediaHook = this.mediaSettings.MediaPrefix.ToLowerInvariant(); bool isMediaHookAvailable = lowerCasePathForComparisonNeeds.Contains(lowerCaseMediaHook); bool isExtensionAvailable = MediaPathValidator.IsItemPathHasExtension(path); string extensionWithDotPrefix = DOT_SEPARATOR + this.mediaSettings.DefaultMediaResourceExtension.ToLowerInvariant(); if (isMediaHookAvailable) { result = result + this.restGrammar.PathComponentSeparator + Uri.EscapeUriString(relativePath); if (!isExtensionAvailable) { result = result + extensionWithDotPrefix; } } else { result = result + this.restGrammar.PathComponentSeparator + lowerCaseMediaHook; string mediaLibraryRoot = this.mediaSettings.MediaLibraryRoot.ToLowerInvariant(); int rootStartIndex = lowerCasePathForComparisonNeeds.IndexOf(mediaLibraryRoot); bool isMediaRootAvailable = (rootStartIndex >= 0); if (isMediaRootAvailable) { relativePath = path.Remove(rootStartIndex, this.mediaSettings.MediaLibraryRoot.Length); } bool isInvalidRelativePath = string.IsNullOrEmpty(relativePath); if (isInvalidRelativePath) { throw new ArgumentException("ResourceUrlBuilder.BuildUrlStringForPath invalid path"); } relativePath = Uri.EscapeUriString(relativePath); result = result + relativePath + extensionWithDotPrefix; } result = this.AppendUrlStringWithDownloadOptions(result, options); return(result.ToLowerInvariant()); }
// https://test.host/~/media/1.png.ashx?w=640&h=480 public string BuildUrlStringForPath(string path, IDownloadMediaOptions options) { MediaPathValidator mediaPathValidator = new MediaPathValidator(this.mediaSettings); mediaPathValidator.ValidateMediaPath(path, this.GetType().Name + ".Path"); string relativePath = path; string result = SessionConfigValidator.AutocompleteInstanceUrl(this.sessionConfig.InstanceUrl); string lowerCasePathForComparisonNeeds = path.ToLowerInvariant(); string lowerCaseMediaHook = this.mediaSettings.MediaPrefix.ToLowerInvariant(); bool isMediaHookAvailable = lowerCasePathForComparisonNeeds.Contains(lowerCaseMediaHook); bool isExtensionAvailable = MediaPathValidator.IsItemPathHasExtension(path); string extensionWithDotPrefix = DOT_SEPARATOR + this.mediaSettings.DefaultMediaResourceExtension.ToLowerInvariant(); if (isMediaHookAvailable) { result = result + this.restGrammar.PathComponentSeparator + Uri.EscapeUriString(relativePath); if (!isExtensionAvailable) { result = result + extensionWithDotPrefix; } } else { result = result + this.restGrammar.PathComponentSeparator + lowerCaseMediaHook; string mediaLibraryRoot = this.mediaSettings.MediaLibraryRoot.ToLowerInvariant(); int rootStartIndex = lowerCasePathForComparisonNeeds.IndexOf(mediaLibraryRoot); bool isMediaRootAvailable = (rootStartIndex >= 0); if (isMediaRootAvailable) { relativePath = path.Remove(rootStartIndex, this.mediaSettings.MediaLibraryRoot.Length); } bool isInvalidRelativePath = string.IsNullOrEmpty(relativePath); if (isInvalidRelativePath) { throw new ArgumentException("ResourceUrlBuilder.BuildUrlStringForPath invalid path"); } relativePath = Uri.EscapeUriString(relativePath); result = result + relativePath + extensionWithDotPrefix; } result = this.AppendUrlStringWithDownloadOptions(result, options); return result.ToLowerInvariant(); }
private async void DownloadImage(string itemPath, string widthStr, string heightStr) { if (string.IsNullOrEmpty(itemPath)) { DialogHelper.ShowSimpleDialog(this, Resource.String.text_error, Resource.String.text_empty_path); return; } try { IMediaOptionsBuilder builder = new MediaOptionsBuilder().Set; if (!string.IsNullOrEmpty(widthStr)) { var width = Int32.Parse(widthStr); builder.Width(width); } if (!string.IsNullOrEmpty(heightStr)) { var height = Int32.Parse(heightStr); builder.Height(height); } var requestBuilder = ItemWebApiRequestBuilder.DownloadResourceRequestWithMediaPath(itemPath); IDownloadMediaOptions options = builder.Build(); if (!options.IsEmpty) { requestBuilder.DownloadOptions(options); } this.SetProgressBarIndeterminateVisibility(true); using (var session = Prefs.From(this).Session) { var response = await session.DownloadMediaResourceAsync(requestBuilder.Build()); this.SetProgressBarIndeterminateVisibility(false); using (var imageBitmap = await BitmapFactory.DecodeStreamAsync(response)) { this.targetImageView.SetImageBitmap(imageBitmap); } } } catch (Exception exception) { this.SetProgressBarIndeterminateVisibility(false); var title = this.GetString(Resource.String.text_item_received); DialogHelper.ShowSimpleDialog(this, title, exception.Message); } }
public MediaResourceDownloadParameters ( ISessionConfig sessionSettings, IItemSource itemSource, IDownloadMediaOptions downloadOptions, string mediaPath ) { this.SessionSettings = sessionSettings; this.ItemSource = itemSource; this.MediaPath = mediaPath; this.DownloadOptions = downloadOptions; }
public string BuildUrlToRequestHashForPath(string path, IDownloadMediaOptions options) { string originalUrl = this.BuildUrlStringForPath(path, options); string encodedOriginalUrl = UrlBuilderUtils.EscapeDataString(originalUrl); var actionBuilder = new SSCActionBuilder(this.restGrammar, this.sscGrammar); string result = actionBuilder.GetHashedMediaUrlAction(this.sessionConfig); result = result + this.restGrammar.HostAndArgsSeparator + this.sscGrammar.UrlForHashingParameterName + this.restGrammar.KeyValuePairSeparator + encodedOriginalUrl; return(result); }
public static bool IsValidMediaOptions(IDownloadMediaOptions options) { if (null == options) { return(false); } if (options.IsEmpty) { return(false); } return(true); }
public static bool IsValidMediaOptions(IDownloadMediaOptions options) { if (null == options) { return false; } if (options.IsEmpty) { return false; } return true; }
private string SerializeOptions(IDownloadMediaOptions options) { bool isValidMediaOptions = MediaOptionsValidator.IsValidMediaOptions(options); if (!isValidMediaOptions) { return(string.Empty); } Dictionary <string, string> optionsDictionary = options.OptionsDictionary; string paramsString = string.Empty; foreach (var pair in optionsDictionary) { paramsString = this.AddOptionValueToPath(paramsString, pair.Key, pair.Value); } return(paramsString); }
public virtual IMediaResourceDownloadRequest DeepCopyReadMediaRequest() { ISessionConfig connection = null; IItemSource itemSource = null; IDownloadMediaOptions resizingOptions = null; if (null != this.SessionSettings) { connection = this.SessionSettings.SessionConfigShallowCopy(); } if (null != this.ItemSource) { itemSource = this.ItemSource.ShallowCopy(); } if (null != this.DownloadOptions) { resizingOptions = this.DownloadOptions.DeepCopyMediaDownloadOptions(); } return(new MediaResourceDownloadParameters(connection, itemSource, resizingOptions, this.MediaPath)); }
private string AppendUrlStringWithDownloadOptions(string path, IDownloadMediaOptions options) { string paramsString = this.SerializeOptions(options); if (this.itemSource.Database != null) { paramsString = this.AddOptionValueToPath(paramsString, MediaItemUrlBuilder.DATABASE_KEY, this.itemSource.Database); } if (this.itemSource.Language != null) { paramsString = this.AddOptionValueToPath(paramsString, MediaItemUrlBuilder.LANGUAGE_KEY, this.itemSource.Language); } if (null != this.itemSource.VersionNumber) { string strVersionNumber = this.itemSource.VersionNumber.Value.ToString(CultureInfo.InvariantCulture); paramsString = this.AddOptionValueToPath(paramsString, MediaItemUrlBuilder.VERSION_KEY, strVersionNumber); } if (!String.IsNullOrEmpty(paramsString)) { paramsString = paramsString.Remove(paramsString.Length - this.restGrammar.FieldSeparator.Length); path += this.restGrammar.HostAndArgsSeparator; path += paramsString; } return path; }
private string SerializeOptions(IDownloadMediaOptions options) { bool isValidMediaOptions = MediaOptionsValidator.IsValidMediaOptions(options); if (!isValidMediaOptions) { return string.Empty; } Dictionary<string, string> optionsDictionary = options.OptionsDictionary; string paramsString = string.Empty; foreach (var pair in optionsDictionary) { paramsString = this.AddOptionValueToPath(paramsString, pair.Key, pair.Value); } return paramsString; }
public string BuildUrlToRequestHashForPath(string path, IDownloadMediaOptions options) { string originalUrl = this.BuildUrlStringForPath(path, options); string encodedOriginalUrl = UrlBuilderUtils.EscapeDataString(originalUrl); var actionBuilder = new WebApiActionBuilder(this.restGrammar, this.webApiGrammar); string result = actionBuilder.GetHashedMediaUrlAction(this.sessionConfig); result = result + this.restGrammar.HostAndArgsSeparator + this.webApiGrammar.UrlForHashingParameterName + this.restGrammar.KeyValuePairSeparator + encodedOriginalUrl; return result; }
public IGetMediaItemRequestParametersBuilder <IMediaResourceDownloadRequest> DownloadOptions(IDownloadMediaOptions downloadMediaOptions) { BaseValidator.CheckForTwiceSetAndThrow(this.downloadMediaOptions, this.GetType().Name + ".DownloadMediaOptions"); BaseValidator.CheckMediaOptionsOrThrow(downloadMediaOptions, this.GetType().Name + ".DownloadMediaOptions"); this.downloadMediaOptions = downloadMediaOptions.DeepCopyMediaDownloadOptions(); return(this); }