Example #1
0
        public void SetDefault()
        {
            var list = Ioc.Resolve <IAutoConfigService>().GetList <ShareHoldersGradeConfig>();

            if (list.Count < 1)
            {
                var configs = new List <ShareHoldersGradeConfig>();
                var config  = new ShareHoldersGradeConfig
                {
                    Id        = Guid.Parse("72be65e6-3a64-414d-972e-1a3d4a36f500"),
                    Name      = "投资股东",
                    Icon      = "/wwwroot/static/images/GradeIcon/RewardHolders01.png",
                    IsDefault = true
                };
                list.Add(config);

                config = new ShareHoldersGradeConfig
                {
                    Id         = Guid.Parse("72be65e6-3a64-414d-972e-1a3d4a36f501"),
                    Name       = "运营股东",
                    Icon       = "/wwwroot/static/images/GradeIcon/RewardHolders02.png",
                    IsDefault  = false,
                    Contribute = 10000
                };
                list.Add(config);

                config = new ShareHoldersGradeConfig
                {
                    Id         = Guid.Parse("72be65e6-3a64-414d-972e-1a3d4a36f502"),
                    Name       = "核心股东",
                    Icon       = "/wwwroot/static/images/GradeIcon/RewardHolders03.png",
                    IsDefault  = false,
                    Contribute = 100000
                };
                list.Add(config);

                config = new ShareHoldersGradeConfig
                {
                    Id         = Guid.Parse("72be65e6-3a64-414d-972e-1a3d4a36f502"),
                    Name       = "原始股东",
                    Icon       = "/wwwroot/static/images/GradeIcon/RewardHolders04.png",
                    IsDefault  = false,
                    Contribute = 100000
                };
                list.Add(config);


                var autoConfig = new AutoConfig
                {
                    Type = config.GetType().FullName,
                    //// AppName = typeclassProperty.AppName,
                    LastUpdated = DateTime.Now,
                    Value       = JsonConvert.SerializeObject(list)
                };
                Ioc.Resolve <IAutoConfigService>().AddOrUpdate(autoConfig);
            }
        }
Example #2
0
        public void Mapping_readOnlyDictionaries()
        {
            var config = AutoConfig.Map <IReadOnlyDictionaryConfiguration>(configFilePath: ConfigFilePath);

            config.Should().NotBeNull();
            config.FrenchWords.Should().HaveCount(3);
            config.FrenchWords.Keys.Should().ContainInOrder("cat", "dog", "monkey");
            config.FrenchWords.Values.Should().ContainInOrder("chat", "chien", "singe");
        }
Example #3
0
        public void Mapping_nested_collections()
        {
            var config = AutoConfig.Map <INestedCollectionsConfiguration>();

            config.Should().NotBeNull();
            config.Numbers.Should().HaveCount(2);
            config.Numbers.First().Should().ContainInOrder(1, 3, 5);
            config.Numbers.Last().Should().ContainInOrder(2, 4);
        }
 private static void TextChanged(object sender, EventArgs e)
 {
     if (m_AutoConfigs.ContainsKey(sender))
     {
         TextBox    textBox = (TextBox)sender;
         AutoConfig config  = m_AutoConfigs[sender];
         SetConfig(config.program, config.key, textBox.Text, config.file);
     }
 }
Example #5
0
 private static void RichTextChanged(object sender, EventArgs e)
 {
     if (m_AutoConfigs.ContainsKey(sender))
     {
         RichTextBox textBox = (RichTextBox)sender;
         AutoConfig  config  = m_AutoConfigs[sender];
         SetConfig(config.program, config.key, Extends.GetText(textBox).Replace("\n", ";"), config.file);
     }
 }
Example #6
0
        public void If_the_named_config_section_is_not_found_the_default_is_used()
        {
            var defaultConfig = new MyConfiguration {
                Name = "config", Value = 1
            };
            var result = AutoConfig.MapWithDefault(defaultConfig, "myConfigType");

            result.Should().Be(defaultConfig);
        }
