Пример #1
0
        private void FillRootElementWithSubElements <T>(
            IEnumerable <T> dataProvider,
            IXmlTransformer <T> xmlTransformer,
            XmlNode xmlRootElement,
            XmlDocument xmlDocument)
        {
            int i = 0;

            foreach (var data in dataProvider)
            {
                i++;
                string xmlString;
                try
                {
                    xmlString = xmlTransformer.TransformToXml(data);
                }
                catch (Exception)
                {
                    this.Logger?.Info($"Data on the {i} iteration of the cycle is not valid.");
                    continue;
                }

                var xmlDocumentFragment = xmlDocument.CreateDocumentFragment();
                xmlDocumentFragment.InnerXml = xmlString;

                xmlRootElement.AppendChild(xmlDocumentFragment);
            }
        }
Пример #2
0
 static Program()
 {
     Kernel = new StandardKernel();
     NInjectDependencyResolver.Configure(Kernel);
     Reader      = Kernel.Get <IReader <string> >();
     Transformer = Kernel.Get <IXmlTransformer>();
 }
        public AbstractXmlNormalizer(IXmlTransformer transformer)
        {
            if (transformer == null)
            {
                throw new ArgumentNullException(nameof(transformer));
            }

            this.transformer = transformer;
        }
Пример #4
0
        public ReleaseNoteGenerator(Configuration configuration, IJiraIssueAggregator jiraIssueAggregator, IXmlTransformer xmlTransformer)
        {
            ArgumentUtility.CheckNotNull ("configuration", configuration);
              ArgumentUtility.CheckNotNull ("jiraIssueAggregator", jiraIssueAggregator);
              ArgumentUtility.CheckNotNull ("xmlTransformer", xmlTransformer);

              _configuration = configuration;
              _jiraIssueAggregator = jiraIssueAggregator;
              _xmlTransformer = xmlTransformer;
        }
        public ReleaseNoteGenerator(Configuration configuration, IJiraIssueAggregator jiraIssueAggregator, IXmlTransformer xmlTransformer)
        {
            ArgumentUtility.CheckNotNull("configuration", configuration);
            ArgumentUtility.CheckNotNull("jiraIssueAggregator", jiraIssueAggregator);
            ArgumentUtility.CheckNotNull("xmlTransformer", xmlTransformer);

            _configuration       = configuration;
            _jiraIssueAggregator = jiraIssueAggregator;
            _xmlTransformer      = xmlTransformer;
        }
Пример #6
0
        private static void VerifyInput <T>(IReader <T> reader, IXmlTransformer transformer)
        {
            if (ReferenceEquals(reader, null))
            {
                throw new ArgumentNullException(nameof(reader));
            }

            if (ReferenceEquals(transformer, null))
            {
                throw new ArgumentNullException(nameof(transformer));
            }
        }
Пример #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="viewName"></param>
        /// <param name="schemaSet"></param>
        /// <param name="typeDetector"></param>
        /// <param name="pattern"></param>
        /// <param name="transformIncomingViaXsl"></param>
        /// <param name="transformOutgoingViaXsl"></param>
        /// <param name="validateOriginal"></param>
        /// <param name="emitAndCompare"></param>
        /// <param name="validateEmitted"></param>
        /// <returns></returns>
        public static LoadCounters LoadFiles(
            string viewName, XmlSchemaSet schemaSet, Func <string, Type> typeDetector, string pattern,
            IXmlTransformer transformIncomingViaXsl, IXmlTransformer transformOutgoingViaXsl,
            bool validateOriginal, bool emitAndCompare, bool validateEmitted)
        {
            ITestLog testLog         = new DebugLog();
            var      counters        = new LoadCounters();
            string   sampleFilesPath = @"..\..\..\..\..\Metadata\FpML.V5r3\fpml.org\samples\5.3\" + viewName;
            // temp files
            string incomingFullPath = Path.GetFullPath(@"..\..\step1incoming.xml");
            string internalFullPath = Path.GetFullPath(@"..\..\step2internal.xml");
            string outgoingFullPath = Path.GetFullPath(@"..\..\step3outgoing.xml");
            string fullPath         = Path.GetFullPath(sampleFilesPath);
            var    fileNames        = Directory.GetFiles(fullPath, pattern, SearchOption.AllDirectories);

            System.Diagnostics.Debug.Print("Loading {0} files from path: {1}", fileNames.Length, fullPath);
            for (int index = 0; index < fileNames.Length; index++)
            {
                string originalFilename = fileNames[index];
                string baseFilename     = Path.GetFileName(originalFilename);
                string relativePath     = Path.GetDirectoryName(originalFilename.Substring(fullPath.Length));
                string testId           = $"File{index}";
                System.Diagnostics.Debug.Print("[{0}] {1} ({2}) processing...", index, baseFilename, relativePath);
                counters.FilesProcessed.Inc();
                // validation
                if (validateOriginal)
                {
                    ValidateXml(testLog, testId, originalFilename, schemaSet, counters.OrigValidationErrors, counters.OrigValidationWarnings);
                }
                // incoming transformation
                TransformXml(testLog, testId, transformIncomingViaXsl, originalFilename, incomingFullPath, counters.IncomingTransformErrors);
                // deserialise
                object fpml = DeserialiseXml(testLog, testId, typeDetector, incomingFullPath, counters.DeserialisationErrors);
                // serialise
                SerialiseXml(testLog, testId, fpml, internalFullPath, counters.SerialisationErrors);
                // compare internal documents
                CompareXml(testLog, testId, incomingFullPath, internalFullPath, counters.InternalComparisonErrors);
                // outgoing transformation
                TransformXml(testLog, testId, transformOutgoingViaXsl, internalFullPath, outgoingFullPath, counters.OutgoingTransformErrors);
                // compare external documents
                if (emitAndCompare)
                {
                    CompareXml(testLog, testId, originalFilename, outgoingFullPath, counters.ExternalComparisonErrors);
                }
                if (validateEmitted)
                {
                    ValidateXml(testLog, testId, outgoingFullPath, schemaSet, counters.CopyValidationErrors, counters.CopyValidationWarnings);
                }
            }
            return(counters);
        }
