Пример #1
0
        /// <summary>
        /// Loads the grammar ONLY of the plugins from the passed PluginHandler. Grammar loaded before will be unloaded!
        /// You can only load plugins while the recognition is not running!
        /// </summary>
        /// <param name="aPluginHandler"></param>
        /// <returns>Boolean if the loading was successful</returns>
        public bool LoadPluginsGrammar(PluginHandler aPluginHandler)
        {
            mPluginHandler = aPluginHandler;
            try
            {
                mRecognitionEngine.UnloadAllGrammars();

                foreach (var plugin in aPluginHandler.Plugins)
                {
                    if (plugin.Initialized)
                    {
                        Grammar pluginGrammar = plugin.GetGrammar();
                        pluginGrammar.Name = plugin.Name;
                        mRecognitionEngine.LoadGrammar(pluginGrammar);
                        plugin.RequestGrammarUpdate += new EventHandler<GrammarUpdateRequestEventArgs>(GrammarUpdateRequested);
                        plugin.TryToEmulateCommand += new EventHandler<EmulateCommandEventArgs>(TryEmulatingCommand);
                    }
                    else
                    {
                        //mPluginHandler.Plugins.Remove(plugin);
                    }
                }
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }
Пример #2
0
        private void menuItemOpenFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog openUserProfileFileDialog = new OpenFileDialog();
            openUserProfileFileDialog.Filter = "ModernSteward user profile|*.msu|All files|*.*";
            bool openedSuccessfull = false;
            if (openUserProfileFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Stream stream = new FileStream(openUserProfileFileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.None);
                try
                {
                    System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(mPluginHandler.GetType());
                    mPluginHandler = (PluginHandler)xmlSerializer.Deserialize(stream);

                    gridViewPlugins.Rows.Clear();

                    foreach (var plugin in mPluginHandler.Plugins)
                    {
                        plugin.LoadPlugin();
                        AddPluginToTheGridView(plugin.Name, plugin.PluginPath);
                    }

                    labelStatusInStatusStrip.Text = openUserProfileFileDialog.FileName + " was added successfully.";
                }
                catch (Exception ex)
                {
                    RadMessageBox.Show("The file is corrupted. \nPlease, connect to the support crew.", "Error");
                    CrashReporter.Report(ex);
                }
                finally
                {
                    if (openedSuccessfull)
                    {
                        labelStatusInStatusStrip.Text = openUserProfileFileDialog.FileName + " was loaded successfully.";
                    }
                    else
                    {
                        labelStatusInStatusStrip.Text = openUserProfileFileDialog.FileName + " was loaded UNsuccessfully.";
                    }
                    if (stream != null)
                    {
                        stream.Close();
                    }
                }
            }
        }