AddCustomParameters() public method

Add the custom parameters from a string.
public AddCustomParameters ( string parameters ) : void
parameters string
return void
Ejemplo n.º 1
0
        /// <summary>
        /// Create a basic launch request for the assignment.
        /// </summary>
        /// <param name="request">The browser request.</param>
        /// <param name="assignment">The assignment to launch.</param>
        /// <param name="user">The user that is launching the assignment.</param>
        /// <returns>An LtiRequestViewModel which can be displayed by the View in such
        /// a way that the browser will invoke the LTI launch.</returns>
        public static LtiRequestViewModel CreateBasicLaunchRequestViewModel(HttpRequestBase request, Assignment assignment, ApplicationUser user)
        {
            var ltiRequest = new LtiRequest(LtiConstants.BasicLaunchLtiMessageType)
            {
                ConsumerKey = assignment.ConsumerKey,
                ResourceLinkId = assignment.AssignmentId.ToString(CultureInfo.InvariantCulture),
                Url = new Uri(assignment.Url)
            };

            var course = assignment.Course;

            // Tool
            ltiRequest.ToolConsumerInfoProductFamilyCode = Assembly.GetExecutingAssembly().GetName().Name;
            ltiRequest.ToolConsumerInfoVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            // Context
            ltiRequest.ContextId = course.CourseId.ToString(CultureInfo.InvariantCulture);
            ltiRequest.ContextTitle = course.Name;
            ltiRequest.ContextType = course.EnrolledUsers.Any(u => u.Id == user.Id)
                ? LisContextType.CourseSection
                : LisContextType.CourseTemplate;

            // Instance
            ltiRequest.ToolConsumerInstanceGuid = "~/".ToAbsoluteUrl();
            var title = Assembly.GetExecutingAssembly().GetCustomAttributes<AssemblyTitleAttribute>().FirstOrDefault();
            ltiRequest.ToolConsumerInstanceName = title == null ? null : title.Title;
            ltiRequest.ResourceLinkTitle = assignment.Name;
            ltiRequest.ResourceLinkDescription = assignment.Description;

            // User
            if (user.SendEmail.GetValueOrDefault(true))
            {
                ltiRequest.LisPersonEmailPrimary = user.Email;
            }
            if (user.SendName.GetValueOrDefault(true))
            {
                ltiRequest.LisPersonNameFamily = user.LastName;
                ltiRequest.LisPersonNameGiven = user.FirstName;
            }
            ltiRequest.UserId = user.Id;
            ltiRequest.UserName = user.UserName;
            ltiRequest.SetRoles(GetLtiRolesForUser(user));

            // Outcomes service
            if (course.EnrolledUsers.Any(u => u.Id == user.Id))
            {
                var outcomesUrl = UrlHelper.GenerateUrl("DefaultApi", null, "Outcomes",
                    new RouteValueDictionary { { "httproute", string.Empty } }, RouteTable.Routes,
                    request.RequestContext, false);
                Uri outcomesUri;
                if (Uri.TryCreate(request.Url, outcomesUrl, out outcomesUri))
                {
                    ltiRequest.LisOutcomeServiceUrl = outcomesUri.AbsoluteUri;
                }
                ltiRequest.LisResultSourcedId =
                    JsonConvert.SerializeObject(new LisResultSourcedId
                    {
                        AssignmentId = assignment.AssignmentId, 
                        UserId = user.Id
                    });
            }

            // Tool Consumer Profile service
            var profileUrl = UrlHelper.GenerateUrl("DefaultApi", null, "ToolConsumerProfile",
                new RouteValueDictionary { { "httproute", string.Empty } }, RouteTable.Routes,
                request.RequestContext, false);
            Uri profileUri;
            if (Uri.TryCreate(request.Url, profileUrl, out profileUri))
            {
                ltiRequest.ToolConsumerProfileUrl = profileUri.AbsoluteUri;
            }

            // Add the custom parameters. This consumer supports 3 special substitutions.
            var customParameters = assignment.CustomParameters;

            if (!string.IsNullOrWhiteSpace(customParameters))
            {
                ltiRequest.AddCustomParameters(customParameters);
            }

            return ltiRequest.GetViewModel(assignment.ConsumerSecret);
        }