Пример #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="log"></param>
 /// <param name="testId"></param>
 /// <param name="transformer"></param>
 /// <param name="sourcePath"></param>
 /// <param name="targetPath"></param>
 /// <param name="errorCounter"></param>
 public static void TransformXml(ITestLog log, string testId, IXmlTransformer transformer, string sourcePath, string targetPath, Counter errorCounter)
 {
     log.LogInfo($"    TransformXml: sourcePath={sourcePath}", testId);
     log.LogInfo($"    TransformXml: targetPath={targetPath}", testId);
     try
     {
         transformer.Transform(sourcePath, targetPath);
     }
     catch (Exception excp)
     {
         errorCounter.Inc();
         log.LogException(excp, testId, false);
     }
 }
Пример #9
0
        public static List <object> LoadAndReturnConfirmationExamples(
            XmlSchemaSet schemaSet, Func <string, Type> typeDetector,
            IXmlTransformer transformIncomingViaXsl, IXmlTransformer transformOutgoingViaXsl,
            bool validateOriginal, bool emitAndCompare, bool validateEmitted)
        {
            ITestLog testLog  = new DebugLog();
            var      counters = new LoadCounters();
            var      result   = new List <object>();
            //string schemaPath = @"..\..\..\nab.QR.FpML.V5r3\" + viewName + ".xsd";
            //string schemaFullPath = Path.GetFullPath(schemaPath);
            //if (!File.Exists(schemaFullPath))
            //    throw new FileNotFoundException("Schema missing!", schemaFullPath);
            const string fileSpec        = "*.xml";
            const string sampleFilesPath = @"..\..\..\..\..\Metadata\FpML.V5r3\fpml.org\samples\5.3\Confirmation\products";

            // temp files
            string incomingFullPath = Path.GetFullPath(@"..\..\step1incoming.xml");

            string fullPath  = Path.GetFullPath(sampleFilesPath);
            var    filenames = Directory.GetFiles(fullPath, fileSpec, SearchOption.AllDirectories);

            System.Diagnostics.Debug.Print("Loading {0}", filenames.Length);
            for (int index = 0; index < filenames.Length; index++)
            {
                string originalFilename = filenames[index];
                //string baseFilename = Path.GetFileName(originalFilename);
                //string relativePath = Path.GetDirectoryName(originalFilename.Substring(fullPath.Length));
                string testId = String.Format("File{0}", index);

                //System.Diagnostics.Debug.Print("[{0}] {1} ({2}) processing...", index, baseFilename, relativePath);
                counters.FilesProcessed.Inc();

                // validation
                //if (validateOriginal)
                //{
                //    ValidateXml(testLog, testId, originalFilename, schemaSet, counters.OrigValidationErrors, counters.OrigValidationWarnings);
                //}

                // incoming transformation
                TransformXml(testLog, testId, transformIncomingViaXsl, originalFilename, incomingFullPath, counters.IncomingTransformErrors);

                // deserialise
                object fpml = DeserialiseXml(testLog, testId, typeDetector, incomingFullPath, counters.DeserialisationErrors);
                result.Add(fpml);
            }
            return(result);
        }
Пример #10
0
        /// <inheritdoc />
        /// <summary>
        /// Converts data provided by <paramref name="reader"/> in XmlDocument with <paramref name="transformer"/>.
        /// </summary>
        /// <param name="reader">Provides converter with data.</param>
        /// <param name="transformer">Performs transformation of data.</param>
        /// <returns>Xml document representing data.</returns>
        /// <exception cref="ArgumentNullException">
        /// Thrown when <paramref name="reader"/> or <paramref name="transformer"/> is null.
        /// </exception>
        public XmlDocument Convert(IReader <string> reader, IXmlTransformer transformer)
        {
            VerifyInput(reader, transformer);

            var xmlDocument    = new XmlDocument();
            var xmlDeclaration = xmlDocument.CreateXmlDeclaration("1.0", "utf-8", null);

            xmlDocument.AppendChild(xmlDeclaration);

            var xmlRootElement = transformer.GetRootElement(xmlDocument);

            GetChildElements(xmlRootElement, xmlDocument, reader, transformer);

            xmlDocument.AppendChild(xmlRootElement);

            return(xmlDocument);
        }
