Esempio n. 1
0
        public void WriteAll()
        {
            var path = @"C:\source\temp\db\sql\HackDay\RedGateScripts";

            var atom = AtomCreator.FromString(File.ReadAllText("Config.atom"));

            var table = SqlGenerator.CreateTable(atom);

            var tablePath = Path.Combine(path, "Tables", string.Format("dbo.{0}.sql", atom.Name));

            File.WriteAllText(tablePath, table.TableSql);

            foreach (var item in SqlGenerator.MakeSprocs(atom, new List <AtomModel> {
                atom
            }))
            {
                var sprocs = Path.Combine(path, "Stored Procedures", string.Format("dbo.{0}.sql", item.Name));

                File.WriteAllText(sprocs, item.Sql);
            }

            foreach (var item in SqlGenerator.MakeCustomTables())
            {
                var sprocs = Path.Combine(path, "Types", "User-defined Data Types", string.Format("dbo.{0}Type.sql", item.Name));

                File.WriteAllText(sprocs, item.Sql);
            }
        }
Esempio n. 2
0
        public void TestStrongTypesRepo()
        {
            var folder = @"..\UnitTests\TestAtoms\CareRelated";

            var args = new GeneratorArguments <CSharpTargetConfig>(
                new CSharpTargetConfig
            {
                Entities =
                {
                    StrongTypes = true
                }
            },
                folder, AtomCreator.LoadDefaults(folder));

            var sqlArgs      = new GeneratorArguments <SqlTargetConfig>(new SqlTargetConfig(), args.AtomsFolder, AtomCreator.LoadDefaults(folder));
            var sqlGenerator = new SqlGenerator().Generate(sqlArgs);


            var result = new RepositoryGenerator(sqlGenerator).Generate(args);

            foreach (var item in result)
            {
                Console.WriteLine(item.Output);
            }
        }
Esempio n. 3
0
    public void AtomGUI()
    {
        EditorGUILayout.Separator();
        numberToggle = GUILayout.Toggle(numberToggle, "Use Number Only");
        if (numberToggle)
        {
            number = EditorGUILayout.IntField("Atomic Number: ", number);

            EditorGUILayout.Separator();
            if (GUILayout.Button("Create"))
            {
                AtomCreator.CreateAtom(number);
                number += 1;
            }
        }
        else
        {
            name = EditorGUILayout.TextField("Name: ", name);

            abbreviation = EditorGUILayout.TextField("Abbreviation: ", abbreviation);

            number = EditorGUILayout.IntField("Atomic Number: ", number);

            EditorGUILayout.Separator();
            if (GUILayout.Button("Create"))
            {
                AtomCreator.CreateAtom(name, abbreviation, number);
                number += 1;
            }
        }
    }
Esempio n. 4
0
    private void displayElement()
    {
        GameObject  hologramObject = GameObject.Find("AtomCreator");
        AtomCreator hologram       = hologramObject.GetComponent <AtomCreator>();

        hologram.displayElement(protons, electrons, neutrons);
    }
Esempio n. 5
0
        public void UpdateSprocGenerators()
        {
            var atom = AtomCreator.FromString(File.ReadAllText("Config.atom"));

            var str = new UpdateSproc(atom).Generate();

            Console.WriteLine(str.Sql);
        }
Esempio n. 6
0
        private static ReadOnlyCollection <AtomModel> LoadAtoms(string atomsFolder, AtomDefaults defaults)
        {
            Log.Information("Loading atoms from {AtomFolder}", atomsFolder);

            var atoms = AtomCreator.FromFolder(atomsFolder, defaults).ToList();

            Log.Information("Loaded {LoadedAtomsCount} atoms", atoms.Count);

            return(atoms.AsReadOnly());
        }
Esempio n. 7
0
        public void RunTestAtom()
        {
            var atom = AtomCreator.FromString(File.ReadAllText("TestAtoms/test.atom"));
            var str  = SqlGenerator.CreateTable(atom);

            Console.WriteLine("=============");
            Console.WriteLine(atom.Name);
            Console.WriteLine("---");
            Console.WriteLine(str);
        }
Esempio n. 8
0
        private static ReadOnlyCollection <ProjectionAtom> LoadProjections(string atomFolder)
        {
            Log.Information("Loading projection atoms from {AtomFolder}", atomFolder);

            var projectionAtoms = AtomCreator.ProjectionsFromFolder(atomFolder)
                                  .ToList();

            Log.Information("Loaded {ProjectionCount} projections", projectionAtoms.Count);

            return(projectionAtoms.AsReadOnly());
        }
Esempio n. 9
0
        private IEnumerable <ProjectedAtomRoot> GetProjectionAtoms(GeneratorArguments <CSharpTargetConfig> generatorArguments, CSharpTargetConfig config)
        {
            var atoms = AtomCreator.FromFolder(generatorArguments.AtomsFolder, generatorArguments.Defaults)
                        .ToList();

            var generator = new ProjectionMemberGenerator(atoms);

            var projectedAtoms = generator.GetProjections(AtomCreator.ProjectionsFromFolder(generatorArguments.AtomsFolder));

            return(atoms.Select(ProjectedAtomRoot.FromAtom)
                   .Concat(projectedAtoms));
        }
