/// <summary>
        /// Tests the map.
        /// </summary>
        /// <param name="map">The map to execute.</param>
        /// <param name="xsltExtensionObjectOverrides">The overrides for the XSLT arguments - allowing you to mock external assembly methods.</param>
        /// <param name="validateInputXml">if set to <c>true</c> then the input XML is validated.</param>
        /// <param name="validateOutputXml">if set to <c>true</c> then the output XML is validated.</param>
        public void TestMap(TransformBase map, IEnumerable <XsltExtensionObjectDescriptor> xsltExtensionObjectOverrides, bool validateInputXml, bool validateOutputXml)
        {
            if (map == null)
            {
                throw new ArgumentNullException(nameof(map));
            }

            if (validateInputXml)
            {
                BizTalkXmlMapTestValidator.ValidateInputXml(map, this.InputXml, this.Logger);
            }

            this.logger.Log("Executing the BizTalk map (XML to XML) " + map.GetType().Name);
            string outputXml = BizTalkXmlMapExecutor.PerformTransform(map, xsltExtensionObjectOverrides, this.InputXml);

            this.logAssert.IsTrue("XML output from the BizTalk map exists", !string.IsNullOrWhiteSpace(outputXml));
            this.logger.Log();
            this.logger.Log("BizTalk map (XML to XML) execution completed");

            base.SetActualOutputXmlFromXmlString(outputXml);

            if (validateOutputXml)
            {
                BizTalkXmlMapTestValidator.ValidateOutputXml(map, this.ActualOutputXml, this.Logger);
            }
        }
Exemplo n.º 2
0
 public void RenderToGlRecursive(TransformBase objectToProcess)
 {
     GL.PushMatrix();
     GL.MultMatrix(objectToProcess.transform.GetAsFloatArray());
     RenderToGlRecursive((dynamic)objectToProcess.objectToTransform);
     GL.PopMatrix();
 }
 internal TransformMetaData(Type transformBaseType)
 {
     this.mapAssembly    = transformBaseType.Assembly.ToString();
     this._transformBase = (TransformBase)Activator.CreateInstance(transformBaseType);
     this._mapType       = transformBaseType;
     this._xmlDecl       = TransformMetaData._getXmlDeclaration(this._transformBase);
 }
        public static void ConvertOutputXmlFileToOutputFlatFile(TransformBase map, string outputXmlFilename, string outputFlatFileFilename, bool validateFlatFile)
        {
            if (map == null)
            {
                throw new ArgumentNullException(nameof(map));
            }

            ITOMErrorInfo[] creationErrors = null;

            string            targetSchemaClassName = map.TargetSchemas[0];
            CMapperSchemaTree targetSchemaTree      = BizTalkMapSchemaUtility.CreateSchemaTreeAndLoadSchema(map, targetSchemaClassName);

            if (!targetSchemaTree.CreateNativeInstanceFromXMLInstance(outputXmlFilename, outputFlatFileFilename, out creationErrors))
            {
                string message = "No details provided.";

                if (creationErrors != null)
                {
                    var messages = creationErrors.Select(e => $"Line:{e.LineNumber} Position:{e.LinePosition} {(e.IsWarning ? "Warning: " : "Error: ")} {e.ErrorInfo}");
                    message = string.Join(". " + Environment.NewLine, messages);
                }

                throw new InvalidDataException($"An error occurred while converting from XML to a flat file format: {Environment.NewLine}{message}");
            }

            if (validateFlatFile)
            {
                BizTalkXmlMapTestValidator.ValidateFlatFile(outputFlatFileFilename, targetSchemaTree, targetSchemaClassName);
            }
        }
        public static string ConvertOutputXmlToOutputFlatFileContents(TransformBase map, XNode outputXml, bool validateFlatFile)
        {
            if (outputXml == null)
            {
                throw new ArgumentNullException(nameof(outputXml));
            }

            string flatFileContentsResult = null;

            var tempXmlFilename      = Path.GetTempFileName();
            var tempFlatFileFilename = Path.GetTempFileName();

            try
            {
                File.WriteAllText(tempXmlFilename, outputXml.ToString());

                ConvertOutputXmlFileToOutputFlatFile(map, tempXmlFilename, tempFlatFileFilename, validateFlatFile);

                flatFileContentsResult = File.ReadAllText(tempFlatFileFilename);
            }
            finally
            {
                if (File.Exists(tempFlatFileFilename))
                {
                    File.Delete(tempFlatFileFilename);
                }

                if (File.Exists(tempXmlFilename))
                {
                    File.Delete(tempXmlFilename);
                }
            }

            return(flatFileContentsResult);
        }
