Exemple #1
0
        protected override bool PrivatePerform()
        {
            while (true)
            {
                List <TOption> allOptions = GetOptions();

                bool           okayed    = false;
                List <TOption> selection = OptionItem.ListOptions(allOptions, Name, 1, out okayed);
                if ((selection == null) || (selection.Count == 0))
                {
                    return(okayed);
                }

                foreach (IOptionItem option in selection)
                {
                    if (option.Perform())
                    {
                        if (option is INestingOption)
                        {
                            return(true);
                        }
                    }
                }
            }
        }
Exemple #2
0
        protected void Remove(OptionItem item)
        {
            if (item == null)
            {
                return;
            }

            string name = item.GetStoreKey();

            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            Type type = item.GetType();

            PersistentNameLookup names = GetExisting(type);

            if (names == null)
            {
                return;
            }

            PersistentOption option = names.Get(name);

            if (option != null)
            {
                mOptions.Remove(option);

                names.Remove(name, option);
            }
        }
Exemple #3
0
        public virtual bool AddOption(OptionItem option)
        {
            if (Main == null)
            {
                return(false);
            }

            mOptions.Add(option);

            return(Main.AddToLookup(option));
        }
Exemple #4
0
        public bool Restore(OptionItem item)
        {
            if (item == null)
            {
                return(false);
            }

            try
            {
                string name = item.GetStoreKey();

                OptionLogger.AddTrace(" Option: " + name);

                PersistentNameLookup names = GetExisting(item.GetType());
                if (names == null)
                {
                    OptionLogger.AddError("  No Name");
                    return(false);
                }

                PersistentOption option = names.Get(name);
                if (option == null)
                {
                    OptionLogger.AddError("  No Option");
                    return(false);
                }

                try
                {
                    if (option.mValue != null)
                    {
                        item.PersistValue = option.mValue;
                    }
                    return(true);
                }
                catch (InvalidCastException e)
                {
                    Common.DebugException(item.GetStoreKey() + ": " + option.mValue + " (" + option.mValue.GetType() + ")", e);

                    OptionLogger.AddError("  Casting Fail");
                    return(false);
                }
            }
            catch (Exception e)
            {
                Common.Exception(item.GetStoreKey(), e);

                OptionLogger.AddError("  Exception");
                return(false);
            }
        }
Exemple #5
0
        public bool Store(OptionItem item)
        {
            if (item is INotPersistableOption)
            {
                return(false);
            }

            string name = item.GetStoreKey();

            if (string.IsNullOrEmpty(name))
            {
                return(false);
            }

            Type type = item.GetType();

            PersistentNameLookup names = Get(type);

            object value = item.PersistValue;

            PersistentOption option = names.Get(name);

            if (option == null)
            {
                option = new PersistentOption(type, name, value);

                mOptions.Add(option);

                names.Add(name, option);
            }
            else
            {
                option.mName  = name;
                option.mValue = value;
            }

            return(true);
        }