public IMediaResourceDownloadRequest FillReadMediaItemGaps(IMediaResourceDownloadRequest userRequest)
    {
      IItemSource mergedSource = this.ItemSourceMerger.FillItemSourceGaps(userRequest.ItemSource);
      ISessionConfig mergedSessionConfig = this.SessionConfigMerger.FillSessionConfigGaps(userRequest.SessionSettings);

      return new MediaResourceDownloadParameters(mergedSessionConfig, mergedSource, userRequest.DownloadOptions, userRequest.MediaPath);
    }
Exemplo n.º 2
0
        public IMediaResourceDownloadRequest FillReadMediaItemGaps(IMediaResourceDownloadRequest userRequest)
        {
            IItemSource    mergedSource        = this.ItemSourceMerger.FillItemSourceGaps(userRequest.ItemSource);
            ISessionConfig mergedSessionConfig = this.SessionConfigMerger.FillSessionConfigGaps(userRequest.SessionSettings);

            return(new MediaResourceDownloadParameters(mergedSessionConfig, mergedSource, userRequest.DownloadOptions, userRequest.MediaPath));
        }
        private async Task <Stream> DownloadHashedMediaResourceAsync(IMediaResourceDownloadRequest request, CancellationToken cancelToken = default(CancellationToken))
        {
            var cryptor = await this.GetCredentialsCryptorAsync(cancelToken);

            MediaItemUrlBuilder urlBuilder = new MediaItemUrlBuilder(
                this.restGrammar,
                this.webApiGrammar,
                this.sessionConfig,
                this.mediaSettings,
                request.ItemSource);

            var    hashUrlGetterFlow = new GetMediaContentHashTask(urlBuilder, this.httpClient, cryptor);
            string hashedMediaUrl    = await RestApiCallFlow.LoadRequestFromNetworkFlow(request, hashUrlGetterFlow, cancelToken);

            try
            {
                Stream result = await this.httpClient.GetStreamAsync(hashedMediaUrl);

                return(result);
            }
            catch (Exception ex)
            {
                throw new LoadDataFromNetworkException(TaskFlowErrorMessages.NETWORK_EXCEPTION_MESSAGE, ex);
            }
        }
        private async Task <Stream> DownloadPlainMediaResourceAsync(IMediaResourceDownloadRequest request, CancellationToken cancelToken = default(CancellationToken))
        {
            MediaItemUrlBuilder urlBuilder = new MediaItemUrlBuilder(
                this.restGrammar,
                this.webApiGrammar,
                this.sessionConfig,
                this.mediaSettings,
                request.ItemSource);

            var taskFlow = new GetResourceTask(urlBuilder, this.httpClient);

            return(await RestApiCallFlow.LoadResourceFromNetworkFlow(request, taskFlow, cancelToken));
        }
        public async Task <Stream> DownloadMediaResourceAsync(IMediaResourceDownloadRequest request, CancellationToken cancelToken = default(CancellationToken))
        {
            IMediaResourceDownloadRequest requestCopy          = request.DeepCopyReadMediaRequest();
            IMediaResourceDownloadRequest autocompletedRequest = this.requestMerger.FillReadMediaItemGaps(requestCopy);
            DownloadStrategy downloadStrategyFromUser          = this.mediaSettings.MediaDownloadStrategy;

            if (DownloadStrategy.Plain == downloadStrategyFromUser)
            {
                return(await this.DownloadPlainMediaResourceAsync(autocompletedRequest, cancelToken));
            }
            else if (DownloadStrategy.Hashed == downloadStrategyFromUser)
            {
                return(await this.DownloadHashedMediaResourceAsync(autocompletedRequest, cancelToken));
            }
            else
            {
                throw new ArgumentException("Unexpected media download strategy specified");
            }
        }
        public async Task <Stream> DownloadMediaResourceAsync(IMediaResourceDownloadRequest request, CancellationToken cancelToken = default(CancellationToken))
        {
            IMediaResourceDownloadRequest requestCopy = request.DeepCopyReadMediaRequest();

            await this.GetPublicKeyAsync(cancelToken);

            IMediaResourceDownloadRequest autocompletedRequest = this.requestMerger.FillReadMediaItemGaps(requestCopy);

            MediaItemUrlBuilder urlBuilder = new MediaItemUrlBuilder(
                this.restGrammar,
                this.sscGrammar,
                this.sessionConfig,
                this.mediaSettings,
                autocompletedRequest.ItemSource);

            var taskFlow = new GetResourceTask(urlBuilder, this.httpClient);

            return(await RestApiCallFlow.LoadResourceFromNetworkFlow(autocompletedRequest, taskFlow, cancelToken));
        }