Exemplo n.º 6
0
    void CreateBaseChannels()
    {
        this.baseChannels = new List <IAnimationChannel>();

        for (int i = 0; i < this.transformLookup.Count; i++)
        {
            TransformBase transform = this.transformLookup[i];

            if (transform is MorphTransform)
            {
                //A small list of keyframes, used to sample values.
                List <float> keys = new List <float>(5)
                {
                    0.0f, 0.0f, 0.0f, 0.0f, 0.0f
                };
                MorphChannel morphChannel = new MorphChannel(transform.GetName(), keys, false, false, false, false, FRAMERATE);

                this.baseChannels.Add(morphChannel);
            }
            else if (transform is BoneTransform)
            {
                BoneTransform boneTransform = transform as BoneTransform;

                //Sample initial rotation value.
                Vector3        angle = boneTransform.GetInitialRotation().eulerAngles;
                List <Vector3> keys  = new List <Vector3>(5)
                {
                    angle, angle, angle, angle, angle
                };
                RotationChannel rotationChannel = new RotationChannel(boneTransform.GetName(), keys, false, false, false, false, FRAMERATE);

                this.baseChannels.Add(rotationChannel);
            }
        }
    }
Exemplo n.º 7
0
 public string GetScadOutputRecursive(TransformBase objectToProcess, int level = 0)
 {
     return(ApplyIndent(AddRenderInfoIfReqired(objectToProcess) + "multmatrix(m = [ ["
                        + objectToProcess.transform.Column0.ToString("0.#######") + "],["
                        + objectToProcess.transform.Column1.ToString("0.#######") + "],["
                        + objectToProcess.transform.Column2.ToString("0.#######") + "],["
                        + objectToProcess.transform.Column3.ToString("0.#######") + "] ])" + AddNameAsComment(objectToProcess) + "\n{\n" + GetScadOutputRecursive((dynamic)objectToProcess.objectToTransform, level + 1) + "\n}", level));
 }
Exemplo n.º 8
0
 /// <summary>
 /// Executes the map using the scalable transform technique
 /// </summary>
 /// <param name="mapInstance"></param>
 /// <param name="inputStream"></param>
 /// <param name="outputStream"></param>
 public static void ExecuteMapScalable(TransformBase mapInstance, Stream inputStream, Stream outputStream)
 {
     ExecuteMapScalable(mapInstance, inputStream, outputStream, new XmlUrlResolver(), false);
     if (outputStream.CanSeek)
     {
         outputStream.Seek(0, SeekOrigin.Begin);
     }
 }
Exemplo n.º 9
0
 public EntityMotionState(Entity entity, bool isKinematic)
 {
     Entity     = entity;
     _transform = entity.Transform;
     if (isKinematic)
     {
         Entity.TransformEvent += (o, tr) => _transform = tr;
     }
 }
Exemplo n.º 10
0
        public Entity(string name, Vec3 position, Vec3 scale, Vec3 rotation)
        {
            Name       = name;
            _transform = new TransformBase(rotation, scale, position);

#if DEBUG
            Log();
#endif
        }
        public BizTalkMapSchemaArtifactLoader(TransformBase map)
        {
            if (map == null)
            {
                throw new ArgumentNullException(nameof(map));
            }

            this.mapperType = map.GetType();
        }
