コード例 #1
0
ファイル: Common.cs プロジェクト: Poyser1911/Cod4.Monitor
        public static Config GetConfig(string configfileName)
        {
            Config config = null;

            if (File.Exists(configfileName))
            {
                try
                {
                    Console.WriteLine("Reading Config..");
                    config = JsonConvert.DeserializeObject <Config>(File.ReadAllText(configfileName));
                    Console.WriteLine("Config Loaded");
                }
                catch (Exception e) { Common.FatalError("Error While Loading Config", e.Message); }
            }
            else
            {
                try
                {
                    Console.WriteLine($"{configfileName} not found..\n<Build New>");
                    config = ConfigBuilder.Build();
                    Console.WriteLine("Saving Config..");
                    File.WriteAllText(configfileName, JsonConvert.SerializeObject(config));
                    Console.WriteLine("Config Saved");
                }
                catch (Exception e)
                { Common.FatalError("Error While Building Config", e.Message); }
            }
            return(config);
        }
コード例 #2
0
ファイル: Startup.cs プロジェクト: guy-lud/CrawlerDemo
        public void ConfigureContainer(Container container)
        {
            var config     = new ConfigBuilder();
            var collection = new AssemblyCollection()
                             .AddPublicTypesAssemblies(GetType().GetTypeInfo().Assembly,
                                                       typeof(Ref).Assembly,
                                                       typeof(DomainRef).Assembly);

            config.Add(new ExistAll.SimpleConfig.Binders.ConfigurationBinder(Configuration));

            var settings = config.Build(collection.Assemblies, new ConfigOptions()
            {
                ConfigSuffix = "Settings"
            });

            foreach (var setting in settings)
            {
                container.RegisterSingleton(setting.Key, setting.Value);
            }

            container.RegisterSingleton <ISystemClock, SystemClock>();
            container.RegisterSingleton <ISiteCrawler, HttpSiteCrawler>();
            container.RegisterDecorator <ISiteCrawler, CacheHttpSiteCrawler>();
            container.RegisterSingleton <ISiteRepository, SiteRepository>();
            container.RegisterSingleton <ICrawlerSiteRequestValidator, SiteInfoRequestValidator>();
        }
コード例 #3
0
        private void BeforeBuildInitService()
        {
            SmartSqlConfig                  = ConfigBuilder.Build(_importProperties);
            SmartSqlConfig.Alias            = Alias;
            SmartSqlConfig.LoggerFactory    = LoggerFactory;
            SmartSqlConfig.DataSourceFilter = DataSourceFilter ?? new DataSourceFilter(SmartSqlConfig.LoggerFactory);
            if (_isCacheEnabled.HasValue)
            {
                SmartSqlConfig.Settings.IsCacheEnabled = _isCacheEnabled.Value;
            }

            if (InvokeSucceeded != null)
            {
                SmartSqlConfig.InvokeSucceedListener.InvokeSucceeded += (sender, args) =>
                {
                    InvokeSucceeded(args.ExecutionContext);
                };
            }

            SmartSqlConfig.SqlParamAnalyzer = new SqlParamAnalyzer(SmartSqlConfig.Settings.IgnoreParameterCase,
                                                                   SmartSqlConfig.Database.DbProvider.ParameterPrefix);

            InitDeserializerFactory();
            InitFilters();
            BuildPipeline();
        }
コード例 #4
0
ファイル: ModuleTest.cs プロジェクト: lucax88x/time-tracker
        public ModuleTest()
        {
            _scopeResolver = new ScopeResolver();

            var configBuilder = new ConfigBuilder();

            _scopeResolver.BuildContainer(new Config.Ioc.Module(configBuilder.Build()), new Application.Ioc.Module());
        }
コード例 #5
0
ファイル: ModuleTest.cs プロジェクト: lucax88x/time-tracker
        public ModuleTest()
        {
            _scopeResolver = new ScopeResolver();

            var configBuilder = new ConfigBuilder();

            _scopeResolver.BuildContainer(new Config.Ioc.Module(configBuilder.Build()), new Infra.Read.Core.Ioc.Module());
        }
