예제 #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.");
            }
        }
 private StorageItem ListItemToStorageItem(SharepointListItem item)
 {
     return(new StorageItem
     {
         Id = item.Id.ToString(),
         Title = item.Title,
         Description = item.Description,
         StartDate = item.EventDate,
         EndDate = item.EndDate,
         Category = item.Category,
         AllDayEvent = item.AllDayEvent,
         CalendarEventId = item.CalendarEventId
     });
 }
예제 #3
0
        public async void CreateListAndAddOrGetItemsTest()
        {
            var    sharepointManager = new SharepointManager(Options.Create(SharepointSettingsFromEnv()));
            var    listToCreate      = _listNameForTest;
            var    description       = "Sharepoint integration test 1 simple list.";
            string FIELD_XML_SCHEMA  = $"<Field DisplayName='Default' Type='Text' Required='TRUE' />";

            bool listExistsBeforeCreating = sharepointManager.CheckListExists(listToCreate);

            Assert.False(listExistsBeforeCreating);

            sharepointManager.CreateList(listToCreate, description, new List <string> {
                FIELD_XML_SCHEMA
            });

            bool listExistsAfterCreating = sharepointManager.CheckListExists(listToCreate);

            Assert.True(listExistsAfterCreating);

            SharepointListItem testItem = new SharepointListItem();

            testItem["Default"] = "testItem";

            var listBeforeAdding = await sharepointManager.GetItemsFromList(listToCreate);

            int numOfItemsBeforeAdding = listBeforeAdding.Count;

            Assert.Equal(0, numOfItemsBeforeAdding);

            var addItem = await sharepointManager.AddItemToList(listToCreate, testItem);

            bool addItemSuccessful = addItem;

            // Add item to list should be successful.
            Assert.True(addItemSuccessful);
            if (addItemSuccessful)
            {
                var listAfterAdding = await sharepointManager.GetItemsFromList(listToCreate);

                int numOfItemsAfterAdding = listAfterAdding.Count;
                Assert.Equal(1, numOfItemsAfterAdding);

                SharepointListItem item        = listAfterAdding.First();
                bool itemContainsExpectedKey   = item.Keys.Contains("Default");
                bool itemContainsExpectedValue = item.Values.Contains("testItem");
                Assert.True(itemContainsExpectedKey && itemContainsExpectedValue);
                Assert.Equal("testItem", item["Default"]);
            }
        }
예제 #4
0
        private SharepointListItem PackEventItem(StudentEvent studentEvent)
        {
            SharepointListItem eventItem = new SharepointListItem();

            // Event Detailed Information.
            eventItem[EVENT_LIST_COURSE_ID]     = studentEvent.CourseID.ToUpper();
            eventItem[EVENT_LIST_STUDENT_NAME]  = studentEvent.Student.LastName + ", " + studentEvent.Student.FirstName;
            eventItem[EVENT_LIST_STUDENT_EMAIL] = studentEvent.Student.Email;
            eventItem[EVENT_LIST_STUDENT_ID]    = studentEvent.Student.ID;
            eventItem[EVENT_LIST_ACTIVITY_TYPE] = studentEvent.ActivityType;
            eventItem[EVENT_LIST_ACTIVITY_NAME] = studentEvent.ActivityName;
            eventItem[EVENT_LIST_TIMESTAMP]     = studentEvent.Timestamp;

            _logger.LogDebug("Event by {0} has been packed.", studentEvent.Student.FirstName);
            return(eventItem);
        }
예제 #5
0
        public async void AddItemToListButFailedTest()
        {
            var sharepointManager = new SharepointManager(Options.Create(SharepointSettingsFromEnv()));
            var listToCreate      = _listNameForTest;

            bool listExists = sharepointManager.CheckListExists(listToCreate);

            Assert.False(listExists);

            SharepointListItem testItem = new SharepointListItem();

            testItem["Default"] = "testItem";

            var addItem = await sharepointManager.AddItemToList(listToCreate, testItem);

            bool addItemSuccessful = addItem;

            Assert.False(addItemSuccessful);
        }
예제 #6
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);
                }
            }
        }
예제 #7
0
 public async Task <bool> AddItemToList(string listName, SharepointListItem item)
 {
     mockEventList[listName].Add(item);
     return(true);
 }