public void Initialize(InitializationEngine context)
        {
            _contentTypeRepository       = ServiceLocator.Current.GetInstance <IContentTypeRepository>();
            _availableSettingsRepository = ServiceLocator.Current.GetInstance <IAvailableSettingsRepository>();
            var sysRoot = _contentTypeRepository.Load("SysRoot") as PageType;
            var setting = new AvailableSetting
            {
                Availability = Availability.None,
                //Availability = Availability.Specific,

                /*AllowedContentTypeNames =
                 * {
                 *  nameof(StartPageType), // can't use custom interfaces with IContentTypeRepository
                 * }*/
            };

            _availableSettingsRepository.RegisterSetting(sysRoot, setting);
            // Disallow insertion for all product and article related pages
            DisallowAll <AboutUsPageType>();
            DisallowAll <ContactPageType>();
            //DisallowAll<NewsPageContainerType>();
            DisallowAll <SearchPageType>();
            DisallowAll <NewsPageType>();
            DisallowAll <StartPageType>();
            // Home Page
            SetPageRestriction <NewsContainerPageType>(new List <Type>
            {
                typeof(NewsPageType)
            });
        }
 private void SaveAvailablePageTypes(ContentType contentType)
 {
     var pageType = contentType as PageType;
     if(pageType != null)
     {
         var availablePageTypeRepository = ServiceLocator.Current.GetInstance<IAvailableSettingsRepository>();
         var settings = new AvailableSetting { Availability = 0 };
         availablePageTypeRepository.RegisterSetting(pageType, settings);
     }
 }
        private void DisallowAll <T>()
        {
            var page    = _contentTypeRepository.Load(typeof(T));
            var setting = new AvailableSetting
            {
                Availability = Availability.None
            };

            _availableSettingsRepository.RegisterSetting(page, setting);
        }
        private void SaveAvailablePageTypes(ContentType contentType)
        {
            var pageType = contentType as PageType;

            if (pageType != null)
            {
                IAvailableSettingsRepository availablePageTypeRepository = ServiceLocator.Current.GetInstance <IAvailableSettingsRepository>();
                AvailableSetting             settings = new AvailableSetting();
                settings.Availability = 0;
                availablePageTypeRepository.RegisterSetting(pageType, settings);
            }
        }
        private void SetPageRestriction <T>(IEnumerable <Type> pageTypes)
        {
            var page    = _contentTypeRepository.Load(typeof(T));
            var setting = new AvailableSetting
            {
                Availability = Availability.Specific
            };

            foreach (var pageType in pageTypes)
            {
                var contentType = _contentTypeRepository.Load(pageType);
                setting.AllowedContentTypeNames.Add(contentType.Name);
            }
            _availableSettingsRepository.RegisterSetting(page, setting);
        }
        public void Initialize(InitializationEngine context)
        {
            var contentTypeRepository = context.Locate.Advanced.GetInstance <IContentTypeRepository>();

            var sysRoot = contentTypeRepository.Load("SysRoot") as PageType;

            var setting = new AvailableSetting {
                Availability = Availability.Specific
            };

            setting.AllowedContentTypeNames.Add(contentTypeRepository.Load <StartPage>().Name);

            var availableSettingsRepository = context.Locate.Advanced.GetInstance <IAvailableSettingsRepository>();

            availableSettingsRepository.RegisterSetting(sysRoot, setting);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Find an available setting value.
        /// </summary>
        /// <param name="availableSetting">The available setting that the value belongs to. If this is null, then null is returned.</param>
        /// <param name="settingValue">The name of the setting value to look for.</param>
        /// <returns>The available setting value or null if no such value was found.</returns>
        public AvailableSettingValue FindSettingValue(AvailableSetting availableSetting, string settingValue)
        {
            if (availableSetting == null)
            {
                throw new ArgumentNullException(nameof(availableSetting));
            }

            if (availableSetting != null && availableSetting.Values != null)
            {
                foreach (var availableValue in availableSetting.Values)
                {
                    if (Util.NullSafeEquals(availableValue.CanonicalName, settingValue))
                    {
                        return(availableValue);
                    }
                }
            }

            return(null);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Apply the user's selection to the setting names.
        /// </summary>
        /// <typeparam name="T">The type.</typeparam>
        /// <param name="state">State object.</param>
        /// <param name="settingEntities">List of entity values.</param>
        /// <param name="changesOrStatuses">The SettingChanges or SettingStatuses to select from.</param>
        /// <returns>The selected SettingChanges or SettingStatuses or null if no selection was made.</returns>
        public IList <T> ApplySelectionToSettings <T>(AutomotiveSkillState state, List <string> settingEntities, IList <T> changesOrStatuses)
            where T : SettingOperation
        {
            if (state == null)
            {
                throw new ArgumentNullException(nameof(state));
            }

            if (settingEntities == null)
            {
                throw new ArgumentNullException(nameof(settingEntities));
            }

            if (changesOrStatuses == null)
            {
                throw new ArgumentNullException(nameof(changesOrStatuses));
            }

            var settingNames = state.GetUniqueSettingNames();

            ISet <string> selectedSettingNames = new HashSet <string>();

            if (settingEntities.Any() && settingNames.Any())
            {
                IList <AvailableSetting> resolvedSettings = new List <AvailableSetting>();
                foreach (var settingName in settingNames)
                {
                    var setting = this.settingList.FindSetting(settingName);
                    if (setting != null)
                    {
                        resolvedSettings.Add(setting);
                    }
                    else
                    {
                        setting = new AvailableSetting
                        {
                            CanonicalName = settingName
                        };
                        resolvedSettings.Add(setting);
                    }
                }

                IList <AvailableSetting> settings_to_select_from = Util.CopyList(resolvedSettings);
                foreach (var setting in resolvedSettings)
                {
                    if (setting.IncludedSettings != null)
                    {
                        foreach (var included_setting_name in setting.IncludedSettings)
                        {
                            if (!settingNames.Contains(included_setting_name))
                            {
                                var included_setting = this.settingList.FindSetting(included_setting_name);
                                if (included_setting == null)
                                {
                                    // Unreachable.
                                    throw new Exception("The included settings of setting \"" + setting.CanonicalName
                                                        + "\" must be canonical names of other settings, but \"" + included_setting_name
                                                        + "\" is not and this should already have been checked when loading the SettingList.");
                                }

                                settings_to_select_from.Add(included_setting);
                            }
                        }
                    }
                }

                var setting_matcher   = new SettingMatcher(this.settingList.CreateSubList(settings_to_select_from));
                var selected_settings = setting_matcher.MatchSettingNamesExactly(settingEntities.First());

                if (!selected_settings.Any())
                {
                    selected_settings = setting_matcher.MatchSettingNames(
                        settingEntities,
                        SettingNameScoreThreshold, SettingNameAntonymDisambPercentageOfMax, true);
                }

                foreach (var setting_info in selected_settings)
                {
                    selectedSettingNames.Add(setting_info.CanonicalName);
                }
            }

            IList <T>     newCandidates     = new List <T>();
            ISet <string> addedSettingNames = new HashSet <string>();

            foreach (var candidate in changesOrStatuses)
            {
                if (candidate == null)
                {
                    continue;
                }

                if (selectedSettingNames.Contains(candidate.SettingName))
                {
                    newCandidates.Add(candidate);
                    addedSettingNames.Add(candidate.SettingName);
                }
            }

            // If NLP tells us to select something that isn't on the list,
            // it's because it's included in one of the settings on the list.
            foreach (var selectedName in selectedSettingNames)
            {
                if (!addedSettingNames.Contains(selectedName))
                {
                    // This search is inefficient, but the lists will be short, so it doesn't matter.
                    foreach (var candidate in changesOrStatuses)
                    {
                        var supportedSetting = settingList.FindSetting(candidate.SettingName);
                        if (supportedSetting != null && supportedSetting.IncludedSettings != null && supportedSetting.IncludedSettings.Contains(selectedName))
                        {
                            var newCandidate = (T)candidate.Clone();
                            newCandidate.SettingName = selectedName;
                            newCandidates.Add(newCandidate);
                            break;
                        }
                    }
                }
            }

            if (!Util.IsNullOrEmpty(newCandidates))
            {
                return(newCandidates);
            }

            return(null);
        }
Exemplo n.º 9
0
        public void Test_ParseDocumentAsList()
        {
            var foo = new AvailableSetting
            {
                CanonicalName = "Foo",
                Values        = new List <AvailableSettingValue>
                {
                    new AvailableSettingValue
                    {
                        CanonicalName  = "Set",
                        RequiresAmount = true,
                    },
                    new AvailableSettingValue
                    {
                        CanonicalName       = "Decrease",
                        ChangesSignOfAmount = true,
                    },
                    new AvailableSettingValue
                    {
                        CanonicalName = "Increase",
                        Antonym       = "Decrease",
                    },
                },
                AllowsAmount = true,
                Amounts      = new List <AvailableSettingAmount>
                {
                    new AvailableSettingAmount
                    {
                        Unit = "bar",
                        Min  = 14,
                        Max  = 32,
                    },
                    new AvailableSettingAmount
                    {
                        Unit = string.Empty,
                        Min  = -5,
                    },
                },
                IncludedSettings = new List <string>
                {
                    "Front Foo",
                    "Rear Foo",
                },
            };

            var qux = new AvailableSetting
            {
                CanonicalName = "Qux",
                Values        = new List <AvailableSettingValue>
                {
                    new AvailableSettingValue
                    {
                        CanonicalName        = "Off",
                        RequiresConfirmation = true,
                    },
                    new AvailableSettingValue
                    {
                        CanonicalName = "On",
                    },
                },
            };

            var expectedAvailableSettings = new List <AvailableSetting>
            {
                foo,
                qux,
            };

            using (TextReader reader = GetTestResourceStream("test_available_settings.yaml"))
            {
                var availableSettings = YamlParseUtil.ParseDocument <List <AvailableSetting> >(reader);
                CollectionAssert.AreEqual(expectedAvailableSettings, availableSettings);
            }
        }