Example #1
0
        /// <summary>
        /// This method is charge of processing all events.
        /// </summary>
        /// <param name="type">The ActionType to process.</param>
        private void Action(ActionType type)
        {
            switch(type) {
                case ActionType.Exit:
                    if (DialogResult.Yes == MessageBox.Show(this,
                                                                                    "Do you really want to exit?",
                                                                                    "Leaving NxBRE Console",
                                                                                    MessageBoxButtons.YesNo,
                                                                                    MessageBoxIcon.Warning,
                                                            MessageBoxDefaultButton.Button2)) {
                        Utils.SaveUserPreferences(iegf.UserPrefs);
                        Application.Exit();
                    }

                    Status("Exit cancelled, let's infer some more!");
                    break;

                case ActionType.LoadRuleBase:
                    LoadRuleBase(false);
                    ConsoleOut(String.Empty);
                    break;

                case ActionType.LoadFacts:
                    LoadRuleBase(true);
                    ConsoleOut(String.Empty);
                    break;

                case ActionType.SaveRuleBase:
                    SaveRuleBase(false);
                    ConsoleOut(String.Empty);
                    break;

                case ActionType.SaveFacts:
                    SaveRuleBase(true);
                    ConsoleOut(String.Empty);
                    break;

                case ActionType.ClearConsole:
                    Status("Console cleared");
                    ResetConsole();
                    break;

                case ActionType.DumpStatus:
                    ConsoleOut(iegf.Status);
                    ConsoleOut(String.Empty);
                    break;

                case ActionType.DumpFacts:
                    if ((iegf.FactsCount > 100) &&
                        (DialogResult.No == MessageBox.Show(this,
                                                                                    "There are " +
                                                                                    iegf.FactsCount +
                                                                                    " facts in the working memory. Do you really want to list them?",
                                                                                    "Massive facts listing",
                                                                                    MessageBoxButtons.YesNo,
                                                                                    MessageBoxIcon.Warning,
                                                                                    MessageBoxDefaultButton.Button2))) return;

                    iegf.DumpFacts(new ConsoleWriter(ConsoleOut));
                    ConsoleOut(String.Empty);
                    break;

                case ActionType.VerbositySilent:
                    verbosity = SourceLevels.Critical;
                    RefreshMenus();
                    break;

                case ActionType.VerbosityLow:
                    verbosity = SourceLevels.Warning;
                    RefreshMenus();
                    break;

                case ActionType.VerbosityMedium:
                    verbosity = SourceLevels.Information;
                    RefreshMenus();
                    break;

                case ActionType.VerbosityHigh:
                    verbosity = SourceLevels.Verbose;
                    RefreshMenus();
                    break;

                case ActionType.Process:
                    Status("Processing started");
                    iegf.Process(new NewFactEvent(HandleNewFactEvent),
                                 new NewFactEvent(HandleDelFactEvent),
                                 new NewFactEvent(HandleModFactEvent));
                    ConsoleOut(String.Empty);
                    RefreshMenus();
                    Status("Processing done");
                    break;

                case ActionType.AssertFact:
                case ActionType.RetractFact:
                    try {
                        string operation = (type == ActionType.AssertFact)?"Assertion":"Retraction";
                        string fact = iegf.PromptFactOperation(this, operation);

                        if (fact != String.Empty) {
                            ConsoleOut(((type == ActionType.AssertFact)?"+ ":"- ") + fact);
                            RefreshMenus();
                            ConsoleOut(String.Empty);
                            Status(operation + " done");
                        }
                    } catch(Exception e) {
                        ConsoleOut(e.Message);
                        ConsoleOut(String.Empty);
                    }
                    break;

                case ActionType.RunQuery:
                    QueryListForm qlf = new QueryListForm(iegf.QueryLabels);
                    if (qlf.ShowDialog(this) == DialogResult.OK ) {
                        ConsoleOut(iegf.RunQuery(qlf.SelectedQueryIndex));
                        ConsoleOut(String.Empty);
                        Status("Query executed");
                    }
                    else Status(String.Empty);
                    break;

                case ActionType.RunCustomQuery:
                    try
                    {
                        string queryResult = iegf.PromptQueryOperation(this);

                        if (queryResult != String.Empty)
                        {
                            ConsoleOut(queryResult);
                            ConsoleOut(String.Empty);
                            Status("Custom Query executed");
                        }
                    }
                    catch (Exception e)
                    {
                        ConsoleOut(e.Message);
                        ConsoleOut(String.Empty);
                    }
                    break;

                case ActionType.WMGlobal:
                    iegf.WMType = WorkingMemoryTypes.Global;
                    RefreshMenus();
                    Action(ActionType.DumpStatus);
                    break;

                case ActionType.WMIsolated:
                    iegf.WMType = WorkingMemoryTypes.Isolated;
                    RefreshMenus();
                    Action(ActionType.DumpStatus);
                    break;

                case ActionType.WMIsolatedEmpty:
                    iegf.WMType = WorkingMemoryTypes.IsolatedEmpty;
                    RefreshMenus();
                    Action(ActionType.DumpStatus);
                    break;

                case ActionType.WMCommit:
                    iegf.WMCommit();
                    RefreshMenus();
                    Action(ActionType.DumpStatus);
                    break;

                case ActionType.ListAssemblies:
                    ConsoleOut("Assemblies loaded in the current domain:");
                    foreach(AssemblyName assemblyName in loadedAssemblyNames)
                        ConsoleOut(" " + assemblyName.Name + "(" + assemblyName.Version + ")");
                    ConsoleOut(String.Empty);
                    Status(String.Empty);
                    break;
            }
        }
