public static void AddController(AspMvcProject project, string path, string name) { var provider = project.LanguageBinding.GetCodeDomProvider(); if (provider == null) { throw new InvalidOperationException("Project language has null CodeDOM provider"); } string outputFile = null; MvcTextTemplateHost host = null; AddControllerDialog dialog = null; try { dialog = new AddControllerDialog(project); if (!String.IsNullOrEmpty(name)) { dialog.ControllerName = name; } bool fileGood = false; while (!fileGood) { var resp = (Gtk.ResponseType)MessageService.RunCustomDialog(dialog); dialog.Hide(); if (resp != Gtk.ResponseType.Ok || !dialog.IsValid()) { return; } outputFile = System.IO.Path.Combine(path, dialog.ControllerName) + ".cs"; if (System.IO.File.Exists(outputFile)) { fileGood = MessageService.AskQuestion("Overwrite file?", String.Format("The file '{0}' already exists.\n", dialog.ControllerName) + "Would you like to overwrite it?", AlertButton.OverwriteFile, AlertButton.Cancel) != AlertButton.Cancel; } else { break; } } host = new MvcTextTemplateHost { LanguageExtension = provider.FileExtension, ItemName = dialog.ControllerName, NameSpace = project.DefaultNamespace + ".Controllers" }; host.ProcessTemplate(dialog.TemplateFile, outputFile); MonoDevelop.TextTemplating.TextTemplatingService.ShowTemplateHostErrors(host.Errors); } finally { if (host != null) { host.Dispose(); } if (dialog != null) { dialog.Destroy(); } } if (System.IO.File.Exists(outputFile)) { project.AddFile(outputFile); IdeApp.ProjectOperations.Save(project); } }
public static void AddView(DotNetProject project, string path, string name) { var provider = project.LanguageBinding.GetCodeDomProvider(); if (provider == null) { throw new InvalidOperationException("Project language has null CodeDOM provider"); } string outputFile = null; MvcTextTemplateHost host = null; AddViewDialog dialog = null; try { dialog = new AddViewDialog(project); dialog.ViewName = name; bool fileGood = false; while (!fileGood) { var resp = (Gtk.ResponseType)MessageService.RunCustomDialog(dialog); dialog.Hide(); if (resp != Gtk.ResponseType.Ok || !dialog.IsValid()) { return; } string ext = ".cshtml"; if (dialog.ActiveViewEngine == "Aspx") { ext = dialog.IsPartialView ? ".ascx" : ".aspx"; } if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } outputFile = System.IO.Path.Combine(path, dialog.ViewName) + ext; if (System.IO.File.Exists(outputFile)) { fileGood = MessageService.AskQuestion(GettextCatalog.GetString("Overwrite file?"), GettextCatalog.GetString("The file '{0}' already exists.\n", dialog.ViewName) + GettextCatalog.GetString("Would you like to overwrite it?"), AlertButton.OverwriteFile, AlertButton.Cancel) != AlertButton.Cancel; } else { break; } } host = new MvcTextTemplateHost { LanguageExtension = provider.FileExtension, ItemName = dialog.ViewName, ViewDataTypeString = "" }; if (dialog.HasMaster) { host.IsViewContentPage = true; host.ContentPlaceholder = dialog.PrimaryPlaceHolder; host.MasterPage = dialog.MasterFile; host.ContentPlaceHolders = dialog.ContentPlaceHolders; } else if (dialog.IsPartialView) { host.IsViewUserControl = true; } else { host.IsViewPage = true; } if (dialog.IsStronglyTyped) { host.ViewDataTypeString = dialog.ViewDataTypeString; } host.ProcessTemplate(dialog.TemplateFile, outputFile); MonoDevelop.TextTemplating.TextTemplatingService.ShowTemplateHostErrors(host.Errors); } finally { if (host != null) { host.Dispose(); } if (dialog != null) { dialog.Destroy(); dialog.Dispose(); } } if (System.IO.File.Exists(outputFile)) { project.AddFile(outputFile); IdeApp.ProjectOperations.SaveAsync(project); } }
public static void AddView(AspMvcProject project, string path, string name) { var provider = project.LanguageBinding.GetCodeDomProvider(); if (provider == null) { throw new InvalidOperationException("Project language has null CodeDOM provider"); } string outputFile = null; MvcTextTemplateHost host = null; Mono.TextTemplating.TemplatingAppDomainRecycler.Handle handle = null; AddViewDialog dialog = null; try { dialog = new AddViewDialog(project); dialog.ViewName = name; bool fileGood = false; while (!fileGood) { Gtk.ResponseType resp = (Gtk.ResponseType)MessageService.RunCustomDialog(dialog); dialog.Hide(); if (resp != Gtk.ResponseType.Ok || !dialog.IsValid()) { return; } outputFile = System.IO.Path.Combine(path, dialog.ViewName) + (dialog.IsPartialView? ".ascx" : ".aspx"); if (System.IO.File.Exists(outputFile)) { fileGood = MessageService.AskQuestion("Overwrite file?", "The file '{0}' already exists.\n" + "Would you like to overwrite it?", AlertButton.OverwriteFile, AlertButton.Cancel) != AlertButton.Cancel; } else { break; } } handle = MonoDevelop.TextTemplating.TextTemplatingService.GetTemplatingDomain(); handle.AddAssembly(typeof(MvcTextTemplateHost).Assembly); host = MvcTextTemplateHost.Create(handle.Domain); host.LanguageExtension = provider.FileExtension; host.ViewDataTypeGenericString = ""; if (dialog.HasMaster) { host.IsViewContentPage = true; host.ContentPlaceholder = dialog.PrimaryPlaceHolder; host.MasterPage = dialog.MasterFile; host.ContentPlaceHolders = dialog.ContentPlaceHolders; } else if (dialog.IsPartialView) { host.IsViewUserControl = true; } else { host.IsViewPage = true; } if (dialog.IsStronglyTyped) { //TODO: use dialog.ViewDataType to construct // host.ViewDataTypeGenericString and host.ViewDataType } host.ProcessTemplate(dialog.TemplateFile, outputFile); MonoDevelop.TextTemplating.TextTemplatingService.ShowTemplateHostErrors(host.Errors); } finally { if (handle != null) { handle.Dispose(); } if (dialog != null) { dialog.Destroy(); } } if (System.IO.File.Exists(outputFile)) { project.AddFile(outputFile); IdeApp.ProjectOperations.Save(project); } }