Ejemplo n.º 2
0
        public ActionResult LtiLaunch(Lti1TestLaunch model, int link)
        {
            var request = new LtiRequest(LtiConstants.BasicLaunchLtiMessageType);
            request.ConsumerKey = model.ConsumerKey;
            request.Url = new Uri(model.Url);
            request.AddCustomParameters(CustomParameters);
            request.LaunchPresentationLocale = Thread.CurrentThread.CurrentUICulture.Name;
            request.LaunchPresentationDocumentTarget = DocumentTarget.frame;
            request.LaunchPresentationWidth = 400;
            request.LaunchPresentationHeight = 300;
            request.LaunchPresentationCssUrl = GetLaunchPresentationCssUrl();
            request.LaunchPresentationReturnUrl = Request.Url.AbsoluteUri;
            request.LisOutcomeServiceUrl = GetLisOutcomeServiceUrl();
            request.ToolConsumerInfoProductFamilyCode = "LtiLibrary";
            request.ToolConsumerInfoVersion = "1";
            request.ToolConsumerProfileUrl = GetToolConsumerProfileUrl();
            request.ToolConsumerInstanceContactEmail = "*****@*****.**";
            request.ToolConsumerInstanceDescription = Assembly.GetExecutingAssembly().GetName().ToString();
            request.ToolConsumerInstanceGuid = Assembly.GetExecutingAssembly().GetName().Name;
            request.ToolConsumerInstanceName = "andyfmiller.com";

            switch (link)
            {
                case 1: // Instructor, Course 1, Resource 1
                    request.ContextId = Course1.CourseId.ToString(CultureInfo.InvariantCulture);
                    request.ContextLabel = request.ContextId;
                    request.ContextTitle = ConvertToPlainText(Course1.Title);
                    request.ContextType = LisContextType.CourseSection;
                    request.LisCourseOfferingSourcedId = request.ContextId;
                    request.LisCourseSectionSourcedId = request.ContextId;
                    request.ResourceLinkId = Course1.Links[0].LinkId;
                    request.ResourceLinkTitle = ConvertToPlainText(Course1.Links[0].Title);
                    request.ResourceLinkDescription = ConvertToPlainText(Course1.Links[0].Description);
                    request.LisPersonEmailPrimary = Instructor.Email;
                    request.LisPersonNameFamily = Instructor.FamilyName;
                    request.LisPersonNameGiven = Instructor.GivenName;
                    request.LisPersonSourcedId = Instructor.UserId;
                    request.UserId = Instructor.UserId;
                    request.UserName = Instructor.Username;
                    request.Roles = Role.Instructor.ToString();
                    break;
                case 2: // Instructor, Course 1, Resource 2
                    request.ContextId = Course1.CourseId.ToString(CultureInfo.InvariantCulture);
                    request.ContextLabel = request.ContextId;
                    request.ContextTitle = ConvertToPlainText(Course1.Title);
                    request.ContextType = LisContextType.CourseSection;
                    request.ResourceLinkId = Course1.Links[1].LinkId;
                    request.ResourceLinkTitle = ConvertToPlainText(Course1.Links[1].Title);
                    request.ResourceLinkDescription = ConvertToPlainText(Course1.Links[1].Description);
                    request.LisPersonEmailPrimary = Instructor.Email;
                    request.LisPersonNameFamily = Instructor.FamilyName;
                    request.LisPersonNameGiven = Instructor.GivenName;
                    request.LisPersonSourcedId = Instructor.UserId;
                    request.UserId = Instructor.UserId;
                    request.UserName = Instructor.Username;
                    request.Roles = Role.Instructor.ToString();
                    break;
                case 3: // Instructor, Course 2, Resource 1
                    request.ContextId = Course2.CourseId.ToString(CultureInfo.InvariantCulture);
                    request.ContextLabel = request.ContextId;
                    request.ContextTitle = ConvertToPlainText(Course2.Title);
                    request.ContextType = LisContextType.CourseSection;
                    request.ResourceLinkId = Course2.Links[0].LinkId;
                    request.ResourceLinkTitle = ConvertToPlainText(Course2.Links[0].Title);
                    request.ResourceLinkDescription = ConvertToPlainText(Course2.Links[0].Description);
                    request.LisPersonEmailPrimary = Instructor.Email;
                    request.LisPersonNameFamily = Instructor.FamilyName;
                    request.LisPersonNameGiven = Instructor.GivenName;
                    request.LisPersonSourcedId = Instructor.UserId;
                    request.UserId = Instructor.UserId;
                    request.UserName = Instructor.Username;
                    request.Roles = Role.Instructor.ToString();
                    break;
                case 4: // Student, Course 1, Resource 1
                    request.ContextId = Course1.CourseId.ToString(CultureInfo.InvariantCulture);
                    request.ContextLabel = request.ContextId;
                    request.ContextTitle = ConvertToPlainText(Course1.Title);
                    request.ContextType = LisContextType.CourseSection;
                    request.ResourceLinkId = Course1.Links[0].LinkId;
                    request.ResourceLinkTitle = ConvertToPlainText(Course1.Links[0].Title);
                    request.ResourceLinkDescription = ConvertToPlainText(Course1.Links[0].Description);
                    request.LisPersonEmailPrimary = Student.Email;
                    request.LisPersonNameFamily = Student.FamilyName;
                    request.LisPersonNameGiven = Student.GivenName;
                    request.LisPersonSourcedId = Student.UserId;
                    request.LisResultSourcedId = Student.UserId;
                    request.UserId = Student.UserId;
                    request.UserName = Student.Username;
                    request.Roles = Role.Learner.ToString();
                    break;
                case 5: // Student, Course 1, Resource 2
                    request.ContextId = Course1.CourseId.ToString(CultureInfo.InvariantCulture);
                    request.ContextLabel = request.ContextId;
                    request.ContextTitle = ConvertToPlainText(Course1.Title);
                    request.ContextType = LisContextType.CourseSection;
                    request.ResourceLinkId = Course1.Links[1].LinkId;
                    request.ResourceLinkTitle = ConvertToPlainText(Course1.Links[1].Title);
                    request.ResourceLinkDescription = ConvertToPlainText(Course1.Links[1].Description);
                    //request.LisPersonEmailPrimary = Student.Email;
                    request.LisPersonNameFamily = Student.FamilyName;
                    request.LisPersonNameGiven = Student.GivenName;
                    request.LisPersonSourcedId = Student.UserId;
                    request.LisResultSourcedId = Student.UserId;
                    request.UserId = Student.UserId;
                    request.UserName = Student.Username;
                    request.Roles = Role.Learner.ToString();
                    break;
                case 6: // Student, Course 2, Resource 1
                    request.ContextId = Course2.CourseId.ToString(CultureInfo.InvariantCulture);
                    request.ContextLabel = request.ContextId;
                    request.ContextTitle = ConvertToPlainText(Course2.Title);
                    request.ContextType = LisContextType.CourseSection;
                    request.ResourceLinkId = Course2.Links[0].LinkId;
                    request.ResourceLinkTitle = ConvertToPlainText(Course2.Links[0].Title);
                    request.ResourceLinkDescription = ConvertToPlainText(Course2.Links[0].Description);
                    //request.LisPersonEmailPrimary = Student.Email;
                    //request.LisPersonNameFamily = Student.FamilyName;
                    //request.LisPersonNameGiven = Student.GivenName;
                    request.LisPersonSourcedId = Student.UserId;
                    request.LisResultSourcedId = Student.UserId;
                    request.UserId = Student.UserId;
                    request.UserName = Student.Username;
                    request.Roles = Role.Learner.ToString();
                    break;
                case 7: // Mentor, Course 1, Resource 1
                        // Tests passed with this launch
                        // 5.9
                    request.ContextId = Course1.CourseId.ToString(CultureInfo.InvariantCulture);
                    request.ContextLabel = request.ContextId;
                    request.ContextTitle = ConvertToPlainText(Course1.Title);
                    request.ContextType = LisContextType.CourseSection;
                    request.ResourceLinkId = Course1.Links[0].LinkId;
                    request.ResourceLinkTitle = ConvertToPlainText(Course1.Links[0].Title);
                    request.ResourceLinkDescription = ConvertToPlainText(Course1.Links[0].Description);
                    request.LisPersonEmailPrimary = Mentor.Email;
                    request.LisPersonNameFamily = Mentor.FamilyName;
                    request.LisPersonNameGiven = Mentor.GivenName;
                    request.UserId = Mentor.UserId;
                    request.UserName = Mentor.Username;
                    request.Roles = Role.Mentor.ToString();
                    request.RoleScopeMentor = Mentor.MentoringUserId;
                    break;
                case 8: // Instructor, No context (6.4)
                        // Tests passed with this launch
                        // 6.4
                    request.ResourceLinkId = GradebookTool.LinkId;
                    request.ResourceLinkTitle = ConvertToPlainText(GradebookTool.Title);
                    request.ResourceLinkDescription = ConvertToPlainText(GradebookTool.Description);
                    request.LisPersonEmailPrimary = Instructor.Email;
                    request.LisPersonNameFamily = Instructor.FamilyName;
                    request.LisPersonNameGiven = Instructor.GivenName;
                    request.LisPersonSourcedId = Instructor.UserId;
                    request.UserId = Instructor.UserId;
                    request.UserName = Instructor.Username;
                    request.Roles = Role.Instructor.ToString();
                    break;
            }
            return View(request.GetViewModel(model.ConsumerSecret));
        }
