コード例 #1
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            propertyGrid1.SelectedObject = e.Node.Tag;
            if (e.Node.Tag is string)
            {
                var context      = db.GetType();
                var _namespace   = textBox1.Text; // "WorkflowWeb";
                var table        = (e.Node.Parent.Parent.Tag as Table);
                var cshtmlGen    = new CshtmlGenerator(_namespace, dbTables, table);
                var csGen        = new CsGenerator(context, _namespace, dbTables, table);
                var templateName = e.Node.Tag.ToString();

                var isCs = templateName.EndsWith(".cs");

                syntaxEditor1.Document.Language = isCs ? cSharpSyntaxLanguage1 as SyntaxLanguage : xmlSyntaxLanguage1;
                syntaxEditor1.Text = isCs ? csGen.GenerateCode(templateName) : cshtmlGen.GenerateCode(templateName);
            }
        }
コード例 #2
0
        public void GenerateFiles()
        {
            var controllerType = "Mvc";
            var csTemplate     = controllerType + "_Controller.cs";
            var vmTemplate     = controllerType + "_ViewModel.cs";
            var bTemplate      = controllerType + "_Business.cs";
            var cshtmlInclude  = "Index,Details,DetailsWithTabs,DetailsWithBar,New,Edit,Delete,ListDetail,ListTable".Split(',').Select(x => controllerType + "_" + x + ".cshtml");

            var _namespace = textBox1.Text; //"WorkflowWeb";

            var controllers = new Dictionary <string, string>();
            var views       = new List <Tuple <string, string, string> >();
            var viewmodels  = new Dictionary <string, string>();
            var business    = new Dictionary <string, string>();

            foreach (var table in dbTables)
            {
                var cshtmlGen = new CshtmlGenerator(_namespace, dbTables, table);
                var csGen     = new CsGenerator(db.GetType(), _namespace, dbTables, table);

                controllers.Add(table.Name + "Controller.cs", csGen.GenerateCode(csTemplate));
                viewmodels.Add(table.Name + "ViewModel.cs", csGen.GenerateCode(vmTemplate));
                business.Add(table.Name + "Business.cs", csGen.GenerateCode(bTemplate));

                foreach (var templateName in cshtmlInclude)
                {
                    views.Add(new Tuple <string, string, string>(table.Name, templateName.Split('_')[1], cshtmlGen.GenerateCode(templateName)));
                }
            }

            //create files
            //Controllers
            foreach (var c in controllers)
            {
                var dir = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "output\\Controllers\\");
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                File.WriteAllText(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "output\\Controllers\\" + c.Key), c.Value);
            }

            //Business
            foreach (var c in business)
            {
                var dir = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "output\\Business\\");
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                File.WriteAllText(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "output\\Business\\" + c.Key), c.Value);
            }

            //ViewModels
            foreach (var c in viewmodels)
            {
                var dir = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "output\\ViewModels\\");
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                File.WriteAllText(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "output\\ViewModels\\" + c.Key), c.Value);
            }

            //Views
            foreach (var c in views)
            {
                var dir = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "output\\Views\\" + c.Item1);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                File.WriteAllText(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "output\\Views\\" + c.Item1 + "\\" + c.Item2), c.Item3);
            }
        }