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 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) { 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.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); } }