コード例 #6
0
ファイル: ModuleTest.cs プロジェクト: lucax88x/time-tracker
        public ModuleTest()
        {
            _scopeResolver = new ScopeResolver();

            var configBuilder = new ConfigBuilder();

            _scopeResolver.BuildContainer(new Module(configBuilder.Build()));
        }
コード例 #7
0
ファイル: ModuleTest.cs プロジェクト: lucax88x/time-tracker
        public ModuleTest()
        {
            _scopeResolver = new ScopeResolver();

            var configBuilder = new ConfigBuilder();

            _scopeResolver.BuildContainer(new Config.Ioc.Module(configBuilder.Build()), new TimeTracker.Utils.Ioc.Module());
        }
コード例 #8
0
        static void Main(string[] args)
        {
            var config = ConfigBuilder.Build("appsettings");

            Parser.Default.ParseArguments <Read, TreeMap>(args)
            .WithParsed <Read>(c => c.Run(config))
            .WithParsed <TreeMap>(c => { })
            .WithNotParsed(e => { });
        }
コード例 #9
0
        public Configuration()
        {
            if (!File.Exists(FileConfig))
            {
                File.Create(FileConfig).Close();
                SaveConfig();
            }

            ConfigBuilder.AddJsonFile(FileConfig);
            ConfigBuilder.Build().Bind(ConfigData);
        }
コード例 #10
0
ファイル: ModuleTest.cs プロジェクト: arialdomartini/kairos
        public ModuleTest()
        {
            _scopeResolver = new ScopeResolver();

            var configBuilder = new ConfigBuilder();

            _scopeResolver.BuildContainer(
                new Module(configBuilder.Build(), new ModuleOptions {
                HasReadRepository = true
            }),
                new Read.Ioc.Module());
        }
コード例 #11
0
 private void BeforeBuildInitService()
 {
     SmartSqlConfig = ConfigBuilder.Build(_importProperties);
     SmartSqlConfig.LoggerFactory    = LoggerFactory;
     SmartSqlConfig.DataSourceFilter = _dataSourceFilter ?? new DataSourceFilter(SmartSqlConfig.LoggerFactory);
     if (_isCacheEnabled.HasValue)
     {
         SmartSqlConfig.Settings.IsCacheEnabled = _isCacheEnabled.Value;
     }
     SmartSqlConfig.SqlParamAnalyzer = new SqlParamAnalyzer(SmartSqlConfig.Settings.IgnoreParameterCase, SmartSqlConfig.Database.DbProvider.ParameterPrefix);
     BuildPipeline();
 }
コード例 #12
0
        public ReadRepositoryTests()
        {
            var configBuilder = new ConfigBuilder();

            _sandbox = new Sandbox(
                new SandboxOptions(),
                new Config.Ioc.Module(configBuilder.Build(), new ModuleOptions {
                HasReadRepository = true
            }),
                new Module());

            _sut = _sandbox.Resolve <ReadRepositoryFactory>().Build("read");
        }
コード例 #13
0
        public Bot()
        {
            var config = ConfigBuilder.Build();

            _config = config;

            _discord = new DiscordClient(config.DiscordConfiguration);

            _commands = _discord.UseCommandsNext(config.CommandsNextConfiguration);

            _commands.RegisterCommands <Commands>();

            _interactivity = _discord.UseInteractivity(new InteractivityConfiguration());
        }
