Exemplo n.º 1
0
        public static Module AddModuleToContextByName(string moduleName, ModulesContext ctx, Context global, AdjacencyGraph<Module, Edge<Module>> dependencyGraph)
        {
            if (ctx.ModuleIndex.ContainsKey(moduleName))
            { // we've got that module already
                return ctx.ModuleIndex[moduleName];
            }

            // we deal with paths mess and add path prefix here
            string fullModuleName = (ctx.PathPrefix ?? "") + moduleName;
            string modulePath = (Path.GetDirectoryName(fullModuleName) ?? "").Replace('\\', '/');
            string moduleFileName = Path.GetFileName(fullModuleName);

            // remember old path prefix
            string oldPathPrefix = ctx.PathPrefix;

            // set new one
            ctx.PathPrefix = String.IsNullOrEmpty(modulePath) 
                ? null 
                : modulePath + (!modulePath.EndsWith("/") ? "/" : "");

            // freaking file system tries to evaluate it for us
            string moduleNameQuoted = "\"" + fullModuleName + "\"";

            // load module file and parse it.
            IFileSystem fileSystem = global.Registers["file_system"] as IFileSystem ?? Template.FileSystem;
            string source = fileSystem.ReadTemplateFile(global, moduleNameQuoted);
            Template template = Template.Parse(source);

            Module rootMod = null;

            // run all the modules from file
            template.Root.NodeList.ForEach(o =>
                                               {
                                                   Module m = o as Module;

                                                   if (m != null)
                                                   {
                                                       AddModuleToContext(m, ctx, global, dependencyGraph);

                                                       if (m.ModuleName == moduleFileName)
                                                       {
                                                           rootMod = m;
                                                       }
                                                   }
                                               });

            // return path prefix
            ctx.PathPrefix = oldPathPrefix;

            return rootMod;
        }
        public ModulesContext GetOrAddModulesContext(Context context)
        {
            // try to get the context
            ModulesContext currentContext = GetModulesContext(context);

            // check that we've found it
            if (currentContext != null)
            {
                return currentContext;
            }

            // create new environment, and add it to the DotLiquid context
            context.Environments.Add(new Hash { { EnvironmentKey, (currentContext = new ModulesContext()) } });

            // return newly created context
            return currentContext;
        }
        public ModulesContext GetOrAddModulesContext(Context context)
        {
            // try to get the context
            ModulesContext currentContext = GetModulesContext(context);

            // check that we've found it
            if (currentContext != null)
            {
                return currentContext;
            }

            // create new context, and store it to the DotLiquid context
            context.Registers[RegisterName] = currentContext = new ModulesContext();

            // return newly created context
            return currentContext;
        }
        public void Test()
        {
            // arrange
            var assemblies = new[]
            {
                // SC 8.2.1
                new AssemblyFile("Antlr3.Runtime.dll", "3.5.0.2", "3.5.0.2"),

                // SPIF 2.1 rev. 150128
                new AssemblyFile("Sitecore.Sharepoint.Common.dll", "2.1.5049", " 2.1 rev. 150128", 37376),
                new AssemblyFile("Sitecore.Sharepoint.Data.Providers.dll", "2.1.5049", " 2.1 rev. 150128", 72704),
                new AssemblyFile("Sitecore.Sharepoint.Data.WebServices.dll", "2.1.5049", " 2.1 rev. 150128"),
                new AssemblyFile("Sitecore.Sharepoint.Installer.dll", "2.1.5049", " 2.1 rev. 150128", 17408),
                new AssemblyFile("Sitecore.Sharepoint.ObjectModel.dll", "2.1.5049", " 2.1 rev. 150128", 65024),
                new AssemblyFile("Sitecore.Sharepoint.Web.dll", "2.1.5049", " 2.1 rev. 150128", 73728),

                // WFFM
                new AssemblyFile("Sitecore.Forms.Mvc.dll", "8.2.5600.0", "8.2 rev. 160801"),
            };

            var assembliesMap = assemblies.ToDictionary(x => x.FileName, x => x);

            var sut = new ModulesContext(assembliesMap);

            // act
            var correct         = sut.InstalledModules;
            var correctModule   = correct.First();
            var incorrect       = sut.IncorrectlyInstalledModules;
            var incorrectModule = incorrect.First();

            // assert
            Assert.Equal("SharePoint Integration Framework", correctModule.Key);
            Assert.Equal("2.1", correctModule.Value?.Release?.Version.MajorMinor);
            Assert.Equal("150128", correctModule.Value?.Release?.Revision);

            Assert.Equal("Web Forms for Marketers", incorrectModule.Key);
            Assert.Equal("8.2", incorrectModule.Value.Single()?.Release?.Version.MajorMinor);
            Assert.Equal("160801", incorrectModule.Value.Single()?.Release?.Revision);

            Assert.Equal(1, correct.Count);
            Assert.Equal(1, incorrect.Count);
        }
Exemplo n.º 5
0
        public static void AddModuleToContext(Module module, ModulesContext ctx, Context global, AdjacencyGraph<Module, Edge<Module>> dependencyGraph)
        {
            // add module to index
            Module storedModule;
            if (ctx.ModuleIndex.ContainsKey(module.ModuleName))
            {
                storedModule = ctx.ModuleIndex[module.ModuleName];
            }
            else
            {
                ctx.ModuleIndex[module.ModuleName] = module;
                dependencyGraph.AddVertex(module);
                storedModule = module;
            }

            // fill in module's sections first
            module.NodeList.ForEach(o =>
                                        {
                                            Section s = o as Section;

                                            if (s != null)
                                            {
                                                List<Section> secList;

                                                if (storedModule.Sections.ContainsKey(s.SectionName))
                                                {
                                                    secList = storedModule.Sections[s.SectionName];
                                                } 
                                                else
                                                {
                                                    secList = new List<Section>();
                                                    storedModule.Sections[s.SectionName] = secList;
                                                }

                                                secList.Add(s);
                                            }
                                        });

            // then parse dependencies and upgrade dependency graph
            module.NodeList.ForEach(o =>
                                        {
                                            DependsOn d = o as DependsOn;

                                            if (d != null)
                                            {
                                                // add this module to context
                                                Module dependsOn = AddModuleToContextByName(d.ModuleName, ctx, global, dependencyGraph);

                                                // upgrade graph
                                                dependencyGraph.AddVerticesAndEdge(new Edge<Module>(dependsOn, storedModule));
                                            }
                                        });
        }