Exemplo n.º 7
0
        public async Task <Byte[]> GetMediaByUrl(string mediaUrl)
        {
            try {
                mediaUrl = CleanUpMediaUrlByReplacingWeirdTildeSignWithCorrect(mediaUrl);

                using (ISitecoreWebApiSession session = await SitecoreSession)
                {
                    IMediaResourceDownloadRequest request = ItemWebApiRequestBuilder.DownloadResourceRequestWithMediaPath(mediaUrl)
                                                            .Language("en")
                                                            .Build();

                    byte[] data = null;

                    using (Stream response = await session.DownloadMediaResourceAsync(request))

                        using (MemoryStream responseInMemory = new MemoryStream())
                        {
                            await response.CopyToAsync(responseInMemory);

                            data = responseInMemory.ToArray();

                            return(data);
                        }
                }
            }
            catch (SitecoreMobileSdkException ex)
            {
                this._loggingService.Log("Error in GetMediaByUrl,  url {0} . Error: {1}", mediaUrl, ex.Message);
                throw ex;
            }
            catch (Exception ex)
            {
                this._loggingService.Log("Error in GetMediaByUrl,  url {0} . Error: {1}", mediaUrl, ex.Message);
                throw ex;
            }
        }
    private async Task<Stream> DownloadHashedMediaResourceAsync(IMediaResourceDownloadRequest request, CancellationToken cancelToken = default(CancellationToken))
    {
      var cryptor = await this.GetCredentialsCryptorAsync(cancelToken);

      MediaItemUrlBuilder urlBuilder = new MediaItemUrlBuilder(
        this.restGrammar,
        this.webApiGrammar,
        this.sessionConfig,
        this.mediaSettings,
        request.ItemSource);

      var hashUrlGetterFlow = new GetMediaContentHashTask(urlBuilder, this.httpClient, cryptor);
      string hashedMediaUrl = await RestApiCallFlow.LoadRequestFromNetworkFlow(request, hashUrlGetterFlow, cancelToken);

      try
      {
        Stream result = await this.httpClient.GetStreamAsync(hashedMediaUrl);
        return result;
      }
      catch (Exception ex)
      {
        throw new LoadDataFromNetworkException(TaskFlowErrorMessages.NETWORK_EXCEPTION_MESSAGE, ex);
      }
    }
    private async Task<Stream> DownloadPlainMediaResourceAsync(IMediaResourceDownloadRequest request, CancellationToken cancelToken = default(CancellationToken))
    {
      MediaItemUrlBuilder urlBuilder = new MediaItemUrlBuilder(
        this.restGrammar,
        this.webApiGrammar,
        this.sessionConfig,
        this.mediaSettings,
        request.ItemSource);

      var taskFlow = new GetResourceTask(urlBuilder, this.httpClient);
      return await RestApiCallFlow.LoadResourceFromNetworkFlow(request, taskFlow, cancelToken);
    }
Exemplo n.º 10
0
    public async Task<Stream> DownloadMediaResourceAsync(IMediaResourceDownloadRequest request, CancellationToken cancelToken = default(CancellationToken))
    {
      IMediaResourceDownloadRequest requestCopy = request.DeepCopyReadMediaRequest();
      IMediaResourceDownloadRequest autocompletedRequest = this.requestMerger.FillReadMediaItemGaps(requestCopy);
      DownloadStrategy downloadStrategyFromUser = this.mediaSettings.MediaDownloadStrategy;

      if (DownloadStrategy.Plain == downloadStrategyFromUser)
      {
        return await this.DownloadPlainMediaResourceAsync(autocompletedRequest, cancelToken);
      }
      else if (DownloadStrategy.Hashed == downloadStrategyFromUser)
      {
        return await this.DownloadHashedMediaResourceAsync(autocompletedRequest, cancelToken);
      }
      else
      {
        throw new ArgumentException("Unexpected media download strategy specified");
      }
    }
Exemplo n.º 11
0
 public async Task <Stream> DownloadMediaResourceAsync(IMediaResourceDownloadRequest request, CancellationToken cancelToken = default(CancellationToken))
 {
     return(await this.InvokeNoThrow(this.workerSession.DownloadMediaResourceAsync(request, cancelToken)));
 }