microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.Apps/AppBuilder.cs
102lines · modecode
| 1 | using Microsoft.Teams.Apps.Plugins; |
| 2 | |
| 3 | namespace Microsoft.Teams.Apps; |
| 4 | |
| 5 | public partial class AppBuilder |
| 6 | { |
| 7 | protected AppOptions _options; |
| 8 | |
| 9 | public AppBuilder(AppOptions? options = null) |
| 10 | { |
| 11 | _options = options ?? new AppOptions(); |
| 12 | } |
| 13 | |
| 14 | public AppBuilder AddLogger(Common.Logging.ILogger logger) |
| 15 | { |
| 16 | _options.Logger = logger; |
| 17 | return this; |
| 18 | } |
| 19 | |
| 20 | public AppBuilder AddLogger(string? name = null, Common.Logging.LogLevel level = Common.Logging.LogLevel.Info) |
| 21 | { |
| 22 | _options.Logger = new Common.Logging.ConsoleLogger(name, level); |
| 23 | return this; |
| 24 | } |
| 25 | |
| 26 | public AppBuilder AddStorage<TStorage>(TStorage storage) where TStorage : Common.Storage.IStorage<string, object> |
| 27 | { |
| 28 | _options.Storage = storage; |
| 29 | return this; |
| 30 | } |
| 31 | |
| 32 | public AppBuilder AddClient(Common.Http.IHttpClient client) |
| 33 | { |
| 34 | _options.Client = client; |
| 35 | return this; |
| 36 | } |
| 37 | |
| 38 | public AppBuilder AddClient(Common.Http.IHttpClientFactory factory) |
| 39 | { |
| 40 | _options.ClientFactory = factory; |
| 41 | return this; |
| 42 | } |
| 43 | |
| 44 | public AppBuilder AddClient(Func<Common.Http.IHttpClient> @delegate) |
| 45 | { |
| 46 | _options.Client = @delegate(); |
| 47 | return this; |
| 48 | } |
| 49 | |
| 50 | public AppBuilder AddClient(Func<Task<Common.Http.IHttpClient>> @delegate) |
| 51 | { |
| 52 | _options.Client = @delegate().GetAwaiter().GetResult(); |
| 53 | return this; |
| 54 | } |
| 55 | |
| 56 | public AppBuilder AddCredentials(Common.Http.IHttpCredentials credentials) |
| 57 | { |
| 58 | _options.Credentials = credentials; |
| 59 | return this; |
| 60 | } |
| 61 | |
| 62 | public AppBuilder AddCredentials(Func<Common.Http.IHttpCredentials> @delegate) |
| 63 | { |
| 64 | _options.Credentials = @delegate(); |
| 65 | return this; |
| 66 | } |
| 67 | |
| 68 | public AppBuilder AddCredentials(Func<Task<Common.Http.IHttpCredentials>> @delegate) |
| 69 | { |
| 70 | _options.Credentials = @delegate().GetAwaiter().GetResult(); |
| 71 | return this; |
| 72 | } |
| 73 | |
| 74 | public AppBuilder AddPlugin(IPlugin plugin) |
| 75 | { |
| 76 | _options.Plugins.Add(plugin); |
| 77 | return this; |
| 78 | } |
| 79 | |
| 80 | public AppBuilder AddPlugin(Func<IPlugin> @delegate) |
| 81 | { |
| 82 | _options.Plugins.Add(@delegate()); |
| 83 | return this; |
| 84 | } |
| 85 | |
| 86 | public AppBuilder AddPlugin(Func<Task<IPlugin>> @delegate) |
| 87 | { |
| 88 | _options.Plugins.Add(@delegate().GetAwaiter().GetResult()); |
| 89 | return this; |
| 90 | } |
| 91 | |
| 92 | public AppBuilder AddOAuth(string defaultConnectionName) |
| 93 | { |
| 94 | _options.OAuth = new OAuthSettings(defaultConnectionName); |
| 95 | return this; |
| 96 | } |
| 97 | |
| 98 | public App Build() |
| 99 | { |
| 100 | return new App(_options); |
| 101 | } |
| 102 | } |