예제 #1
0
        protected Dictionary <string, Component> GetActiveModules()
        {
            Schema  moduleConfigSchema = GetSchema(ModuleConfigurationSchemaRootElementName);
            Session session            = moduleConfigSchema.Session;

            UsingItemsFilter moduleConfigComponentsFilter = new UsingItemsFilter(session)
            {
                ItemTypes   = new[] { ItemType.Component },
                BaseColumns = ListBaseColumns.Id
            };

            Dictionary <string, Component> results = new Dictionary <string, Component>();

            foreach (Component comp in moduleConfigSchema.GetUsingItems(moduleConfigComponentsFilter).Cast <Component>())
            {
                // GetUsingItems returns the items in their Owning Publication, which could be lower in the BluePrint than were we are (so don't exist in our context Repository).
                Component moduleConfigComponent = (Component)Publication.GetObject(comp.Id);
                if (!session.IsExistingObject(moduleConfigComponent.Id))
                {
                    continue;
                }

                ItemFields fields     = new ItemFields(moduleConfigComponent.Content, moduleConfigComponent.Schema);
                string     moduleName = fields.GetTextValue("name").Trim().ToLower();
                if (fields.GetTextValue("isActive").ToLower() == "yes" && !results.ContainsKey(moduleName))
                {
                    results.Add(moduleName, moduleConfigComponent);
                }
            }

            return(results);
        }
예제 #2
0
        private string DetermineLocale()
        {
            // TODO: use a less complicated (and more explicit) way to store locale/language. What about Publication metadata?
            Schema generalConfigSchema = GetSchema("GeneralConfiguration");

            UsingItemsFilter configComponentsFilter = new UsingItemsFilter(Session)
            {
                ItemTypes   = new[] { ItemType.Component },
                BaseColumns = ListBaseColumns.IdAndTitle
            };

            IEnumerable <Component> configComponents = generalConfigSchema.GetUsingItems(configComponentsFilter).Cast <Component>();
            Component localizationConfigComponent    = configComponents.FirstOrDefault(c => c.Title == "Localization Configuration");

            if (localizationConfigComponent == null)
            {
                Logger.Warning("No Localization Configuration Component found.");
                return(null);
            }

            // Ensure we load the Component in the current context Publication
            localizationConfigComponent = (Component)Publication.GetObject(localizationConfigComponent.Id);

            Dictionary <string, string> settings = ExtractKeyValuePairs(localizationConfigComponent);

            string       result;
            const string cultureSetting = "culture";

            if (!settings.TryGetValue(cultureSetting, out result))
            {
                Logger.Warning($"No '{cultureSetting}' setting found in Localization Configuration {localizationConfigComponent.FormatIdentifier()}.");
            }

            return(result);
        }