Exemplo n.º 12
0
        public Entity(Entity entity, string name, Vec3 position, Vec3 scale, Vec3 rotation)
        {
            Name       = name;
            _transform = new TransformBase(rotation, scale, position);
            Components = entity.Components;

#if DEBUG
            Log();
#endif
        }
 /// <summary>
 /// Executes the map using the in memory technique
 /// </summary>
 /// <param name="mapInstance"></param>
 /// <param name="inputFilePath"></param>
 /// <param name="outputFilePath"></param>
 public static void ExecuteMapInMemory(TransformBase mapInstance, string inputFilePath, string outputFilePath)
 {
     using (FileStream inputStream = new FileStream(inputFilePath, FileMode.Open, FileAccess.Read))
     {
         using (FileStream outputStream = new FileStream(outputFilePath, FileMode.Create, FileAccess.Write))
         {
             XPathDocument doc = new XPathDocument(inputStream);
             mapInstance.Transform.Transform(doc, mapInstance.TransformArgs, outputStream);
         }
     }
 }
Exemplo n.º 14
0
 /// <summary>
 /// Executes the map using the scalable transform technique
 /// </summary>
 /// <param name="mapInstance"></param>
 /// <param name="inputFilePath"></param>
 /// <param name="outputFilePath"></param>
 /// <param name="resolver"></param>
 /// <param name="whitespaceCorrect"></param>
 public static void ExecuteMapScalable(TransformBase mapInstance, string inputFilePath, string outputFilePath, XmlResolver resolver, bool whitespaceCorrect)
 {
     using (FileStream inputStream = new FileStream(inputFilePath, FileMode.Open, FileAccess.Read))
     {
         using (FileStream outputStream = new FileStream(outputFilePath, FileMode.Create, FileAccess.Write))
         {
             XmlReader xmlRdr = new XmlTextReader(inputStream);
             mapInstance.StreamingTransform.ScalableTransform(xmlRdr, mapInstance.TransformArgs, outputStream, resolver, whitespaceCorrect);
         }
     }
 }
        public static XNode ConvertInputFlatFileContentsToInputXml(TransformBase map, string inputFlatFileContents)
        {
            if (map == null)
            {
                throw new ArgumentNullException(nameof(map));
            }

            string            sourceSchemaClassName = map.SourceSchemas[0];
            CMapperSchemaTree sourceSchemaTree      = BizTalkMapSchemaUtility.CreateSchemaTreeAndLoadSchema(map, sourceSchemaClassName);
            string            convertedXml          = BizTalkXmlMapTestValidator.ValidateFlatFileContents(inputFlatFileContents, sourceSchemaTree, sourceSchemaClassName);

            return(XElement.Parse(convertedXml));
        }
Exemplo n.º 16
0
        public static CMapperSchemaTree CreateSchemaTreeAndLoadSchema(TransformBase map, string schemaClassName)
        {
            string errorMessage = null;

            CMapperSchemaTree schemaTree = BizTalkMapSchemaUtility.CreateSchemaTree(map);

            if (!schemaTree.LoadFromDotNetPath(schemaClassName, null, out errorMessage))
            {
                throw new TypeLoadException($"An error occurred while loading the schema type '{schemaClassName}': {errorMessage}");
            }

            return(schemaTree);
        }
Exemplo n.º 17
0
        public static CMapperSchemaTree CreateSchemaTree(TransformBase map)
        {
            var schemaLoader         = new BizTalkMapSchemaArtifactLoader(map);
            var schemaResolveHandler = new SchemaResolver();

            schemaResolveHandler.CustomResolution(schemaLoader);

            var schemaTree = new CMapperSchemaTree();

            schemaTree.SetSchemaResolveHandler(schemaResolveHandler);

            return(schemaTree);
        }
