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