Esempio n. 1
0
        public void CanSaveAndLoadIntermediate()
        {
            var sln = new SourceLineNumber("test.wxs", 1);

            var section = new IntermediateSection("test", SectionType.Product, 65001);

            section.Symbols.Add(new ComponentSymbol(sln, new Identifier(AccessModifier.Public, "TestComponent"))
            {
                ComponentId  = new Guid(1, 0, 0, new byte[8]).ToString("B"),
                DirectoryRef = "TestFolder",
                Location     = ComponentLocation.Either,
            });

            var intermediate = new Intermediate("TestIntermediate", IntermediateLevels.Compiled, new[] { section }, null);

            intermediate.UpdateLevel(IntermediateLevels.Linked);
            intermediate.UpdateLevel(IntermediateLevels.Resolved);

            var path = Path.GetTempFileName();

            try
            {
                intermediate.Save(path);

                var loaded = Intermediate.Load(path);

                Assert.True(loaded.HasLevel(IntermediateLevels.Compiled));
                Assert.True(loaded.HasLevel(IntermediateLevels.Linked));
                Assert.True(loaded.HasLevel(IntermediateLevels.Resolved));

                var symbol = (ComponentSymbol)loaded.Sections.Single().Symbols.Single();

                Assert.Equal("TestComponent", symbol.Id.Id);
                Assert.Equal(AccessModifier.Public, symbol.Id.Access);
                Assert.Equal("TestFolder", symbol.DirectoryRef);
                Assert.Equal(ComponentLocation.Either, symbol.Location);
            }
            finally
            {
                File.Delete(path);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Create a library by combining several intermediates (objects).
        /// </summary>
        /// <returns>Returns the new library.</returns>
        public Intermediate Combine(ILibraryContext context)
        {
            if (String.IsNullOrEmpty(context.LibraryId))
            {
                context.LibraryId = Convert.ToBase64String(Guid.NewGuid().ToByteArray()).TrimEnd('=').Replace('+', '.').Replace('/', '_');
            }

            foreach (var extension in context.Extensions)
            {
                extension.PreCombine(context);
            }

            Intermediate library = null;

            try
            {
                var sections = context.Intermediates.SelectMany(i => i.Sections).ToList();

                var collate = new CollateLocalizationsCommand(this.Messaging, context.Localizations);
                var localizationsByCulture = collate.Execute();

                if (this.Messaging.EncounteredError)
                {
                    return(null);
                }

                this.ResolveFilePathsToEmbed(context, sections);

                foreach (var section in sections)
                {
                    section.AssignToLibrary(context.LibraryId);
                }

                library = new Intermediate(context.LibraryId, IntermediateLevels.Compiled, sections, localizationsByCulture);

                library.UpdateLevel(IntermediateLevels.Combined);

                this.Validate(library);
            }
            finally
            {
                foreach (var extension in context.Extensions)
                {
                    extension.PostCombine(library);
                }
            }

            return(this.Messaging.EncounteredError ? null : library);
        }