Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
        public async Task MergeJsonFiles_NoFileFound()
        {
            var testDir = Path.Combine(new AppSettings().BaseDirectoryProject, "_not_found");
            var result  = await SetupAppSettings.MergeJsonFiles(testDir);

            Assert.AreEqual(result.Verbose, new AppSettings().Verbose);
        }
Ejemplo n.º 5
0
        public async Task SetLocalAppData_ShouldRead()
        {
            var appDataFolderFullPath =
                Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "setup_app_settings_test");

            _hostStorage.CreateDirectory(appDataFolderFullPath);
            var path = Path.Combine(appDataFolderFullPath, "appsettings.json");

            var example =
                new PlainTextFileHelper().StringToStream(
                    "{\n \"app\" :{\n   \"isAccountRegisterOpen\": \"true\"\n }\n}\n");

            await _hostStorage.WriteStreamAsync(example, path);

            Environment.SetEnvironmentVariable("app__appsettingspath", path);
            var builder = await SetupAppSettings.AppSettingsToBuilder();

            var services    = new ServiceCollection();
            var appSettings = SetupAppSettings.ConfigurePoCoAppSettings(services, builder);

            Assert.IsFalse(string.IsNullOrEmpty(appSettings.AppSettingsPath));
            Assert.IsTrue(appSettings.IsAccountRegisterOpen);
            Assert.AreEqual(path, appSettings.AppSettingsPath);

            _hostStorage.FolderDelete(appDataFolderFullPath);
            Environment.SetEnvironmentVariable("app__appsettingspath", null);
        }
Ejemplo n.º 6
0
        public async Task MergeJsonFiles_StackFromEnv()
        {
            var testDir = Path.Combine(new AppSettings().BaseDirectoryProject, "_test");

            _hostStorage.FolderDelete(testDir);
            _hostStorage.CreateDirectory(testDir);

            await _hostStorage.WriteStreamAsync(new PlainTextFileHelper().StringToStream(
                                                    "{\n  \"app\": {\n   " +
                                                    " \"StorageFolder\": \"/data/test\",\n \"addSwagger\": \"true\" " +
                                                    " }\n}\n"), Path.Combine(testDir, "appsettings.json"));

            await _hostStorage.WriteStreamAsync(new PlainTextFileHelper().StringToStream(
                                                    "{\n  \"app\": {\n  \"addSwagger\": \"false\" " +
                                                    " }\n}\n"), Path.Combine(testDir, "appsettings_ref_patch.json"));

            Environment.SetEnvironmentVariable("app__appsettingspath", Path.Combine(testDir, "appsettings_ref_patch.json"));

            var result = await SetupAppSettings.MergeJsonFiles(testDir);

            Assert.AreEqual(PathHelper.AddBackslash("/data/test"), result.StorageFolder);
            Assert.AreEqual(false, result.AddSwagger);

            Environment.SetEnvironmentVariable("app__appsettingspath", null);
        }
Ejemplo n.º 7
0
        public async Task SetLocalAppData_ShouldTakeDefault()
        {
            Environment.SetEnvironmentVariable("app__appsettingspath", null);

            var builder = await SetupAppSettings.AppSettingsToBuilder();

            var services    = new ServiceCollection();
            var appSettings = SetupAppSettings.ConfigurePoCoAppSettings(services, builder);

            var expectedPath = Path.Combine(appSettings.BaseDirectoryProject, "appsettings.patch.json");

            Assert.AreEqual(expectedPath, appSettings.AppSettingsPath);
            Assert.IsFalse(appSettings.IsAccountRegisterOpen);
        }
Ejemplo n.º 8
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();
        }
Ejemplo n.º 9
0
        public async Task MergeJsonFiles_DefaultFile()
        {
            var testDir = Path.Combine(new AppSettings().BaseDirectoryProject, "_test");

            if (_hostStorage.ExistFolder(testDir))
            {
                _hostStorage.FolderDelete(testDir);
            }
            _hostStorage.CreateDirectory(testDir);

            await _hostStorage.WriteStreamAsync(new PlainTextFileHelper().StringToStream(
                                                    "{\n  \"app\": {\n   " +
                                                    " \"StorageFolder\": \"/data/test\"\n " +
                                                    " }\n}\n"), Path.Combine(testDir, "appsettings.json"));

            var result = await SetupAppSettings.MergeJsonFiles(testDir);

            Assert.AreEqual(PathHelper.AddBackslash("/data/test"), result.StorageFolder);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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();
        }
Ejemplo n.º 13
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>();
        }
Ejemplo n.º 14
0
 public Startup()
 {
     Console.WriteLine("app__appsettingspath: " + Environment.GetEnvironmentVariable("app__appsettingspath"));
     _configuration = SetupAppSettings.AppSettingsToBuilder().Result;
 }