Example #7
0
        /// <summary>
        ///     设置默认值
        /// </summary>
        public void SetDefault()
        {
            var list = Ioc.Resolve <IAutoConfigService>().GetList <MoneyTypeConfig>();

            if (list == null || list.Count == 0)
            {
                var configs = new List <MoneyTypeConfig>();
                var config  = new MoneyTypeConfig();
                foreach (Currency item in Enum.GetValues(typeof(Currency)))
                {
                    config = new MoneyTypeConfig {
                        Currency = item,
                        Unit     = item.GetFieldAttribute().Mark
                    };
                    var color = item.GetFieldAttribute().PlaceHolder;
                    if (!color.IsNullOrEmpty())
                    {
                        config.BackGroudColor = (ColorLibrary)Enum.Parse(typeof(ColorLibrary), color);
                    }

                    if (item.GetFieldAttribute().SortOrder > 0)
                    {
                        SortOrder = item.GetFieldAttribute().SortOrder;
                    }

                    if (config.Currency == Currency.Custom)
                    {
                        config.Id = Guid.NewGuid();
                    }
                    else
                    {
                        config.Id = item.GetFieldAttribute().GuidId.ToGuid();
                    }

                    config.Name = item.GetDisplayName();
                    if (item.IsDefault())
                    {
                        config.Status = Status.Normal;
                    }
                    else
                    {
                        continue;
                        // config.Status = Status.Freeze;
                    }

                    configs.Add(config);
                }

                var autoConfig = new AutoConfig {
                    Type        = config.GetType().FullName,
                    LastUpdated = DateTime.Now,
                    Value       = JsonConvert.SerializeObject(configs)
                };
                Ioc.Resolve <IAutoConfigService>().AddOrUpdate(autoConfig);
            }
        }
Example #8
0
        public void Mapping_collections()
        {
            var config = AutoConfig.Map <ICollectionsConfiguration>();

            config.Should().NotBeNull();
            config.Primes.Should().HaveCount(4);
            config.Primes.Should().ContainInOrder(2L, 3L, 5L, 7L);
            config.Colors.Should().HaveCount(2);
            config.Colors.Should().ContainInOrder(ConsoleColor.Red, ConsoleColor.Green);
            config.Unicorns.Should().BeEmpty();
        }
Example #9
0
        public LocalProfile()
        {
            AutoConfigResult result = AutoConfigResult.Create();

            AutoConfig.MapToObject <LocalProfile>(true, ref result);
            if (printToolStack)
            {
                toolStackGraph = new ReferenceGraph();
                toolGraphLock  = new PooledSpinLock();
            }
        }
Example #10
0
        public void Mapping_from_the_default_file_path()
        {
            var foo = AutoConfig.Map <IFoo>();
            var bar = AutoConfig.Map <IFoo>("bar");

            foo.Should().NotBeNull();
            foo.Name.Should().Be("foo");

            bar.Should().NotBeNull();
            bar.Name.Should().Be("bar");
        }
Example #11
0
        public void Mapping_complex_readOnlyDictionaries()
        {
            var config = AutoConfig.Map <IComplexReadOnlyDictionaryConfiguration>(configFilePath: ConfigFilePath);

            config.Should().NotBeNull();
            config.Endpoints.Should().HaveCount(2);
            config.Endpoints["Primary"].Should().HaveCount(2);
            config.Endpoints["Primary"].First().Name.Should().Be("Foo");
            config.Endpoints["Primary"].First().Port.Should().Be(1);
            config.Endpoints["Secondary"].Should().HaveCount(1);
        }
Example #12
0
        public void Mapping_from_a_specific_file_path()
        {
            var foo = AutoConfig.Map <IFoo>(configFilePath: "SpecifyingTheConfigFilePath.xml");
            var bar = AutoConfig.Map <IFoo>("bar", "SpecifyingTheConfigFilePath.xml");

            foo.Should().NotBeNull();
            foo.Name.Should().Be("foo");

            bar.Should().NotBeNull();
            bar.Name.Should().Be("bar");
        }
