Exemplo n.º 1
0
 public void Test()
 {
     var configs = new DefaultConfigParser().ParseFile(@"C:\svn\AwishWork\Awish.Lars\trunk\Awish.Lars.Data\hyperactive.config");
     Assert.AreEqual(1, configs.Count());
     var configOptions = configs.ElementAt(0);
     Assert.AreEqual(1, configOptions.Components.Count());
     var ioc = new Ioc(@"C:\svn\AwishWork\lib", configOptions.Components);
     var type = ioc.ResolveType("Awish.Common.ActiveRecordExtensions.AwishActiveRecordGenerator, Awish.Common.ActiveRecordExtensions");
     Assert.IsNotNull(type);
 }
Exemplo n.º 2
0
        public void can_get_key_values()
        {
            var contentsOfConfigFile = new Element("hyperactive",
                new Element("config",
                    new Element("add", "key=abstractbasename;value=LarsBase"),
                    new Element("add", @"key=outputpath;value=Data\Generated")));

            var configParser = new DefaultConfigParser();
            var configs = configParser.ParseXml(contentsOfConfigFile);
            Assert.AreEqual(1, configs.Count());
            var options = configs.ElementAt(0);
            Assert.AreEqual("LarsBase", options.AbstractBaseName);
            Assert.AreEqual(@"Data\Generated", options.OutputPath);
        }
Exemplo n.º 3
0
        public void can_get_enums()
        {
            var contentsOfConfigFile = new Element("hyperactive",
                new Element("config",
                    new Element("enums",
                        new Element("add", "table=TransactionLineType;nameField=Label;valueField=ID;"))));

            var configParser = new DefaultConfigParser();
            var options = configParser.ParseXml(contentsOfConfigFile).ElementAt(0);
            Assert.AreEqual(1, options.Enums.Count());
            var @enum = options.Enums.ElementAt(0);
            Assert.AreEqual("TransactionLineType", @enum.TableName);
            Assert.AreEqual("Label", @enum.NameField);
            Assert.AreEqual("ID", @enum.ValueField);
        }
Exemplo n.º 4
0
 public void Save(EditConfigsViewModel model)
 {
     var configParser = new DefaultConfigParser();
     foreach (var config in model.Configs)
     {
         //find the generator node, if GeneratorTypeName is diff than the service, add  it as a component
         var generator = config.Components.FirstOrDefault(x => { return x.ServiceTypeName.Equals("HyperActive.Core.Generators.ActiveRecordGenerator, HyperActive"); });
         if (generator != null && !String.IsNullOrEmpty(config.GeneratorTypeName))
         {
             generator.ServiceImplementationTypeName = config.GeneratorTypeName;
         }
     }
     var options = Convert(model.Configs);
     configParser.WriteXml(model.ConfigFilePath, options);
 }
Exemplo n.º 5
0
        public void can_get_components()
        {
            var contentsOfConfigFile = new Element("hyperactive",
                new Element("config",
                    new Element("components",
                        new Element("component", "service=TheService;serviceimpl=TheImpl;",
                            new Element("param", "name=myParam;type=string;value=$IRock;")))));

            var configParser = new DefaultConfigParser();
            var options = configParser.ParseXml(contentsOfConfigFile).ElementAt(0);
            Assert.AreEqual(1, options.Components.Count());
            var comp = options.Components.ElementAt(0);
            Assert.AreEqual("TheService", comp.ServiceTypeName);
            Assert.AreEqual("TheImpl", comp.ServiceImplementationTypeName);
            Assert.AreEqual(1, comp.Parameters.Count);
            var p = comp.Parameters.ElementAt(0);
            Assert.AreEqual("myParam", p.Name);
            Assert.AreEqual("string", p.Type);
            Assert.AreEqual("$IRock", p.Value);
        }
Exemplo n.º 6
0
        public EditConfigsViewModel EditConfigs(string configFilePath)
        {
            var result = new EditConfigsViewModel();
            result.ConfigFilePath = configFilePath;
            var configParser = new DefaultConfigParser();
            var options = configParser.ParseXml(File.ReadAllText(configFilePath));
            var models = Convert(options);
            foreach (var model in models)
            {
                var generator = model.Components.FirstOrDefault(x => { return x.ServiceTypeName.Equals("HyperActive.Core.Generators.ActiveRecordGenerator, HyperActive"); });
                if (generator != null && !String.IsNullOrEmpty(generator.ServiceImplementationTypeName))
                {
                    model.GeneratorTypeName = generator.ServiceImplementationTypeName;
                }
                result.Configs.Add(model);
            }

            //ensure that each config section has at least one component node which defines the AR generator
            return result;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Responsible for executing a <see cref="ICodeRunner"/> implementation for
        /// each of the configuration sections specified in the hyperactive config file.
        /// </summary>
        public void Run()
        {
            var configParser = new DefaultConfigParser();
            var configs = configParser.ParseXml(_contentsOfConfigFile);

            foreach (IConfigurationOptions config in configs)
            {
                EnsureOutputPath(config);
                EnsureEnumOutputPath(config);

                var assemblyDirectory = String.IsNullOrEmpty(config.AssemblyDirectory) ? _assemblyDirectory : config.AssemblyDirectory;
                Log.WriteLine("AssemblyDirectory: {0}", assemblyDirectory);

                var ioc = new Ioc(assemblyDirectory, config.Components, true);

                var cfg = new CodeRunnerConfig();
                cfg.DbProvider = ioc.Get<IDbProvider>();
                if (cfg.DbProvider == null)
                {
                    if (String.IsNullOrEmpty(config.ConnectionString))
                    {
                        Log.WriteLine("It seems as though no DbProvider component was specified in the config and no connectionstring was specified.");
                        Log.WriteLine("Either define <add key=\"connectionstring\" value=\"your connection string\" /> at the root of the config node");
                        Log.WriteLine("or define a DbProvider component in the components section.");
                        continue;
                    }
                    cfg.DbProvider = new SqlServerProvider(new DbHelper(config.ConnectionString));
                }
                Log.WriteLine("DbProvider -> {0}", cfg.DbProvider.GetType().Name);
                cfg.Generator = ioc.Get<ActiveRecordGenerator>() ?? new ConfigurableActiveRecordGenerator(config);
                if (cfg.Generator.ConfigOptions == null)
                {
                    cfg.Generator.ConfigOptions = config;
                }
                Log.WriteLine("Generator -> {0}", cfg.Generator.GetType().Name);

                cfg.NameProvider = InitializeNameProvider(config, ioc);
                cfg.Generator.NameProvider = cfg.NameProvider;

                cfg.Options = config;
                cfg.Writer =
                    (path) =>
                    {
                        return new StreamWriter(path, false);
                    };
                var codeRunner = new CodeRunnerImpl(cfg);
                codeRunner.VerboseLogging = true;
                codeRunner.Execute();
            }
        }