Пример #1
0
        public async Task ProcessEvent(StudentEvent studentEvent)
        {
            //Check courseId exist in the coursecatalog
            if (_courseCatalog.CheckCourseIdExist(studentEvent.CourseID))
            {
                if (studentEvent.EventType == EventType.Attendance)
                {
                    // Check the corresponding list of this course according to Catalog.
                    string targetList = _courseCatalog.GetListNameForCourse(studentEvent.CourseID);
                    _logger.LogInformation("Event aggregator will send event to list {0}.", targetList);

                    SharepointListItem eventItem = new SharepointListItem();
                    // Event Detailed Information.
                    eventItem["Title"]        = "Event by " + studentEvent.Student.Email;
                    eventItem["CourseID"]     = studentEvent.CourseID.ToUpper();
                    eventItem["StudentName"]  = studentEvent.Student.FirstName + " (" + studentEvent.Student.LastName + ")";
                    eventItem["StudentID"]    = studentEvent.Student.ID;
                    eventItem["StudentEmail"] = studentEvent.Student.Email;
                    eventItem["EventType"]    = studentEvent.EventType.ToString();
                    eventItem["ActivityType"] = studentEvent.ActivityType;
                    eventItem["ActivityName"] = studentEvent.ActivityName;
                    eventItem["Timestamp"]    = studentEvent.Timestamp;

                    // Assign to different list by course ID.
                    await _sharePointManager.AddItemToList(targetList, eventItem);
                }

                StoreInDatabase(studentEvent);
            }
            else
            {
                _logger.LogInformation($"Cannot find the courseId '{studentEvent.CourseID}', event aggregator has cancelled current event.");
            }
        }
Пример #2
0
        public async Task ProcessEvent(StudentEvent studentEvent)
        {
            // Check whether courseId exist in the courseCatalog.
            if (_courseCatalog.CheckCourseIdExist(studentEvent.CourseID))
            {
                // Only Attendance event will be sent to ORCA SharePoint.
                if (studentEvent.EventType == EventType.Attendance)
                {
                    // Check the corresponding list of this course according to Catalog.
                    string targetList = _courseCatalog.GetListNameForCourse(studentEvent.CourseID);
                    _logger.LogDebug("Event aggregator will send event to list \"{0}\".", targetList);

                    // Check whether the target list exist in ORCA SharePoint.
                    // Once the list has been created successful, do the next step.
                    while (!_sharePointManager.CheckListExists(targetList))
                    {
                        _logger.LogInformation("Currently \"{0}\" does not exist, event aggregator will create the list.", targetList);
                        // If not exist, create new list.
                        string        description = "This list is for store " + targetList + ".";
                        List <string> list        = CreateDefaultSharePointEventListSchema();
                        _sharePointManager.CreateList(targetList, description, list);
                    }
                    _logger.LogDebug("List \"{0}\" is now exist and ready to store events.", targetList);
                    // Assign to different list by course ID.
                    SharepointListItem eventItem = PackEventItem(studentEvent);
                    bool addedEvent = await _sharePointManager.AddItemToList(targetList, eventItem);

                    if (!addedEvent)
                    {
                        _logger.LogError($"Failed to store attendance event {eventItem}");
                    }
                }

                // All events will then be stored in database if have database.
                if (_scope != null)
                {
                    await StoreEventInDatabase(studentEvent);
                }
            }
        }