Пример #11
0
        private static void VerifyInput <T>(
            IDataProvider <T> dataProvider, IXmlTransformer <T> xmlTransformer, string rootElementName)
        {
            if (ReferenceEquals(dataProvider, null))
            {
                throw new ArgumentNullException(nameof(dataProvider));
            }

            if (ReferenceEquals(xmlTransformer, null))
            {
                throw new ArgumentNullException(nameof(xmlTransformer));
            }

            if (string.IsNullOrWhiteSpace(rootElementName))
            {
                throw new ArgumentException($"{nameof(rootElementName)} is invalid", nameof(rootElementName));
            }
        }
Пример #12
0
        /// <summary>
        /// Converts data of type <typeparamref name="T"/> to xml document.
        /// </summary>
        /// <typeparam name="T">Data type to convert to xml.</typeparam>
        /// <param name="dataProvider">Class supplying data to transform</param>
        /// <param name="xmlTransformer">Class that converts data to xml</param>
        /// <param name="rootElementName">root element name</param>
        /// <returns>Xml document representing data.</returns>
        /// <exception cref="ArgumentNullException">Exception thrown when
        /// <paramref name="dataProvider"/> or <paramref name="xmlTransformer"/>
        /// is null.</exception>
        /// <exception cref="ArgumentException">Exception thrown when
        /// <paramref name="rootElementName"/> is invalid.</exception>
        public XmlDocument ConvertDataToXml <T>(
            IDataProvider <T> dataProvider, IXmlTransformer <T> xmlTransformer, string rootElementName)
        {
            VerifyInput(dataProvider, xmlTransformer, rootElementName);

            var xmlDocument    = new XmlDocument();
            var xmlDeclaration = xmlDocument.CreateXmlDeclaration("1.0", "utf-8", null);

            xmlDocument.AppendChild(xmlDeclaration);

            var xmlRootElement = xmlDocument.CreateElement(rootElementName);

            FillRootElementWithSubElements(
                dataProvider.GetData(), xmlTransformer, xmlRootElement, xmlDocument);

            xmlDocument.AppendChild(xmlRootElement);

            return(xmlDocument);
        }
Пример #13
0
        public async Task <T> Deserialize <T>(IXmlTransformer transformer, XmlNode node)
        {
            if (transformer == null)
            {
                throw new ArgumentNullException(nameof(transformer));
            }

            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            var stream = transformer.TransformToStream(node);

            var result = await this.deserializer.Deserialize <T>(stream);

            stream.Close();
            stream.Dispose();

            return(result);
        }
Пример #14
0
        public async Task <T> Deserialize <T>(IXmlTransformer transformer, string xml)
        {
            if (transformer == null)
            {
                throw new ArgumentNullException(nameof(transformer));
            }

            if (string.IsNullOrWhiteSpace(xml))
            {
                throw new ArgumentNullException(nameof(xml));
            }

            var stream = transformer.TransformToStream(xml);

            var result = await this.deserializer.Deserialize <T>(stream);

            stream.Close();
            stream.Dispose();

            return(result);
        }
Пример #15
0
 public XmlLayout(IXmlTransformer _xmlTransformer)
 {
     xmlTransformer = _xmlTransformer;
 }
Пример #16
0
 public void Setup()
 {
     testSubject  = new XmlTransformer();
     templatePath = Path.Combine(basePath, "../../../PeterStankowski/Templates/xslt/Default.xslt");
     dataPath     = Path.Combine(basePath, "../../../PeterStankowski/Templates/Empty.xml");
 }
 public void SetUp()
 {
     _jiraIssueAggregatorStub = MockRepository.GenerateStub<IJiraIssueAggregator>();
       _xmlTransformerStub = MockRepository.GenerateMock<IXmlTransformer>();
       _releaseNoteGenerator = new ReleaseNoteGenerator (_configuration, _jiraIssueAggregatorStub, _xmlTransformerStub);
 }
Пример #18
0
        private void GetChildElements <T>(XmlNode root, XmlDocument xmlDocument, IReader <T> reader, IXmlTransformer transformer)
        {
            int i = 0;

            foreach (var data in reader.GetData())
            {
                i++;
                XmlNode currentNode;
                try
                {
                    currentNode = transformer.Transform(data as string, xmlDocument);
                }
                catch (Exception)
                {
                    this.Logger?.Warn($"Url address on the {i} line is not valid.");
                    continue;
                }

                root.AppendChild(currentNode);
            }
        }
 public void SetUp()
 {
     _jiraIssueAggregatorStub = MockRepository.GenerateStub <IJiraIssueAggregator>();
     _xmlTransformerStub      = MockRepository.GenerateMock <IXmlTransformer>();
     _releaseNoteGenerator    = new ReleaseNoteGenerator(_configuration, _jiraIssueAggregatorStub, _xmlTransformerStub);
 }