Exemplo n.º 18
0
        private static XslCompiledTransform LoadXslCompiledTransform(TransformBase transform)
        {
            using (var xmlReader = XmlReader.Create(new StringReader(transform.XmlContent), new XmlReaderSettings {
                CloseInput = true
            }))
            {
                var xslt =
#if DEBUG
                    new XslCompiledTransform(true);
#else
                    new XslCompiledTransform();
#endif
                xslt.Load(xmlReader, XsltSettings.Default, new XmlUrlResolver());
                return(xslt);
            }
        }
Exemplo n.º 19
0
        public static XslCompiledTransform LoadStylesheetFromMap(TransformBase map, XmlResolver stylesheetResolver)
        {
            if (map == null)
            {
                throw new ArgumentNullException(nameof(map));
            }

            var transform = new XslCompiledTransform();

            using (var stylesheet = new XmlTextReader(new StringReader(map.XmlContent)))
            {
                transform.Load(stylesheet, new XsltSettings(true, true), stylesheetResolver);
            }

            return(transform);
        }
        /// <summary>
        /// Perform the transform using the map.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="xsltExtensionObjectOverrides">Overrides the extension objects in the map with the specified types.</param>
        /// <param name="inputXml"></param>
        /// <returns>The resulting XML output from the map.</returns>
        public static string PerformTransform(TransformBase map, IEnumerable <XsltExtensionObjectDescriptor> xsltExtensionObjectOverrides, XNode inputXml)
        {
            if (map == null)
            {
                throw new ArgumentNullException(nameof(map));
            }

            XsltArgumentList xsltArguments = map.TransformArgs;      // map.TransformArgs is immutable and created each time the property is called ;)

            if (xsltExtensionObjectOverrides != null)
            {
                ApplyXsltExtensionObjectOverridesToXsltArguments(xsltArguments, xsltExtensionObjectOverrides, map);
            }

            return(PerformTransform(map, xsltArguments, inputXml));
        }
