Beispiel #1
0
        public static IConfigurationBuilder AddCubesConfigurationProvider(this IConfigurationBuilder configuration,
                                                                          ICubesEnvironment cubes)
        {
            const string section     = CubesConstants.Configuration_Section;
            var          cubesConfig = new Dictionary <string, string>
            {
                { $"{section}:Version", cubes.GetEnvironmentInformation().FullVersion },
                { $"{section}:RootFolder", cubes.GetRootFolder() },
                { $"{section}:AdminPath", cubes.GetAdminPath() },
                { $"{section}:ContentFolder", cubes.GetFolder(CubesFolderKind.Content) },
                { $"{section}:LibrariesFolder", cubes.GetFolder(CubesFolderKind.Libraries) },
                { $"{section}:LogsFolder", cubes.GetFolder(CubesFolderKind.Logs) },
                { $"{section}:ConfigFolder", cubes.GetConfigurationFolder() },
                { $"{section}:StorageFolder", cubes.GetStorageFolder() },
                { $"{section}:TempFolder", cubes.GetFolder(CubesFolderKind.Temp) },
                { $"{section}:WebRootFolder", cubes.GetFolder(CubesFolderKind.WebRoot) },
                { $"{section}:BinariesFolder", cubes.GetBinariesFolder() },
            };
            var swaggerFiles = cubes
                               .GetSwaggerXmlFiles()
                               .Select((f, i) => new KeyValuePair <string, string>($"{section}:SwaggerXMLFiles:{i}", f))
                               .ToList();

            foreach (var item in swaggerFiles)
            {
                cubesConfig.Add(item.Key, item.Value);
            }

            configuration.AddInMemoryCollection(cubesConfig);
            return(configuration);
        }
        public void Save(Type configType, object configInstance)
        {
            var storeAttribute = configType.GetAttribute <ConfigurationStoreAttribute>();

            if (storeAttribute == null)
            {
                throw new ArgumentException($"No configuration storage attribute for type '{configType.Name}'.");
            }

            var path   = Path.Combine(_cubesEnvironment.GetFolder(storeAttribute.CubesFolder), storeAttribute.FilePath);
            var format = Path.GetExtension(path);

            if (format.StartsWith("."))
            {
                format = format.Substring(1);
            }

            var serializer = _serializers.Find(s => s.Format.Equals(format, StringComparison.CurrentCultureIgnoreCase));

            if (serializer == null)
            {
                throw new ArgumentException($"No serializer defined for format '{format}'.");
            }

            var toWrite = new ExpandoObject();

            toWrite.TryAdd(configType.Name, configInstance);

            var configRaw = serializer.Serialize(toWrite);

            File.WriteAllText(path, configRaw);
        }
        public static IConfigurationBuilder AddCubesConfigurationProvider(this IConfigurationBuilder configuration,
                                                                          ICubesEnvironment cubes)
        {
            var cubesConfig = new Dictionary <string, string>
            {
                { $"{CubesConstants.Configuration_Section}:Version", cubes.GetEnvironmentInformation().FullVersion },
                { $"{CubesConstants.Configuration_Section}:RootFolder", cubes.GetRootFolder() },
                { $"{CubesConstants.Configuration_Section}:AppsFolder", cubes.GetAppsFolder() },
                { $"{CubesConstants.Configuration_Section}:LogsFolder", cubes.GetFolder(CubesFolderKind.Logs) },
                { $"{CubesConstants.Configuration_Section}:SettingsFolder", cubes.GetSettingsFolder() },
                { $"{CubesConstants.Configuration_Section}:StorageFolder", cubes.GetStorageFolder() },
                { $"{CubesConstants.Configuration_Section}:TempFolder", cubes.GetFolder(CubesFolderKind.Temp) },
                { $"{CubesConstants.Configuration_Section}:StaticContentFolder", cubes.GetFolder(CubesFolderKind.Content) },
                { $"{CubesConstants.Configuration_Section}:BinariesFolder", cubes.GetBinariesFolder() },
            };
            var swaggerFiles = cubes
                               .GetSwaggerFiles()
                               .Select((f, i) => new KeyValuePair <string, string>($"{CubesConstants.Configuration_Section}:SwaggerFiles:{i}", f))
                               .ToList();

            foreach (var item in swaggerFiles)
            {
                cubesConfig.Add(item.Key, item.Value);
            }

            var allAssembliesWithControllers = cubes
                                               .GetActivatedApplications()
                                               .SelectMany(app => app.AssembliesWithControllers.ToList())
                                               .Select((f, i) => new KeyValuePair <string, string>($"{CubesConstants.Configuration_Section}:AssembliesWithControllers:{i}", f))
                                               .ToList();

            foreach (var item in allAssembliesWithControllers)
            {
                cubesConfig.Add(item.Key, item.Value);
            }

            configuration.AddInMemoryCollection(cubesConfig);
            return(configuration);
        }
        public static IHostBuilder CreateHostBuilder(string[] args, ICubesEnvironment cubes)
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(cubes.GetBinariesFolder())
                                .AddJsonFile(CubesConstants.Config_AppSettings, optional: false)
                                .AddCommandLine(args)
                                .Build();
            var urls = configuration.GetValue <string>(CubesConstants.Config_HostURLs, "http://localhost:3001");

            return(Microsoft.Extensions.Hosting.Host
                   .CreateDefaultBuilder(args)
                   .UseServiceProviderFactory(new AutofacServiceProviderFactory())
                   .UseWindowsService()
                   .UseContentRoot(cubes.GetRootFolder())
                   .ConfigureAppConfiguration((builder, config) =>
            {
                config.SetBasePath(cubes.GetBinariesFolder());
                config.AddCubesConfiguration(cubes);
                config.AddApplicationsConfiguration(cubes);
            })
                   .ConfigureLogging(logging =>
            {
                logging.ClearProviders();
                logging.AddNLog();
            })
                   .ConfigureContainer <ContainerBuilder>(builder =>
            {
                builder
                .RegisterCubeServices()
                .RegisterApplicationServices(cubes);
            })
                   .ConfigureServices((builder, services) =>
            {
                services.AddSingleton(cubes);
                services.AddCubesCore(builder.Configuration);

                services.AddApplicationsServices(cubes);
            })
                   .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup <Startup>();
                webBuilder.UseUrls(urls);
                webBuilder.UseWebRoot(cubes.GetFolder(CubesFolderKind.Content));
            }));
        }
