コード例 #1
0
        private static XElement GetXElementForFile(FileEventRaisedArgs args, ISrcMLGlobalService srcMLService)
        {
            XElement xelement = null;

            if (!args.EventType.Equals(FileEventType.FileDeleted))
            {
                if (args.FilePath.EndsWith(".xml") || args.FilePath.EndsWith(".xaml"))
                {
                    var allText = File.ReadAllText(args.FilePath);
                    try
                    {
                        xelement = XDocument.Parse(allText, LoadOptions.SetLineInfo |
                                                   LoadOptions.PreserveWhitespace).Root;
                    }
                    catch (Exception e)
                    {
                        return(xelement);
                    }
                }
                else
                {
                    xelement = srcMLService.GetXElementForSourceFile(args.FilePath);
                }
            }
            return(xelement);
        }
コード例 #2
0
ファイル: SrcMLCppParser.cs プロジェクト: abb-iss/Sando
        public List <ProgramElement> Parse(string fileName)
        {
            var      programElements = new List <ProgramElement>();
            XElement sourceElements;

            if (SrcMLService != null)
            {
                sourceElements = SrcMLService.GetXElementForSourceFile(fileName);
                if (sourceElements != null)
                {
                    programElements = Parse(fileName, sourceElements);
                }
                else
                {
                    FileLogger.DefaultLogger.ErrorFormat("SrcMLCppParser: File not found in SrcMLService: {0}", fileName);
                }
            }
            else if (Archive != null)
            {
                sourceElements = Archive.GetXElementForSourceFile(fileName);
                if (sourceElements != null)
                {
                    programElements = Parse(fileName, sourceElements);
                }
                else
                {
                    LogEvents.ParserFileNotFoundInArchiveError(this, fileName);
                }
            }
            else if (Generator != null)
            {
                string outFile = Path.GetTempFileName();
                try {
                    //This is a C++ parser, so we'll convert the input file as C++ no matter what the file extension is
                    Generator.GenerateSrcMLFromFile(fileName, outFile, Language.CPlusPlus);
                    sourceElements = SrcMLElement.Load(outFile);
                    if (sourceElements != null)
                    {
                        programElements = Parse(fileName, sourceElements);
                    }
                } finally {
                    File.Delete(outFile);
                }
            }
            else
            {
                throw new InvalidOperationException("SrcMLCppParser - Archive and Generator are both null");
            }

            return(programElements);
        }
コード例 #3
0
        public void CheckCSharpSolutionStartup()
        {
            SrcMLArchive archive = srcMLService.GetSrcMLArchive();

            Assert.IsNotNull(archive, "GetSrcMLArchive returned null.");
            string sourcePath = Path.Combine(testCSharpProjectFolder, "Class1.cs");
            string srcMLPath  = archive.GetXmlPathForSourcePath(sourcePath);

            Assert.IsTrue(File.Exists(sourcePath), "The source file [" + sourcePath + "] does not exist.");
            Assert.IsTrue(File.Exists(srcMLPath), "The srcML file [" + srcMLPath + "] does not exist.");
            Assert.AreEqual(new FileInfo(sourcePath).LastWriteTime, new FileInfo(srcMLPath).LastWriteTime);
            XElement xelement = srcMLService.GetXElementForSourceFile(sourcePath);

            Assert.IsNotNull(xelement, "GetXElementForSourceFile returned null.");
            string   sourcePathX = Path.Combine(testCSharpProjectFolder, "AlreadyDeletedClass1.cs");
            XElement xelementX   = srcMLService.GetXElementForSourceFile(sourcePathX);

            Assert.IsNull(xelementX, "GetXElementForSourceFile returned not null.");
        }
コード例 #4
0
 private static XElement GetXElement(FileEventRaisedArgs args, ISrcMLGlobalService srcMLService)
 {
     try
     {
         return srcMLService.GetXElementForSourceFile(args.FilePath);
     }
     catch (ArgumentException e)
     {
         return XElement.Load(args.FilePath);
     }
 }