Ejemplo n.º 1
0
 protected XmlIR(XmlIR xmlIR)
 {
     this._isValidated     = xmlIR._isValidated;
     this._documents       = xmlIR._documents;
     this._xmlSchemaSet    = xmlIR._xmlSchemaSet;
     this._id              = xmlIR._id;
     this._message         = xmlIR._message;
     this._documentsLoaded = xmlIR._documentsLoaded;
 }
Ejemplo n.º 2
0
 protected XmlIR(XmlIR xmlIR)
 {
     IsValidated         = xmlIR.IsValidated;
     BimlFiles           = xmlIR.BimlFiles;
     SchemaSet           = xmlIR.SchemaSet;
     DefaultXmlNamespace = xmlIR.DefaultXmlNamespace;
     Id = xmlIR.Id;
     VulcanOnPropertyChanged("BimlFiles", null, BimlFiles);
 }
Ejemplo n.º 3
0
Archivo: XmlIR.cs Proyecto: japj/vulcan
 protected XmlIR(XmlIR xmlIR)
 {
     IsValidated = xmlIR.IsValidated;
     BimlFiles = xmlIR.BimlFiles;
     SchemaSet = xmlIR.SchemaSet;
     DefaultXmlNamespace = xmlIR.DefaultXmlNamespace;
     Id = xmlIR.Id;
     VulcanOnPropertyChanged("BimlFiles", null, BimlFiles);
 }
Ejemplo n.º 4
0
        public IIR Execute(IIR predecessorIR)
        {
            var xmlIR = predecessorIR as XmlIR;
            if (xmlIR == null)
            {
                MessageEngine.Trace(Severity.Error, Resources.ErrorPhaseWorkflowIncorrectInputIRType, predecessorIR.GetType().ToString(), Name);
            }

            var xsltFileList = new List<string>();
            string xsltFolderPath = PathManager.GetToolSubpath(Settings.Default.SubPathXsltTransformFolder);
            foreach (string xsltFile in _xsltFiles.Split(';'))
            {
                if (!String.IsNullOrEmpty(xsltFile))
                {
                    xsltFileList.Add(Path.Combine(xsltFolderPath, xsltFile));
                }
            }

            var settings = new XsltSettings(true, false);
            var output = new XmlIR();

            // REVIEW: The approach I take here is to pipeline XSLT transforms using a MemoryStream.  This isn't great.
            //         In the next .NET Fx, they are expecting to fix XslCompiledTransform so it can pipeline more resonably.  This should be changed at that time.
            foreach (BimlFile bimlFile in xmlIR.BimlFiles)
            {
                XDocument document = bimlFile.XDocument;
                var intermediateXmlDocument = new XmlDocument();
                intermediateXmlDocument.Load(document.CreateReader());
                    if (!String.IsNullOrEmpty(xmlIR.TemplatePath))
                    {
                        foreach (string s in xsltFileList)
                        {
                            var xslt = new XslCompiledTransform();
                            var args = new XsltArgumentList();

                            args.AddParam("TemplatePath", String.Empty, xmlIR.TemplatePath);

                            xslt.Load(s, settings, new XmlUrlResolver());

                            var intermediateMemoryStream = new MemoryStream();
                            xslt.Transform(intermediateXmlDocument, args, intermediateMemoryStream);

                            intermediateMemoryStream.Position = 0;

                            intermediateXmlDocument = new XmlDocument();
                            intermediateXmlDocument.Load(intermediateMemoryStream);
                        }
                    }

                output.AddXml(bimlFile.FilePath, intermediateXmlDocument, bimlFile.EmitType, true);
            }

            output.SchemaSet = xmlIR.SchemaSet;
            output.DefaultXmlNamespace = xmlIR.DefaultXmlNamespace;
            return output;
        }
