public override void Deserialize(object obj, ITypeSerializer handler, DataCollection data)
        {
            //deserialise as normal
            base.Deserialize(obj, handler, data);

            AspNetAppProject proj = obj as AspNetAppProject;

            if (proj == null)
            {
                return;
            }

            //find files that are web content and have been deserialised from the obsolete "FileCopy" BuildAction
            foreach (MonoDevelop.Projects.ProjectFile pf in proj.Files)
            {
                if (pf.BuildAction != MonoDevelop.Projects.BuildAction.Content ||
                    pf.CopyToOutputDirectory != MonoDevelop.Projects.FileCopyMode.Always)
                {
                    continue;
                }

                WebSubtype type = proj.DetermineWebSubtype(pf);
                if (type != WebSubtype.None && type != WebSubtype.Code)
                {
                    //and mark them to not copy, since we don't actually want this;
                    // the obsolete behaviour was a hack
                    pf.CopyToOutputDirectory = MonoDevelop.Projects.FileCopyMode.None;
                }
            }
        }
        public override ParsedDocument Parse(bool storeAst, string fileName, TextReader tr, Project project = null)
        {
            var info     = new PageInfo();
            var rootNode = new RootNode();
            var errors   = new List <Error> ();

            try {
                rootNode.Parse(fileName, tr);
            } catch (Exception ex) {
                LoggingService.LogError("Unhandled error parsing ASP.NET document '" + (fileName ?? "") + "'", ex);
                errors.Add(new Error(ErrorType.Error, "Unhandled error parsing ASP.NET document: " + ex.Message));
            }


            foreach (var pe in rootNode.ParseErrors)
            {
                errors.Add(new Error(ErrorType.Error, pe.Message, pe.Location.BeginLine, pe.Location.BeginColumn));
            }

            info.Populate(rootNode, errors);

            var type = AspNetAppProject.DetermineWebSubtype(fileName);

            if (type != info.Subtype)
            {
                if (info.Subtype == WebSubtype.None)
                {
                    errors.Add(new Error(ErrorType.Error, "File directive is missing", 1, 1));
                }
                else
                {
                    type = info.Subtype;
                    errors.Add(new Error(ErrorType.Warning, "File directive does not match page extension", 1, 1));
                }
            }

            var result = new AspNetParsedDocument(fileName, type, rootNode, info);

            result.Add(errors);

            /*
             * if (MonoDevelop.Core.LoggingService.IsLevelEnabled (MonoDevelop.Core.Logging.LogLevel.Debug)) {
             *      DebugStringVisitor dbg = new DebugStringVisitor ();
             *      rootNode.AcceptVisit (dbg);
             *      System.Text.StringBuilder sb = new System.Text.StringBuilder ();
             *      sb.AppendLine ("Parsed AspNet file:");
             *      sb.AppendLine (dbg.DebugString);
             *      if (errors.Count > 0) {
             *              sb.AppendLine ("Errors:");
             *              foreach (ParserException ex in errors)
             *                      sb.AppendLine (ex.ToString ());
             *      }
             *      MonoDevelop.Core.LoggingService.LogDebug (sb.ToString ());
             * }*/

            return(result);
        }
        public bool IsCompatibleWith(MonoDevelop.Ide.Gui.Document document)
        {
            switch (AspNetAppProject.DetermineWebSubtype(document.FileName))
            {
            case WebSubtype.WebForm:
            case WebSubtype.MasterPage:
            case WebSubtype.WebControl:
                break;

            default:
                return(false);
            }

            var clrVersion = ClrVersion.Net_2_0;
            var aspProj    = document.Project as AspNetAppProject;

            if (aspProj != null && aspProj.TargetFramework.ClrVersion != ClrVersion.Default)
            {
                clrVersion = aspProj.TargetFramework.ClrVersion;
            }

            foreach (var tbfa in ItemFilters)
            {
                ClrVersion filterVersion;
                switch (tbfa.FilterString)
                {
                case "ClrVersion.Net_1_1":
                    filterVersion = ClrVersion.Net_1_1;
                    break;

                case "ClrVersion.Net_2_0":
                    filterVersion = ClrVersion.Net_2_0;
                    break;

                case "ClrVersion.Net_4_0":
                    filterVersion = ClrVersion.Net_4_0;
                    break;

                default:
                    continue;
                }

                if (tbfa.FilterType == ToolboxItemFilterType.Require && filterVersion != clrVersion)
                {
                    return(false);
                }

                if (tbfa.FilterType == ToolboxItemFilterType.Prevent && filterVersion == clrVersion)
                {
                    return(false);
                }
            }
            return(true);
        }
        public override DataCollection Serialize(object obj, ITypeSerializer handler)
        {
            //serialise as normal
            DataCollection data = base.Serialize(obj, handler);

            AspNetAppProject proj = obj as AspNetAppProject;

            if (proj == null)
            {
                return(data);
            }

            //for the old format we need to make sure each Content file that's a web type and is NOT set
            //to copy actually gets changed to the FileCopy build target
            DataItem files = data ["Contents"] as DataItem;

            if (files == null || !files.HasItemData)
            {
                return(data);
            }

            foreach (object f in files.ItemData)
            {
                DataItem file = f as DataItem;
                if (file == null || !file.HasItemData)                // || file.Name != "File")
                {
                    continue;
                }

                DataValue ctod = file ["copyToOutputDirectory"] as DataValue;
                if (ctod != null && ctod.Value == "Never")
                {
                    DataValue action = file ["buildaction"] as DataValue;
                    DataValue name   = file ["name"] as DataValue;
                    if (action != null && name != null && action.Value == "Content")
                    {
                        WebSubtype type = AspNetAppProject.DetermineWebSubtype(name.Value);
                        if (type != WebSubtype.None && type != WebSubtype.Code)
                        {
                            file.Extract("copyToOutputDirectory");
                            int index = file.ItemData.IndexOf(action);
                            file.ItemData.Remove(action);
                            file.ItemData.Insert(index, new DataValue("buildaction", "FileCopy"));
                        }
                    }
                }
            }

            return(data);
        }
