public virtual string BuildUrlString(IUTSessionConfig config)
        {
            this.ValidateRequest(config);

            string autocompletedInstanceUrl = SessionConfigValidator.AutocompleteInstanceUrlWithHttps(config.InstanceUrl);

            return(autocompletedInstanceUrl.ToLowerInvariant());
        }
        private void Validate()
        {
            BaseValidator.CheckForNullEmptyAndWhiteSpaceOrThrow(this.InstanceUrl, "SessionConfig.InstanceUrl is required");

            if (!SessionConfigValidator.IsValidSchemeOfInstanceUrl(this.InstanceUrl))
            {
                Debug.WriteLine("[WARNING] : SessionConfig - instance URL does not have a scheme");
            }
        }
Пример #3
0
        //    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());
        }
Пример #4
0
        public virtual string BuildUrlString(ISessionConfig request)
        {
            this.ValidateRequest(request);

            string autocompletedInstanceUrl = SessionConfigValidator.AutocompleteInstanceUrlForcingHttps(request.InstanceUrl);

            string result =
                autocompletedInstanceUrl + this.sscGrammar.ItemSSCEndpoint;

            return(result.ToLowerInvariant());
        }
        protected virtual async Task <ScAuthResponse> GetPublicKeyAsync(CancellationToken cancelToken = default(CancellationToken))
        {
            ScAuthResponse response = null;

            if (this.credentials != null)
            {
                string url = SessionConfigValidator.AutocompleteInstanceUrlForcingHttps(this.Config.InstanceUrl);
                IEnumerable <Cookie> prevCookies = this.cookies.GetCookies(new Uri(url)).Cast <Cookie>();
                bool noCookies = true;

                if (prevCookies.Count() > 0)
                {
                    noCookies = this.CookiesExpired(prevCookies);
                }

                if (noCookies)
                {
                    try {
                        var sessionConfigBuilder = new SessionConfigUrlBuilder(this.restGrammar, this.sscGrammar);
                        var taskFlow             = new GetPublicKeyTasks(this.credentials, sessionConfigBuilder, this.sscGrammar, this.httpClient);

                        response = await RestApiCallFlow.LoadRequestFromNetworkFlow(this.sessionConfig, taskFlow, cancelToken);

                        IEnumerable <Cookie> newCookies = this.cookies.GetCookies(new Uri(url)).Cast <Cookie>();
                        Debug.WriteLine(newCookies.ToString());
                    } catch (ObjectDisposedException) {
                        // CancellationToken.ThrowIfCancellationRequested()
                        throw;
                    } catch (OperationCanceledException) {
                        // CancellationToken.ThrowIfCancellationRequested()
                        // and TaskCanceledException
                        throw;
                    } catch (SitecoreMobileSdkException ex) {
                        // throw unwrapped exception as if GetPublicKeyAsync() is an atomic phase
                        throw new RsaHandshakeException("[Sitecore Mobile SDK] ASPXAUTH not received properly", ex.InnerException);
                    } catch (Exception ex) {
                        throw new RsaHandshakeException("[Sitecore Mobile SDK] ASPXAUTH not received properly", ex);
                    }
                }
                else
                {
                    response = new ScAuthResponse("200");
                }
            }

            return(response);
        }
        public virtual string BuildUrlString(ISessionConfig request)
        {
            this.ValidateRequest(request);

            string autocompletedInstanceUrl = SessionConfigValidator.AutocompleteInstanceUrl(request.InstanceUrl);
            string escapedVersion           = UrlBuilderUtils.EscapeDataString(request.ItemWebApiVersion);

            string result =
                autocompletedInstanceUrl;

            result +=
                this.webApiGrammar.ItemWebApiEndpoint +
                escapedVersion;

            if (!string.IsNullOrEmpty(request.Site))
            {
                string escapedSite = UrlBuilderUtils.EscapeDataString(request.Site);
                result +=
                    escapedSite;
            }

            return(result.ToLowerInvariant());
        }