Ejemplo n.º 5
0
        public VulcanEngine.IR.IIR Execute(IIR PredecessorIR)
        {
            XmlIR xmlIR = PredecessorIR as XmlIR;
            if (xmlIR == null)
            {
                _message.Trace(Severity.Error, Resources.ErrorPhaseWorkflowIncorrectInputIRType, PredecessorIR.GetType().ToString(), this.Name);
            }

            string XsltFolderPath = PathManager.GetToolSubpath(Settings.Default.SubPathXsltTransformFolder);
            string[] XsltFileNames = Directory.GetFiles(XsltFolderPath, "*.xsl");

            if (XsltFileNames.Length <= 0)
            {
                _message.Trace(Severity.Warning, Resources.WarningNoPreProcessorFound);
                return null;
            }

            XsltSettings settings = new XsltSettings(true, false);
            XmlIR output = new XmlIR();

            // REVIEW: The approach I take here is to pipeline XSLT transforms using a MemoryStream.  This isn't great.
            //         In the next .NET Fx, they are expecting to fix XslCompiledTransform so it can pipeline more resonably.  This should be changed at that time.
            foreach (XmlIRDocumentType docType in xmlIR.XDocuments.Keys)
            {
                foreach (XDocument xDocument in xmlIR.XDocuments[docType])
                {
                    XmlDocument intermediateXMLDocument = new XmlDocument();
                    intermediateXMLDocument.Load(xDocument.CreateReader());
                    foreach (string s in XsltFileNames)
                    {
                        XslCompiledTransform xslt = new XslCompiledTransform();
                        XsltArgumentList args = new XsltArgumentList();
                        args.AddParam("XSLTFolderPath", String.Empty, XsltFolderPath);

                        xslt.Load(s, settings, new XmlUrlResolver());

                        MemoryStream intermediateMemoryStream = new MemoryStream();
                        xslt.Transform(intermediateXMLDocument, args, intermediateMemoryStream);

                        intermediateMemoryStream.Position = 0;

                        intermediateXMLDocument = new XmlDocument();
                        intermediateXMLDocument.Load(intermediateMemoryStream);
                    }
                    output.AddXml(intermediateXMLDocument,docType);
                }
            }
            return output;   
        }
Ejemplo n.º 6
0
        public override bool Execute()
        {
            MessageEngine.Reset();
            MessageEngine Message = MessageEngine.Create("__VULCAN MAIN");
            Message.Trace(Severity.Notification, Resources.VulcanStart + Assembly.GetExecutingAssembly().GetName().Version);

#if DEBUG
            Message.Trace(Severity.Notification, "DEBUG VERSION");
#endif

            PhaseWorkflowLoader WorkflowLoader = new PhaseWorkflowLoader();
            PhaseWorkflow Workflow = WorkflowLoader.PhaseWorkflowsByName[WorkflowLoader.DefaultWorkflowName];
            PathManager.TargetPath = Path.GetFullPath(OutputPath) + Path.DirectorySeparatorChar;

            XmlIR xmlIR = new XmlIR();

            foreach (ITaskItem item in Sources)
            {
                string filename = item.ItemSpec;
                if (File.Exists(filename))
                {
                    xmlIR.AddXml(Path.GetFullPath(filename),XmlIRDocumentType.SOURCE);
                }
                else
                {
                    Message.Trace(Severity.Error, new FileNotFoundException("Vulcan File Not Found", filename), Resources.VulcanFileNotFound, filename);
                }
            }

            foreach (ITaskItem item in Includes)
            {
                string filename = item.ItemSpec;
                if (File.Exists(filename))
                {
                    xmlIR.AddXml(Path.GetFullPath(filename), XmlIRDocumentType.INCLUDE);
                }
                else
                {
                    Message.Trace(Severity.Error, new FileNotFoundException("Vulcan File Not Found", filename), Resources.VulcanFileNotFound, filename);
                }
            }

            Workflow.ExecutePhaseWorkflowGraph(xmlIR);

            return (MessageEngine.AllEnginesErrorCount + MessageEngine.AllEnginesWarningCount) <= 0;
        }
Ejemplo n.º 7
0
 public AstIR(XmlIR xmlIR) : base(xmlIR)
 {
 }
