Ejemplo n.º 1
0
        protected override void BeginProcessing()
        {
            //Validate all incoming catalogs once
            WriteDebug("Loading SpecializedCatalogFilePath[${SpecializedCatalogFilePath}]");
            XmlResolverUsingCatalog specializedXmlResolver = new XmlResolverUsingCatalog(SpecializedCatalogFilePath);

            WriteDebug("Loading GeneralizedCatalogFilePath[${GeneralizedCatalogFilePath}]");
            XmlResolverUsingCatalog generalizedXmlResolver = new XmlResolverUsingCatalog(GeneralizedCatalogFilePath);

            WriteDebug("Loading GeneralizationCatalogMappingFilePath[${GeneralizationCatalogMappingFilePath}]");
            DitaXmlGeneralizationCatalogMapping generalizationCatalogMapping = new DitaXmlGeneralizationCatalogMapping(GeneralizationCatalogMappingFilePath);

            _ditaXMLGeneralization = new HelperClasses.DitaXmlGeneralization(specializedXmlResolver, generalizedXmlResolver, generalizationCatalogMapping);
            if (AttributesToGeneralizeToProps != null)
            {
                WriteDebug("Loading AttributesToGeneralizeToProps[" + String.Join(",", AttributesToGeneralizeToProps) + "]");
                _ditaXMLGeneralization.AttributesToGeneralizeToProps = AttributesToGeneralizeToProps;
            }
            if (AttributesToGeneralizeToBase != null)
            {
                WriteDebug("Loading AttributesToGeneralizeToBase[" + String.Join(",", AttributesToGeneralizeToBase) + "]");
                _ditaXMLGeneralization.AttributesToGeneralizeToBase = AttributesToGeneralizeToBase;
            }

            if (!Directory.Exists(FolderPath))
            {
                WriteDebug("Creating FolderPath[${FolderPath}]");
                string tempLocation = Directory.CreateDirectory(FolderPath).FullName;
            }
            base.BeginProcessing();
        }
Ejemplo n.º 2
0
 protected override void BeginProcessing()
 {
     WriteDebug("Loading XmlResolverUsingCatalog[${XmlCatalogFilePath}]");
     _xmlResolverUsingCatalog = new XmlResolverUsingCatalog(XmlCatalogFilePath);
     // When ProhibitDTD = true, the following error occurs:
     // "For security reasons DTD is prohibited in this XML document. To enable DTD processing set the ProhibitDtd property on XmlReaderSettings to false and pass the settings into XmlReader.Create method."
     WriteDebug("Loading XmlReaderSettings");
     _xmlReaderSettings.ConformanceLevel             = ConformanceLevel.Auto;
     _xmlReaderSettings.DtdProcessing                = DtdProcessing.Parse;
     _xmlReaderSettings.ValidationType               = ValidationType.DTD;
     _xmlReaderSettings.ValidationEventHandler      += new System.Xml.Schema.ValidationEventHandler(ValidationHandler);
     _xmlReaderSettings.XmlResolver                  = _xmlResolverUsingCatalog;
     _xmlReaderSettings.IgnoreComments               = false;
     _xmlReaderSettings.IgnoreProcessingInstructions = false;
     _xmlReaderSettings.IgnoreWhitespace             = false;
     _xmlReaderSettings.CloseInput = true;
     base.BeginProcessing();
 }
        protected override void ProcessRecord()
        {
            try
            {
                int current = 0;

                WriteDebug("Generalizing");

                if (!String.IsNullOrEmpty(FilePath))
                {
                    File = new FileInfo[] { new FileInfo(FilePath) };
                }

                XmlResolverUsingCatalog             specializedXmlResolver       = new XmlResolverUsingCatalog(SpecializedCatalogLocation);
                XmlResolverUsingCatalog             generalizedXmlResolver       = new XmlResolverUsingCatalog(GeneralizedCatalogLocation);
                DitaXmlGeneralizationCatalogMapping generalizationCatalogMapping = new DitaXmlGeneralizationCatalogMapping(GeneralizationCatalogMappingLocation);

                DitaXmlGeneralization ditaXMLGeneralization = new HelperClasses.DitaXmlGeneralization(specializedXmlResolver,
                                                                                                      generalizedXmlResolver, generalizationCatalogMapping);

                ditaXMLGeneralization.AttributesToGeneralizeToProps = AttributesToGeneralizeToProps;
                ditaXMLGeneralization.AttributesToGeneralizeToBase  = AttributesToGeneralizeToBase;


                List <FileInfo> outFiles = new List <FileInfo>();
                foreach (FileInfo inputFile in File)
                {
                    FileInfo outFile = null;
                    try
                    {
                        WriteParentProgress("Generalizing file[" + inputFile.FullName + "]", ++current, File.Length);

                        outFile = new FileInfo(Path.ChangeExtension(inputFile.FullName, ".gen"));
                        // file.MoveTo(file.FullName + ".bak");
                        ditaXMLGeneralization.Generalize(inputFile, outFile);
                        outFiles.Add(outFile);
                        System.IO.File.Delete(inputFile.FullName);
                    }
                    catch (Exception ex)
                    {
                        WriteWarning("Generalizing file " + inputFile.FullName + " failed: " + ex.Message);
                        if (System.IO.File.Exists(Path.ChangeExtension(inputFile.FullName, ".gen")))
                        {
                            System.IO.File.Move(Path.ChangeExtension(inputFile.FullName, ".gen"), Path.ChangeExtension(inputFile.FullName, ".errxml"));
                        }
                        System.IO.File.Move(inputFile.FullName, Path.ChangeExtension(inputFile.FullName, ".err"));
                        StreamWriter errFile = System.IO.File.CreateText(Path.ChangeExtension(inputFile.FullName, ".log"));
                        errFile.Write("Generalizing file " + outFile.FullName + " failed: " + ex.Message);
                        errFile.Close();
                    }
                }
                WriteDebug("outFiles.length[" + outFiles.Count + "]");
                WriteObject(outFiles, true);
            }
            catch (TrisoftAutomationException trisoftAutomationException)
            {
                ThrowTerminatingError(new ErrorRecord(trisoftAutomationException, base.GetType().Name, ErrorCategory.InvalidOperation, null));
            }
            catch (Exception exception)
            {
                ThrowTerminatingError(new ErrorRecord(exception, base.GetType().Name, ErrorCategory.NotSpecified, null));
            }
        }