public GetMediaContentHashTask(
     MediaItemUrlBuilder urlBuilder,
     HttpClient httpClient)
 {
     this.httpClient = httpClient;
     this.urlBuilder = urlBuilder;
 }
        public GetResourceTask(MediaItemUrlBuilder urlBuilder, HttpClient httpClient)
        {
            this.urlBuilder = urlBuilder;
            this.httpClient = httpClient;

            this.Validate();
        }
        public void SetUp()
        {
            SessionConfigPOD mockConfig = new SessionConfigPOD();

            mockConfig.InstanceUrl       = "localhost";
            mockConfig.ItemWebApiVersion = "v1";
            mockConfig.Site = null;

            var itemSource = new ItemSourcePOD("master", "fr");

            var mediaSettings = new MutableMediaLibrarySettings();

            this.builder = new MediaItemUrlBuilder(
                RestServiceGrammar.ItemWebApiV2Grammar(),
                WebApiUrlParameters.ItemWebApiV2UrlParameters(),
                mockConfig,
                mediaSettings,
                itemSource);


            SessionConfigPOD mockConfigWithShell = new SessionConfigPOD();

            mockConfigWithShell.InstanceUrl       = "localhost";
            mockConfigWithShell.ItemWebApiVersion = "v1";
            mockConfigWithShell.Site  = "/sitecore/shell";
            this.builderWithShellSite = new MediaItemUrlBuilder(
                RestServiceGrammar.ItemWebApiV2Grammar(),
                WebApiUrlParameters.ItemWebApiV2UrlParameters(),
                mockConfigWithShell,
                mediaSettings,
                itemSource);
        }
        public void TestCustomMediaHook()
        {
            SessionConfigPOD sessionConfig = new SessionConfigPOD();

            sessionConfig.InstanceUrl       = "htTP://CUSTOM.hoST";
            sessionConfig.ItemWebApiVersion = "v1";
            sessionConfig.Site             = "/sitecore/shell";
            sessionConfig.MediaLibraryRoot = "/SiteCore/Other Media Library";
            sessionConfig.DefaultMediaResourceExtension = "ZIP";
            sessionConfig.MediaPrefix = "~/MediaXyZ";

            ISessionConfig        sessionSettings = sessionConfig;
            IMediaLibrarySettings mediaSettings   = sessionConfig;


            ItemSource itemSource = LegacyConstants.DefaultSource();

            this.builder = new MediaItemUrlBuilder(this.restGrammar, this.webApiGrammar, sessionSettings, mediaSettings, itemSource);

            var customBuilder =
                new MediaItemUrlBuilder(
                    this.restGrammar,
                    this.webApiGrammar,
                    sessionSettings,
                    mediaSettings,
                    itemSource);


            string result   = customBuilder.BuildUrlStringForPath("~/mediaXYZ/1.png.ashx", null);
            string expected = "http://custom.host/~/mediaxyz/1.png.ashx?db=web&la=en";

            Assert.AreEqual(expected, result);
        }
        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);
            }
        }
Esempio n. 6
0
 public GetMediaContentHashTask(
     MediaItemUrlBuilder urlBuilder,
     HttpClient httpClient,
     ICredentialsHeadersCryptor credentialsHeadersCryptor)
 {
     this.httpClient = httpClient;
     this.urlBuilder = urlBuilder;
     this.credentialsHeadersCryptor = credentialsHeadersCryptor;
 }
        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));
        }
Esempio n. 8
0
        public void SetUp()
        {
            this.webApiGrammar = SSCUrlParameters.ItemSSCV2UrlParameters();
            this.restGrammar   = RestServiceGrammar.ItemSSCV2Grammar();

            SessionConfigPOD sessionConfig = new SessionConfigPOD();

            sessionConfig.InstanceUrl      = "http://test.host";
            sessionConfig.MediaLibraryRoot = "/sitecore/media library";
            sessionConfig.DefaultMediaResourceExtension = "ashx";
            sessionConfig.MediaPrefix = "~/media";

            ISessionConfig        sessionSettings = sessionConfig;
            IMediaLibrarySettings mediaSettings   = sessionConfig;

            ItemSource itemSource = LegacyConstants.DefaultSource();

            this.builder = new MediaItemUrlBuilder(this.restGrammar, this.webApiGrammar, sessionSettings, mediaSettings, itemSource);
        }
        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));
        }
 public void TearDown()
 {
     this.builder = null;
     this.builderWithShellSite = null;
 }
 public void TearDown()
 {
     this.builder = null;
 }