Esempio n. 10
0
        public void ViewGenCarePlanComplex()
        {
            var allAtoms = AtomCreator.FromFolder("TestAtoms/CareRelated/");

            var projection = JsonConvert.DeserializeObject <QueryProjectionAtom>(File.ReadAllText("TestAtoms/CareRelated/CarePlan.proj.atom"));

            ViewGenerator generator = new ViewGenerator(projection, allAtoms: allAtoms);

            var refs = generator.Generate();

            Console.WriteLine(string.Join(Environment.NewLine, refs.References));
            Console.WriteLine(refs.Sql);
        }
Esempio n. 11
0
        public void TestStrongTypesCode()
        {
            var folder = @"..\UnitTests\TestAtoms\CareRelated";

            var result = new CodeGenerator().Generate(new GeneratorArguments <CSharpTargetConfig>(new CSharpTargetConfig()
            {
                Entities = { StrongTypes = true }
            }, folder, AtomCreator.LoadDefaults(folder)));

            foreach (var item in result)
            {
                Console.WriteLine(item.Output);
            }
        }
Esempio n. 12
0
        public void CreateSqlGenerates()
        {
            var atoms = AtomCreator.FromFolder("TestAtoms/CareRelated");

            foreach (var atom in atoms)
            {
                var str = SqlGenerator.CreateTable(atom);

                Console.WriteLine("=============");
                Console.WriteLine(atom.Name);
                Console.WriteLine("---");
                Console.WriteLine(str);
            }
        }
Esempio n. 13
0
    public void AtomInfoGUI()
    {
        EditorGUILayout.Separator();

        amountType = GUILayout.SelectionGrid(amountType, new string[] { "Single", "Range" }, 2);
        EditorGUILayout.Separator();

        if (amountType == 0)
        {
        }
        else
        {
            range = EditorGUILayout.Vector2IntField("Range (Atomic Number): ", range);

            EditorGUILayout.Separator();
            if (GUILayout.Button("Create"))
            {
                // All objects of type Atom
                var obj = AssetDatabase.FindAssets("t: Atom", new string[] { "Assets/Prefabs/ScriptableObjects/Atom" });

                List <Atom> atoms = new List <Atom>();

                // Load them
                for (int i = 0; i < obj.Length; i++)
                {
                    var path = AssetDatabase.GUIDToAssetPath(obj[i]);

                    Atom atom = AssetDatabase.LoadAssetAtPath <Atom>(path);
                    atoms.Add(atom);
                }

                for (int i = range.x; i <= range.y; i++)
                {
                    Atom a = atoms.Find((x) => x.GetAtomicNumber() == i);
                    if (a != null)
                    {
                        AtomCreator.CreateAtomInfo(a);
                    }
                    else
                    {
                        Debug.Log("Atomic Number " + i + " Is null");
                    }
                }
            }
        }
    }
Esempio n. 14
0
        public GeneratorResult Generate(GeneratorArguments <CSharpTargetConfig> generatorArguments)
        {
            var result = new GeneratorResult();

            var allAtoms = AtomCreator.FromFolder(generatorArguments.AtomsFolder);

            var repositoryMembers = _sqlGenerationResults.SqlAccessors.Select(sqlAccessorMetadata => ToRepoMember(sqlAccessorMetadata, allAtoms))
                                    .ToList();

            var singleRepoGenerator = new CSharpSingleRepositoryGenerator(generatorArguments.Config);

            var singleRepo = singleRepoGenerator.Generate(repositoryMembers);

            result.AddOutput(Path.ChangeExtension(singleRepo.Name, generatorArguments.Config.FileExtension), singleRepo.CodeString);

            var dbFile = singleRepoGenerator.GenerateDbFile(repositoryMembers);

            result.AddOutput(Path.ChangeExtension(dbFile.Name, generatorArguments.Config.FileExtension), dbFile.CodeString);

            return(result);
        }
Esempio n. 15
0
        public void Test()
        {
            var folder = @"..\UnitTests\TestAtoms\CareRelated";

            var result = new CodeGenerator().Generate(new GeneratorArguments <CSharpTargetConfig>(new CSharpTargetConfig(), folder, AtomCreator.LoadDefaults(folder)));
        }
Esempio n. 16
0
        private IEnumerable <GeneratorResult> FromTargetConfigs(CSharpTargetConfig targetConfig)
        {
            var args = new GeneratorArguments <CSharpTargetConfig>(targetConfig, AtomsFolder, AtomCreator.LoadDefaults(AtomsFolder));

            if (targetConfig.Repository != null)
            {
                var sqlArgs      = new GeneratorArguments <SqlTargetConfig>(new SqlTargetConfig(), args.AtomsFolder, AtomCreator.LoadDefaults(AtomsFolder));
                var sqlGenerator = new SqlGenerator().Generate(sqlArgs);

                var repoResult = new RepositoryGenerator(sqlGenerator).Generate(args);

                repoResult.OutputPath = targetConfig.Repository.OutputPath;

                yield return(repoResult);
            }

            var codeResult = new CodeGenerator().Generate(args);

            codeResult.OutputPath = targetConfig.Entities.OutputPath;

            yield return(codeResult);
        }