Ejemplo n.º 8
0
        public static int Main(string[] args)
        {
            int errorCount = 0;

            MessageEngine.Trace(Severity.Notification, Resources.VulcanStart, Assembly.GetAssembly(typeof(XmlIR)).GetName().Version);
            try
            {
                var workflowLoader = new PhaseWorkflowLoader();
                PhaseWorkflow workflow = workflowLoader.PhaseWorkflowsByName[workflowLoader.DefaultWorkflowName];

                var cmdLineParser = new SimpleCommandLineParser("-/", args);

                if (args.Length == 0 || cmdLineParser["?"] != null)
                {
                    DisplayHelpMenu();
                    return errorCount;
                }

                if (cmdLineParser["t"] != null && cmdLineParser["t"].Count > 0)
                {
                    PathManager.TargetPath = Path.GetFullPath(cmdLineParser["t"][0]); //// +Path.DirectorySeparatorChar;
                }
                else
                {
                    PathManager.TargetPath = Path.GetFullPath(".");
                }

                var xmlIR = new XmlIR();

                foreach (string filename in cmdLineParser.NoSwitchArguments)
                {
                    if (File.Exists(filename))
                    {
                        xmlIR.AddXml(Path.GetFullPath(filename), XmlIRDocumentType.Source, true);
                    }
                    else
                    {
                        MessageEngine.Trace(Severity.Error, new FileNotFoundException("Vulcan File Not Found", filename), Resources.VulcanFileNotFound, filename);
                    }
                }

                IList<string> includedFiles = cmdLineParser["i"];

                if (includedFiles != null)
                {
                    foreach (string filename in includedFiles)
                    {
                        if (File.Exists(filename))
                        {
                            xmlIR.AddXml(Path.GetFullPath(filename), XmlIRDocumentType.Include, true);
                        }
                    }
                }

                workflow.ExecutePhaseWorkflowGraph(xmlIR);
            }
            catch (Exception ex)
            {
                MessageEngine.Trace(Severity.Error, ex, "One or more fatal errors were encountered!");
            }

            errorCount = (MessageEngine.ErrorCount + MessageEngine.WarningCount) * -1;
            return errorCount;
        } // end main
Ejemplo n.º 9
0
        private void CheckFrameworkItems(string parentFile, string subFile, bool isSubsetOf)
        {
            Assert.IsTrue(File.Exists(parentFile), "PRE file was not found");
            Assert.IsTrue(File.Exists(subFile), "POST file was not found");

            // TODO: Fix this hack
            MessageEngine.ClearMessages();

            var parser = new XmlToAstParserPhase("TestParser", _defaultXmlNamespace);
            var lowerer = new AstLowererPhase("TestLowerer");

            var parentXmlIR = new XmlIR();
            parentXmlIR.AddXml(parentFile, XmlIRDocumentType.Source, true);
            IIR parentParsed = parser.Execute(parentXmlIR);
            Assert.IsTrue(MessageEngine.ErrorCount == 0, "There were parse errors in the PRE file.");

            // TODO: Fix this hack
            MessageEngine.ClearMessages();

            var parentAstRootNode = ((AstIR)lowerer.Execute(parentParsed)).AstRootNode;
            Assert.IsTrue(MessageEngine.ErrorCount == 0, "There were lowering errors in the PRE file.");

            // TODO: Fix this hack
            MessageEngine.ClearMessages();

            var subXmlIR = new XmlIR();
            subXmlIR.AddXml(subFile, XmlIRDocumentType.Source, true);
            IIR subParsed = parser.Execute(subXmlIR);
            Assert.IsTrue(MessageEngine.ErrorCount == 0, "There were parse errors in the POST file.");

            // TODO: Fix this hack
            MessageEngine.ClearMessages();

            var subAstRootNode = ((AstIR)lowerer.Execute(subParsed)).AstRootNode;
            Assert.IsTrue(MessageEngine.ErrorCount == 0, "There were lowering errors in the POST file.");

            CheckFrameworkItems(parentAstRootNode, subAstRootNode, isSubsetOf);
        }
Ejemplo n.º 10
0
        public void CheckFrameworkItemsNoLowering(string file)
        {
            Assert.IsTrue(File.Exists(file), "File was not found");

            // TODO: Fix this hack
            MessageEngine.ClearMessages();

            var parser = new XmlToAstParserPhase("TestParser", _defaultXmlNamespace);
            var lowerer = new AstLowererPhase("TestLowerer");

            var unloweredXmlIR = new XmlIR();
            unloweredXmlIR.AddXml(file, XmlIRDocumentType.Source, true);
            var unloweredAstRootNode = ((AstIR)parser.Execute(unloweredXmlIR)).AstRootNode;
            Assert.IsTrue(MessageEngine.ErrorCount == 0, "There were parse errors in the unlowered file pass.");

            // TODO: Fix this hack
            MessageEngine.ClearMessages();

            var loweredXmlIR = new XmlIR();
            loweredXmlIR.AddXml(file, XmlIRDocumentType.Source, true);
            IIR loweredParsed = parser.Execute(loweredXmlIR);
            Assert.IsTrue(MessageEngine.ErrorCount == 0, "There were parse errors in the lowered file pass.");

            // TODO: Fix this hack
            MessageEngine.ClearMessages();

            var loweredAstRootNode = ((AstIR)lowerer.Execute(loweredParsed)).AstRootNode;
            Assert.IsTrue(MessageEngine.ErrorCount == 0, "There were lowering errors in the file.");

            CheckFrameworkItems(unloweredAstRootNode, loweredAstRootNode, false);
        }
