/// <inheritdoc/> internal override async Task <DirectoryObject> CallGraphServiceWithResultAsync(IGraphServiceClient client, IReadOnlyDictionary <string, object> parameters, CancellationToken cancellationToken) { string userId = (string)parameters["UserId"]; string propertiesToSelect = (string)parameters["PropertiesToSelect"]; DirectoryObject result = await client.Users[userId].Manager.Request().Select(propertiesToSelect).GetAsync(cancellationToken).ConfigureAwait(false); return(result); }
public MSGraphCalendarAPI(IGraphServiceClient serviceClient) { _graphClient = serviceClient; }
private static async Task <ClaimsPrincipal> UpdateUserRole(ClaimsPrincipal user, string role, string id, string extensionId, IGraphServiceClient graphClient) { var claims = user.Claims.Append(new Claim("extension_zaprole", role)); ClaimsPrincipal principal = new ClaimsPrincipal(new ClaimsIdentity(user.Identity, claims)); Thread.CurrentPrincipal = principal; IDictionary <string, object> extensions = new Dictionary <string, object>(); extensions.Add($"extension_{extensionId}_zaprole", role); var adUser = new Microsoft.Graph.User { AdditionalData = extensions }; int retries = 0; async Task updateUser(string userId) { try { await graphClient.Users[userId].Request().UpdateAsync(adUser); } catch (Exception exception) { await Task.Delay(1000); retries++; if (retries > 2) { throw exception; } await updateUser(id); } } await updateUser(id); return(principal); }
/// <inheritdoc/> internal override async Task <IEnumerable <User> > CallGraphServiceWithResultAsync(IGraphServiceClient client, IReadOnlyDictionary <string, object> parameters, CancellationToken cancellationToken) { string nameToSearch = (string)parameters["NameToSearch"]; int maxCount = (int)parameters["MaxResults"]; string propertiesToSelect = (string)parameters["PropertiesToSelect"]; string filterClause = $"startsWith(displayName, '{nameToSearch}') or startsWith(surname, '{nameToSearch}') or startsWith(givenname, '{nameToSearch}')"; IGraphServiceUsersCollectionRequest request = client.Users.Request().Filter(filterClause).Select(propertiesToSelect); // Apply the Top() filter if there is a value to apply if (maxCount > 0) { request = request.Top(maxCount); } IGraphServiceUsersCollectionPage result = await request.GetAsync(cancellationToken).ConfigureAwait(false); // The "Top" clause in Graph is just more about max number of results per page. // This is unlike SQL where by the results are capped to max. In this case we will just // take the result from the first page and don't move on. return(result.CurrentPage); }
public ExcelService(IGraphServiceClient client) { _client = client; }
/// <summary> /// 刪除訊息API /// </summary> /// <param name="graphClient"></param> /// <param name="mailId"></param> /// <returns></returns> private static async Task DeleteMessageAsync(IGraphServiceClient graphClient, string mailId) { await graphClient.Me.Messages[mailId].Request().DeleteAsync(); }
/// <summary> /// Initializes a new instance of the <see cref="GraphServiceFactory"/> class. /// </summary> /// <param name="serviceClient">Microsoft Graph service client.</param> public GraphServiceFactory( IGraphServiceClient serviceClient) { this.serviceClient = serviceClient ?? throw new ArgumentNullException(nameof(serviceClient)); }
/// <inheritdoc/> internal override async Task <List <CalendarSkillContactModel> > CallGraphServiceWithResultAsync(IGraphServiceClient client, IReadOnlyDictionary <string, object> parameters, CancellationToken cancellationToken) { var name = (string)parameters["Name"]; var results = new List <CalendarSkillContactModel>(); var optionList = new List <QueryOption>(); optionList.Add(new QueryOption("$search", $"\"{name}\"")); // Get the current user's profile. IUserContactsCollectionPage contacts = await client.Me.Contacts.Request(optionList).Select("displayName,emailAddresses,imAddresses").GetAsync(cancellationToken).ConfigureAwait(false); var contactsResult = new List <CalendarSkillContactModel>(); if (contacts?.Count > 0) { foreach (var contact in contacts) { var emailAddresses = contact.EmailAddresses.Where(e => this.IsEmail(e.Address)).Select(e => e.Address).ToList(); if (!emailAddresses.Any()) { emailAddresses = contact.ImAddresses.Where(e => this.IsEmail(e)).ToList(); } if (emailAddresses.Any()) { // Get user properties. contactsResult.Add(new CalendarSkillContactModel { Name = contact.DisplayName, EmailAddresses = emailAddresses, Id = contact.Id, }); } } } IUserPeopleCollectionPage people = await client.Me.People.Request(optionList).Select("displayName,emailAddresses").GetAsync(cancellationToken).ConfigureAwait(false); if (people?.Count > 0) { var existingResult = new HashSet <string>(contactsResult.SelectMany(c => c.EmailAddresses), StringComparer.OrdinalIgnoreCase); foreach (var person in people) { var emailAddresses = new List <string>(); foreach (var email in person.EmailAddresses) { // If the email address isn't already included in the contacts list, add it if (!existingResult.Contains(email.Address) && this.IsEmail(email.Address)) { emailAddresses.Add(email.Address); } } // Get user properties. if (emailAddresses.Any()) { results.Add(new CalendarSkillContactModel { Name = person.DisplayName, EmailAddresses = emailAddresses, Id = person.Id, }); } } } results.AddRange(contactsResult); return(results); }
public AlertFunctions(AlerterSecurity security, IGraphServiceClient graphClient) { this.security = security; this.graphClient = graphClient; }
/// <summary> /// 取得聯絡人資訊API /// </summary> /// <param name="graphClient"></param> /// <param name="Id"></param> /// <returns></returns> public static async Task <Contact> GetContact(IGraphServiceClient graphClient, string Id) { return(await graphClient.Me.Contacts[Id] .Request() .GetAsync()); }
/// <inheritdoc/> internal override async Task <List <CalendarSkillEventModel> > CallGraphServiceWithResultAsync(IGraphServiceClient client, IReadOnlyDictionary <string, object> parameters, CancellationToken cancellationToken) { var startProperty = (DateTime?)parameters["StartProperty"]; var endProperty = (DateTime?)parameters["EndProperty"]; var timeZoneProperty = (string)parameters["TimeZoneProperty"]; var dateTimeTypeProperty = (string)parameters["DateTimeTypeProperty"]; var isFuture = (bool)parameters["FutureEventsOnlyProperty"]; var maxResults = (int)parameters["MaxResultsProperty"]; var userEmail = (string)parameters["UserEmailProperty"]; var timeZone = GraphUtils.ConvertTimeZoneFormat((string)parameters["TimezoneProperty"]); // if start date is not provided, default to DateTime.Now var now = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, timeZone); // if datetime field just contains time but no date, use date today at use's timezone if (!dateTimeTypeProperty.Contains("date")) { if (startProperty != null) { startProperty = now.Date + startProperty.Value.TimeOfDay; } if (endProperty != null) { endProperty = now.Date + endProperty.Value.TimeOfDay; } } if (startProperty == null || startProperty.Value == DateTime.MinValue || (startProperty <= now && isFuture)) { startProperty = now; } // if end date is not provided, default to end of the current day if (endProperty == null || endProperty.Value == DateTime.MinValue) { endProperty = startProperty.Value.Date.AddHours(23).AddMinutes(59); } var parsedEvents = new List <CalendarSkillEventModel>(); // Define the time span for the calendar view. var queryOptions = new List <QueryOption> { // The API expects the parameters in UTC, but the datetimes come into the action in the user's timezone new QueryOption("startDateTime", TimeZoneInfo.ConvertTimeToUtc(startProperty.Value, timeZone).ToString("o")), new QueryOption("endDateTime", TimeZoneInfo.ConvertTimeToUtc(endProperty.Value, timeZone).ToString("o")), new QueryOption("$orderBy", "start/dateTime"), }; IUserCalendarViewCollectionPage events = await client.Me.CalendarView.Request(queryOptions).GetAsync(cancellationToken).ConfigureAwait(false); int index = 0; if (events?.Count > 0) { foreach (var ev in events) { parsedEvents.Add(this.ParseEvent(ev, timeZone, index++, userEmail)); } } while (events.NextPageRequest != null) { events = await events.NextPageRequest.GetAsync().ConfigureAwait(false); if (events?.Count > 0) { foreach (var ev in events) { parsedEvents.Add(this.ParseEvent(ev, timeZone, index++, userEmail)); } } } // Filter results by datetime if dateTimeType is a specific datetime if (dateTimeTypeProperty != null && dateTimeTypeProperty.Contains("time")) { parsedEvents = parsedEvents.Where(r => DateTime.Parse(r.Start.DateTime) == startProperty).ToList(); } parsedEvents = parsedEvents .Where(ev => ev.IsAllDay == false && DateTime.Parse(ev.Start.DateTime).Date >= startProperty.Value.Date) .OrderBy(ev => DateTime.Parse(ev.Start.DateTime).Date) .Take(maxResults) .ToList(); return(parsedEvents); }
public PersonalContactsApi(IGraphServiceClient graphClient) : base(graphClient) { }
/// <summary> /// 刪除聯絡人資訊API /// </summary> /// <param name="graphClient"></param> /// <param name="Id"></param> /// <returns></returns> public static async Task DeleteContact(IGraphServiceClient graphClient, string Id) { await graphClient.Me.Contacts[Id] .Request() .DeleteAsync(); }
public IUserService InitUserService(IGraphServiceClient graphClient, TimeZoneInfo info) { return(new MSGraphUserService(graphClient, info)); }
public OutlookApi(IGraphServiceClient graphClient) : base(graphClient) { }
public GraphClient(IGraphServiceClient graphServiceClient) { _graphServiceClient = graphServiceClient; }
/// <summary> /// 發送訊息API /// </summary> /// <param name="graphClient"></param> /// <param name="mailId"></param> /// <returns></returns> private static async Task SendMessageAsync(IGraphServiceClient graphClient, string mailId) { await graphClient.Me.Messages[mailId].Send().Request().PostAsync(); await Task.Delay(5000); }
internal async Task <WorkbookTable> GetExcelTableAsync(ExcelAttribute attr, CancellationToken token) { IGraphServiceClient client = await _clientProvider.GetMSGraphClientFromTokenAttributeAsync(attr, token); return(await client.GetTableWorkbookAsync(attr.Path, attr.TableName, token)); }
/// <summary> /// 取得訊息API /// </summary> /// <param name="graphClient"></param> /// <param name="mailId"></param> /// <returns></returns> private static async Task <Message> GetMessageAsync(IGraphServiceClient graphClient, string mailId) { return(await graphClient.Me.Messages[mailId].Request().GetAsync()); }
/// <inheritdoc/> internal override async Task CallGraphServiceAsync(IGraphServiceClient client, IReadOnlyDictionary <string, object> parameters, CancellationToken cancellationToken) { var eventId = (string)parameters["EventId"]; await client.Me.Events[eventId].TentativelyAccept("tentativelyAccept").Request().PostAsync().ConfigureAwait(false); }
public MSGraphUserService(IGraphServiceClient graphClient) { this._graphClient = graphClient; }
/// <summary> /// Initializes a new instance of the <see cref="MSGraphUserService"/> class. /// Init service use token. /// </summary> /// <param name="serviceClient">serviceClient.</param> /// <param name="timeZoneInfo">timeZoneInfo.</param> /// <returns>User service itself.</returns> public MSGraphUserService(IGraphServiceClient serviceClient, TimeZoneInfo timeZoneInfo) { this._graphClient = serviceClient; this._timeZoneInfo = timeZoneInfo; }
public MicrosoftGraphService(IGraphServiceClient graphClient) : base(graphClient) { _graphClient = graphClient; }
/// <summary> /// Initializes a new instance of the <see cref="MailService"/> class. /// Init service use token. /// </summary> /// <param name="token">access token.</param> /// <returns>Mail service itself.</returns> public async Task <IMailService> InitAsync(string token) { httpClient = ServiceHelper.GetHttpClient(token); graphServiceClient = ServiceHelper.GetAuthenticatedClient(token); return(await Task.FromResult(this)); }
private GraphService(IGraphServiceClient client) { _client = client; }
/// <summary> /// Initializes a new instance of the <see cref="GroupsService"/> class. /// </summary> /// <param name="graphServiceClient">graph service client.</param> public GroupsService(IGraphServiceClient graphServiceClient) { this.graphServiceClient = graphServiceClient; }
/// <summary> /// Initializes a new instance of the <see cref="UsersService"/> class. /// </summary> /// <param name="graphServiceClient">Microsoft Graph service client.</param> internal UsersService(IGraphServiceClient graphServiceClient) { this.graphServiceClient = graphServiceClient ?? throw new ArgumentNullException(nameof(graphServiceClient)); }
public GraphContactProvider(IGraphServiceClient serviceClient) { this._graphClient = serviceClient; }
public GraphGroupRepository(IGraphServiceClient graphServiceClient, TelemetryClient telemetryClient, ILoggingRepository logger) { _graphServiceClient = graphServiceClient; _telemetryClient = telemetryClient; _log = logger; }
private async Task <ServicePrincipal> GetServicePrincipalAsync(IGraphServiceClient client, string resourceAppId) { IGraphServiceServicePrincipalsCollectionPage servicePrincipal = await client.ServicePrincipals.Request().Filter($"AppId eq '{resourceAppId}'").GetAsync().ConfigureAwait(false); return(servicePrincipal[0]); }