Exemplo n.º 21
0
    public void BindAllChannels(Dictionary <string, TransformBase> animationTransforms)
    {
        for (int i = 0; i < this.animationChannels.Count; i++)
        {
            IAnimationChannel channel     = this.animationChannels[i];
            string            channelName = channel.GetChannelName();

            //Bind channel to a transform.
            if (animationTransforms.ContainsKey(channelName))
            {
                TransformBase animationTransform = animationTransforms[channelName];

                //Bind channel to animatable transform.
                channel.Bind(animationTransform);
            }
        }
    }
        /// <summary>
        /// Perform the transform using the map.
        /// </summary>
        /// <param name="map"></param>
        /// <param name="xsltArguments"></param>
        /// <param name="inputXml"></param>
        /// <returns>The resulting XML output from the map.</returns>
        private static string PerformTransform(TransformBase map, XsltArgumentList xsltArguments, XNode inputXml)
        {
            if (map == null)
            {
                throw new ArgumentNullException(nameof(map));
            }
            if (inputXml == null)
            {
                throw new ArgumentNullException(nameof(inputXml));
            }

            try
            {
                XslCompiledTransform transform = BizTalkMapSchemaUtility.LoadStylesheetFromMap(map);

                using (var input = XmlReader.Create(new StringReader(inputXml.ToString())))
                {
                    var sb       = new StringBuilder();
                    var settings = new XmlWriterSettings
                    {
                        Indent = true
                    };

                    using (var results = XmlWriter.Create(sb, settings))
                    {
                        transform.Transform(input, xsltArguments, results);
                    }

                    return(sb.ToString());
                }
            }
            catch (Exception exception)
            {
                var sb = new StringBuilder("An error occurred while executing the transform:" + Environment.NewLine);

                var currentException = exception;
                while (currentException != null)
                {
                    sb.AppendLine(currentException.ToString());

                    currentException = currentException.InnerException;
                }

                throw new InvalidDataException(sb.ToString());
            }
        }
        public static void ValidateOutputXml(TransformBase map, XNode outputXml, ISimpleLogger logger)
        {
            if (map == null)
            {
                throw new ArgumentNullException(nameof(map));
            }
            if (outputXml == null)
            {
                throw new ArgumentNullException(nameof(outputXml));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            logger.Log("Validating the output XML from the BizTalk map");
            ValidateXml(outputXml.ToString(), map.TargetSchemas, BizTalkMapSchemaUtility.GetSchemaReferenceAttributes(map));
        }
        //Step 3: The core work magic here
        private static void Map(TransformBase map, string xmlInputFile, string outputXmlFile,
            Dictionary<string, object> namespaceToInstanceObjectsMap)
        {
            //Construct XsltArgumentList mapping the namespace to the mocked object
            var argumentsInstanceExtensionObjects = new XsltArgumentList();
            foreach (var entry in namespaceToInstanceObjectsMap)
            {
                argumentsInstanceExtensionObjects.AddExtensionObject(entry.Key, entry.Value);
            }

            //Do the transform using XslCompiledTransform
            var transform = new XslCompiledTransform();
            var setting = new XsltSettings(false, true);
            transform.Load(XmlReader.Create(new StringReader(map.XmlContent)), setting, new XmlUrlResolver());
            using (var stream = new FileStream(outputXmlFile, FileMode.CreateNew))
            {
                //using XslCompiledTransform to transform the source to output messahe
                transform.Transform(xmlInputFile, argumentsInstanceExtensionObjects, stream);
            }
        }
Exemplo n.º 25
0
        private static XmlDeclaration _getXmlDeclaration(TransformBase t)
        {
            XmlDocument xmlDocument = XmlHelpers.CreateXmlDocument();

            xmlDocument.LoadXml(t.XmlContent);
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDocument.NameTable);

            nsmgr.AddNamespace("xsl", "http://www.w3.org/1999/XSL/Transform");
            XmlNode xmlNode = xmlDocument.SelectSingleNode("//xsl:output", nsmgr);

            if (xmlNode == null || xmlNode.Attributes.GetNamedItem("omit-xml-declaration") != null && xmlNode.Attributes.GetNamedItem("omit-xml-declaration").Value == "yes")
            {
                return((XmlDeclaration)null);
            }
            string version    = xmlNode.Attributes.GetNamedItem("version") == null ? "1.0" : xmlNode.Attributes.GetNamedItem("version").Value;
            string encoding   = xmlNode.Attributes.GetNamedItem("encoding") == null ? "UTF-8" : xmlNode.Attributes.GetNamedItem("encoding").Value;
            string standalone = xmlNode.Attributes.GetNamedItem("standalone") == null ? "no" : xmlNode.Attributes.GetNamedItem("standalone").Value;

            return(xmlDocument.CreateXmlDeclaration(version, encoding, standalone));
        }
