Beispiel #1
0
        public static async Task Main(string[] args)
        {
            // Use args in application
            new ArgsHelper().SetEnvironmentByArgs(args);

            var services = new ServiceCollection();

            // Setup AppSettings
            services = await SetupAppSettings.FirstStepToAddSingleton(services);

            // Inject services
            RegisterDependencies.Configure(services);
            var serviceProvider = services.BuildServiceProvider();
            var appSettings     = serviceProvider.GetRequiredService <AppSettings>();

            services.AddMonitoringWorkerService(appSettings, AppSettings.StarskyAppType.Importer);
            services.AddApplicationInsightsLogging(appSettings);

            new SetupDatabaseTypes(appSettings, services).BuilderDb();
            serviceProvider = services.BuildServiceProvider();

            var import           = serviceProvider.GetService <IImport>();
            var console          = serviceProvider.GetRequiredService <IConsole>();
            var exifToolDownload = serviceProvider.GetRequiredService <IExifToolDownload>();
            var webLogger        = serviceProvider.GetRequiredService <IWebLogger>();

            // Migrations before importing
            await RunMigrations.Run(serviceProvider.GetService <ApplicationDbContext>(), webLogger, appSettings);

            // Help and other Command Line Tools args are included in the ImporterCli
            await new ImportCli(import, appSettings, console, exifToolDownload).Importer(args);

            await new FlushApplicationInsights(serviceProvider, appSettings, webLogger).FlushAsync();
        }
Beispiel #2
0
        public static async Task Main(string[] args)
        {
            // Use args in application
            new ArgsHelper().SetEnvironmentByArgs(args);

            var services = new ServiceCollection();

            // Setup AppSettings
            services = await SetupAppSettings.FirstStepToAddSingleton(services);

            // Inject services
            RegisterDependencies.Configure(services);
            var serviceProvider = services.BuildServiceProvider();
            var appSettings     = serviceProvider.GetRequiredService <AppSettings>();

            services.AddMonitoringWorkerService(appSettings, AppSettings.StarskyAppType.Thumbnail);
            services.AddApplicationInsightsLogging(appSettings);

            new SetupDatabaseTypes(appSettings, services).BuilderDb();
            serviceProvider = services.BuildServiceProvider();

            var thumbnailService = serviceProvider.GetService <IThumbnailService>();
            var thumbnailCleaner = serviceProvider.GetService <IThumbnailCleaner>();

            var console         = serviceProvider.GetRequiredService <IConsole>();
            var selectorStorage = serviceProvider.GetRequiredService <ISelectorStorage>();

            // Help and other Command Line Tools args are included in the ThumbnailCLI
            await new ThumbnailCli(appSettings, console, thumbnailService, thumbnailCleaner, selectorStorage).Thumbnail(args);

            await new FlushApplicationInsights(serviceProvider).FlushAsync();
        }
Beispiel #3
0
        public static async Task Main(string[] args)
        {
            // Use args in application
            new ArgsHelper().SetEnvironmentByArgs(args);

            var services = new ServiceCollection();

            // Setup AppSettings
            services = await SetupAppSettings.FirstStepToAddSingleton(services);

            // Inject services
            RegisterDependencies.Configure(services);
            var serviceProvider = services.BuildServiceProvider();
            var appSettings     = serviceProvider.GetRequiredService <AppSettings>();

            serviceProvider = services.BuildServiceProvider();
            var selectorStorage = serviceProvider.GetRequiredService <ISelectorStorage>();

            var console = serviceProvider.GetRequiredService <IConsole>();
            var metaExifThumbnailService = serviceProvider.GetRequiredService <IMetaExifThumbnailService>();

            // Help and other Command Line Tools args are included in the Geo tools
            await new MetaThumbnailCommandLineHelper(selectorStorage,
                                                     appSettings, console, metaExifThumbnailService).CommandLineAsync(args);
        }
