Exemple #1
0
        public OnlineMeetingInformation GenerateOnlineMeeting(OnlineMeetingInformation onlineMeetingRequest, AccessToken token, Guid azureAdUserObjectId)
        {
            Uri    graphEndpoint = new Uri($"https://graph.microsoft.com/v1.0/users/{azureAdUserObjectId}/onlineMeetings");
            string meetingJson   = SerializeOnlineMeeting(onlineMeetingRequest);

            HttpClient httpClient = new HttpClient();

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(token.Type, token.Value);

            HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, graphEndpoint);

            httpRequestMessage.Content = new StringContent(meetingJson, Encoding.UTF8, "application/json");

            var response = httpClient.SendAsync(httpRequestMessage).GetAwaiter().GetResult();

            if (!response.IsSuccessStatusCode)
            {
                throw new Exception($"Create Online Meeting failed : {response.ReasonPhrase}");
            }

            DataContractJsonSerializerSettings settings = new DataContractJsonSerializerSettings()
            {
                UseSimpleDictionaryFormat = true
            };

            DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(OnlineMeetingInformation), settings);
            var onlineMeetindDeserialized  = (OnlineMeetingInformation)ser.ReadObject(response.Content.ReadAsStreamAsync().GetAwaiter().GetResult());

            return(onlineMeetindDeserialized);
        }
Exemple #2
0
        public void Execute(IServiceProvider serviceProvider)
        {
            string clientId     = "";
            string clientSecret = "";
            string tenantId     = "";
            string scope        = "https://graph.microsoft.com/.default";

            IPluginExecutionContext     context        = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
            var orgService = serviceFactory.CreateOrganizationService(context.UserId);

            try
            {
                var tokenProvider = new TokenProvider();
                var token         = tokenProvider.GetToken(clientId, clientSecret, tenantId, scope);

                Entity systemUser          = orgService.Retrieve("systemuser", context.UserId, new ColumnSet("azureactivedirectoryobjectid"));
                Guid   userAzureAdObjectId = systemUser.GetAttributeValue <Guid>("azureactivedirectoryobjectid");
                OnlineMeetingGenerator   onlineMeetingGenerator   = new OnlineMeetingGenerator();
                OnlineMeetingInformation onlineMeetingInformation = new OnlineMeetingInformation();

                var onlineMeetingResponse = onlineMeetingGenerator.GenerateOnlineMeeting(onlineMeetingInformation, token, userAzureAdObjectId);

                var meetingContent = WebUtility.UrlDecode(onlineMeetingResponse.JoinInformationData.Content).Remove(0, 15);

                context.OutputParameters.AddOrUpdateIfNotNull("OnlineMeeting", meetingContent);
            }
            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException(ex.Message);
            }
        }
Exemple #3
0
        private string SerializeOnlineMeeting(OnlineMeetingInformation onlineMeeting)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                DataContractJsonSerializerSettings settings = new DataContractJsonSerializerSettings()
                {
                    UseSimpleDictionaryFormat = true
                };
                DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(OnlineMeetingInformation), settings);

                ser.WriteObject(ms, onlineMeeting);

                using (StreamReader sr = new StreamReader(ms))
                {
                    ms.Position = 0;
                    return(sr.ReadToEnd());
                }
            }
        }