microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.Apps/AppBuilder.cs
123lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Microsoft.Teams.Api.Auth; |
| 5 | using Microsoft.Teams.Apps.Plugins; |
| 6 | |
| 7 | namespace Microsoft.Teams.Apps; |
| 8 | |
| 9 | public partial class AppBuilder |
| 10 | { |
| 11 | protected AppOptions _options; |
| 12 | |
| 13 | public AppBuilder(AppOptions? options = null) |
| 14 | { |
| 15 | _options = options ?? new AppOptions(); |
| 16 | } |
| 17 | |
| 18 | public AppBuilder AddLogger(Common.Logging.ILogger logger) |
| 19 | { |
| 20 | _options.Logger = logger; |
| 21 | return this; |
| 22 | } |
| 23 | |
| 24 | public AppBuilder AddLogger(string? name = null, Common.Logging.LogLevel level = Common.Logging.LogLevel.Info) |
| 25 | { |
| 26 | _options.Logger = new Common.Logging.ConsoleLogger(name, level); |
| 27 | return this; |
| 28 | } |
| 29 | |
| 30 | public AppBuilder AddStorage<TStorage>(TStorage storage) where TStorage : Common.Storage.IStorage<string, object> |
| 31 | { |
| 32 | _options.Storage = storage; |
| 33 | return this; |
| 34 | } |
| 35 | |
| 36 | public AppBuilder AddClient(Common.Http.IHttpClient client) |
| 37 | { |
| 38 | _options.Client = client; |
| 39 | return this; |
| 40 | } |
| 41 | |
| 42 | public AppBuilder AddClient(Common.Http.IHttpClientFactory factory) |
| 43 | { |
| 44 | _options.ClientFactory = factory; |
| 45 | return this; |
| 46 | } |
| 47 | |
| 48 | public AppBuilder AddClient(Func<Common.Http.IHttpClient> @delegate) |
| 49 | { |
| 50 | _options.Client = @delegate(); |
| 51 | return this; |
| 52 | } |
| 53 | |
| 54 | public AppBuilder AddClient(Func<Task<Common.Http.IHttpClient>> @delegate) |
| 55 | { |
| 56 | _options.Client = @delegate().GetAwaiter().GetResult(); |
| 57 | return this; |
| 58 | } |
| 59 | |
| 60 | public AppBuilder AddCredentials(Common.Http.IHttpCredentials credentials) |
| 61 | { |
| 62 | _options.Credentials = credentials; |
| 63 | return this; |
| 64 | } |
| 65 | |
| 66 | public AppBuilder AddCredentials(Func<Common.Http.IHttpCredentials> @delegate) |
| 67 | { |
| 68 | _options.Credentials = @delegate(); |
| 69 | return this; |
| 70 | } |
| 71 | |
| 72 | public AppBuilder AddCredentials(Func<Task<Common.Http.IHttpCredentials>> @delegate) |
| 73 | { |
| 74 | _options.Credentials = @delegate().GetAwaiter().GetResult(); |
| 75 | return this; |
| 76 | } |
| 77 | |
| 78 | public AppBuilder AddPlugin(IPlugin plugin) |
| 79 | { |
| 80 | _options.Plugins.Add(plugin); |
| 81 | return this; |
| 82 | } |
| 83 | |
| 84 | public AppBuilder AddPlugin(Func<IPlugin> @delegate) |
| 85 | { |
| 86 | _options.Plugins.Add(@delegate()); |
| 87 | return this; |
| 88 | } |
| 89 | |
| 90 | public AppBuilder AddPlugin(Func<Task<IPlugin>> @delegate) |
| 91 | { |
| 92 | _options.Plugins.Add(@delegate().GetAwaiter().GetResult()); |
| 93 | return this; |
| 94 | } |
| 95 | |
| 96 | public AppBuilder AddOAuth(string defaultConnectionName) |
| 97 | { |
| 98 | _options.OAuth = new OAuthSettings(defaultConnectionName); |
| 99 | return this; |
| 100 | } |
| 101 | |
| 102 | public AppBuilder AddCloud(CloudEnvironment cloud) |
| 103 | { |
| 104 | _options.Cloud = cloud; |
| 105 | return this; |
| 106 | } |
| 107 | |
| 108 | /// <summary> |
| 109 | /// When true, performs a per-activity user OAuth token lookup to populate |
| 110 | /// <c>IContext.IsSignedIn</c> / <c>IContext.UserGraphToken</c>. Set to false to |
| 111 | /// skip the call when SSO is not configured. Defaults to true. |
| 112 | /// </summary> |
| 113 | public AppBuilder AutoUserTokenLookup(bool enabled) |
| 114 | { |
| 115 | _options.AutoUserTokenLookup = enabled; |
| 116 | return this; |
| 117 | } |
| 118 | |
| 119 | public App Build() |
| 120 | { |
| 121 | return new App(_options); |
| 122 | } |
| 123 | } |