コード例 #1
1
ファイル: SourceAnnotator.cs プロジェクト: csf-dev/ZPT-Sharp
        private string CreateCommentBody(IRenderingContext targetContext,
                                     bool skipLineNumber,
                                     string extraText,
                                     bool useEndTagPosition,
                                     IRenderingContext replacementContext)
        {
            IZptElement
            targetElement = targetContext.Element,
            sourceElement = replacementContext?.Element ?? targetContext.Element;
              string
            fullFilename = targetContext.Element.SourceFile.FullName,
            filename,
            filePosition = useEndTagPosition? sourceElement.GetEndTagFileLocation() : sourceElement.GetFileLocation(),
            previousElement;

              if(!String.IsNullOrEmpty(targetContext.SourceAnnotationRootPath)
             && Directory.Exists(targetContext.SourceAnnotationRootPath)
             && File.Exists(fullFilename))
              {
            var root = new DirectoryInfo(targetContext.SourceAnnotationRootPath);
            var file = new FileInfo(fullFilename);
            filename = file.IsChildOf(root)? file.GetRelativePath(root).Substring(1) : fullFilename;
              }
              else
              {
            filename = fullFilename;
              }

              filename = filename.Replace(Path.DirectorySeparatorChar.ToString(), "/");

              if((!targetElement.IsRoot && targetElement.HasParent) || targetElement.CanWriteCommentWithoutParent)
              {
            previousElement = String.Empty;
              }
              else
              {
            previousElement = PREVIOUS_ELEMENT;
              }

              var body = (skipLineNumber || String.IsNullOrEmpty(filePosition))? filename : String.Format(POSITION_FORMAT, filename, filePosition);
              var extra = _renderExtraText? extraText?? String.Empty : String.Empty;
              return String.Concat(previousElement, extra, body);
        }
コード例 #2
0
 public void TestGetRelative()
 {
   FileInfo file = new FileInfo(@"C:\SomeDirectory\SomeFile.txt");
   
   Assert.AreEqual(@"SomeDirectory\SomeFile.txt",
                   file.GetRelativePath(new DirectoryInfo(@"C:\")),
                   "Correct relative path");
 }
コード例 #3
0
ファイル: RenderingJob.cs プロジェクト: csf-dev/ZPT-Sharp
        private FileInfo GetOutputFile(DirectoryInfo outputRoot, string extensionOverride)
        {
            if(_inputFile == null)
              {
            throw new BatchRenderingException(Resources.ExceptionMessages.InputMustBeFileIfOutputIsDirectory);
              }

              var extension = _inputFile.Extension;
              var filenameWithoutExtension = _inputFile.Name.Substring(0, _inputFile.Name.Length - extension.Length);
              string newFilename;

              if(extensionOverride != null)
              {
            string newExtension = extensionOverride;
            if(!newExtension.StartsWith("."))
            {
              newExtension = String.Concat(".", newExtension);
            }

            newFilename = String.Concat(filenameWithoutExtension, newExtension);
              }
              else if(_document.Mode == RenderingMode.Xml)
              {
            newFilename = String.Concat(filenameWithoutExtension, ".xml");
              }
              else
              {
            newFilename = String.Concat(filenameWithoutExtension, ".html");
              }

              var tempOutputPath = new FileInfo(System.IO.Path.Combine(_inputFile.GetParentDirectory().FullName, newFilename));

              var relativePath = tempOutputPath.GetRelativePath(_inputRootDirectory);
              if(relativePath.StartsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
              {
            relativePath = relativePath.Substring(1);
              }
              var outputPath = outputRoot.FullName;
              return new FileInfo(System.IO.Path.Combine(outputPath, relativePath));
        }
コード例 #4
0
 public void TestGetRelativeNotRooted()
 {
   FileInfo file = new FileInfo(@"C:\SomeDirectory\SomeFile.txt");
   file.GetRelativePath(new DirectoryInfo(@"D:\"));
   Assert.Fail("Test should not reach this point");
 }