コード例 #14
0
        private void BeforeBuildInitService()
        {
            var rootConfigBuilder = new RootConfigBuilder(ImportProperties);

            if (ConfigBuilder.Parent == null)
            {
                ConfigBuilder.SetParent(rootConfigBuilder);
            }

            if (IsUseCUDConfigBuilder)
            {
                ConfigBuilder = new CUDConfigBuilder(ConfigBuilder, EntityTypes, LoggerFactory);
            }

            SmartSqlConfig                  = ConfigBuilder.Build();
            SmartSqlConfig.Alias            = Alias;
            SmartSqlConfig.LoggerFactory    = LoggerFactory;
            SmartSqlConfig.DataSourceFilter = DataSourceFilter ?? new DataSourceFilter(SmartSqlConfig.LoggerFactory);
            SmartSqlConfig.CommandExecuter  =
                CommandExecuter ?? new CommandExecuter(LoggerFactory.CreateLogger <CommandExecuter>());
            if (IsCacheEnabled.HasValue)
            {
                SmartSqlConfig.Settings.IsCacheEnabled = IsCacheEnabled.Value;
            }

            if (IgnoreDbNull.HasValue)
            {
                SmartSqlConfig.Settings.IgnoreDbNull = IgnoreDbNull.Value;
            }

            if (InvokeSucceeded != null)
            {
                SmartSqlConfig.InvokeSucceedListener.InvokeSucceeded += (sender, args) =>
                {
                    InvokeSucceeded(args.ExecutionContext);
                };
            }

            SmartSqlConfig.SqlParamAnalyzer = new SqlParamAnalyzer(SmartSqlConfig.Settings.IgnoreParameterCase,
                                                                   SmartSqlConfig.Database.DbProvider.ParameterPrefix);
            SmartSqlConfig.CacheTemplateAnalyzer = new SqlParamAnalyzer(SmartSqlConfig.Settings.IgnoreParameterCase,
                                                                        SmartSqlConfig.Settings.ParameterPrefix);
            InitDeserializerFactory();
            InitFilters();
            InitTypeHandlers();
            BuildPipeline();
        }
コード例 #15
0
        /// <summary>
        /// Save a flow with the gui input
        /// </summary>
        /// <param name="flowConfig"></param>
        /// <returns></returns>
        public async Task <Result> SaveFlowConfig(FlowGuiConfig flowConfig)
        {
            var config = await ConfigBuilder.Build(flowConfig);

            var existingFlow = await FlowData.GetByName(config.Name);

            Result result = null;

            if (existingFlow != null)
            {
                existingFlow.Gui = config.Gui;
                existingFlow.CommonProcessor.Template            = config.CommonProcessor.Template;
                existingFlow.CommonProcessor.SparkJobTemplateRef = config.CommonProcessor.SparkJobTemplateRef;
                existingFlow.DisplayName = config.DisplayName;
                config = existingFlow;
                result = await FlowData.UpdateGuiForFlow(config.Name, config.Gui);

                if (result.IsSuccess)
                {
                    result = await FlowData.UpdateCommonProcessorForFlow(config.Name, config.CommonProcessor);
                }
            }
            else
            {
                result = await this.FlowData.Upsert(config);
            }

            if (result.IsSuccess)
            {
                // pass the generated config back with the result
                var properties = new Dictionary <string, object>()
                {
                    { FlowConfigPropertyName, config }
                };

                if (result.Properties != null)
                {
                    result.Properties.AppendDictionary(properties);
                }
                else
                {
                    result.Properties = properties;
                }
            }
            return(result);
        }
        public virtual XmlDocument GetShowconfig(bool normalize = false)
        {
            using (new ProfileSection("Computing showconfig", this))
            {
                try
                {
                    ProfileSection.Argument("normalize", normalize);

                    var showConfig = ConfigBuilder.Build(WebConfigPath, false, normalize);

                    return(ProfileSection.Result(showConfig));
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException($"Failed to get showconfig of {Instance.WebRootPath}", ex);
                }
            }
        }
        public virtual XmlDocument GetWebConfigResult(bool normalize = false)
        {
            using (new ProfileSection("Computing web config result", this))
            {
                try
                {
                    ProfileSection.Argument("normalize", normalize);

                    var webConfigResult = ConfigBuilder.Build(WebConfigPath, true, normalize);

                    return(ProfileSection.Result(webConfigResult));
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException($"Failed to get web config result of {Instance.WebRootPath}", ex);
                }
            }
        }
        public void OneTimeSetUp()
        {
            var config = ConfigBuilder.Build();

            repository = new OrderRepositoryDapperSql(config.GetConnectionString("DefaultConnection"));
        }