Example #13
0
        public void Mapping_from_a_combination_of_properties_and_attributes()
        {
            var config = AutoConfig.Map <IPizzaConfiguration>(configFilePath: ConfigFilePath);

            config.Should().NotBeNull();
            config.Name.Should().Be("Vege Deluxe");
            config.Base.Should().Be("Stuffed Crust");
            config.Size.Should().Be(PizzaSize.XLarge);
            config.Price.Should().Be(9.99M);
            config.Toppings.Should().HaveCount(3);
            config.Toppings.Should().ContainInOrder("Aubergine", "Spinach", "Artichoke");
        }
            public void Should_Configure_Default_Config()
            {
                AutoConfig config = null;

                AutoFaker.Configure(builder =>
                {
                    var instance = builder as AutoConfigBuilder;
                    config       = instance.Config;
                });

                config.Should().Be(AutoFaker.DefaultConfig);
            }
Example #15
0
 static Connection GetConnection()
 {
     try
     {
         return(AutoConfig.Map <Common.Settings>().Connection);
     }
     catch (Exception e)
     {
         Log.ErrorException("failed to read configuration", e);
         throw new ApplicationException("can't read configuration", e);
     }
 }
Example #16
0
        public void Mapping_keyed_collections()
        {
            var config = AutoConfig.Map <IThemeConfig>(configFilePath: ConfigFilePath);

            config.Should().NotBeNull();
            config.Themes.Should().NotBeNull();
            config.Themes.Should().HaveCount(3);
            config.Themes["Blue"].Should().Match <ITheme>(theme => theme.Name == "Blue");
            config.Themes["Red"].Should().Match <ITheme>(theme => theme.Name == "Red");
            config.Themes["Black"].Should().Match <ITheme>(theme => theme.Name == "Black");
            config.Default.Should().Be("Red");
        }
        public async void HealthCheck_Return_WithError()
        {
            // Usa o autoConfig para ler uma seção do web.config com todas as tabelas e permissões
            var tablesDiagnostics = AutoConfig.Map <ITablesDiagnostics>();

            // Repositório para validar a saúde
            var heathCheckRepository = new HeathCheckRepository("DrHouse.Wrapper", "BdName");

            var healthCheck = new HealthCheck(heathCheckRepository);
            var result      = await healthCheck.HealthCheckAsync(tablesDiagnostics);

            Assert.False(result.First().IsSuccess);
        }
        private Action <TBuilder> CreateConfigure <TBuilder>(AutoConfig assertConfig, Action <TBuilder> configure = null)
        {
            return(builder =>
            {
                if (configure != null)
                {
                    configure.Invoke(builder);
                }

                var instance = builder as AutoConfigBuilder;
                instance.Config.Should().NotBe(assertConfig);
            });
        }
Example #19
0
        public void Mapping_to_a_concrete_class()
        {
            var config = AutoConfig.Map <SimpleConfiguration>(configFilePath: ConfigFilePath);

            config.Should().BeOfType <SimpleConfiguration>();
            config.Should().NotBeNull();
            config.MyString.Should().Be("hello");
            config.MyInt.Should().Be(42);
            config.MyDate.Should().Be(new DateTime(1969, 07, 21));
            config.MyBool.Should().BeTrue();
            config.MyNullable.Should().Be(23);
            config.MyEmptyNullable.Should().NotHaveValue();
            config.MyTimeSpan.Should().Be(TimeSpan.FromMinutes(5));
        }
Example #20
0
        public void Mapping_to_an_interface()
        {
            var config = AutoConfig.Map <ISimpleConfiguration>();

            config.Should().BeAssignableTo <ISimpleConfiguration>();
            config.Should().NotBeNull();
            config.MyString.Should().Be("hello");
            config.MyInt.Should().Be(42);
            config.MyDate.Should().Be(new DateTime(1969, 07, 21));
            config.MyBool.Should().BeTrue();
            config.MyNullable.Should().Be(23);
            config.MyEmptyNullable.Should().NotHaveValue();
            config.MyTimeSpan.Should().Be(TimeSpan.FromMinutes(5));
        }
