상속: LtiLibrary.Core.Common.JsonLdObject
        /// <summary>
        /// Create an LtiRequestViewModel that contains a ContentItemPlacementResponse.
        /// </summary>
        /// <param name="url">The content_item_return_url from the content-item message.</param>
        /// <param name="consumerKey">The OAuth consumer key to use to sign the request.</param>
        /// <param name="consumerSecret">The OAuth consumer secret to use to sign the request.</param>
        /// <param name="contentItems">The ContentItemPlacementResponse to send.</param>
        /// <param name="data">The data received in the original content-item message.</param>
        /// <param name="ltiErrorLog">Optional plain text error message to be logged by the Tool Consumer.</param>
        /// <param name="ltiErrorMsg">Optional plain text error message to be displayed by the Tool Consumer.</param>
        /// <param name="ltiLog">Optional plain text message to be logged by the Tool Consumer.</param>
        /// <param name="ltiMsg">Optional plain text message to be displayed by the Tool Consumer.</param>
        /// <returns>The LtiRequestViewModel which contains a signed version of the response.</returns>
        public static LtiRequestViewModel CreateContentItemSelectionViewModel(
            string url, string consumerKey, string consumerSecret,
            ContentItemSelectionGraph contentItems, string data,
            string ltiErrorLog, string ltiErrorMsg, string ltiLog, string ltiMsg)
        {
            var ltiRequest = new LtiRequest(LtiConstants.ContentItemSelectionLtiMessageType)
            {
                Url = new Uri(url),
                ConsumerKey = consumerKey,
                ContentItems = contentItems.ToJsonLdString(),
                Data = data,
                LtiErrorLog = ltiErrorLog,
                LtiErrorMsg = ltiErrorMsg,
                LtiLog = ltiLog,
                LtiMsg = ltiMsg
            };

            return ltiRequest.GetViewModel(consumerSecret);
        }
예제 #2
0
        public ActionResult PlaceContentItem(int id)
        {
            var tool = ProviderContext.Tools.Find(id);
            if (tool == null)
            {
                return RedirectToAction("BadRequest", "Error", new { error = "Invalid tool id" });
            }

            var ltiRequest = GetLtiRequestFromClaim();
            if (ltiRequest == null)
            {
                return RedirectToAction("BadRequest", "Error", new { error = "Invalid LTI request" });
            }

            var consumer = ProviderContext.Consumers.SingleOrDefault(c => c.Key.Equals(ltiRequest.ConsumerKey));
            if (consumer == null)
            {
                return RedirectToAction("BadRequest", "Error", new { error = "Invalid consumer" });
            }

            // Prepare the custom parameters this TP would like on each link.
            var custom = new Dictionary<string, string>();
            // The next two custom parameters use well-known custom parameter substitution variables.
            custom.Add("username", "$User.username"); // Used by this TP when pairing a new user
            custom.Add("tc_profile_url", "$ToolConsumerProfile.url"); // Used by this TP to determine TC capabilities

            // Determine the best PresentationDocumentTarget from the list of targets acceptable
            // to the TC assuming the TC sent the list of acceptable targets in priority order
            var presentationDocumentTarget = DocumentTarget.iframe;
            var acceptablePresentationDocumentTargets =
                ParseDocumentTargets(ltiRequest.AcceptPresentationDocumentTargets);
            if (acceptablePresentationDocumentTargets.Count > 0)
            {
                if (!acceptablePresentationDocumentTargets.Contains(presentationDocumentTarget))
                {
                    presentationDocumentTarget = acceptablePresentationDocumentTargets[0];
                }
            }

            // Calculate the full qualified URL for the tool.
            var toolUrl = UrlHelper.GenerateUrl("Default", "View", "Tool", new RouteValueDictionary(new { id }), 
                RouteTable.Routes, Request.RequestContext, false);
            Uri toolUri;
            Uri.TryCreate(Request.Url, toolUrl, out toolUri);

            // Start building the response
            var graph = new List<ContentItem>
            {
                new LtiLink
                {
                    Custom = custom,
                    Id = toolUri,
                    MediaType = LtiConstants.LtiLinkMediaType,
                    Text = tool.Description ?? ltiRequest.Text,
                    Title = tool.Name ?? ltiRequest.Title,
                    PlacementAdvice = new ContentItemPlacement
                    {
                        PresentationDocumentTarget = presentationDocumentTarget
                    }
                }
            };
            var response = new ContentItemSelectionGraph
            {
                Graph = graph
            };

            // Content-Item Message 1.0 sends each request (which can have many items)
            // back to the Tool Consumer.
            var model = ContentItemsClient.CreateContentItemSelectionViewModel(
                ltiRequest.ContentItemReturnUrl, consumer.Key,
                consumer.Secret, response, ltiRequest.Data,
                null, null, null, "Selected " + tool.Name);
            return View(model);
        }
 /// <summary>
 /// Create an LtiRequestViewModel that contains a ContentItemPlacementResponse.
 /// </summary>
 /// <param name="url">The content_item_return_url from the content-item message.</param>
 /// <param name="consumerKey">The OAuth consumer key to use to sign the request.</param>
 /// <param name="consumerSecret">The OAuth consumer secret to use to sign the request.</param>
 /// <param name="contentItems">The ContentItemPlacementResponse to send.</param>
 /// <param name="data">The data received in the original content-item message.</param>
 /// <returns>The LtiRequestViewModel which contains a signed version of the response.</returns>
 public static LtiRequestViewModel CreateContentItemSelectionViewModel(
     string url, string consumerKey, string consumerSecret,
     ContentItemSelectionGraph contentItems, string data)
 {
     return CreateContentItemSelectionViewModel(url, consumerKey, consumerSecret, contentItems, data, null, null, null, null);
 }