Ejemplo n.º 3
0
        public static LtiRequestViewModel CreateContentItemSelectionRequestViewModel(HttpRequestBase request, ContentItemTool contentItemTool, Course course, ApplicationUser user, string returnUrl)
        {
            var ltiRequest = new LtiRequest(LtiConstants.ContentItemSelectionRequestLtiMessageType)
            {
                ConsumerKey = contentItemTool.ConsumerKey,
                Url = new Uri(contentItemTool.Url)
            };

            // Tool Consumer
            ltiRequest.ToolConsumerInfoProductFamilyCode = Assembly.GetExecutingAssembly().GetName().Name;
            ltiRequest.ToolConsumerInfoVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            // Context
            ltiRequest.ContextId = course.CourseId.ToString(CultureInfo.InvariantCulture);
            ltiRequest.ContextTitle = course.Name;
            ltiRequest.ContextType = course.EnrolledUsers.Any(u => u.Id == user.Id)
                ? LisContextType.CourseSection
                : LisContextType.CourseTemplate;
            ltiRequest.LisCourseSectionSourcedId = course.CourseId.ToString(CultureInfo.InvariantCulture);

            // Instance
            ltiRequest.ToolConsumerInstanceGuid = "~/".ToAbsoluteUrl();
            var title = Assembly.GetExecutingAssembly().GetCustomAttributes<AssemblyTitleAttribute>().FirstOrDefault();
            ltiRequest.ToolConsumerInstanceName = title == null ? null : title.Title;

            // User
            if (user.SendEmail.GetValueOrDefault(true))
            {
                ltiRequest.LisPersonEmailPrimary = user.Email;
            }
            if (user.SendName.GetValueOrDefault(true))
            {
                ltiRequest.LisPersonNameFamily = user.LastName;
                ltiRequest.LisPersonNameGiven = user.FirstName;
            }
            ltiRequest.UserId = user.Id;
            ltiRequest.UserName = user.UserName;
            ltiRequest.SetRoles(GetLtiRolesForUser(user));

            // Presentation
            ltiRequest.LaunchPresentationDocumentTarget = DocumentTarget.iframe;

            // Content Item Tool
            ltiRequest.AcceptMediaTypes = LtiConstants.LtiLinkMediaType; // Only accept LTI Link
            ltiRequest.AcceptMultiple = true;
            ltiRequest.AcceptPresentationDocumentTargets = "iframe";
            ltiRequest.AcceptUnsigned = false;
            ltiRequest.ContentItemReturnUrl = returnUrl;
            //ltiRequest.ContentItemServiceUrl = "about:blank";
            ltiRequest.Data = JsonConvert.SerializeObject(new ContentItemData
            {
                ContentItemToolId = contentItemTool.ContentItemToolId, 
                CourseId = course.CourseId
            });

            // Add the custom parameters.
            var customParameters = contentItemTool.CustomParameters;

            // This tool consumer supports 3 non-spec custom parameters
            if (!string.IsNullOrWhiteSpace(customParameters))
            {
                ltiRequest.AddCustomParameters(customParameters);
            }

            return ltiRequest.GetViewModel(contentItemTool.ConsumerSecret);
        }