Beispiel #4
0
        /// <summary>
        /// Starsky Admin CLI to manage user admin tasks
        /// </summary>
        /// <param name="args">use -h to see all options</param>
        internal static async Task Main(string[] args)
        {
            // Use args in application
            new ArgsHelper().SetEnvironmentByArgs(args);

            var services = new ServiceCollection();

            // Setup AppSettings
            services = await SetupAppSettings.FirstStepToAddSingleton(services);

            // Inject services
            RegisterDependencies.Configure(services);
            var serviceProvider = services.BuildServiceProvider();
            var appSettings     = serviceProvider.GetRequiredService <AppSettings>();

            services.AddMonitoringWorkerService(appSettings, AppSettings.StarskyAppType.Geo);
            services.AddApplicationInsightsLogging(appSettings);

            var webLogger = serviceProvider.GetRequiredService <IWebLogger>();

            new SetupDatabaseTypes(appSettings, services).BuilderDb();
            serviceProvider = services.BuildServiceProvider();

            // Use args in application
            appSettings.Verbose = ArgsHelper.NeedVerbose(args);

            var userManager = serviceProvider.GetService <IUserManager>();

            appSettings.ApplicationType = AppSettings.StarskyAppType.Admin;

            if (new ArgsHelper().NeedHelp(args))
            {
                new ArgsHelper(appSettings).NeedHelpShowDialog();
                return;
            }

            await RunMigrations.Run(serviceProvider.GetService <ApplicationDbContext>(),
                                    webLogger, appSettings);

            await new ConsoleAdmin(userManager, new ConsoleWrapper()).Tool(
                ArgsHelper.GetName(args), ArgsHelper.GetUserInputPassword(args));

            await new FlushApplicationInsights(serviceProvider).FlushAsync();
        }
Beispiel #5
0
        public static async Task Main(string[] args)
        {
            // Use args in application
            new ArgsHelper().SetEnvironmentByArgs(args);

            // Setup AppSettings
            var services = await SetupAppSettings.FirstStepToAddSingleton(new ServiceCollection());

            // Inject services
            RegisterDependencies.Configure(services);
            var serviceProvider = services.BuildServiceProvider();
            var appSettings     = serviceProvider.GetRequiredService <AppSettings>();

            serviceProvider = services.BuildServiceProvider();

            var storageSelector   = serviceProvider.GetService <ISelectorStorage>();
            var console           = serviceProvider.GetRequiredService <IConsole>();
            var webRequestFactory = serviceProvider.GetRequiredService <IFtpWebRequestFactory>();

            new WebFtpCli(appSettings, storageSelector, console, webRequestFactory).Run(args);
        }
Beispiel #6
0
        public static async Task Main(string[] args)
        {
            // Use args in application
            new ArgsHelper().SetEnvironmentByArgs(args);
            var services = new ServiceCollection();

            services = await SetupAppSettings.FirstStepToAddSingleton(services);

            // Inject services
            RegisterDependencies.Configure(services);
            var serviceProvider = services.BuildServiceProvider();
            var appSettings     = serviceProvider.GetRequiredService <AppSettings>();

            serviceProvider = services.BuildServiceProvider();

            var publishPreflight = serviceProvider.GetService <IPublishPreflight>();
            var publishService   = serviceProvider.GetService <IWebHtmlPublishService>();
            var storageSelector  = serviceProvider.GetService <ISelectorStorage>();
            var console          = serviceProvider.GetRequiredService <IConsole>();

            // Help and args selectors are defined in the PublishCli
            await new PublishCli(storageSelector, publishPreflight, publishService, appSettings, console).Publisher(args);
        }
