コード例 #1
0
        public void Test_generated_entity_classes()
        {
            using (var tempFolder = new TempFolder())
            {
                const string projectConfigurationFile = "solution/DesignProject/ProjectConfiguration.xml";

                tempFolder.CreateWriteTextFile(projectConfigurationFile,
                                               @"
<ProjectConfiguration xmlns='uri:polygen/1.0/project-configuration'>
    <Solution path='..'>
        <Project name='DesignProject' path='DesignProject' type='Design' />
        <Project name='DataProject' path='DataProject' type='Data' />
    </Solution>
</ProjectConfiguration>
");

                const string designModelsFile = "solution/DesignProject/DesignModels/DesignModels.xml";

                tempFolder.CreateWriteTextFile(designModelsFile,
                                               @"
<DesignModels xmlns='uri:polygen/1.0/designmodel'>
    <Namespace name='TestApp.MyClasses'>
        <Entity name='MyEntity'>
            <Attribute name='Name' type='string' />
        </Entity>
    </Namespace>
</DesignModels>
");

                var outputFolder = tempFolder.CreateFolder("output");
                var runner       = TestRunner.Create(new Core.AutofacModule(), new Base.AutofacModule(), new Templates.HandlebarsNet.AutofacModule(), new AutofacModule());

                runner.Execute(new Core.RunnerConfiguration
                {
                    ProjectConfigurationFile = tempFolder.GetPath(projectConfigurationFile),
                    TempFolder = outputFolder
                });

                var generatedEntityClassFile = tempFolder.GetPath("output/DataProject/Entity/TestApp/MyClasses/MyEntity.gen.cs");
                var customEntityClassFile    = tempFolder.GetPath("output/DataProject/Entity/TestApp/MyClasses/MyEntity.cs");

                File.Exists(generatedEntityClassFile).Should().BeTrue();

                var generatedEntityClass = File.ReadAllText(generatedEntityClassFile).Trim();

                generatedEntityClass.Should().Contain("public partial class MyEntity");
                generatedEntityClass.Should().Contain("namespace TestApp.MyClasses");
                generatedEntityClass.Should().Contain("public string Name { get; set; }");
                generatedEntityClass.Should().Contain("using System;");

                File.Exists(customEntityClassFile).Should().BeTrue();

                var customEntityClass = File.ReadAllText(customEntityClassFile).Trim();

                customEntityClass.Should().Contain("public partial class MyEntity");
                customEntityClass.Should().Contain("namespace TestApp.MyClasses");
                customEntityClass.Should().NotContain("public string Name { get; set; }");
                customEntityClass.Should().Contain("using System;");
            }
        }
コード例 #2
0
ファイル: BasePluginTests.cs プロジェクト: mpoyhonen/polygen
        public void Test_project_configuration_file_parsing()
        {
            using (var tempFolder = new TempFolder())
            {
                const string designModelPath = "ProjectConfiguration.xml";

                tempFolder.CreateWriteTextFile(designModelPath,
                                               @"
<ProjectConfiguration xmlns='uri:polygen/1.0/project-configuration'>
    <Solution path='solution'>
        <Project name='DesignProject' path='DesignProject' type='Design' />
        <Project name='WebProject' path='WebProject' type='Web' />
    </Solution>
</ProjectConfiguration>
");

                var runner = TestRunner.Create(new Core.AutofacModule(), new AutofacModule());

                runner.Initialize();
                runner.RegisterSchemas();
                runner.ParseProjectConfiguration(tempFolder.GetPath(designModelPath));

                var projectConfiguration = runner.Context.DesignModels.GetByType(Core.CoreConstants.DesignModelType_ProjectConfiguration).FirstOrDefault() as IProjectConfiguration;

                projectConfiguration.Should().NotBeNull();
                projectConfiguration.Projects.Projects.Count().Should().Be(2);

                var projects = projectConfiguration.Projects.Projects.Select(x => (name: x.Name, path: x.SourceFolder, type: x.Type));

                projects.Should().BeEquivalentTo(new[] {
コード例 #3
0
        public void Test_template_loading_with_override()
        {
            using (var tempFolder = new TempFolder())
            {
                var collection = new TemplateCollection();

                tempFolder.CreateWriteTextFile("folder1/template-a.hbs", "Contents A");
                tempFolder.CreateWriteTextFile("folder2/template-a.hbs", "Contents B");

                collection.LoadTemplates(new[] { tempFolder.GetPath("folder1"), tempFolder.GetPath("folder2") });

                var templateA = collection.GetTemplate("template-a");

                templateA.Should().NotBeNull();
                templateA.Name.Should().Be("template-a");
                templateA.RenderIntoString(new object()).Should().Be("Contents B");
            }
        }
コード例 #4
0
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            mySqlServer1.ConnectionPool.RemoveAllConnections();

            TempFolder.CleanTransientFolder();

            var xml = TempFolder.GetPath("DockPanelLayout", "xml", false);

            this.dockPanel.SaveAsXml(xml);
        }
コード例 #5
0
        public void Test_generated_schemas()
        {
            using (var tempFolder = new TempFolder())
            {
                const string projectConfigurationFile = "ProjectConfiguration.xml";

                tempFolder.CreateWriteTextFile(projectConfigurationFile,
                                               @"
<ProjectConfiguration xmlns='uri:polygen/1.0/project-configuration'>
    <Solution path='solution'>
        <Project name='DesignProject' path='DesignProject' type='Design' />
    </Solution>
</ProjectConfiguration>
");

                var outputFolder = tempFolder.CreateFolder("output");
                var runner       = TestRunner.Create(new Core.AutofacModule(), new AutofacModule());

                runner.Execute(new Core.RunnerConfiguration
                {
                    ProjectConfigurationFile = tempFolder.GetPath(projectConfigurationFile),
                    TempFolder = outputFolder
                });

                var projectConfigurationSchemaFile = tempFolder.GetPath("output/DesignProject/Schemas/XSD/ProjectConfiguration.xsd");

                File.Exists(projectConfigurationSchemaFile).Should().BeTrue();

                var projectConfigurationSchema = File.ReadAllText(projectConfigurationSchemaFile).Trim();

                projectConfigurationSchema.Should().Contain("<xs:element name=\"Solution\"");

                var designModelSchemaFile = tempFolder.GetPath("output/DesignProject/Schemas/XSD/DesignModels.xsd");

                File.Exists(designModelSchemaFile).Should().BeTrue();

                var designModelSchema = File.ReadAllText(designModelSchemaFile).Trim();

                designModelSchema.Should().Contain("<xs:element name=\"Namespace\"");
            }
        }
コード例 #6
0
        public void Generate_code_from_Solution1()
        {
            var testProjectDir = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", ".."));

            using (var tempFolder = new TempFolder())
            {
                tempFolder.CopyFrom(Path.Combine(testProjectDir, "Solution1"));

                var app      = new Program();
                var exitCode = app.Execute(new[]
                {
                    "--config", Path.Combine(tempFolder.GetPath("DesignProject/ProjectConfiguration.xml"))
                });

                exitCode.Should().Be(0);

                var outputClassExists = File.Exists(tempFolder.GetPath("DataProject/Entity/TestApp/MyClasses/MyEntity.cs"));

                outputClassExists.Should().BeTrue();
            }
        }
コード例 #7
0
        private void tsbOpenInSSMS_Click(object sender, EventArgs e)
        {
            string queryPath = TempFolder.GetPath(null, "sql", true);

            File.WriteAllText(queryPath, string.Format("SELECT TOP 1000 * FROM {0} WITH (NOLOCK)", _mySqlObject.ObjectNameFull));

            if (Process.GetProcessesByName("ssms").Length == 0)
            {
                string arguments = string.Concat(" -S ", _mySqlObject.ServerObjectName, "-d ", _mySqlObject.DatabaseName, " '", queryPath, "'");
                Process.Start(new ProcessStartInfo {
                    FileName = "ssms.exe", Arguments = arguments
                });
            }
            else
            {
                string str = string.Concat(" -S ", _mySqlObject.ServerObjectName, " -d ", _mySqlObject.DatabaseName);
                Process.Start(queryPath, str);
            }
        }
コード例 #8
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            bool layoutLoadedSuccessfully = true;

            //AppSettings.Default.MySqlConnection = new MySqlConnection();
            //AppSettings.Default.MySqlConnection.OnConnectionStateChangedEvent += MySqlConn__OnConnectionStateChangedEvent;
            //AppSettings.Default.MySqlConnection.OnInfoMessage += mySqlConn__OnInfoMessage;

            Assembly        assembly = Assembly.GetExecutingAssembly();
            FileVersionInfo fvi      = FileVersionInfo.GetVersionInfo(assembly.Location);

            this.Text = string.Format("{0} - {1}", this.Text, fvi.FileVersion);

            // Docking Windows

            this.DatabaseBrowserDockForm     = new DatabaseBrowserDockForm(ref mySqlServer1);
            this.SqlServerPropertiesDockForm = new SqlServerPropertiesDockForm(ref mySqlServer1);
            this.PropertiesDockForm          = new PropertiesDockForm();
            this.ChildrenSummaryDockForm     = new ChildrenSummaryDockForm();
            this.DataPreviewDockForm         = new DataPreviewDockForm(ref mySqlServer1);
            this.ObjectDefinitionDockForm    = new ObjectDefinitionDockForm(ref mySqlServer1);
            this.OutputDockForm     = new OutputDockForm();
            this.TopObjectsDockForm = new TopObjectsDockForm(ref mySqlServer1);


            var mf = this;

            this.StartDockForm = new StartDockForm(ref mf);

            try
            {
                // Load saved layout
                var xml = TempFolder.GetPath("DockPanelLayout", "xml", false);
                DeserializeDockContent ddc = GetContentFromPersistString;
                this.dockPanel.LoadFromXml(xml, ddc);
            }
            catch { layoutLoadedSuccessfully = false; }

            if (!this.dockPanel.Contains(this.DatabaseBrowserDockForm))
            {
                this.DatabaseBrowserDockForm.Show(this.dockPanel, DockState.DockLeft);
            }

            if (!this.dockPanel.Contains(this.SqlServerPropertiesDockForm))
            {
                this.SqlServerPropertiesDockForm.Show(this.dockPanel, DockState.DockRight);
            }

            if (!this.dockPanel.Contains(this.PropertiesDockForm))
            {
                this.PropertiesDockForm.Show(this.dockPanel, DockState.DockRight);
            }

            if (!this.dockPanel.Contains(this.ChildrenSummaryDockForm))
            {
                this.ChildrenSummaryDockForm.Show(this.dockPanel, DockState.DockRight);
            }

            if (!this.dockPanel.Contains(this.DataPreviewDockForm))
            {
                this.DataPreviewDockForm.Show(this.dockPanel, DockState.DockRight);
            }

            if (!this.dockPanel.Contains(this.ObjectDefinitionDockForm))
            {
                this.ObjectDefinitionDockForm.Show(this.dockPanel, DockState.DockBottom);
            }

            if (!this.dockPanel.Contains(this.OutputDockForm))
            {
                this.OutputDockForm.Show(this.dockPanel, DockState.DockBottom);
            }

            if (!this.dockPanel.Contains(this.TopObjectsDockForm))
            {
                this.TopObjectsDockForm.Show(this.dockPanel, DockState.DockBottom);
            }


            this.StartDockForm.Show(this.dockPanel, DockState.Document);

            if (!layoutLoadedSuccessfully)
            {
                PropertiesDockForm.Show();
                OutputDockForm.Show();
            }

            MyOutput.Initialize(ref this.OutputDockForm);
            MyOutput.NewMessage(EOutputMessageType.INFORMATION, "Application started.");
        }
コード例 #9
0
        private void export(object sender, EventArgs e)
        {
            if (!_dependencyObjectList.Any())
            {
                return;
            }

            try
            {
                string workbookName = TempFolder.GetPath(null, "xlsx", true);

                var spreadsheet = Excel.CreateWorkbook(workbookName);

                Excel.AddBasicStyles(spreadsheet);
                Excel.AddWorksheet(spreadsheet, "Sheet1");
                var worksheet = spreadsheet.WorkbookPart.WorksheetParts.First().Worksheet;

                // Excel file ready for the data

                //
                uint maxDepth = (uint)_dependencyObjectList.Max(o => o.HierarchyLevel) + 1;

                // Columns
                for (uint i = 1; i <= maxDepth; i++)
                {
                    string text = string.Format("Level {0}", /*this.treeListView1.Columns[0].Text,*/ i);
                    Excel.SetCellValue(spreadsheet, worksheet, i, 1, text, false, false);
                }

                for (uint i = maxDepth + 1; i <= (uint)this.treeListView1.Columns.Count + maxDepth - 1; i++)
                {
                    string text = this.treeListView1.Columns[(int)i - (int)maxDepth].Text;
                    Excel.SetCellValue(spreadsheet, worksheet, i, 1, text, false, false);
                }

                // data
                uint row = 2;
                foreach (object obj in this.treeListView1.Objects)
                {
                    MySqlObject sqlObj = (MySqlObject)obj;
                    Excel.SetCellValue(spreadsheet, worksheet, (uint)sqlObj.HierarchyLevel + 1, row, sqlObj.ObjectName, false, false);
                    Excel.SetCellValue(spreadsheet, worksheet, (uint)maxDepth + 1, row, sqlObj.ObjectId, null, false);
                    Excel.SetCellValue(spreadsheet, worksheet, (uint)maxDepth + 2, row, sqlObj.ServerObjectName, false, false);
                    Excel.SetCellValue(spreadsheet, worksheet, (uint)maxDepth + 3, row, sqlObj.DatabaseName, false, false);
                    Excel.SetCellValue(spreadsheet, worksheet, (uint)maxDepth + 4, row, sqlObj.SchemaName, false, false);
                    Excel.SetCellValue(spreadsheet, worksheet, (uint)maxDepth + 5, row, sqlObj.ObjectType, false, false);
                    Excel.SetCellValue(spreadsheet, worksheet, (uint)maxDepth + 6, row, sqlObj.MaximumUnderlyingLevels, null, false);
                    Excel.SetCellValue(spreadsheet, worksheet, (uint)maxDepth + 7, row, sqlObj.IsSelfReferencing, false, false);

                    row++;

                    IEnumerable <MySqlObject> children = GetChildren(sqlObj);
                    foreach (MySqlObject child in children)
                    {
                        Excel.SetCellValue(spreadsheet, worksheet, (uint)child.HierarchyLevel + 1, row, child.ObjectName, false, false);
                        Excel.SetCellValue(spreadsheet, worksheet, (uint)maxDepth + 1, row, child.ObjectId, null, false);
                        Excel.SetCellValue(spreadsheet, worksheet, (uint)maxDepth + 2, row, child.ServerObjectName, false, false);
                        Excel.SetCellValue(spreadsheet, worksheet, (uint)maxDepth + 3, row, child.DatabaseName, false, false);
                        Excel.SetCellValue(spreadsheet, worksheet, (uint)maxDepth + 4, row, child.SchemaName, false, false);
                        Excel.SetCellValue(spreadsheet, worksheet, (uint)maxDepth + 5, row, child.ObjectType, false, false);
                        Excel.SetCellValue(spreadsheet, worksheet, (uint)maxDepth + 6, row, child.MaximumUnderlyingLevels, null, false);
                        Excel.SetCellValue(spreadsheet, worksheet, (uint)maxDepth + 7, row, child.IsSelfReferencing, false, false);

                        row++;
                    }
                }

                worksheet.Save();
                spreadsheet.Close();

                Process.Start(workbookName);
            }
            catch (Exception ex)
            {
            }
        }