コード例 #1
0
        /// <summary>
        /// Creates commands and categories from configuration.
        /// </summary>
        /// <param name="catsInfo">Categories information.</param>
        private void _CreateCommandsAndCategories(CategoriesInfo catsInfo)
        {
            foreach (CategoryInfo catInfo in catsInfo.Categories)
            {
                _pageByGroupDictionary.Add(catInfo.Name, catInfo.PageType);

                var catCommands = new List <ICommand>(catInfo.Commands.Length);
                foreach (CommandInfo cmdInfo in catInfo.Commands)
                {
                    Type type = Type.GetType(cmdInfo.Type);
                    if (type == null)
                    {
                        string error =
                            App.Current.GetString("CommandTypeCannotBeFound", cmdInfo.Type);
                        throw new ApplicationException(error); // exception
                    }

                    var cmd = (ICommand)Activator.CreateInstance(type);
                    _AddCommandToCategory(cmd, catCommands);
                }

                // add category to the categories cache
                Debug.Assert(!_categories.ContainsKey(catInfo.Name)); // only unique
                _categories.Add(catInfo.Name, catCommands);
            }
        }
コード例 #2
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Loads commands from Commands.xml embedded resource file.
        /// </summary>
        private void _LoadInternalCommands()
        {
            // get commands.xml stream
            Assembly assembly  = Assembly.GetExecutingAssembly();
            Stream   xmlStream = assembly.GetManifestResourceStream(APP_COMMANDS_DESCRIPTION);

            // deserialize Categories Info
            var            ser       = new XmlSerializer(typeof(CategoriesInfo));
            CategoriesInfo _catsInfo = null;

            try
            {
                _catsInfo = (CategoriesInfo)ser.Deserialize(xmlStream);
            }
            finally
            {
                xmlStream.Close();
            }

            // create commands and categories
            _CreateCommandsAndCategories(_catsInfo);
        }
コード例 #3
0
        /// <summary>
        /// Creates commands and categories from configuration.
        /// </summary>
        /// <param name="catsInfo">Categories information.</param>
        private void _CreateCommandsAndCategories(CategoriesInfo catsInfo)
        {
            foreach (CategoryInfo catInfo in catsInfo.Categories)
            {
                _pageByGroupDictionary.Add(catInfo.Name, catInfo.PageType);

                var catCommands = new List<ICommand>(catInfo.Commands.Length);
                foreach (CommandInfo cmdInfo in catInfo.Commands)
                {
                    Type type = Type.GetType(cmdInfo.Type);
                    if (type == null)
                    {
                        string error =
                            App.Current.GetString("CommandTypeCannotBeFound", cmdInfo.Type);
                        throw new ApplicationException(error); // exception
                    }

                    var cmd = (ICommand)Activator.CreateInstance(type);
                    _AddCommandToCategory(cmd, catCommands);
                }

                // add category to the categories cache
                Debug.Assert(!_categories.ContainsKey(catInfo.Name)); // only unique
                _categories.Add(catInfo.Name, catCommands);
            }
        }