Esempio n. 5
0
        public static ProjectFile GetDesignerFile(ProjectFile file)
        {
            var project = file.Project as AspNetAppProject;

            var type = AspNetAppProject.DetermineWebSubtype(file.FilePath);

            if (type != WebSubtype.WebForm && type != WebSubtype.WebControl && type != WebSubtype.MasterPage)
            {
                return(null);
            }

            var dfName = project.LanguageBinding.GetFileName(file.FilePath + ".designer");

            return(project.Files.GetFile(dfName));
        }
        public bool CanAttachTo(IViewContent content)
        {
            if (content.GetContent(typeof(MonoDevelop.Ide.Gui.Content.IEditableTextBuffer)) == null)
            {
                return(false);
            }

            switch (AspNetAppProject.DetermineWebSubtype(content.IsUntitled? content.UntitledName : content.ContentName))
            {
            case WebSubtype.WebForm:
                return(true);

            default:
                return(false);
            }
        }
Esempio n. 7
0
        public override ParsedDocument Parse(bool storeAst, string fileName, TextReader tr, Project project = null)
        {
            var info   = new WebFormsPageInfo();
            var errors = new List <Error> ();

            var parser = new XmlParser(
                new WebFormsRootState(),
                true
                );

            try {
                parser.Parse(tr);
            } catch (Exception ex) {
                LoggingService.LogError("Unhandled error parsing ASP.NET document '" + (fileName ?? "") + "'", ex);
                errors.Add(new Error(ErrorType.Error, "Unhandled error parsing ASP.NET document: " + ex.Message));
            }

            // get the errors from the StateEngine parser
            errors.AddRange(parser.Errors);

            // populating the PageInfo instance
            XDocument xDoc = parser.Nodes.GetRoot();

            info.Populate(xDoc, errors);

            var type = AspNetAppProject.DetermineWebSubtype(fileName);

            if (type != info.Subtype)
            {
                if (info.Subtype == WebSubtype.None)
                {
                    errors.Add(new Error(ErrorType.Error, "File directive is missing", 1, 1));
                }
                else
                {
                    type = info.Subtype;
                    errors.Add(new Error(ErrorType.Warning, "File directive does not match page extension", 1, 1));
                }
            }

            var result = new WebFormsParsedDocument(fileName, type, info, xDoc);

            result.Add(errors);

            return(result);
        }