예제 #1
0
파일: Library.cs 프로젝트: fyodorkor/Data
        /// <summary>
        /// Saves a library to a path on disk.
        /// </summary>
        /// <param name="path">Path to save library file to on disk.</param>
        /// <param name="resolver">The WiX path resolver.</param>
        public void Save(string path, ILibraryBinaryFileResolver resolver)
        {
            List <string> embedFilePaths = new List <string>();

            // Resolve paths to files that are to be embedded in the library.
            if (null != resolver)
            {
                foreach (Table table in this.sections.SelectMany(s => s.Tables))
                {
                    foreach (Row row in table.Rows)
                    {
                        foreach (ObjectField objectField in row.Fields.Where(f => f is ObjectField))
                        {
                            if (null != objectField.Data)
                            {
                                string file = resolver.Resolve(row.SourceLineNumbers, table.Name, (string)objectField.Data);
                                if (!String.IsNullOrEmpty(file))
                                {
                                    // File was successfully resolved so track the embedded index as the embedded file index.
                                    objectField.EmbeddedFileIndex = embedFilePaths.Count;
                                    embedFilePaths.Add(file);
                                }
                                else
                                {
                                    Messaging.Instance.OnMessage(WixDataErrors.FileNotFound(row.SourceLineNumbers, (string)objectField.Data, table.Name));
                                }
                            }
                            else // clear out embedded file id in case there was one there before.
                            {
                                objectField.EmbeddedFileIndex = null;
                            }
                        }
                    }
                }
            }

            // Do not save the library if errors were found while resolving object paths.
            if (Messaging.Instance.EncounteredError)
            {
                return;
            }

            // Ensure the location to output the library exists and write it out.
            Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path)));

            using (FileStream stream = File.Create(path))
                using (FileStructure fs = FileStructure.Create(stream, FileFormat.Wixlib, embedFilePaths))
                    using (XmlWriter writer = XmlWriter.Create(fs.GetDataStream()))
                    {
                        writer.WriteStartDocument();

                        this.Write(writer);

                        writer.WriteEndDocument();
                    }
        }
예제 #2
0
        /// <summary>
        /// Saves an intermediate to a path on disk.
        /// </summary>
        /// <param name="path">Path to save intermediate file to disk.</param>
        public void Save(string path)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path)));

            using (var stream = File.Create(path))
                using (var fs = FileStructure.Create(stream, FileFormat.WixIR, this.EmbedFilePaths))
                    using (var writer = new StreamWriter(fs.GetDataStream()))
                    {
                        var jsonObject = new JsonObject
                        {
                            { "id", this.Id },
                            { "version", Intermediate.CurrentVersion.ToString() }
                        };

                        var sectionsJson = new JsonArray(this.Sections.Count);
                        foreach (var section in this.Sections)
                        {
                            var sectionJson = section.Serialize();
                            sectionsJson.Add(sectionJson);
                        }

                        jsonObject.Add("sections", sectionsJson);

                        var customDefinitions = this.GetCustomDefinitionsInSections();

                        if (customDefinitions.Count > 0)
                        {
                            var customDefinitionsJson = new JsonArray(customDefinitions.Count);

                            foreach (var kvp in customDefinitions.OrderBy(d => d.Key))
                            {
                                var customDefinitionJson = kvp.Value.Serialize();
                                customDefinitionsJson.Add(customDefinitionJson);
                            }

                            jsonObject.Add("definitions", customDefinitionsJson);
                        }

                        if (this.Localizations.Any())
                        {
                            var localizationsJson = new JsonArray();
                            foreach (var localization in this.Localizations)
                            {
                                var localizationJson = localization.Serialize();
                                localizationsJson.Add(localizationJson);
                            }

                            jsonObject.Add("localizations", localizationsJson);
                        }

                        var json = SimpleJson.SerializeObject(jsonObject);
                        writer.Write(json);
                    }
        }
예제 #3
0
        /// <summary>
        /// Saves a pdb to a path on disk.
        /// </summary>
        /// <param name="path">Path to save pdb file to on disk.</param>
        public void Save(string path)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path)));

            using (FileStream stream = File.Create(path))
                using (FileStructure fs = FileStructure.Create(stream, FileFormat.Wixpdb, null))
                    using (XmlWriter writer = XmlWriter.Create(fs.GetDataStream()))
                    {
                        writer.WriteStartDocument();
                        this.Write(writer);
                        writer.WriteEndDocument();
                    }
        }