Ejemplo n.º 11
0
        private bool FindASTNodeReferenceForNewObject(XmlIR xmlIR, NewBindingItem item)
        {
            Type t = item.node.GetType();
            if (IsContainerOf(typeof(ICollection<object>), t))
            {
                t = t.GetGenericArguments()[0];
            }

            string value = item.XValue;
            AstNode boundASTNode = null;
            AstParserScopeManager scopeManager = item.ScopeManager.Clone();

            // Walk scopes
            while (boundASTNode == null && !scopeManager.IsEmpty)
            {
                boundASTNode = FindASTNode(t, scopeManager.GetScopedName(value));
                scopeManager.Pop();
            }

            // Attempt scopeless binding
            if (boundASTNode == null)
            {
                boundASTNode = FindASTNode(t, value);
            }

            if (boundASTNode != null)
            {
                XElement xElement = new XElement((XElement)boundASTNode.BoundXElement);
                XmlSchemaObject schemaObject = ((XElement)boundASTNode.BoundXElement).GetSchemaInfo().SchemaElement;
                xElement.SetAttributeValue("AsClassOnly", false);
                xElement.SetAttributeValue("Name", item.node.Name);
                Dictionary<string, string> dictParams = new Dictionary<string, string>();
                foreach (XElement param in xElement.Elements(XName.Get("Argument", GetDefaultXMLNamespace(boundASTNode))))
                {
                    string sParam = param.Attribute("Name").Value;
                    XAttribute xAttribute = (item.node.BoundXElement as XElement).
                        Element(XName.Get("New", GetDefaultXMLNamespace(item.node))).Attribute(sParam);
                    if (xAttribute != null)
                    {
                        dictParams.Add("{argument(" + sParam + ")}", xAttribute.Value);
                    }
                    else
                    {
                        dictParams.Add("{argument(" + sParam + ")}", param.Attribute("DefaultValue").Value);
                    }
                }
                ReplaceParameters(xElement, dictParams);
                xmlIR.ValidateXElement(schemaObject, xElement);
                parseElement(xElement, item.node, item.docType);
                return true;
            }
            return false;
        }
Ejemplo n.º 12
0
 private void ProcessNewObjectQueue(XmlIR xmlIR)
 {
     foreach (NewBindingItem item in this._NewObjectItems)
     {
         FindASTNodeReferenceForNewObject(xmlIR, item);
     }
 }
Ejemplo n.º 13
0
        public static int Main(string[] args)
        {
            int errorCount = 0;

            MessageEngine Message = MessageEngine.Create("__VULCAN MAIN");

            Message.Trace(Severity.Notification, Resources.VulcanStart + Assembly.GetAssembly(typeof(XmlIR)).GetName().Version);

#if DEBUG
            Message.Trace(Severity.Notification, "DEBUG VERSION");
#endif

            // TODO: Can we set permissions so that only PhaseworkflowLoader can see the workflow editing methods?  (Vsabella: yes you can if you make it its own dll and mark the classes internal)
            PhaseWorkflowLoader WorkflowLoader = new PhaseWorkflowLoader();
            PhaseWorkflow Workflow = WorkflowLoader.PhaseWorkflowsByName[WorkflowLoader.DefaultWorkflowName];

            SimpleCommandLineParser cmdLineParser = new SimpleCommandLineParser("-/", args);

            if (args.Length == 0 || cmdLineParser["?"] != null)
            {
                DisplayHelpMenu();
                return errorCount;
            }

            if (cmdLineParser["t"] != null && cmdLineParser["t"].Count > 0)
            {
                PathManager.TargetPath = Path.GetFullPath(cmdLineParser["t"][0]);// +Path.DirectorySeparatorChar;
            }
            else
            {
                PathManager.TargetPath = Path.GetFullPath(".");
            }

            XmlIR xmlIR = new XmlIR();

            if (cmdLineParser["r"] != null && cmdLineParser["r"].Count > 0)
            {
                string[] rootPath = cmdLineParser["r"][0].Split(new char[] { '=' });

                if (rootPath != null && rootPath.Length == 2 && Directory.Exists(rootPath[1]))
                {
                    xmlIR.SetDocumentRoot(rootPath[0].ToUpperInvariant(), Path.GetFullPath(rootPath[1]));
                }
            }

            foreach (string filename in cmdLineParser.NoSwitchArguments)
            {
                if (File.Exists(filename))
                {
                    VulcanEngine.IR.XmlIRDocumentType docType = XmlIRDocumentType.SOURCE;
                    xmlIR.AddXml(Path.GetFullPath(filename), docType);
                }
                else
                {
                    Message.Trace(Severity.Error, new FileNotFoundException("Vulcan File Not Found", filename), Resources.VulcanFileNotFound, filename);
                }
            }

            IList<string> includedFiles = cmdLineParser["i"];

            if (includedFiles != null)
            {
                foreach (string filename in includedFiles)
                {
                    if (File.Exists(filename))
                    {
                        VulcanEngine.IR.XmlIRDocumentType docType = XmlIRDocumentType.INCLUDE;
                        xmlIR.AddXml(Path.GetFullPath(filename), docType);
                    }
                }
            }

            Workflow.ExecutePhaseWorkflowGraph(xmlIR);
            errorCount = (MessageEngine.AllEnginesErrorCount + MessageEngine.AllEnginesWarningCount) * -1;
            return errorCount;
        }// end main