Beispiel #5
0
 private static IHostBuilder CreateHostBuilder(string[] args, ICubesEnvironment cubes)
 => Microsoft.Extensions.Hosting.Host
 .CreateDefaultBuilder(args)
 .UseServiceProviderFactory(new AutofacServiceProviderFactory())
 .UseWindowsService()
 .UseContentRoot(cubes.GetRootFolder())
 .ConfigureAppConfiguration((_, configBuilder) =>
 {
     configBuilder
     .SetBasePath(cubes.GetBinariesFolder())
     .AddCubesConfiguration(cubes)
     .AddApplicationsConfiguration(cubes);
 })
 .ConfigureLogging(logging =>
 {
     logging
     .ClearProviders()
     .AddNLog();
 })
 .ConfigureContainer <ContainerBuilder>(builder =>
 {
     builder
     .RegisterCubeServices()
     .RegisterApplicationServices(cubes);
 })
 .ConfigureServices((builder, services) =>
 {
     services
     .AddSingleton(cubes)
     .AddCubesCore(builder.Configuration)
     .AddApplicationsServices(builder.Configuration, cubes);
 })
 .ConfigureWebHostDefaults(webBuilder =>
 {
     webBuilder
     .UseStartup <Startup>()
     .UseWebRoot(cubes.GetFolder(CubesFolderKind.WebRoot));
 });
 public static string GetFileOnPath(this ICubesEnvironment cubesEnvironment,
                                    CubesFolderKind folderKind,
                                    string fileName)
 => Path.Combine(cubesEnvironment.GetFolder(folderKind), fileName);
 public static string GetStorageFolder(this ICubesEnvironment cubesEnvironment)
 => cubesEnvironment.GetFolder(CubesFolderKind.Storage);
 public static string GetSettingsFolder(this ICubesEnvironment cubesEnvironment)
 => cubesEnvironment.GetFolder(CubesFolderKind.Settings);
 public static string GetAppsFolder(this ICubesEnvironment cubesEnvironment)
 => cubesEnvironment.GetFolder(CubesFolderKind.Apps);
 public static string GetRootFolder(this ICubesEnvironment cubesEnvironment)
 => cubesEnvironment.GetFolder(CubesFolderKind.Root);
 public static string GetConfigurationFolder(this ICubesEnvironment cubesEnvironment)
 => cubesEnvironment.GetFolder(CubesFolderKind.Config);