/// <summary>
 /// Gets the filename stored in the unit element of <paramref name="targetPath"/>
 /// </summary>
 /// <param name="targetPath">The target srcML file</param>
 /// <returns>The file name stored in <paramref name="targetPath"/></returns>
 protected override string GetSourcePathFromTargetFile(string targetPath)
 {
     try {
         var unit = XmlHelper.StreamElements(targetPath, SRC.Unit, 0).FirstOrDefault();
         return(null != unit ? SrcMLElement.GetFileNameForUnit(unit) : null);
     } catch (XmlException) {
         return(null);
     }
 }
Пример #2
0
 /// <summary>
 /// Reads the mapping file in XmlDirectory. If this doesn't exist, it constructs a mapping
 /// from any existing SrcML files in the directory.
 /// </summary>
 protected void ReadMapping()
 {
     lock (mappingLock) {
         mapping.Clear();
         var mappingPath = Path.Combine(XmlDirectory, mappingFile);
         if (File.Exists(mappingPath))
         {
             //read mapping file
             foreach (var line in File.ReadLines(mappingPath))
             {
                 var paths = line.Split('|');
                 if (paths.Length != 2)
                 {
                     Debug.WriteLine(string.Format("Bad line found in mapping file. Expected 2 fields, has {0}: {1}", paths.Length, line));
                     continue;
                 }
                 ProcessMapFileEntry(paths[0].Trim(), paths[1].Trim());
             }
             //TODO: remove file from disk
         }
         else
         {
             //mapping file doesn't exist, so construct mapping from the xml files in the directory
             Debug.WriteLine(string.Format("Mapping file not found: {0}", mappingPath));
             if (Directory.Exists(XmlDirectory))
             {
                 foreach (var xmlFile in Directory.GetFiles(XmlDirectory, "*.xml"))
                 {
                     var unit = XmlHelper.StreamElements(xmlFile, SRC.Unit, 0).FirstOrDefault();
                     if (unit != null)
                     {
                         //should be a SrcML file
                         var sourcePath = SrcMLElement.GetFileNameForUnit(unit);
                         if (!string.IsNullOrWhiteSpace(sourcePath))
                         {
                             ProcessMapFileEntry(sourcePath, Path.GetFullPath(xmlFile));
                         }
                     }
                 }
             }
         }
     }
 }