Example #21
0
        DataLoader GetLoader()
        {
            var config = AutoConfig.Map <Settings>();

            if (config.Connection == null)
            {
                throw new NullReferenceException("no Connection element");
            }
            var remote     = new DataServiceRemote(config.Connection);
            var dataLoader = new DataLoader(remote);

            dataLoader.Users.LoadAsync().ContinueWith(CheckTaskStatus);
            return(dataLoader);
        }
Example #22
0
        public void Save(Type type, object model)
        {
            var key = type.FullName;

            var config = Resolve <IAlaboAutoConfigService>().GetConfig(type.FullName);

            if (config == null)
            {
                config = new AutoConfig {
                    Type        = key,
                    AppName     = Resolve <ITypeService>().GetAppName(type.FullName),
                    LastUpdated = DateTime.Now
                };
            }

            var classDescription = type.FullName.GetClassDescription();

            if (classDescription.ClassPropertyAttribute.PageType == ViewPageType.Edit)
            {
                config.Value = model.ToJsons();
            }
            else
            {
                var list    = ServiceInterpreter.Eval <List <JObject> >("IAutoConfigService", "GetList", key);
                var idValue = Reflection.GetPropertyValue("Id", model);
                var guid    = idValue.ConvertToGuid();
                //如果Id不存在则创建Id
                if (guid.IsGuidNullOrEmpty())
                {
                    Reflection.SetPropertyValue("Id", model, Guid.NewGuid());
                }
                else
                {
                    JObject current = null;
                    foreach (var item in list)
                    {
                        if (idValue.ToGuid() == item["Id"].ToGuid())
                        {
                            current = item;
                            break;
                        }
                    }
                    list.Remove(current);
                }
                list.Add(JObject.FromObject(model));
                config.Value = list.ToJsons();
            }

            Ioc.Resolve <IAlaboAutoConfigService>().AddOrUpdate(config);
        }
Example #23
0
    public static void Bind(TextBox textBox, PROGRAM program, string key, ConfigFile file)
    {
        if (m_AutoConfigs.ContainsKey(textBox))
        {
            return;
        }
        AutoConfig config = new AutoConfig()
        {
            program = program, key = key, file = file
        };

        textBox.Text = GetConfig(program, key, file);
        Extends.RegisterEvent(textBox, new System.EventHandler(TextChanged));
        m_AutoConfigs[textBox] = config;
    }
Example #24
0
    public static void Bind(CheckBox textBox, PROGRAM program, string key, ConfigFile file)
    {
        if (m_AutoConfigs.ContainsKey(textBox))
        {
            return;
        }
        AutoConfig config = new AutoConfig()
        {
            program = program, key = key, file = file
        };

        Extends.SetChecked(textBox, Util.ToBoolean(GetConfig(program, key, file), false));
        Extends.RegisterEvent(textBox, new System.EventHandler(CheckedChanged));
        m_AutoConfigs[textBox] = config;
    }
        public object Map(XElement element, Type type)
        {
            if (!CanMap(type))
            {
                throw new InvalidOperationException(
                          string.Format("Type '{0}' cannot be mapped by {1} because it is not a KeyValuePair<,>.", type, GetType()));
            }

            var typeArgs = type.GetGenericArguments();
            var keyValuePairBuilderType     = typeof(KeyValuePairBuilder <,>).MakeGenericType(typeArgs);
            var keyValuePairBuilderInstance = AutoConfig.Map(keyValuePairBuilderType, element);
            var keyValuePair = keyValuePairBuilderType.GetMethod("Build").Invoke(keyValuePairBuilderInstance, null);

            return(keyValuePair);
        }