Exemplo n.º 26
0
        /// <summary>
        /// Tests the map.
        /// </summary>
        /// <param name="map">The map to execute.</param>
        /// <param name="xsltExtensionObjectOverrides">The overrides for the XSLT arguments - allowing you to mock external assembly methods.</param>
        /// <param name="validateInput">if set to <c>true</c> then the input flat file contents and converted XML is validated.</param>
        /// <param name="validateOutput">if set to <c>true</c> then the output is validated.</param>
        public void TestMap(TransformBase map, IEnumerable <XsltExtensionObjectDescriptor> xsltExtensionObjectOverrides, bool validateInput, bool validateOutput)
        {
            if (map == null)
            {
                throw new ArgumentNullException(nameof(map));
            }

            XNode inputXml = BizTalkXmlFlatFileAdapter.ConvertInputFlatFileContentsToInputXml(map, this.InputFlatFileContents);

            if (validateInput)
            {
                BizTalkXmlMapTestValidator.ValidateInputXml(map, inputXml, this.Logger);
            }

            Logger.Log("Executing the BizTalk map (flat file to flat file) " + map.GetType().Name);
            string outputXmlString = BizTalkXmlMapExecutor.PerformTransform(map, xsltExtensionObjectOverrides, inputXml);

            LogAssert.IsTrue("XML output from the BizTalk map exists", !string.IsNullOrWhiteSpace(outputXmlString));

            var actualOutputXml = XElement.Parse(outputXmlString);

            if (validateOutput)
            {
                BizTalkXmlMapTestValidator.ValidateOutputXml(map, actualOutputXml, this.Logger);
            }

            var schemaTree = BizTalkMapSchemaUtility.CreateSchemaTreeAndLoadSchema(map, map.TargetSchemas[0]);

            if (schemaTree.IsStandardXML)
            {
                throw new InvalidOperationException("The map does not have a schema for converting to a flat file.");
            }
            else
            {
                Logger.Log("Converting the XML output of the BizTalk map to a flat file");
                this.ActualOutputFlatFileContents = BizTalkXmlFlatFileAdapter.ConvertOutputXmlToOutputFlatFileContents(map, actualOutputXml, validateOutput);
            }

            Logger.Log();
            Logger.Log("BizTalk map (flat file to flat file) execution completed");
        }
Exemplo n.º 27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="map"></param>
        /// <param name="xml"></param>
        /// <param name="extObjects"></param>
        /// <returns></returns>
        public string ExecuteMap(TransformBase map, string xml, string extObjects = null)
        {
            string result = string.Empty;
            XslCompiledTransform transform = new XslCompiledTransform();
            XsltSettings         setting   = new XsltSettings(false, true);
            var xmlContent = map.XmlContent;

            if (!String.IsNullOrWhiteSpace(xmlContent))
            {
                xmlContent = FixSpecialNamespaceLocalName(xmlContent);

                transform.Load(XmlReader.Create(new StringReader(xmlContent)), setting, new XmlUrlResolver());

                using (StringWriter writer = new StringWriter())
                {
                    transform.Transform(XmlReader.Create(new StringReader(xml)),
                                        GetExtensionObjects(extObjects), XmlWriter.Create(writer));
                    result = writer.ToString();
                }
            }
            return(result);
        }
Exemplo n.º 28
0
 public CsgObject DoCopyAndFlatten(TransformBase objectToProcess)
 {
     return(new TransformBase(DoCopyAndFlatten((dynamic)objectToProcess.objectToTransform), objectToProcess.transform, objectToProcess.Name));
 }
Exemplo n.º 29
0
 /// <summary>
 /// Tests the map.
 /// </summary>
 /// <param name="map">The map to execute.</param>
 /// <param name="validateInputXml">if set to <c>true</c> then the input XML is validated.</param>
 /// <param name="validateOutput">if set to <c>true</c> then the output is validated.</param>
 public void TestMap(TransformBase map, bool validateInputXml, bool validateOutput)
 {
     TestMap(map, null, validateInputXml, validateOutput);
 }
Exemplo n.º 30
0
 /// <summary>
 /// Tests the map and performs validation on both the input XML and output.
 /// </summary>
 /// <param name="map">The map.</param>
 /// <param name="xsltExtensionObjectOverrides">The overrides for the XSLT arguments - allowing you to mock external assembly methods.</param>
 public void TestMap(TransformBase map, IEnumerable <XsltExtensionObjectDescriptor> xsltExtensionObjectOverrides)
 {
     TestMap(map, xsltExtensionObjectOverrides, true, true);
 }
Exemplo n.º 31
0
 /// <summary>
 /// Constructor for helper class to execute BizTalk maps
 /// </summary>
 /// <param name='mapType'>The type of the BizTalk map to execute</param>
 public BizTalkMapTester(Type mapType)
 {
     _map = CreateMapFromType(mapType);
 }