public IInMemoryDoc Convert(string htmlString, string newSubDirectoryName, string outputDirectory, string newTitle)
        {
            if (htmlString == null) {
                return new InMemoryDoc();
            }

            InMemoryDoc ReturnValue = new InMemoryDoc(htmlString);
            HtmlDocument Doc = new HtmlDocument();
            Doc.LoadHtml(htmlString);
            var TitleNode = Doc.DocumentNode.Descendants("title").FirstOrDefault() ;
            if (TitleNode != null) {
                Doc.DocumentNode.InnerHtml = Doc.DocumentNode.InnerHtml.Replace(TitleNode.InnerHtml, "<title>"+newTitle+"</titlel>");
            }
            foreach (HtmlNode Node in GetImageNodes(Doc)) {
                _Logger.Debug("Image node with value {0} was founded.", Node.GetAttributeValue("src", string.Empty));
                ValuesFromNode Values = ExtractValuesFromNode(Node, newSubDirectoryName);
                _Logger.Debug("New value of node: {0} .", Values.FileName);
                Node.SetAttributeValue("src", Values.FileName);
                if (ReturnValue.ContainsBinaryReference(Values.AtributeValue)) {
                    continue;
                }
                BinaryReference BinaryReference = new BinaryReference(Values.AtributeValue, Path.Combine(outputDirectory, Values.FileName), Values.BinaryValue);
                ReturnValue.AddBinaryReference(BinaryReference);
            }
            ReturnValue.Text = Doc.DocumentNode.InnerHtml;
            return ReturnValue;
        }
 internal void AddBinaryReference(BinaryReference binaryReference)
 {
     _BinaryReferences.Add(binaryReference);
 }
Example #3
0
 private void SaveBinaryReference(BinaryReference binaryReference)
 {
     string LocalDirectory = _PathWrap.GetDirectoryName(binaryReference.NewLocalLink);
     try {
         if (!Directory.Exists(LocalDirectory)) {
             Directory.CreateDirectory(LocalDirectory);
         }
         _File.WriteAllBytes(binaryReference.NewLocalLink, binaryReference.BinaryValue);
     }
     catch (Exception ex) {
         _Logger.Error(String.Format("Exception saving binary file {0}. The exception was ignored.", binaryReference.NewLocalLink),ex);
         // all the esceptions like file existent, illegal name, etc. are passed;
         // binary data is not prioritary
     }
 }