Пример #1
0
        /// <summary>
        /// Method posting an incoming change of an event into the MS Graph API.
        /// </summary>
        /// <param name="rabbitMQEvent">Updated event sent by the RabbitMQ message broker</param>
        public void EventUpdate(RabbitMQEvent rabbitMQEvent)
        {
            //Console.WriteLine("Update van Event nog niet klaar!");
            Master masterUserId  = masterDBService.GetGraphIdFromMUUID(rabbitMQEvent.OrganiserId);
            Master masterEventId = masterDBService.GetGraphIdFromMUUID(rabbitMQEvent.UUID);

            if (masterEventId != null && masterUserId != null && masterDBService.CheckSourceEntityVersionIsHigher(rabbitMQEvent.UUID, rabbitMQEvent.Header.Source))
            {
                RestClient  restClient  = new RestClient();
                RestRequest restRequest = new RestRequest();

                CalendarEvent calendarEvent = new CalendarEvent();
                calendarEvent.Subject = rabbitMQEvent.Title;

                calendarEvent.Start.DateTime   = DateTime.Parse(rabbitMQEvent.Start.ToString());
                calendarEvent.Start.Zone       = "Romance Standard Time";
                calendarEvent.End.DateTime     = DateTime.Parse(rabbitMQEvent.End.ToString());
                calendarEvent.End.Zone         = "Romance Standard Time";
                calendarEvent.Body.ContentType = "text";
                calendarEvent.Body.Content     = rabbitMQEvent.Description;
                calendarEvent.Organizer.EmailAddress.Address = rabbitMQEvent.OrganiserId.ToString();
                string[] location = rabbitMQEvent.Location.Split('%');
                calendarEvent.Location.Address.Street     = location[0] + " " + location[1] + " " + location[2];
                calendarEvent.Location.Address.City       = location[3];
                calendarEvent.Location.Address.PostalCode = location[4];

                /* --- Retrieve a valid accestoken for creating the event in the MS Graph API --- */
                BearerToken = services.RefreshAccesToken();

                /* --- Serialize the event into json and attach it to the rest request --- */
                var json = JsonConvert.SerializeObject(calendarEvent);

                restRequest.AddHeader("Authorization", BearerToken.Token_type + " " + BearerToken.Access_token);
                restRequest.AddJsonBody(json);

                /* --- execute the rest request to post the new event in the MS Graph API --- */
                restClient.BaseUrl = new Uri($"https://graph.microsoft.com/v1.0/users/{masterUserId.SourceEntityId}/events/{masterEventId.SourceEntityId}");
                var response = restClient.Patch(restRequest);

                Console.WriteLine(response.StatusCode);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    masterDBService.ChangeEntityVersion(rabbitMQEvent.UUID);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Method posting an incoming change of a user into the MS Graph API.
        /// </summary>
        /// <param name="rabbitMQUser">Updated user sent by the RabbitMQ message broker</param>
        public void UserUpdate(RabbitMQUser rabbitMQUser)
        {
            //Console.WriteLine("Update van User nog niet klaar!");
            Master masterUserId = masterDBService.GetGraphIdFromMUUID(rabbitMQUser.UUID);

            if (masterUserId != null && masterDBService.CheckSourceEntityVersionIsHigher(rabbitMQUser.UUID, rabbitMQUser.Header.Source))
            {
                RestClient  restClient  = new RestClient();
                RestRequest restRequest = new RestRequest();

                User user = new User();
                //required
                user.AccountEnabled    = true;
                user.DisplayName       = rabbitMQUser.FirstName + " " + rabbitMQUser.LastName;
                user.MailNickname      = rabbitMQUser.FirstName.Replace(' ', '.') + "." + rabbitMQUser.LastName;
                user.UserPrincipalName = user.MailNickname + "@ipwt3.onmicrosoft.com";
                user.Mail          = user.UserPrincipalName;
                user.UsageLocation = "BE";
                //user.PasswordProfile = new UserPasswordProfile();
                //user.PasswordProfile.ForceChangePasswordNextSignIn = false;
                //user.PasswordProfile.Password = Constant.StandardPassword;

                user.GivenName = rabbitMQUser.FirstName;
                user.SurName   = rabbitMQUser.LastName;
                user.JobTitle  = rabbitMQUser.Role;

                BearerToken = services.RefreshAccesToken();

                var json = JsonConvert.SerializeObject(user);
                restRequest.AddHeader("Authorization", BearerToken.Token_type + " " + BearerToken.Access_token);
                restRequest.AddJsonBody(json);
                Console.WriteLine(json);

                restClient.BaseUrl = new Uri($"https://graph.microsoft.com/v1.0/users/{masterUserId.SourceEntityId}");
                Console.WriteLine(restClient.BaseUrl);
                var response = restClient.Patch(restRequest);

                Console.WriteLine(response.StatusCode);

                if (response.StatusCode == System.Net.HttpStatusCode.NoContent)
                {
                    masterDBService.ChangeEntityVersion(rabbitMQUser.UUID);
                }
            }
        }