コード例 #19
0
 /// <summary>
 ///     添加自定义的json文件配置到系统配置,PS:因是后期加入,取值优先级较高 bob 2019-07-13
 /// </summary>
 /// <param name="jsonFileName">相对当前应用工作路径的json配置文件地址</param>
 /// <param name="optional">该配置文件是否可选:false = 必需,但找不到该文件时会抛出异常;true = 可选,该配置文件不是必需的</param>
 /// <returns></returns>
 public static ConfigurationBuilder AddJsonFile(string jsonFileName, bool optional = false)
 {
     ConfigBuilder.AddJsonFile(jsonFileName, optional, true);
     ConfigRoot = (ConfigurationRoot)ConfigBuilder.Build();
     return(ConfigBuilder);
 }
コード例 #20
0
 /// <summary>
 ///     添加内存数据到系统配置中,PS:因是后期加入,取值优先级高。 典型应用场景如:在测试项目中,需要指定不同的配置值来做值覆盖测试 bob 2019-07-13
 /// </summary>
 /// <param name="dic">配置数据</param>
 /// <returns></returns>
 public static ConfigurationBuilder AddInMemoryCollection(Dictionary <string, string> dic)
 {
     ConfigBuilder.AddInMemoryCollection(dic);
     ConfigRoot = (ConfigurationRoot)ConfigBuilder.Build();
     return(ConfigBuilder);
 }
コード例 #21
0
ファイル: WebHostBase.cs プロジェクト: 0xc0dec/draft
 protected WebHostBase(string[] cmd)
 {
     Config = ConfigBuilder.Build(cmd, Directory.GetCurrentDirectory());
 }
コード例 #22
0
        public static XmlDocument GetConfiguration([NotNull] IDirectory webRoot)
        {
            Assert.ArgumentNotNull(webRoot, nameof(webRoot));
            var webConfigFile = webRoot.GetChildFile("web.config");

            if (!webConfigFile.Exists)
            {
                return(null);
            }

            // workaround for asp.net hosting doesn't let config builder work (due to appdomain)
            var configuration  = new XmlDocument();
            var showConfigFile = webRoot.GetChildFile("Runtime/showconfig.xml");

            if (showConfigFile.Exists)
            {
                using (var webConfigStream = webConfigFile.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    configuration.Load(webConfigStream);
                }

                var sitecoreNode   = configuration.SelectSingleElement("/configuration/sitecore");
                var showConfigText = showConfigFile.ReadAllText();
                var showConfigXml  = new XmlDocument();
                showConfigXml.LoadXml(showConfigText);

                sitecoreNode.SetAttribute("xmlns:patch", "http://www.sitecore.net/xmlconfig/");
                sitecoreNode.InnerXml = showConfigXml.SelectSingleElement("/sitecore").InnerXml;
            }
            else
            {
                configuration = ConfigBuilder.Build(webConfigFile.FullName, true, true);
            }

            var configurationElement = (XmlElement)configuration.SelectSingleNode("/configuration");

            Assert.IsNotNull(configurationElement, "configurationElement");

            var locations = configuration.SelectNodes("/configuration/location").OfType <XmlElement>();

            foreach (var location in locations)
            {
                var path = location.GetAttribute("path");
                if (!string.IsNullOrEmpty(path) && !path.Equals("/"))
                {
                    // we can ignore non-global locations
                    Log.Warn($"The configuration contains <location path=\"{path}\">");
                    continue;
                }

                Log.Warn("The configuration contains <location>, which is being moved to <configuration>");
                var children = location.ChildNodes.OfType <XmlElement>().ToArray();
                foreach (var child in children)
                {
                    location.RemoveChild(child);
                    var localname = child.Name;
                    if (configurationElement[localname] == null)
                    {
                        configurationElement.AppendChild(child);
                    }
                    else
                    {
                        Log.Error(string.Format("There is a conflict between /configuration/location/{0} and /configuration/{0}. The element is ignored.", localname));
                    }
                }
            }

            return(configuration);
        }