Beispiel #1
0
        /// <summary>
        /// Changes language of project XML - removes all modules that are not in new language
        /// </summary>
        /// <param name="projectXML">The project XML</param>
        /// <param name="newLang">The new lang</param>
        /// <returns></returns>
        public String ChangeProjectLanguage(String projectXML, String newLang)
        {
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(projectXML);

            HtmlNodeCollection moduleNodeList = doc.DocumentNode.SelectNodes("//module");

            if (moduleNodeList != null)
            {
                foreach (HtmlNode moduleNode in moduleNodeList)
                {
                    AModule       module         = this.GetModuleFromNode(moduleNode);
                    List <String> availableLangs = CModuleReader.GetAvailableLanguages(module.GetType());
                    if (!availableLangs.Contains(newLang) && availableLangs.Count != 0)
                    {
                        moduleNode.Remove();
                    }
                }
            }
            return(doc.DocumentNode.OuterHtml);
        }
Beispiel #2
0
        /// <summary>
        /// Loads modules to inner dictionary (CModuleReader.modules)
        /// </summary>
        private void LoadModules()
        {
            langToModulesMap.Clear();
            modules.Clear();
            languages.Clear();
            moduleToSetupMap.Clear();

            String modulesDir = GetModulesDir();

            if (!Directory.Exists(modulesDir))
            {
                return;
            }

            // All assemblies
            foreach (String dll in Directory.GetFiles(modulesDir, "*.dll"))
            {
                // All classes in assembly
                foreach (Type type in Assembly.LoadFile(dll).GetTypes())
                {
                    // AModule children
                    if (type.IsSubclassOf(typeof(AModule)))
                    {
                        this.modules.Add(type);

                        if (CModuleReader.GetAvailableLanguages(type).Count == 0)
                        {
                            // Create 'languageless' in dictionary if there isnt
                            if (!langToModulesMap.ContainsKey(String.Empty))
                            {
                                langToModulesMap.Add(String.Empty, new List <Type>());
                            }

                            this.langToModulesMap[String.Empty].Add(type);
                        }
                        foreach (String lang in CModuleReader.GetAvailableLanguages(type))
                        {
                            // Save all languages
                            if (!this.languages.Contains(lang))
                            {
                                this.languages.Add(lang);
                            }

                            // Create the lang in dictionary if there isnt
                            if (!langToModulesMap.ContainsKey(lang))
                            {
                                langToModulesMap.Add(lang, new List <Type>());
                            }

                            this.langToModulesMap[lang].Add(type);
                        }
                    }

                    // Make usersetup array
                    if (type.IsSubclassOf(typeof(AModuleUserSetup)))
                    {
                        String moduleName = (String)type.GetField("moduleName", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy).GetValue(null);
                        if (!moduleToSetupMap.ContainsKey(moduleName))
                        {
                            moduleToSetupMap.Add(moduleName, type);
                        }
                        else
                        {
                            moduleToSetupMap[moduleName] = type;
                        }
                    }
                }
            }
            return;
        }