/// <inheritdoc/> public async Task <bool> IsAppInstalledForUserAsync(string appId, string userId) { if (string.IsNullOrWhiteSpace(appId)) { throw new ArgumentNullException(nameof(appId)); } if (string.IsNullOrWhiteSpace(userId)) { throw new ArgumentNullException(nameof(userId)); } var retryPolicy = PollyPolicy.GetGraphRetryPolicy(GraphConstants.MaxRetry); var pagedApps = await retryPolicy.ExecuteAsync(async() => await this.graphServiceClient.Users[userId] .Teamwork .InstalledApps .Request() .Expand("teamsApp") .Filter($"teamsApp/id eq '{appId}'") .WithMaxRetry(GraphConstants.MaxRetry) .GetAsync()); return(pagedApps.CurrentPage.Any()); }
private PollyPolicy GetPollyPolicy() { PollyPolicy pollyPolicy = new PollyPolicy(); pollyPolicy.RetryPolicy = new RetryPolicy(3); return(pollyPolicy); }
/// <inheritdoc/> public async Task InstallAppForTeamAsync(string appId, string teamId) { if (string.IsNullOrWhiteSpace(appId)) { throw new ArgumentNullException(nameof(appId)); } if (string.IsNullOrWhiteSpace(teamId)) { throw new ArgumentNullException(nameof(teamId)); } var userScopeTeamsAppInstallation = new TeamsAppInstallation() { AdditionalData = new Dictionary <string, object>() { { "*****@*****.**", $"{GraphConstants.V1BaseUrl}/appCatalogs/teamsApps/{appId}" }, }, }; var retryPolicy = PollyPolicy.GetGraphRetryPolicy(GraphConstants.MaxRetry); await retryPolicy.ExecuteAsync(async() => await this.graphServiceClient.Teams[teamId] .InstalledApps .Request() .WithMaxRetry(GraphConstants.MaxRetry) .AddAsync(userScopeTeamsAppInstallation)); }
public PolicyFactory() { PollyPolicy pollyPolicy = GetPollyPolicy(); this._asyncPolicy = GetAsyncPolicyConfigs(pollyPolicy.Policies); this._syncPolicy = GetSyncPolicyConfigs(pollyPolicy.Policies); }
/// <inheritdoc/> public async Task <string> GetChatThreadIdAsync(string userId, string appId) { if (string.IsNullOrWhiteSpace(userId)) { throw new ArgumentNullException(nameof(userId)); } if (string.IsNullOrWhiteSpace(appId)) { throw new ArgumentNullException(nameof(appId)); } var installationId = await this.appManagerService.GetAppInstallationIdForUserAsync(appId, userId); var retryPolicy = PollyPolicy.GetGraphRetryPolicy(GraphConstants.MaxRetry); var chat = await retryPolicy.ExecuteAsync(async() => await this.graphServiceClient.Users[userId] .Teamwork .InstalledApps[installationId] .Chat .Request() .WithMaxRetry(GraphConstants.MaxRetry) .GetAsync()); return(chat?.Id); }
public void InitTest1() { PollyPolicy policy = new PollyPolicy(); Assert.Empty(policy.Policies); Assert.Null(policy.BreakerPolicy); }
public void InitTest2() { PollyPolicy policy = new PollyPolicy(); policy.RetryPolicy = new RetryPolicy(3, 500); Assert.NotEmpty(policy.Policies); Assert.NotNull(policy.RetryPolicy); Assert.Null(policy.BreakerPolicy); Assert.Null(policy.TimeoutPolicy); Assert.Null(policy.FallBackPolicy); policy = new PollyPolicy(); policy.BreakerPolicy = new BreakerPolicy(); Assert.NotNull(policy.BreakerPolicy); policy = new PollyPolicy(); policy.TimeoutPolicy = new TimeoutPolicy(100); Assert.NotNull(policy.TimeoutPolicy); policy = new PollyPolicy(); policy.FallBackPolicy = null; Assert.Null(policy.FallBackPolicy); }
/// <inheritdoc/> public async Task <string> GetAppInstallationIdForTeamAsync(string appId, string teamId) { if (string.IsNullOrWhiteSpace(appId)) { throw new ArgumentNullException(nameof(appId)); } if (string.IsNullOrWhiteSpace(teamId)) { throw new ArgumentNullException(nameof(teamId)); } var retryPolicy = PollyPolicy.GetGraphRetryPolicy(GraphConstants.MaxRetry); var collection = await retryPolicy.ExecuteAsync(async() => await this.graphServiceClient.Teams[teamId] .InstalledApps .Request() .Expand("teamsApp") .Filter($"teamsApp/id eq '{appId}'") .WithMaxRetry(GraphConstants.MaxRetry) .GetAsync()); return(collection?.FirstOrDefault().Id); }