Example #2
0
        /// <summary>
        /// This method is charge of processing all events.
        /// </summary>
        /// <param name="type">The ActionType to process.</param>
        private void Action(ActionType type)
        {
            switch (type)
            {
            case ActionType.Exit:
                if (DialogResult.Yes == MessageBox.Show(this,
                                                        "Do you really want to exit?",
                                                        "Leaving NxBRE Console",
                                                        MessageBoxButtons.YesNo,
                                                        MessageBoxIcon.Warning,
                                                        MessageBoxDefaultButton.Button2))
                {
                    Utils.SaveUserPreferences(iegf.UserPrefs);
                    Application.Exit();
                }

                Status("Exit cancelled, let's infer some more!");
                break;

            case ActionType.LoadRuleBase:
                LoadRuleBase(false);
                ConsoleOut(String.Empty);
                break;

            case ActionType.LoadFacts:
                LoadRuleBase(true);
                ConsoleOut(String.Empty);
                break;

            case ActionType.SaveRuleBase:
                SaveRuleBase(false);
                ConsoleOut(String.Empty);
                break;

            case ActionType.SaveFacts:
                SaveRuleBase(true);
                ConsoleOut(String.Empty);
                break;

            case ActionType.ClearConsole:
                Status("Console cleared");
                ResetConsole();
                break;

            case ActionType.DumpStatus:
                ConsoleOut(iegf.Status);
                ConsoleOut(String.Empty);
                break;

            case ActionType.DumpFacts:
                if ((iegf.FactsCount > 100) &&
                    (DialogResult.No == MessageBox.Show(this,
                                                        "There are " +
                                                        iegf.FactsCount +
                                                        " facts in the working memory. Do you really want to list them?",
                                                        "Massive facts listing",
                                                        MessageBoxButtons.YesNo,
                                                        MessageBoxIcon.Warning,
                                                        MessageBoxDefaultButton.Button2)))
                {
                    return;
                }

                iegf.DumpFacts(new ConsoleWriter(ConsoleOut));
                ConsoleOut(String.Empty);
                break;

            case ActionType.VerbositySilent:
                verbosity = SourceLevels.Critical;
                RefreshMenus();
                break;

            case ActionType.VerbosityLow:
                verbosity = SourceLevels.Warning;
                RefreshMenus();
                break;

            case ActionType.VerbosityMedium:
                verbosity = SourceLevels.Information;
                RefreshMenus();
                break;

            case ActionType.VerbosityHigh:
                verbosity = SourceLevels.Verbose;
                RefreshMenus();
                break;

            case ActionType.Process:
                Status("Processing started");
                iegf.Process(new NewFactEvent(HandleNewFactEvent),
                             new NewFactEvent(HandleDelFactEvent),
                             new NewFactEvent(HandleModFactEvent));
                ConsoleOut(String.Empty);
                RefreshMenus();
                Status("Processing done");
                break;

            case ActionType.AssertFact:
            case ActionType.RetractFact:
                try {
                    string operation = (type == ActionType.AssertFact)?"Assertion":"Retraction";
                    string fact      = iegf.PromptFactOperation(this, operation);

                    if (fact != String.Empty)
                    {
                        ConsoleOut(((type == ActionType.AssertFact)?"+ ":"- ") + fact);
                        RefreshMenus();
                        ConsoleOut(String.Empty);
                        Status(operation + " done");
                    }
                } catch (Exception e) {
                    ConsoleOut(e.Message);
                    ConsoleOut(String.Empty);
                }
                break;

            case ActionType.RunQuery:
                QueryListForm qlf = new QueryListForm(iegf.QueryLabels);
                if (qlf.ShowDialog(this) == DialogResult.OK)
                {
                    ConsoleOut(iegf.RunQuery(qlf.SelectedQueryIndex));
                    ConsoleOut(String.Empty);
                    Status("Query executed");
                }
                else
                {
                    Status(String.Empty);
                }
                break;

            case ActionType.RunCustomQuery:
                try
                {
                    string queryResult = iegf.PromptQueryOperation(this);

                    if (queryResult != String.Empty)
                    {
                        ConsoleOut(queryResult);
                        ConsoleOut(String.Empty);
                        Status("Custom Query executed");
                    }
                }
                catch (Exception e)
                {
                    ConsoleOut(e.Message);
                    ConsoleOut(String.Empty);
                }
                break;

            case ActionType.WMGlobal:
                iegf.WMType = WorkingMemoryTypes.Global;
                RefreshMenus();
                Action(ActionType.DumpStatus);
                break;

            case ActionType.WMIsolated:
                iegf.WMType = WorkingMemoryTypes.Isolated;
                RefreshMenus();
                Action(ActionType.DumpStatus);
                break;

            case ActionType.WMIsolatedEmpty:
                iegf.WMType = WorkingMemoryTypes.IsolatedEmpty;
                RefreshMenus();
                Action(ActionType.DumpStatus);
                break;

            case ActionType.WMCommit:
                iegf.WMCommit();
                RefreshMenus();
                Action(ActionType.DumpStatus);
                break;

            case ActionType.ListAssemblies:
                ConsoleOut("Assemblies loaded in the current domain:");
                foreach (AssemblyName assemblyName in loadedAssemblyNames)
                {
                    ConsoleOut(" " + assemblyName.Name + "(" + assemblyName.Version + ")");
                }
                ConsoleOut(String.Empty);
                Status(String.Empty);
                break;
            }
        }