Exemplo n.º 1
0
        public XmlDocument Read(out string title)
        {
            var result = new XmlDocument();
            var pkgDoc = new XmlDocument();

            pkgDoc.Load(_path);
            string folderPath;

            result.AppendChild(result.CreateElement("AML"));
            XmlElement child;

            var scripts = new List <InstallItem>();

            title = null;
            foreach (var pkg in pkgDoc.DocumentElement.Elements("package"))
            {
                title      = pkg.Attribute("name", "");
                folderPath = pkg.Attribute("path");
                if (folderPath == ".\\")
                {
                    folderPath = InnovatorPackage.CleanFileName(title).Replace('.', '\\');
                }
                foreach (var file in Directory.GetFiles(Path.Combine(Path.GetDirectoryName(_path), folderPath), "*.xml", SearchOption.AllDirectories))
                {
                    child          = result.CreateElement("AML");
                    child.InnerXml = System.IO.File.ReadAllText(file);
                    foreach (var item in child.Element("AML").Elements("Item"))
                    {
                        result.AppendChild(item);
                    }
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        public void Write(InstallScript script)
        {
            using (var xml = XmlTextWriter.Create(_path, _settings))
            {
                xml.WriteStartElement("imports");
                xml.WriteStartElement("package");
                xml.WriteAttributeString("name", script.Title);

                if (script.Title.StartsWith("com.aras.innovator"))
                {
                    if (script.Title.StartsWith("com.aras.innovator.solution."))
                    {
                        _baseFolderPath = InnovatorPackage.CleanFileName(script.Title).Substring(28).Replace('.', '\\') + "\\Import";
                        xml.WriteAttributeString("path", _baseFolderPath);
                    }
                    else
                    {
                        _baseFolderPath = InnovatorPackage.CleanFileName(script.Title).Replace('.', '\\');
                        xml.WriteAttributeString("path", ".\\");
                    }
                }
                else
                {
                    _baseFolderPath = InnovatorPackage.CleanFileName(script.Title) + "\\Import";
                    xml.WriteAttributeString("path", _baseFolderPath);
                }

                xml.WriteEndElement();
                xml.WriteEndElement();
            }

            _baseFolderPath = Path.Combine(Path.GetDirectoryName(_path), _baseFolderPath);

            XmlWriter   writer;
            InstallItem first;
            var         existingPaths = new HashSet <string>();
            string      newPath;

            foreach (var group in script.GroupLines(i => i.Type != InstallType.DependencyCheck))
            {
                first   = group.First();
                newPath = first.Reference.Type + "\\" + InnovatorPackage.CleanFileName(first.Reference.KeyedName ?? first.Reference.Unique) + ".xml";
                if (existingPaths.Contains(newPath))
                {
                    newPath = first.Reference.Type + "\\" + InnovatorPackage.CleanFileName((first.Reference.KeyedName ?? "") + "_" + first.Reference.Unique) + ".xml";
                }

                writer = GetWriter(newPath);
                try
                {
                    writer.WriteStartElement("AML");
                    foreach (var line in group)
                    {
                        line.Script.WriteTo(writer);
                    }
                    writer.WriteEndElement();
                    writer.Flush();
                }
                finally
                {
                    writer.Close();
                }

                existingPaths.Add(newPath);
            }
        }