Esempio n. 1
0
        /// <summary>
        /// Given the method name and the parameters and configuration associated
        /// with this object, generate the full URL for the web service invocation.
        /// </summary>
        /// <param name="methodName">Method name for the HOSTED Engine api call</param>
        /// <returns>Fully qualified URL to be used for invocation</returns>
        public string ConstructUrl(string methodName)
        {
            // The local parameter map just contains method methodParameters.  We'll
            // now create a complete parameter map that contains the web-service
            // params as well the actual method params.
            IDictionary <string, object> parameterMap = new Dictionary <string, object>();

            parameterMap.Add("method", methodName);
            parameterMap.Add("appid", configuration.AppId);
            parameterMap.Add("origin", configuration.Origin);
            parameterMap.Add("ts", DateTime.UtcNow.ToString("yyyyMMddHHmmss"));
            parameterMap.Add("applib", "net");
            foreach (string key in methodParameters.Keys)
            {
                parameterMap.Add(key, methodParameters[key]);
            }

            // Construct the url, concatonate all parameters as query string parameters
            string url = this.engineServiceUrl + "/api";
            int    cnt = 0;

            foreach (string key in parameterMap.Keys)
            {
                // Create a query string with URL-encoded values
                url += (cnt++ == 0 ? "?" : "&") + key + "=" + HttpUtility.UrlEncode(parameterMap[key].ToString());
            }
            url += "&sig=" + RequestSigner.GetSignatureForRequest(configuration.SecurityKey, parameterMap);

            if (url.Length > 2000)
            {
                throw new ApplicationException("URL > 2000 bytes");
            }

            return(url);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the url to view/edit the package properties for this course.  Typically
        /// used within an IFRAME
        /// </summary>
        /// <param name="courseId">Unique Identifier for the course</param>
        /// <returns>Signed URL to package property editor</returns>
        /// <param name="notificationFrameUrl">Tells the property editor to render a sub-iframe
        /// with the provided url as the src.  This can be used to simulate an "onload"
        /// by using a notificationFrameUrl that's the same domain as the host system and
        /// calling parent.parent.method()</param>
        /// <param name="useLatestEditor">Whether or not to use the latest version of the
        /// properties editor. We recommend setting this to true, as the new editor supports
        /// more properties and is used directly on SCORM Cloud's site. Defaults to false
        /// for backwards compatibility.</param>
        public string GetPropertyEditorUrl(string courseId, string stylesheetUrl, string notificationFrameUrl, bool useLatestEditor = false)
        {
            // The local parameter map just contains method methodParameters.  We'll
            // now create a complete parameter map that contains the web-service
            // params as well the actual method params.
            IDictionary <string, object> parameterMap = new Dictionary <string, object>();

            parameterMap.Add("action", "properties.view");
            parameterMap.Add("package", "ApiCourseId|" + courseId);
            parameterMap.Add("appid", configuration.AppId);
            parameterMap.Add("ts", DateTime.UtcNow.ToString("yyyyMMddHHmmss"));

            if (!String.IsNullOrEmpty(notificationFrameUrl))
            {
                parameterMap.Add("notificationframesrc", notificationFrameUrl);
            }

            if (!String.IsNullOrEmpty(stylesheetUrl))
            {
                parameterMap.Add("stylesheet", stylesheetUrl);
            }

            if (useLatestEditor)
            {
                parameterMap.Add("editor", "latest");
            }

            // Construct the url, concatonate all parameters as query string parameters
            string url = configuration.ScormEngineServiceUrl + "/widget";
            int    cnt = 0;

            foreach (string key in parameterMap.Keys)
            {
                // Create a query string with URL-encoded values
                url += (cnt++ == 0 ? "?" : "&") + key + "=" + HttpUtility.UrlEncode(parameterMap[key].ToString());
            }
            url += "&sig=" + RequestSigner.GetSignatureForRequest(configuration.SecurityKey, parameterMap);

            if (url.Length > 2000)
            {
                throw new ApplicationException("URL > 2000 bytes");
            }

            return(url);
        }