1
- using Cocona ;
2
- using Dataverse . ConfigurationMigrationTool . Console . Features . Import ;
1
+ using Dataverse . ConfigurationMigrationTool . Console . Features . Import ;
3
2
using Dataverse . ConfigurationMigrationTool . Console . Features . Shared ;
4
3
using Dataverse . ConfigurationMigrationTool . Console . Services . Dataverse ;
5
4
using Dataverse . ConfigurationMigrationTool . Console . Services . Dataverse . Configuration ;
11
10
using Microsoft . Extensions . Logging ;
12
11
using Microsoft . PowerPlatform . Dataverse . Client ;
13
12
using System . Reflection ;
14
-
15
- var builder = CoconaApp . CreateBuilder ( ) ;
16
- builder . Configuration
13
+ var builder = new HostBuilder ( ) ;
14
+ builder . ConfigureHostConfiguration ( ( config ) =>
15
+ {
16
+ // Configure the host configuration, such as environment variables, command line arguments, etc.
17
+ config . AddEnvironmentVariables ( ) ;
18
+ } ) ;
19
+ builder . ConfigureAppConfiguration ( ( context , config ) =>
20
+ {
21
+ config
17
22
. AddEnvironmentVariables ( )
18
23
. AddJsonFile ( "appsettings.json" , false , false )
19
- . AddJsonFile ( $ "appsettings.{ builder . Environment . EnvironmentName } .json", false , false ) ;
20
- Console . WriteLine ( $ "Using configuration file: appsettings.{ builder . Environment . EnvironmentName } .json") ;
21
- foreach ( var arg in args )
24
+ . AddJsonFile ( $ "appsettings.{ context . HostingEnvironment . EnvironmentName } .json", false , false ) ;
25
+ if ( ! context . HostingEnvironment . IsProduction ( ) )
26
+ {
27
+ //Secrets should never be in clear text in source controlled file such appsettings.json.
28
+ //For Developement, we therefore store them locally into UserSecrets Store, part of dotnet foundation.
29
+ //For Production, secrets can be either written into appsettings.Production.json file by pipeline
30
+ //or you can configure another Configuration Provider to provide the secrets like AzureKeyvault or Hashicorp Vault.
31
+ config . AddUserSecrets ( Assembly . GetExecutingAssembly ( ) ) ;
32
+ }
33
+ Console . WriteLine ( $ "Using configuration file: appsettings.{ context . HostingEnvironment . EnvironmentName } .json") ;
34
+ foreach ( var arg in context . Configuration . AsEnumerable ( ) )
35
+ {
36
+ Console . WriteLine ( $ "Configuration: { arg . Key } => { arg . Value } ") ;
37
+ }
38
+ } ) ;
39
+ builder . ConfigureServices ( ( context , services ) =>
22
40
{
23
- Console . WriteLine ( $ "Argument: { arg } ") ;
24
- }
25
- if ( ! builder . Environment . IsProduction ( ) )
26
- {
27
- //Secrets should never be in clear text in source controlled file such appsettings.json.
28
- //For Developement, we therefore store them locally into UserSecrets Store, part of dotnet foundation.
29
- //For Production, secrets can be either written into appsettings.Production.json file by pipeline
30
- //or you can configure another Configuration Provider to provide the secrets like AzureKeyvault or Hashicorp Vault.
31
- builder . Configuration . AddUserSecrets ( Assembly . GetExecutingAssembly ( ) ) ;
32
- }
33
- builder . Services
41
+
42
+ services
34
43
. AddLogging ( lb => lb . AddConsole ( ) )
35
- . Configure < SdkDataverseServiceFactoryOptions > ( builder . Configuration . GetSection ( "Dataverse" ) )
36
- . Configure < ParallelismBulkOrganizationServiceOptions > ( builder . Configuration . GetSection ( "Dataverse" ) )
44
+ . Configure < SdkDataverseServiceFactoryOptions > ( context . Configuration . GetSection ( "Dataverse" ) )
45
+ . Configure < ParallelismBulkOrganizationServiceOptions > ( context . Configuration . GetSection ( "Dataverse" ) )
37
46
. AddTransient < IImportDataProvider , FileReaderDataImportProvider > ( )
38
47
. AddSingleton < IFileDataReader , XmlFileDataReader > ( )
39
48
. AddTransient < IMetadataService , DataverseMetadataService > ( )
40
49
. AddTransient < ServiceClient > ( ( sp ) => ( ServiceClient ) sp . GetRequiredService < IDataverseClientFactory > ( ) . Create ( ) )
41
50
. AddSingleton < IBulkOrganizationService , ParallelismBulkOrganizationService > ( )
42
51
. AddDataverseClient ( )
43
52
. AddImportFeature ( ) ;
44
- Console . WriteLine ( $ "Services are completed") ;
45
- var app = builder . Build ( ) ;
46
- app . UseImportFeature ( ) ;
47
- Console . WriteLine ( $ "Running App") ;
48
- await app . RunAsync ( ) ;
53
+ // Configure other services.
54
+ } ) ;
55
+ builder . ConfigureCocona ( args , configureApplication : app =>
56
+ {
57
+ // Configure your app's commands normally as you would with app
58
+ app . UseImportFeature ( ) ;
59
+ } ) ;
60
+ await builder . RunConsoleAsync ( x => x . SuppressStatusMessages = true ) ;
61
+ //var builder = CoconaApp.CreateBuilder();
62
+ //builder.Configuration
63
+ // .AddEnvironmentVariables()
64
+ // .AddJsonFile("appsettings.json", false, false)
65
+ // .AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", false, false);
66
+ //Console.WriteLine($"Using configuration file: appsettings.{builder.Environment.EnvironmentName}.json");
67
+ //foreach (var arg in args)
68
+ //{
69
+ // Console.WriteLine($"Argument: {arg}");
70
+ //}
71
+ //if (!builder.Environment.IsProduction())
72
+ //{
73
+ // //Secrets should never be in clear text in source controlled file such appsettings.json.
74
+ // //For Developement, we therefore store them locally into UserSecrets Store, part of dotnet foundation.
75
+ // //For Production, secrets can be either written into appsettings.Production.json file by pipeline
76
+ // //or you can configure another Configuration Provider to provide the secrets like AzureKeyvault or Hashicorp Vault.
77
+ // builder.Configuration.AddUserSecrets(Assembly.GetExecutingAssembly());
78
+ //}
79
+ //builder.Services
80
+ // .AddLogging(lb => lb.AddConsole())
81
+ // .Configure<SdkDataverseServiceFactoryOptions>(builder.Configuration.GetSection("Dataverse"))
82
+ // .Configure<ParallelismBulkOrganizationServiceOptions>(builder.Configuration.GetSection("Dataverse"))
83
+ // .AddTransient<IImportDataProvider, FileReaderDataImportProvider>()
84
+ // .AddSingleton<IFileDataReader, XmlFileDataReader>()
85
+ // .AddTransient<IMetadataService, DataverseMetadataService>()
86
+ // .AddTransient<ServiceClient>((sp) => (ServiceClient)sp.GetRequiredService<IDataverseClientFactory>().Create())
87
+ // .AddSingleton<IBulkOrganizationService, ParallelismBulkOrganizationService>()
88
+ // .AddDataverseClient()
89
+ // .AddImportFeature();
90
+ //Console.WriteLine($"Services are completed");
91
+ //var app = builder.Build();
92
+ //app.UseImportFeature();
93
+ //Console.WriteLine($"Running App");
94
+ //await app.RunAsync();
0 commit comments