Пример #1
0
        public virtual void Write(InstallScript script)
        {
            string newPath;
            var    existingPaths = new HashSet <string>();

            // Record the import order
            var settings = new XmlWriterSettings();

            settings.OmitXmlDeclaration = true;
            settings.Indent             = true;
            settings.IndentChars        = "  ";
            using (var manifestStream = GetNewStream(null))
            {
                using (var manifestWriter = XmlWriter.Create(manifestStream, settings))
                {
                    manifestWriter.WriteStartElement("Import");

                    if (script.Created.HasValue)
                    {
                        manifestWriter.WriteAttributeString("created", script.Created.Value.ToString("s"));
                    }
                    manifestWriter.WriteAttributeString("creator", script.Creator);
                    manifestWriter.WriteAttributeString("description", script.Description);
                    if (script.Modified.HasValue)
                    {
                        manifestWriter.WriteAttributeString("modified", script.Modified.Value.ToString("s"));
                    }
                    manifestWriter.WriteAttributeString("revision", script.Version);
                    manifestWriter.WriteAttributeString("title", script.Title);
                    if (script.Website != null)
                    {
                        manifestWriter.WriteAttributeString("website", script.Website.ToString());
                    }

                    InstallItem first;
                    foreach (var group in script.GroupLines())
                    {
                        first = group.First();
                        if (first.Type == InstallType.DependencyCheck)
                        {
                            foreach (var line in group)
                            {
                                line.Script.WriteTo(manifestWriter);
                            }
                        }
                        else
                        {
                            switch (first.Reference.Type)
                            {
                            case "Report":
                                newPath = first.Reference.Type + "\\" + CleanFileName(first.Reference.KeyedName ?? first.Reference.Unique) + ".xslt";
                                if (existingPaths.Contains(newPath))
                                {
                                    newPath = first.Reference.Type + "\\" + CleanFileName((first.Reference.KeyedName ?? "") + "_" + first.Reference.Unique) + ".xslt";
                                }

                                WriteReport(group, newPath);
                                break;

                            default:
                                newPath = first.Reference.Type + "\\" + CleanFileName(first.Reference.KeyedName ?? first.Reference.Unique) + ".xml";
                                if (existingPaths.Contains(newPath))
                                {
                                    newPath = first.Reference.Type + "\\" + CleanFileName((first.Reference.KeyedName ?? "") + "_" + first.Reference.Unique) + ".xml";
                                }

                                using (var stream = GetNewStream(newPath))
                                {
                                    using (var writer = GetWriter(stream))
                                    {
                                        writer.WriteStartElement("AML");
                                        foreach (var line in group)
                                        {
                                            line.Script.WriteTo(writer);
                                        }
                                        writer.WriteEndElement();
                                    }
                                }
                                break;
                            }

                            existingPaths.Add(newPath);
                            manifestWriter.WriteStartElement("Path");
                            manifestWriter.WriteAttributeString("path", newPath);
                            manifestWriter.WriteEndElement();
                        }
                    }
                    manifestWriter.WriteEndElement();
                }
            }
        }
Пример #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);
            }
        }