コード例 #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        internal UrlParts GetUrlParts()
        {
            UrlParts urlParts = new UrlParts
            {
                ApiVersion = ClientSecrets.ApiVersion,
                BaseUrl = ClientSecrets.BaseUrl,
                CustomerAlias = ClientSecrets.CustomerAlias,
                DatabaseAlias = ClientSecrets.DatabaseAlias,
                OAuthTokenEndPoint = ClientSecrets.OAuthTokenEndPoint
            };

            return urlParts;
        }
コード例 #2
0
        private static string CreateUrl(UrlParts urlParts, string virtualPath, string queryString, string fields = "", bool expand = false)
        {
            string baseUrl = urlParts.BaseUrl;

            if (!baseUrl.EndsWith("/"))
            {
                baseUrl += "/";
            }

            string customerDatabaseUrl = string.Format("{0}api/v{1}/{2}/{3}/", baseUrl, urlParts.ApiVersion, urlParts.CustomerAlias, urlParts.DatabaseAlias);

            string url;

            virtualPath = virtualPath.Replace(@"\", "/");
            if (virtualPath.StartsWith("~/"))
            {
                url = customerDatabaseUrl + virtualPath.Substring(2);
            }
            else if (virtualPath.StartsWith("/"))
            {
                url = customerDatabaseUrl + customerDatabaseUrl.Substring(1);
            }
            else
            {
                url = customerDatabaseUrl + virtualPath;
            }


            if (queryString == null)
            {
                //Make sure that we aren't dealing with a null item
                queryString = string.Empty;
            }


            if (!String.IsNullOrEmpty(fields))
            {
                if (queryString.Length > 0)
                {
                    queryString += "&";
                }


                queryString += "f=" + fields;
            }


            if (expand)
            {


                if (queryString.Length > 0)
                {
                    queryString += "&";
                }


                queryString += "expand=data";
            }


            if (url.Contains("?"))
            {
                //the url has a query string in it, split out the query string
                var parts = url.Split("?".ToCharArray());
                if (parts.Length > 1)
                {
                    //Parts[0] = the base url
                    //Parts[1] = the query string
                    url = parts[0];


                    if (queryString.Length > 0)
                    {
                        //A query string already exists, append on to it
                        queryString += "&" + parts[1];
                    }
                    else
                    {
                        //no query string yet, replace it
                        queryString = parts[1];
                    }
                }


            }

            //Remove the leading question mark
            if (!String.IsNullOrEmpty(queryString) && queryString.StartsWith("?"))
            {
                queryString = queryString.Substring(1);
            }

            StringBuilder sbQuery = new StringBuilder();

            if (GlobalConfiguration.SuppressResponseCodes)
            {
                sbQuery.Append("suppress_response_codes=true&");
            }

            if (!string.IsNullOrEmpty(queryString))
            {
                sbQuery.Append(queryString);
            }

            if (sbQuery.Length > 0)
            {
                sbQuery.Insert(0, "?");
            }

            url = url + sbQuery;

            return url;
        }
コード例 #3
0
        private static string CreateUrl(UrlParts urlParts, string virtualPath, string queryString, string fields = "", bool expand = false)
        {
            string baseUrl = urlParts.BaseUrl;

            if (!baseUrl.EndsWith("/"))
            {
                baseUrl += "/";
            }

            string customerDatabaseUrl = string.Format("{0}api/v{1}/{2}/{3}/", baseUrl, urlParts.ApiVersion, urlParts.CustomerAlias, urlParts.DatabaseAlias);

            string url;

            virtualPath = virtualPath.Replace(@"\", "/");
            if (virtualPath.StartsWith("~/"))
            {
                url = customerDatabaseUrl + virtualPath.Substring(2);
            }
            else if (virtualPath.StartsWith("/"))
            {
                url = customerDatabaseUrl + customerDatabaseUrl.Substring(1);
            }
            else
            {
                url = customerDatabaseUrl + virtualPath;
            }


            if (queryString == null)
            {
                //Make sure that we aren't dealing with a null item
                queryString = string.Empty;
            }


            if (!String.IsNullOrEmpty(fields))
            {
                if (queryString.Length > 0)
                {
                    queryString += "&";
                }


                queryString += "f=" + fields;
            }


            if (expand)
            {
                if (queryString.Length > 0)
                {
                    queryString += "&";
                }


                queryString += "expand=data";
            }


            if (url.Contains("?"))
            {
                //the url has a query string in it, split out the query string
                var parts = url.Split("?".ToCharArray());
                if (parts.Length > 1)
                {
                    //Parts[0] = the base url
                    //Parts[1] = the query string
                    url = parts[0];


                    if (queryString.Length > 0)
                    {
                        //A query string already exists, append on to it
                        queryString += "&" + parts[1];
                    }
                    else
                    {
                        //no query string yet, replace it
                        queryString = parts[1];
                    }
                }
            }

            //Remove the leading question mark
            if (!String.IsNullOrEmpty(queryString) && queryString.StartsWith("?"))
            {
                queryString = queryString.Substring(1);
            }

            StringBuilder sbQuery = new StringBuilder();

            if (GlobalConfiguration.SuppressResponseCodes)
            {
                sbQuery.Append("suppress_response_codes=true&");
            }

            if (!string.IsNullOrEmpty(queryString))
            {
                sbQuery.Append(queryString);
            }

            if (sbQuery.Length > 0)
            {
                sbQuery.Insert(0, "?");
            }

            url = url + sbQuery;

            return(url);
        }
コード例 #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="virtualPath"></param>
        /// <param name="queryString"></param>
        /// <param name="options"></param>
        /// <param name="urlParts"></param>
        /// <param name="apiTokens"></param>
        /// <param name="clientSecrets"></param>
        /// <param name="virtualPathArgs"></param>
        /// <returns></returns>
        public static Stream GetStream(string virtualPath, string queryString, RequestOptions options, UrlParts urlParts, Tokens apiTokens, ClientSecrets clientSecrets, params object[] virtualPathArgs)
        {
            if (options == null)
            {
                options = new RequestOptions();
            }

            options.PrepForRequest();

            CleanupVirtualPathArgs(virtualPathArgs);

            string url = CreateUrl(urlParts, string.Format(virtualPath, virtualPathArgs), options.GetQueryString(queryString), options.Fields, options.Expand);

            WebRequest httpWebRequest = WebRequest.Create(url);
            httpWebRequest.Method = "Get";

            httpWebRequest.Headers.Add("Authorization", "Bearer " + apiTokens.AccessToken);

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            Stream stream = httpResponse.GetResponseStream();

            return stream;
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="virtualPath"></param>
        /// <param name="queryString"></param>
        /// <param name="options"></param>
        /// <param name="urlParts"></param>
        /// <param name="apiTokens"></param>
        /// <param name="clientSecrets"></param>
        /// <param name="virtualPathArgs"></param>
        /// <returns></returns>
        public static Stream GetStream(string virtualPath, string queryString, RequestOptions options, UrlParts urlParts, Tokens apiTokens, ClientSecrets clientSecrets, params object[] virtualPathArgs)
        {
            if (options == null)
            {
                options = new RequestOptions();
            }

            options.PrepForRequest();

            CleanupVirtualPathArgs(virtualPathArgs);

            string url = CreateUrl(urlParts, string.Format(virtualPath, virtualPathArgs), options.GetQueryString(queryString), options.Fields, options.Expand);

            WebRequest httpWebRequest = WebRequest.Create(url);

            httpWebRequest.Method = "Get";

            httpWebRequest.Headers.Add("Authorization", "Bearer " + apiTokens.AccessToken);

            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            Stream stream = httpResponse.GetResponseStream();

            return(stream);
        }