Esempio n. 17
0
        protected override IEnumerable <GeneratorResult> Generate()
        {
            AtomConfig config = TryLoadAtomConfig();

            if (config == null)
            {
                yield break;
            }

            var sqlConfig    = config.Targets.Values.OfType <SqlTargetConfig>().Single();
            var csharpConfig = config.Targets.Values.OfType <CSharpTargetConfig>().Single();

            var defaults = AtomCreator.LoadDefaults(config.AtomPath);

            var sqlArgs = new GeneratorArguments <SqlTargetConfig>(sqlConfig, config.AtomPath, defaults);
            var args    = new GeneratorArguments <CSharpTargetConfig>(csharpConfig, config.AtomPath, defaults, sqlArgs.Atoms);

            var sqlResult = new SqlGenerator().Generate(sqlArgs);

            sqlResult.OutputPath = sqlConfig.OutputPath;

            //if (Directory.Exists(sqlResult.OutputPath))
            //{
            //    foreach (var file in Directory.EnumerateFiles(sqlResult.OutputPath, "*.generated.sql", SearchOption.AllDirectories))
            //    {
            //        sqlResult.Deletions.Add(file);
            //    }
            //}

            string redGateFile = Path.Combine(sqlConfig.OutputPath, "RedGateDatabaseInfo.xml");

            Log.Information("Looking for redgate database info xml at {RedGateDatabaseInfoXml}", redGateFile);


            if (sqlResult.DataFiles.Any() &&
                File.Exists(redGateFile))
            {
                Log.Information("Found redgate file, updating...");

                var regate       = XDocument.Load(uri: redGateFile);
                var dataFiles    = regate.Root.Elements("DataFileSet").First();
                var allDataFiles = dataFiles.Elements("DataFile")
                                   .Select(n => n.Value).Union(sqlResult.DataFiles, StringComparer.OrdinalIgnoreCase).ToList();

                dataFiles.Elements("Count")
                .First()
                .Value = allDataFiles.Count().ToString();

                Log.Information("DataFiles Count: {DataFileCount}", allDataFiles.Count());

                dataFiles.Elements("DataFile").Remove();

                dataFiles.Add(allDataFiles.Select(s => new XElement("DataFile", s)));

                var genResult = new GeneratorResult()
                {
                    OutputPath = sqlConfig.OutputPath
                };

                genResult.AddOutput("RedGateDatabaseInfo.xml", regate.ToString());

                yield return(genResult);
            }

            yield return(sqlResult);

            if (csharpConfig.Repository != null)
            {
                var repoResult = new RepositoryGenerator(sqlResult).Generate(args);

                repoResult.OutputPath = csharpConfig.Repository.OutputPath;

                yield return(repoResult);
            }

            var codeResult = new CodeGenerator().Generate(args);

            codeResult.OutputPath = csharpConfig.Entities.OutputPath;

            yield return(codeResult);
        }
Esempio n. 18
0
        private IEnumerable <GeneratorResult> FromTargetConfigs(SqlTargetConfig sqlConfig)
        {
            var args = new GeneratorArguments <SqlTargetConfig>(sqlConfig, AtomsFolder, AtomCreator.LoadDefaults(AtomsFolder));

            var sqlResult = new SqlGenerator().Generate(args);

            sqlResult.OutputPath = sqlConfig.OutputPath;

            if (Directory.Exists(sqlResult.OutputPath))
            {
                foreach (var file in Directory.EnumerateFiles(sqlResult.OutputPath, "*.generated.sql", SearchOption.AllDirectories))
                {
                    sqlResult.Deletions.Add(file);
                }
            }

            string redGateFile = Path.Combine(sqlConfig.OutputPath, "RedGateDatabaseInfo.xml");

            Log.Information("Looking for redgate database info xml at {RedGateDatabaseInfoXml}", redGateFile);


            if (sqlResult.DataFiles.Any() &&
                File.Exists(redGateFile))
            {
                Log.Information("Found redgate file, updating...");

                var regate       = XDocument.Load(uri: redGateFile);
                var dataFiles    = regate.Root.Elements("DataFileSet").First();
                var allDataFiles = dataFiles.Elements("DataFile")
                                   .Select(n => n.Value).Union(sqlResult.DataFiles, StringComparer.OrdinalIgnoreCase).ToList();

                dataFiles.Elements("Count")
                .First()
                .Value = allDataFiles.Count().ToString();

                Log.Information("DataFiles Count: {DataFileCount}", allDataFiles.Count());

                dataFiles.Elements("DataFile").Remove();

                dataFiles.Add(allDataFiles.Select(s => new XElement("DataFile", s)));

                var genResult = new GeneratorResult()
                {
                    OutputPath = _config.OutputPath
                };

                genResult.AddOutput("RedGateDatabaseInfo.xml", regate.ToString());

                yield return(genResult);
            }

            yield return(sqlResult);
        }