Ejemplo n.º 14
0
        public override bool Execute()
        {
            MessageEngine.MSBuildTask = this;

            MessageEngine.Trace(Severity.Notification, Resources.VulcanStart + Assembly.GetExecutingAssembly().GetName().Version);
            try
            {
                InitializeVulcanParameters();

                var workflowLoader = new PhaseWorkflowLoader();
                PhaseWorkflow workflow = workflowLoader.PhaseWorkflowsByName[workflowLoader.DefaultWorkflowName];
                PathManager.TargetPath = Path.GetFullPath(OutputPath) + Path.DirectorySeparatorChar + Path.DirectorySeparatorChar;

                var xmlIR = new XmlIR();

                if (!String.IsNullOrEmpty(TemplatePath))
                {
                    xmlIR.TemplatePath = Path.GetFullPath(TemplatePath) + Path.DirectorySeparatorChar;
                }

                if (Sources != null)
                {
                    foreach (ITaskItem item in Sources)
                    {
                        string filename = item.ItemSpec;
                        if (File.Exists(filename))
                        {
                            xmlIR.AddXml(Path.GetFullPath(filename), XmlIRDocumentType.Source, true);
                        }
                        else
                        {
                            MessageEngine.Trace(Severity.Error, new FileNotFoundException("Vulcan File Not Found", filename), Resources.VulcanFileNotFound, filename);
                        }
                    }
                }

                if (Includes != null)
                {
                    foreach (ITaskItem item in Includes)
                    {
                        string filename = item.ItemSpec;
                        if (File.Exists(filename))
                        {
                            xmlIR.AddXml(Path.GetFullPath(filename), XmlIRDocumentType.Include, true);
                        }
                        else
                        {
                            MessageEngine.Trace(Severity.Error, new FileNotFoundException("Vulcan File Not Found", filename), Resources.VulcanFileNotFound, filename);
                        }
                    }
                }

                workflow.ExecutePhaseWorkflowGraph(xmlIR);
            }
            catch (Exception e)
            {
                MessageEngine.Trace(Severity.Error, e, "One or more fatal errors were encountered!");
            }

            return (MessageEngine.ErrorCount + MessageEngine.WarningCount) <= 0;
        }
Ejemplo n.º 15
0
Archivo: XmlIR.cs Proyecto: japj/vulcan
 protected XmlIR(XmlIR xmlIR)
 {
     this._isValidated = xmlIR._isValidated;
     this._documents = xmlIR._documents;
     this._xmlSchemaSet = xmlIR._xmlSchemaSet;
     this._id = xmlIR._id;
     this._message = xmlIR._message;
     this._documentsLoaded = xmlIR._documentsLoaded;
 }
Ejemplo n.º 16
0
Archivo: AstIR.cs Proyecto: japj/vulcan
 public AstIR(XmlIR xmlIR)
     : base(xmlIR)
 {
 }