public static BuildResult UpdateDesignerFile ( CodeBehindWriter writer, AspNetAppProject project, ProjectFile file, ProjectFile designerFile ) { var result = new BuildResult (); //parse the ASP.NET file var parsedDocument = TypeSystemService.ParseFile (project, file.FilePath) as WebFormsParsedDocument; if (parsedDocument == null) { result.AddError (string.Format ("Failed to parse file '{0}'", file.Name)); return result; } //TODO: ensure type system is up to date CodeCompileUnit ccu; result.Append (GenerateCodeBehind (project, designerFile.FilePath, parsedDocument, out ccu)); if (ccu != null) { writer.WriteFile (designerFile.FilePath, ccu); } return result; }
public AddControllerDialog (AspNetAppProject project) { Build (); provider = project.LanguageBinding.GetCodeDomProvider (); loadedTemplateList = project.GetCodeTemplates ("AddController"); bool foundEmptyTemplate = false; int templateIndex = 0; foreach (string file in loadedTemplateList) { string name = System.IO.Path.GetFileNameWithoutExtension (file); templateCombo.AppendText (name); if (!foundEmptyTemplate) { if (name == "Empty") { templateCombo.Active = templateIndex; foundEmptyTemplate = true; } else templateIndex++; } } if (!foundEmptyTemplate) throw new Exception ("The Empty.tt template is missing."); nameEntry.Text = "Controller"; nameEntry.Position = 0; Validate (); }
public static void AddController (AspNetAppProject 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 (); dialog.Dispose (); } } if (System.IO.File.Exists (outputFile)) { project.AddFile (outputFile); IdeApp.ProjectOperations.Save (project); } }
public XspOptionsPanelWidget (AspNetAppProject project) { Build (); XspParameters xPar = project.XspParameters; //index should be equivalent to XspSslMode enum ((ListStore) sslMode.Model).Clear (); sslMode.AppendText (GettextCatalog.GetString ("None")); sslMode.AppendText (GettextCatalog.GetString ("Enabled")); sslMode.AppendText (GettextCatalog.GetString ("Accept Client Certificates")); sslMode.AppendText (GettextCatalog.GetString ("Require Client Certificates")); //index should be equivalent to XspSslProtocol enum ((ListStore) sslProtocol.Model).Clear (); sslProtocol.AppendText (GettextCatalog.GetString ("Default")); sslProtocol.AppendText ("TLS"); sslProtocol.AppendText ("SSL 2"); sslProtocol.AppendText ("SSL 3"); ((ListStore) keyType.Model).Clear (); keyType.AppendText (GettextCatalog.GetString ("None")); keyType.AppendText ("Pkcs12"); keyType.AppendText ("PVK"); ((ListStore) passwordOptions.Model).Clear (); passwordOptions.AppendText (GettextCatalog.GetString ("None")); passwordOptions.AppendText (GettextCatalog.GetString ("Ask")); passwordOptions.AppendText (GettextCatalog.GetString ("Store (insecure)")); //load all options ipAddress.Text = xPar.Address; portNumber.Value = xPar.Port; verboseCheck.Active = xPar.Verbose; sslMode.Active = (int) xPar.SslMode; sslProtocol.Active = (int) xPar.SslProtocol; keyType.Active = (int) xPar.KeyType; keyLocation.Path = xPar.PrivateKeyFile; certLocation.Path = xPar.CertificateFile; passwordOptions.Active = (int) xPar.PasswordOptions; passwordEntry.Text = xPar.PrivateKeyPassword; }
static WebFormsTestingEditorExtension CreateEditor (string text, string extension, out string editorText, out TestViewContent sev) { string parsedText; int cursorPosition = text.IndexOf ('$'); int endPos = text.IndexOf ('$', cursorPosition + 1); if (endPos == -1) parsedText = editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1); else { parsedText = text.Substring (0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring (endPos + 1); editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring (endPos + 1); cursorPosition = endPos - 1; } var project = new AspNetAppProject ("C#"); project.References.Add (new ProjectReference (ReferenceType.Package, "System")); project.References.Add (new ProjectReference (ReferenceType.Package, "System.Web")); project.FileName = UnitTests.TestBase.GetTempFile (".csproj"); string file = UnitTests.TestBase.GetTempFile (extension); project.AddFile (file); var pcw = TypeSystemService.LoadProject (project); TypeSystemService.ForceUpdate (pcw); pcw.ReconnectAssemblyReferences (); sev = new TestViewContent (); sev.Project = project; sev.ContentName = file; sev.Text = editorText; sev.CursorPosition = cursorPosition; var tww = new TestWorkbenchWindow (); tww.ViewContent = sev; var doc = new TestDocument (tww); doc.Editor.Document.FileName = sev.ContentName; var parser = new WebFormsParser (); var parsedDoc = (WebFormsParsedDocument) parser.Parse (false, sev.ContentName, new StringReader (parsedText), project); doc.HiddenParsedDocument = parsedDoc; return new WebFormsTestingEditorExtension (doc); }
public override ParsedDocument Parse (bool storeAst, string fileName, System.IO.TextReader content, Project project = null) { currentDocument = openDocuments.FirstOrDefault (d => d != null && d.FileName == fileName); // We need document and project to be loaded to correctly initialize Razor Host. this.project = project as DotNetProject; if (currentDocument == null && !TryAddDocument (fileName)) return new RazorCSharpParsedDocument (fileName, new RazorCSharpPageInfo ()); this.aspProject = project as AspNetAppProject; EnsureParserInitializedFor (fileName); var errors = new List<Error> (); using (var source = new SeekableTextReader (content)) { var textChange = CreateTextChange (source); var parseResult = editorParser.CheckForStructureChanges (textChange); if (parseResult == PartialParseResult.Rejected) { parseComplete.WaitOne (); if (!capturedArgs.GeneratorResults.Success) GetRazorErrors (errors); } } ParseHtmlDocument (errors); CreateCSharpParsedDocument (); ClearLastChange (); RazorHostKind kind = RazorHostKind.WebPage; if (editorParser.Host is WebCodeRazorHost) { kind = RazorHostKind.WebCode; } else if (editorParser.Host is MonoDevelop.AspNet.Razor.Generator.PreprocessedRazorHost) { kind = RazorHostKind.Template; } var pageInfo = new RazorCSharpPageInfo () { HtmlRoot = htmlParsedDocument, GeneratorResults = capturedArgs.GeneratorResults, Spans = editorParser.CurrentParseTree.Flatten (), CSharpParsedFile = parsedCodeFile, CSharpCode = csharpCode, Errors = errors, FoldingRegions = GetFoldingRegions (), Comments = comments, Compilation = CreateCompilation (), HostKind = kind, }; return new RazorCSharpParsedDocument (fileName, pageInfo); }
public static BuildResult GenerateCodeBehind ( AspNetAppProject project, string filename, WebFormsParsedDocument document, out CodeCompileUnit ccu) { ccu = null; var result = new BuildResult (); string className = document.Info.InheritedClass; AddErrorsToResult (result, filename, document.Errors); if (result.ErrorCount > 0) return result; if (string.IsNullOrEmpty (className)) return result; var refman = new WebFormsTypeContext { Project = project, Doc = document }; var memberList = new WebFormsMemberListBuilder (refman, document.XDocument); memberList.Build (); AddErrorsToResult (result, filename, memberList.Errors); if (result.ErrorCount > 0) return result; //initialise the generated type ccu = new CodeCompileUnit (); var namespac = new CodeNamespace (); ccu.Namespaces.Add (namespac); var typeDecl = new CodeTypeDeclaration { IsClass = true, IsPartial = true, }; namespac.Types.Add (typeDecl); //name the class and namespace int namespaceSplit = className.LastIndexOf ('.'); if (namespaceSplit > -1) { namespac.Name = project.StripImplicitNamespace (className.Substring (0, namespaceSplit)); typeDecl.Name = className.Substring (namespaceSplit + 1); } else { typeDecl.Name = className; } string masterTypeName = null; if (!String.IsNullOrEmpty (document.Info.MasterPageTypeName)) { masterTypeName = document.Info.MasterPageTypeName; } else if (!String.IsNullOrEmpty (document.Info.MasterPageTypeVPath)) { try { ProjectFile resolvedMaster = project.ResolveVirtualPath (document.Info.MasterPageTypeVPath, document.FileName); WebFormsParsedDocument masterParsedDocument = null; if (resolvedMaster != null) masterParsedDocument = TypeSystemService.ParseFile (project, resolvedMaster.FilePath) as WebFormsParsedDocument; if (masterParsedDocument != null && !String.IsNullOrEmpty (masterParsedDocument.Info.InheritedClass)) masterTypeName = masterParsedDocument.Info.InheritedClass; } catch (Exception ex) { LoggingService.LogWarning ("Error resolving master page type", ex); } if (string.IsNullOrEmpty (masterTypeName)) { var msg = string.Format ("Could not find type for master '{0}'", document.Info.MasterPageTypeVPath); result.AddError (filename, msg); return result; } } if (masterTypeName != null) { var masterProp = new CodeMemberProperty { Name = "Master", Type = new CodeTypeReference (masterTypeName), HasGet = true, HasSet = false, Attributes = MemberAttributes.Public | MemberAttributes.New | MemberAttributes.Final, }; masterProp.GetStatements.Add (new CodeMethodReturnStatement ( new CodeCastExpression (masterTypeName, new CodePropertyReferenceExpression ( new CodeBaseReferenceExpression (), "Master")))); typeDecl.Members.Add (masterProp); } //shortcut building the existing members type map if (memberList.Members.Count == 0) return result; var dom = refman.Compilation; var cls = ReflectionHelper.ParseReflectionName (className).Resolve (dom); var members = GetDesignerMembers (memberList.Members.Values, cls, filename); //add fields for each control in the page foreach (var member in members) { var type = new CodeTypeReference (member.Type.FullName); typeDecl.Members.Add (new CodeMemberField (type, member.Name) { Attributes = MemberAttributes.Family }); } return result; }
public void Store (AspNetAppProject project) { XspParameters xPar = project.XspParameters; xPar.Address = ipAddress.Text; xPar.Port = Convert.ToUInt16 (portNumber.Value); xPar.Verbose = verboseCheck.Active; xPar.SslMode = (XspSslMode) sslMode.Active; xPar.SslProtocol = (XspSslProtocol) sslProtocol.Active; xPar.KeyType = (XspKeyType) keyType.Active; xPar.PrivateKeyFile = keyLocation.Path; xPar.CertificateFile = certLocation.Path; xPar.PasswordOptions = (XspPasswordOptions) passwordOptions.Active; xPar.PrivateKeyPassword = passwordEntry.Text; }
public static void AddView (AspNetAppProject 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 ("Overwrite file?", String.Format ("The file '{0}' already exists.\n", dialog.ViewName) + "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 (); } if (System.IO.File.Exists (outputFile)) { project.AddFile (outputFile); IdeApp.ProjectOperations.Save (project); } }
static RazorTestingEditorExtension CreateEditor (string text, bool isInCSharpContext, out string editorText, out TestViewContent sev) { string parsedText; int cursorPosition = text.IndexOf ('$'); int endPos = text.IndexOf ('$', cursorPosition + 1); if (endPos == -1) parsedText = editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1); else { parsedText = text.Substring (0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring (endPos + 1); editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring (endPos + 1); cursorPosition = endPos - 1; } var project = new AspNetAppProject ("C#"); project.FileName = UnitTests.TestBase.GetTempFile (".csproj"); string file = UnitTests.TestBase.GetTempFile (extension); project.AddFile (file); var pcw = TypeSystemService.LoadProject (project); TypeSystemService.ForceUpdate (pcw); pcw.ReconnectAssemblyReferences (); sev = new TestViewContent (); sev.Project = project; sev.ContentName = file; sev.Text = editorText; sev.CursorPosition = cursorPosition; var tww = new TestWorkbenchWindow (); tww.ViewContent = sev; var doc = new Document (tww); var parser = new RazorTestingParser { Doc = doc }; var parsedDoc = parser.Parse (false, sev.ContentName, new StringReader (parsedText), project); return new RazorTestingEditorExtension (doc, parsedDoc as RazorCSharpParsedDocument, isInCSharpContext); }