コード例 #1
0
ファイル: MeetingService.cs プロジェクト: NT-D/MsTeamsCall
        public async Task <Meeting> GetOnlineMeetingInfo(string meetingId, string userId, string accessToken)
        {
            if (String.IsNullOrEmpty(meetingId))
            {
                throw new ArgumentException("meetingId should be valid string");
            }

            try
            {
                var   requestHeaders = AuthUtil.CreateRequestHeader(accessToken);
                Event targetEvent    = await _graphClient.Users[userId].Calendar.Events[meetingId].Request(requestHeaders).GetAsync();

                if (targetEvent.Attendees == null || targetEvent.Attendees.Count() == 0)
                {
                    throw new ArgumentException("The meeting doesn't have attendee");
                }

                return(new Meeting(targetEvent.Attendees.ToArray(), targetEvent.OnlineMeeting));
            }
            catch (ServiceException)
            {
                // MS Graph may throw ServiceException
                throw;
            }
        }
コード例 #2
0
        public async Task <bool> InviteUserToOnlineMeeting(string userId, string tenantId, string callId, string accessToken)
        {
            try
            {
                var participants   = CreateParticipant();
                var requestHeaders = AuthUtil.CreateRequestHeader(accessToken);
                await _graphClient.Communications.Calls[callId].Participants.Invite(participants).Request(requestHeaders).PostAsync();

                return(true);
            }
            catch (ServiceException)
            {
                throw;
            }

            InvitationParticipantInfo[] CreateParticipant()
            {
                var participantInfo = new InvitationParticipantInfo();

                participantInfo.Identity = new IdentitySet()
                {
                    User = new Identity()
                    {
                        Id             = userId,
                        AdditionalData = new Dictionary <string, object>()
                        {
                            { "tenantId", tenantId }
                        }
                    }
                };

                return(new InvitationParticipantInfo[] { participantInfo });
            }
        }
コード例 #3
0
        public async Task <bool> JoinExistingOnlineMeeting(string userId, Meeting meetingInfo, string accessToken)
        {
            try
            {
                var  requestHeaders     = AuthUtil.CreateRequestHeader(accessToken);
                Call joinMeetingRequest = this.CreateJoinCallRequest(userId, meetingInfo);
                await _graphClient.Communications.Calls.Request(requestHeaders).AddAsync(joinMeetingRequest);

                return(true);
            }
            catch (ServiceException ex)
            {
                throw;
            }
        }
コード例 #4
0
        public async Task <bool> StartGroupCallWithSpecificMembers(string[] userIds, string tenantId, string accessToken)
        {
            try
            {
                var  requestHeaders = AuthUtil.CreateRequestHeader(accessToken);
                Call callRequest    = CreateGroupCallRequest(userIds, tenantId);
                await _graphClient.Communications.Calls.Request(requestHeaders).AddAsync(callRequest);

                return(true);
            }
            catch (ServiceException ex)
            {
                throw;
            }
        }
コード例 #5
0
ファイル: UsersService.cs プロジェクト: NT-D/MsTeamsCall
        public async Task <string[]> GetUserIdsFromEmailAsync(string[] emails, string accessToken)
        {
            BatchRequestStep[] batchSteps = new BatchRequestStep[emails.Length];

            for (int index = 0; index < emails.Length; index++)
            {
                Uri requestUri             = new Uri($"https://graph.microsoft.com/v1.0/users?$filter=mail eq \'{emails[index]}\'&$select=id");
                BatchRequestStep batchStep = new BatchRequestStep(index.ToString(), new HttpRequestMessage(HttpMethod.Get, requestUri));
                batchSteps[index] = batchStep;
            }
            BatchRequestContent batchContent = new BatchRequestContent(batchSteps);

            try
            {
                var requestHeaders = AuthUtil.CreateRequestHeader(accessToken);
                var batchResult    = await _graphClient.Batch.Request(requestHeaders).PostAsync(batchContent).ConfigureAwait(false);

                var batchResultContent = await batchResult.GetResponsesAsync();

                var ids = new List <string>();
                foreach (var item in batchResultContent.Values)
                {
                    // TODO: Need to handle if each batch request http response is not 200
                    Users users = await item.Content.ReadAsAsync <Users>();

                    var targetUser = users.Value.FirstOrDefault();
                    if (targetUser != null)
                    {
                        ids.Add(targetUser.Id);
                    }
                }

                return(ids.ToArray());
            }
            catch (ServiceException)
            {
                // Catch Microsoft Graph SDK exception
                throw;
            }
            catch (Exception)
            {
                throw;
            }
        }