Example #26
0
        private AutoGenerateContext CreateContext(Type type, IList <AutoGeneratorOverride> generatorOverrides = null)
        {
            var faker  = new Faker();
            var config = new AutoConfig();

            if (generatorOverrides != null)
            {
                config.Overrides = generatorOverrides;
            }

            return(new AutoGenerateContext(faker, config)
            {
                GenerateType = type
            });
        }
Example #27
0
        public AutoRuntime(AutoConfig config, Type t_kernel)
            : base(config, t_kernel)
        {
            var cudaDevice = CudaDevice.Current;

            if (cudaDevice != null)
            {
                var cfg = CudaConfig.Default;
                _impl = new CudaRuntime(cfg, t_kernel);
            }
            else
            {
                var cfg = CpuConfig.Default;
                _impl = new CpuRuntime(cfg, t_kernel);
            }
        }
Example #28
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            var connection = Configuration.GetConnectionString("DefaultConnection");

            services.AddDbContext <PictureContext>(options =>
                                                   options.UseSqlServer(connection));

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });
            services.AddTransient <IFileService, FileService>();
            return(AutoConfig.ConfigureContainer(services));
        }
        public void Using_a_custom_mapper()
        {
            AutoConfig.WhenMapping <ICustomMapperExample>(
                mapper =>
            {
                mapper.Map(x => x.Foo).Using <CommaSeparatedListMapper>();
                mapper.Map(x => x.Bar).Using <CommaSeparatedListMapper>();
                mapper.Map(x => x.Baz).Using <CommaSeparatedListMapper>();
            });

            var config = AutoConfig.Map <ICustomMapperExample>();

            config.Foo.Should().Equal(1, 2, 3, 4, 5);
            config.Bar.Should().Equal("one", "two", "three");
            config.Baz.Should().Equal(DayOfWeek.Monday, DayOfWeek.Tuesday);
        }
Example #30
0
        public void Mapping_from_specified_sections()
        {
            var foo      = AutoConfig.Map <IFooBarBaz>("foo");
            var bar      = AutoConfig.Map <IFooBarBaz>("bar");
            var baz      = AutoConfig.Map <IFooBarBaz>("baz");
            var bazUpper = AutoConfig.Map <IFooBarBaz>("BAZ");

            foo.Should().NotBeNull();
            foo.Name.Should().Be("foo");

            bar.Should().NotBeNull();
            bar.Name.Should().Be("bar");

            baz.Should().NotBeNull();
            baz.Name.Should().Be("baz");

            bazUpper.Should().NotBeNull();
            bazUpper.Name.Should().Be("BAZ");
        }
Example #31
0
        public CoreEngine(AutoConfig config, Parser parser)
        {
            if (config == null || parser == null)
            {
                throw new ArgumentNullException("AutoConfig and/or KeywordParser can not be null.");
            }

            this._autoConfig = config;
            this._parser = parser;

            this.OnNewMessage += new _frameworkInfoDelegate(WriteMsgToConsole);
        }
Example #32
0
        /* void InitProject()
         * Init AutoConfig and Parser to parse config file and driver file.
         *
         */
        private void InitProject()
        {
            _autoConfig = AutoConfig.GetInstance();
            _autoConfig.ProjectConfigFile = this._projectConfigFile;

            //if user input the framework config file, we will use it,
            // or we will search the framework config file in current folder.
            if (!String.IsNullOrEmpty(this._frameworkConfigFile))
            {
                _autoConfig.FrameworkConfigFile = this._frameworkConfigFile;
            }

            _autoConfig.ParseConfigFile();
            _autoConfig.Close();

            _parser = Parser.GetInstance();
            _parser.AutoConfig = _autoConfig;

            _parser.ParseDriveFile();
            _parser.Close();
        }
Example #33
0
 private Parser(AutoConfig config)
 {
     _autoConfig = config;
 }
Example #34
0
        public static Parser GetInstance(AutoConfig autoConfig)
        {
            if (autoConfig == null)
            {
                throw new CannotLoadConfigException("AutoConfig can not be null.");
            }

            _autoConfig = autoConfig;

            return _parser;
        }