Ejemplo n.º 1
0
        private MeetingDTO SaveMeeting(CanvasConnectCredentials credentials, int courseId, AdobeConnectProvider provider, MeetingDTO meetingDTO)
        {
            var meeting = this.CanvasCourseMeetingModel.GetOneByCourseId(credentials.Id, courseId).Value
                          ?? new CanvasCourseMeeting()
            {
                CanvasConnectCredentialsId = credentials.Id, CourseId = courseId
            };

            var meetingItem = new MeetingUpdateItem()
            {
                ScoId = meeting.ScoId
            };

            //meetingItem.DateBegin = DateTime.Now.ToString();
            //meetingItem.DateEnd = DateTime.Now.AddDays(1).ToString();
            meetingItem.Name        = String.Format("{0} [{1}] {2}", DateTime.Now.ToString("MM.dd.yy "), Model.context_label, meetingDTO.name);
            meetingItem.Description = meetingDTO.summary;
            meetingItem.UrlPath     = meetingDTO.ac_room_url;

            DateTime startDate, startTime, dateBegin;

            /*
             * if (DateTime.TryParse(meetingDTO.start_date, out startDate)
             *  && DateTime.TryParse(meetingDTO.start_time, out startTime))
             */
            if (meetingDTO.start_time.IndexOf(":") == 1)
            {
                meetingDTO.start_time = "0" + meetingDTO.start_time;
            }
            var oldStartDate = meetingDTO.start_date;

            if (meetingDTO.start_date != null)
            {
                meetingDTO.start_date = meetingDTO.start_date.Substring(6, 4) + "-"
                                        + meetingDTO.start_date.Substring(0, 5);
            }
            if (DateTime.TryParse(meetingDTO.start_date + " " + meetingDTO.start_time, out dateBegin))
            {
                /*
                 * var dateBegin = new DateTime(
                 *  startDate.Year,
                 *  startDate.Month,
                 *  startDate.Day,
                 *  startTime.Hour,
                 *  startTime.Minute,
                 *  startTime.Second);
                 */
                meetingItem.DateBegin = dateBegin.ToString("yyyy-MM-ddTHH:mm:ssZ");
                TimeSpan duration;
                if (TimeSpan.TryParse(meetingDTO.duration, out duration))
                {
                    meetingItem.DateEnd = dateBegin.AddMinutes((int)duration.TotalMinutes).ToString("yyyy-MM-ddTHH:mm:ssZ");
                }
            }

            meetingItem.FolderId    = credentials.ACScoId;
            meetingItem.Language    = "en";
            meetingItem.Type        = ScoType.meeting;
            meetingItem.SourceScoId = meetingDTO.template;

            var result = meeting.ScoId != null?
                         provider.UpdateSco(meetingItem) :
                             provider.CreateSco(meetingItem);

            if (result.ScoInfo != null)
            {
                meetingDTO.id = result.ScoInfo.ScoId;
            }

            if (meetingItem.ScoId == null && result.ScoInfo != null)
            {
                meeting.ScoId = result.ScoInfo.ScoId;
                this.CanvasCourseMeetingModel.RegisterSave(meeting);

                var users = CourseAPI.GetUsersForCourse(Credentials.CanvasDomain, credentials.CanvasToken, courseId);
                this.SetDefaultUsers(users, provider, result.ScoInfo.ScoId);

                if (Credentials.CanvasDomain.IndexOf("canvas") > -1 && !String.IsNullOrEmpty(Model.context_title))
                {
                    var rets = CourseAPI.CreateAnnouncement(
                        Credentials.CanvasDomain,
                        Credentials.CanvasToken,
                        Model.custom_canvas_course_id,
                        String.Format("A new Adobe Connect room was created for course {0}", Model.context_title),
                        String.Format("Meeting \"{0}\" will start {1} at {2}. It's duration will be {3}. You can join it in your Adobe Connect Conference section.",
                                      meetingDTO.name, oldStartDate, meetingDTO.start_time, meetingDTO.duration));
                }
            }

            if (result.ScoInfo != null)
            {
                var specialPermissionId = meetingDTO.access_level == "denied"
                    ? SpecialPermissionId.denied
                    : (meetingDTO.access_level == "view_hidden"
                        ? SpecialPermissionId.view_hidden
                        : SpecialPermissionId.remove);

                provider.UpdatePublicAccessPermissions(result.ScoInfo.ScoId, specialPermissionId);
                var permission = provider.GetScoPublicAccessPermissions(result.ScoInfo.ScoId).Values;

                return(this.GetMeetingDTOByScoInfo(result.ScoInfo, permission));
            }
            else
            {
                return(new MeetingDTO()
                {
                    id = "0", connect_server = Credentials.ACDomain
                });
            }
        }