Beispiel #7
0
        public static async Task Main(string[] args)
        {
            // Use args in application
            new ArgsHelper().SetEnvironmentByArgs(args);

            var services = new ServiceCollection();

            // Setup AppSettings
            services = await SetupAppSettings.FirstStepToAddSingleton(services);

            // Inject services
            RegisterDependencies.Configure(services);
            var serviceProvider = services.BuildServiceProvider();
            var appSettings     = serviceProvider.GetRequiredService <AppSettings>();

            services.AddMonitoringWorkerService(appSettings, AppSettings.StarskyAppType.Geo);
            services.AddApplicationInsightsLogging(appSettings);

            new SetupDatabaseTypes(appSettings, services).BuilderDb();
            serviceProvider = services.BuildServiceProvider();

            var geoReverseLookup = serviceProvider.GetService <IGeoReverseLookup>();
            var geoLocationWrite = serviceProvider.GetRequiredService <IGeoLocationWrite>();
            var geoFileDownload  = serviceProvider.GetRequiredService <IGeoFileDownload>();

            var selectorStorage = serviceProvider.GetRequiredService <ISelectorStorage>();

            var console          = serviceProvider.GetRequiredService <IConsole>();
            var exifToolDownload = serviceProvider.GetRequiredService <IExifToolDownload>();

            // Help and other Command Line Tools args are included in the Geo tools
            await new GeoCli(geoReverseLookup, geoLocationWrite, selectorStorage,
                             appSettings, console, geoFileDownload, exifToolDownload).CommandLineAsync(args);

            await new FlushApplicationInsights(serviceProvider).FlushAsync();
        }
Beispiel #8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            _appSettings = SetupAppSettings.ConfigurePoCoAppSettings(services, _configuration);

            // before anything else
            EnableCompression(services);

            services.AddMemoryCache();
            // this is ignored here: appSettings.AddMemoryCache; but implemented in cache

            // Detect Application Insights (used in next SetupDatabaseTypes)
            services.AddMonitoring(_appSettings);

            // LoggerFactory
            services.AddApplicationInsightsLogging(_appSettings);

            var foundationDatabaseName = typeof(ApplicationDbContext).Assembly.FullName?.Split(",").FirstOrDefault();

            new SetupDatabaseTypes(_appSettings, services).BuilderDb(foundationDatabaseName);
            new SetupHealthCheck(_appSettings, services).BuilderHealth();

            // Enable Dual Authentication
            services
            .AddAuthentication(sharedOptions =>
            {
                sharedOptions.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
                sharedOptions.DefaultSignInScheme       = CookieAuthenticationDefaults.AuthenticationScheme;
                sharedOptions.DefaultChallengeScheme    = CookieAuthenticationDefaults.AuthenticationScheme;
            })
            .AddCookie(options =>
            {
                options.Cookie.Name              = "_id";
                options.ExpireTimeSpan           = TimeSpan.FromDays(60);
                options.SlidingExpiration        = false;
                options.Cookie.HttpOnly          = true;
                options.Cookie.IsEssential       = true;
                options.Cookie.Path              = "/";
                options.Cookie.SameSite          = SameSiteMode.Lax; // allow links from non-domain sites
                options.LoginPath                = "/account/login";
                options.LogoutPath               = "/account/logout";
                options.Events.OnRedirectToLogin = ReplaceReDirector(HttpStatusCode.Unauthorized, options.Events.OnRedirectToLogin);
            }
                       );

            // There is a base-cookie and in index controller there is an method to generate a token that is used to send with the header: X-XSRF-TOKEN
            services.AddAntiforgery(
                options =>
            {
                options.Cookie.Name         = "_af";
                options.Cookie.HttpOnly     = true; // only used by .NET, there is a separate method to generate a X-XSRF-TOKEN cookie
                options.Cookie.SameSite     = SameSiteMode.Lax;
                options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest;
                options.Cookie.Path         = "/";
                options.Cookie.IsEssential  = true;
                options.HeaderName          = "X-XSRF-TOKEN";
            }
                );

            // to add support for swagger
            new SwaggerSetupHelper(_appSettings).Add01SwaggerGenHelper(services);

            // Now only for dev
            services.AddCors(options =>
            {
                options.AddPolicy("CorsDevelopment",
                                  builder => builder
                                  .WithOrigins("http://localhost:4200",
                                               "http://localhost:8080")
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  .AllowCredentials());

                options.AddPolicy("CorsProduction",
                                  builder => builder
                                  .AllowCredentials());
            });



            services.AddMvcCore().AddApiExplorer().AddAuthorization().AddViews();

            ConfigureForwardedHeaders(services);

            // Application Insights
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            RegisterDependencies.Configure(services);

            // Reference due missing links between services
            services.AddSingleton <PackageTelemetryBackgroundService>();
        }