Ejemplo n.º 1
0
        public string[] CreateAnnouncement(string courseId, string userUuid, Dictionary <string, object> licenseSettings, string announcementTitle, string announcementMessage)
        {
            string error;
            var    courseIdFixed = string.Format("_{0}_1", courseId);

            var client = BeginBatch(out error, licenseSettings);

            CourseMembershipWrapper membershipWS = client.getCourseMembershipWrapper();
            var membershipFilter = new MembershipFilter
            {
                filterType          = 2,
                filterTypeSpecified = true,
                courseIds           = new[] { courseIdFixed },
            };
            var enrollments = membershipWS.loadCourseMembership(courseIdFixed, membershipFilter);

            var userWS            = client.getUserWrapper();
            var courseUsersFilter = new UserFilter
            {
                filterTypeSpecified = true,
                filterType          = 2,
                id = enrollments.Select(x => x.userId).ToArray(),
            };
            var courseUsers = userWS.getUser(courseUsersFilter);
            var uuidString  = "USER.UUID=" + userUuid;
            var user        = courseUsers.FirstOrDefault(cu => cu != null &&
                                                         cu.expansionData != null &&
                                                         cu.expansionData.Any(ed => string.Compare(uuidString, ed, StringComparison.OrdinalIgnoreCase) == 0));

            if (user == null)
            {
                var adminRoles = new[] { "SYSTEM_ADMIN", "COURSE_CREATOR" };
                user = courseUsers.FirstOrDefault(x => x.systemRoles.Any(role => adminRoles.Contains(role)));
            }

            if (user != null)
            {
                var announcementVO = new AnnouncementVO
                {
                    body                = announcementMessage,
                    creatorUserId       = user.id,
                    courseId            = courseIdFixed,
                    permanent           = true,
                    permanentSpecified  = true,
                    position            = 1,
                    positionSpecified   = true,
                    pushNotify          = true,
                    pushNotifySpecified = true,
                    title               = announcementTitle,
                };

                var annWS   = client.getAnnouncementWrapper();
                var results = annWS.saveCourseAnnouncements(courseIdFixed, new[] { announcementVO });

                return(results);
            }

            return(null);
        }
Ejemplo n.º 2
0
 static void initWrappers()
 {
     // Initialize the wrappers used for this sample.
     ctx = ws.getContextWrapper();
     crs = ws.getCourseWrapper();
     crm = ws.getCourseMembershipWrapper();
     usr = ws.getUserWrapper();
 }
Ejemplo n.º 3
0
        public List <LmsUserDTO> GetUsersForCourse(
            Dictionary <string, object> licenseSettings,
            string courseId,
            string[] userIds,
            out string error,
            ref WebserviceWrapper client)
        {
            var courseIdFixed = string.Format("_{0}_1", courseId);

            var enrollmentsResult = LoginIfNecessary(
                ref client,
                c =>
            {
                string errorDuringEnrollments = null;
                var resultedList = new List <LmsUserDTO>();

                // NOTE: check http://library.blackboard.com/ref/fd8c40a0-f670-4c48-9e02-c5d84e61eda7/blackboard/ws/coursemembership/CourseMembershipWS.html
                // for filterType
                //var membershipFilter = new MembershipFilter
                //{
                //    filterType = (userIds == null) ? 2 : 6,
                //    filterTypeSpecified = true,
                //    courseIds = new[] { courseIdFixed },
                //    userIds = userIds,
                //};
                var membershipFilter = new MembershipFilter
                {
                    filterType          = 2,
                    filterTypeSpecified = true,
                    courseIds           = new[] { courseIdFixed },
                };

                CourseMembershipWrapper membership = c.getCourseMembershipWrapper();

                if (membership != null)
                {
                    CourseMembershipVO[] enrollments = membership.loadCourseMembership(courseIdFixed, membershipFilter);
                    if (HadError(c, out errorDuringEnrollments))
                    {
                        return(new Tuple <List <LmsUserDTO>, string>(resultedList, errorDuringEnrollments));
                    }

                    if (enrollments != null)
                    {
                        var activeEnrollments = enrollments.Where(x => x.available.HasValue && x.available.Value);

                        CourseMembershipRoleVO[] roles = membership.loadRoles(null);
                        var userFilter = new UserFilter
                        {
                            filterTypeSpecified = true,
                            filterType          = 2,
                            id = activeEnrollments.Select(x => x.userId).ToArray(),
                        };
                        UserWrapper userService = c.getUserWrapper();
                        if (userService != null)
                        {
                            UserVO[] users = userService.getUser(userFilter);
                            if (users == null)
                            {
                                HadError(c, out errorDuringEnrollments);
                                return(new Tuple <List <LmsUserDTO>, string>(resultedList, errorDuringEnrollments));
                            }

                            resultedList = activeEnrollments.Select(
                                e =>
                            {
                                var user        = users.FirstOrDefault(u => e.userId == u.id);
                                var ltiIdString = user != null && user.expansionData != null
                                            ? user.expansionData.FirstOrDefault(ed => ed.StartsWith("USER.UUID", StringComparison.OrdinalIgnoreCase))
                                            : null;
                                if (ltiIdString != null)
                                {
                                    ltiIdString = ltiIdString.Substring(ltiIdString.IndexOf('=') + 1);
                                }

                                return(new LmsUserDTO
                                {
                                    Id = e.userId,
                                    Login = user.With(x => x.name),
                                    Email = user.With(x => x.extendedInfo).With(x => x.emailAddress),
                                    Name = user.With(x => x.extendedInfo).Return(x => string.Format("{0} {1}", x.givenName, x.familyName).Trim(), user.With(s => s.name)),
                                    LmsRole = GetRole(e.roleId, roles),
                                    LtiId = ltiIdString,
                                });
                            }).ToList();
                        }
                    }
                }

                return(new Tuple <List <LmsUserDTO>, string>(resultedList, errorDuringEnrollments));
            },
                licenseSettings,
                out error);

            if (enrollmentsResult == null)
            {
                error = error ?? "SOAP. Unable to retrive result from API";
                return(new List <LmsUserDTO>());
            }
            return(enrollmentsResult);
        }