Example #1
0
        public ModuleDifference[] CompareTo(ModuleManifest other)
        {
            var modulePathComparer = new ModulePathComparer(pathComparer);
            var currentModules     = new HashSet <Module>(modules, modulePathComparer);
            var oldModules         = new HashSet <Module>(other.Modules, modulePathComparer);

            var addedModules = currentModules.Except(oldModules, modulePathComparer);
            var added        = addedModules.Select(m => new ModuleDifference(m, ModuleDifferenceType.Added));

            var deletedModules = oldModules.Except(currentModules, modulePathComparer);
            var deleted        = deletedModules.Select(m => new ModuleDifference(m, ModuleDifferenceType.Deleted));

            // Changed module means old and current have the same path, but different hash.
            // Use Join to pair up the modules by path.
            // Then use Where to filter out those with same hash.
            var changedModules = oldModules.Join(currentModules, m => m.Path, m => m.Path, (old, current) => new { old, current })
                                 .Where(c => c.current.Equals(c.old) == false);
            // So deleted the old modules and add the current modules.
            var changes = changedModules.SelectMany(c => new[]
            {
                new ModuleDifference(c.old, ModuleDifferenceType.Deleted),
                new ModuleDifference(c.current, ModuleDifferenceType.Added)
            }
                                                    );

            return(added.Concat(deleted).Concat(changes).ToArray());
        }
Example #2
0
        public void Identical_ModuleManifests_have_no_differences()
        {
            var oldModuleManifest = new ModuleManifest(new[]
            {
                new Module(
                    @"scripts/module-a",
                    new Resource[]
                {
                    new Resource(@"scripts/module-a/test.js", new byte[0], new string[0])
                },
                    new string[0],
                    null
                    ),
                new Module(@"scripts/module-b", new Resource[0], new string[0], null)
            });

            var newModuleManifest = new ModuleManifest(new[]
            {
                new Module(
                    @"scripts/module-a",
                    new Resource[]
                {
                    new Resource(@"scripts/module-a/test.js", new byte[0], new string[0])
                },
                    new string[0],
                    null
                    ),
                new Module(@"scripts/module-b", new Resource[0], new string[0], null)
            });

            var differences = newModuleManifest.CompareTo(oldModuleManifest);

            differences.Length.ShouldEqual(0);
        }
Example #3
0
        public ModuleContainer(IEnumerable <Module> modules, IsolatedStorageFile storage, Func <TextWriter, IModuleWriter> createModuleWriter)
        {
            this.modules            = modules.ToArray();
            this.manifest           = new ModuleManifest(this.modules);
            this.storage            = storage;
            this.createModuleWriter = createModuleWriter;

            modulesByScriptPath = (
                from module in this.modules
                from resource in module.Resources
                select new { resource.Path, module }
                ).ToDictionary(x => x.Path, x => x.module, pathComparer);
        }
Example #4
0
        public void Compare_ModuleManifest_with_added_module_to_old_returns_difference()
        {
            var oldModuleManifest = new ModuleManifest(new Module[0]);

            Module module;
            var    newModuleManifest = new ModuleManifest(new[]
            {
                module = new Module(
                    @"scripts/module-a",
                    new Resource[0],
                    new string[0],
                    null
                    )
            });


            var differences = newModuleManifest.CompareTo(oldModuleManifest);

            differences.Length.ShouldEqual(1);
            differences[0].Type.ShouldEqual(ModuleDifferenceType.Added);
            differences[0].Module.ShouldEqual(module);
        }
Example #5
0
        public void Compare_ModuleManifest_with_changed_module_to_old_returns_Add_and_Delete_differences()
        {
            Module oldModule;
            var    oldModuleManifest = new ModuleManifest(new[]
            {
                oldModule = new Module(
                    @"scripts/module-a",
                    new Resource[]
                {
                    new Resource(@"scripts/module-a/test.js", new byte[] { 1 }, new string[0])
                },
                    new string[0],
                    null
                    )
            });

            Module changedModule;
            var    newModuleManifest = new ModuleManifest(new[]
            {
                changedModule = new Module(
                    @"scripts/module-a",
                    new Resource[]
                {
                    new Resource(@"scripts/module-a/test.js", new byte[] { 2 }, new string[0])
                },
                    new string[0],
                    null
                    )
            });

            var differences = newModuleManifest.CompareTo(oldModuleManifest);

            differences.Length.ShouldEqual(2);
            differences[0].Type.ShouldEqual(ModuleDifferenceType.Deleted);
            differences[0].Module.ShouldEqual(oldModule);
            differences[1].Type.ShouldEqual(ModuleDifferenceType.Added);
            differences[1].Module.ShouldEqual(changedModule);
        }
        XDocument CreateManifestXml(ModuleManifest moduleContainer)
        {
            return(new XDocument(
                       new XElement("manifest",
                                    from module in moduleContainer.Modules
                                    select new XElement("module",
                                                        new XAttribute("path", module.Path),
                                                        module.Location != null ? new XAttribute("location", module.Location) : null,

                                                        from resource in module.Resources
                                                        select new XElement("resource",
                                                                            new XAttribute("path", resource.Path),
                                                                            new XAttribute("hash", resource.Hash.ToHexString())
                                                                            ),

                                                        from reference in module.References
                                                        select new XElement("reference",
                                                                            new XAttribute("path", reference)
                                                                            )
                                                        )
                                    )
                       ));
        }
 public void Write(ModuleManifest manifest)
 {
     CreateManifestXml(manifest).Save(stream);
 }