コード例 #1
0
ファイル: IEGUIFacade.cs プロジェクト: Ghasan/NxBRE
        public void SaveRuleBase(MainForm mf, string uri, bool onlyFacts)
        {
            switch(Path.GetExtension(uri).ToLower()) {
                case ".ruleml":
                    if (onlyFacts) ie.SaveFacts(new RuleML09NafDatalogAdapter(uri, FileAccess.Write));
                    else ie.SaveRuleBase(new RuleML09NafDatalogAdapter(uri, FileAccess.Write));
                    break;

                case ".hrf":
                    if (onlyFacts) ie.SaveFacts(new HRF086Adapter(uri, FileAccess.Write));
                    else ie.SaveRuleBase(new HRF086Adapter(uri, FileAccess.Write));
                    break;

                default:
                    throw new Exception(Path.GetExtension(uri) + " is an unsupported saving extension.");
            }
        }
コード例 #2
0
ファイル: IEGUIFacade.cs プロジェクト: Ghasan/NxBRE
        public string PromptFactOperation(MainForm mf, string operation)
        {
            up.lastHRFFact = mf.PromptForString("Manual Fact " + operation,
                                            "Enter a fact in Human Readable Format (ASCII):",
                                         	  up.lastHRFFact);

            if (up.lastHRFFact != String.Empty) {
                if (!up.lastHRFFact.EndsWith(";")) up.lastHRFFact += ";";
                int iniNbFacts = ie.FactsCount;
                using(HRF086Adapter hrfa = new HRF086Adapter(new MemoryStream(Encoding.ASCII.GetBytes("#DIRECTION_FORWARD\n\r+" + up.lastHRFFact)),
                                                           FileAccess.Read)) {

                    foreach(Fact f in hrfa.Facts)
                        if (operation == "Assertion") ie.Assert(f);
                        else ie.Retract(f);
                }

                if (iniNbFacts != ie.FactsCount) return up.lastHRFFact;
            }

            return String.Empty;
        }
コード例 #3
0
ファイル: IEGUIFacade.cs プロジェクト: Ghasan/NxBRE
        public string PromptQueryOperation(MainForm mf)
        {
            up.lastHRFQuery = mf.PromptForString("Custom Query",
                                            "Enter a query in Human Readable Format (ASCII):",
                                         	  up.lastHRFQuery);

                if (up.lastHRFQuery != string.Empty)
                {
                    if (!up.lastHRFQuery.EndsWith(";")) up.lastHRFQuery += ";";

                    using (HRF086Adapter hrfa =
                        new HRF086Adapter(new MemoryStream(
                                                Encoding.ASCII.GetBytes("#DIRECTION_FORWARD\n\r[custom query]\n\r" + up.lastHRFQuery)),
                                                FileAccess.Read))
                    {
                        if (hrfa.Queries.Count == 1)
                        {
                            return getResultsAsString(ie.RunQuery(hrfa.Queries[0]));
                        }
                        else
                        {
                            throw new ApplicationException("custom query text must contain exactly one query");
                        }
                    }
                }

            return string.Empty;
        }
コード例 #4
0
ファイル: IEGUIFacade.cs プロジェクト: Ghasan/NxBRE
        public void LoadRuleBase(MainForm mf, string uri, bool onlyFacts)
        {
            IBinder binder = null;
            // give priority to custom compiled binders
            if (File.Exists(uri + ".ccb")) {
                up.lastBinderClassName = mf.PromptForString("C# Custom Binder - " + uri + ".ccb",
                                                      	 "Enter the fully qualified name of the binder class:",
                                                     		 up.lastBinderClassName);
                binder = CSharpBinderFactory.LoadFromFile(up.lastBinderClassName, uri + ".ccb");
            }
            else if (File.Exists(uri + ".vcb")) {
                up.lastBinderClassName = mf.PromptForString("VB.NET Custom Binder - " + uri + ".vcb",
                                                      	 "Enter the fully qualified name of the binder class:",
                                                     		 up.lastBinderClassName);
                binder = VisualBasicBinderFactory.LoadFromFile(up.lastBinderClassName, uri + ".vcb");
            }
            else if (File.Exists(uri + ".xbre")) {
                bool isBeforeAfter = mf.AskYesNoQuestion("Flow Engine Binder - " + uri + ".xbre",
                                                         uri + ".xbre\n\nIs this binder running in Before/After mode ?\n\n(No would mean that it runs in Control Process mode)");

                binder = new FlowEngineBinder(uri + ".xbre", isBeforeAfter?BindingTypes.BeforeAfter:BindingTypes.Control);
            }

            if (!onlyFacts) ie = new IEImpl(binder);

            switch(Path.GetExtension(uri).ToLower()) {
                case ".ruleml":
                    try {
                        if (onlyFacts) ie.LoadFacts(new RuleML09NafDatalogAdapter(uri, FileAccess.Read));
                        else ie.LoadRuleBase(new RuleML09NafDatalogAdapter(uri, FileAccess.Read));
                    }
                    catch(Exception firstAttemptException) {
                        try {
                            if (onlyFacts) ie.LoadFacts(new RuleML086NafDatalogAdapter(uri, FileAccess.Read));
                            else ie.LoadRuleBase(new RuleML086NafDatalogAdapter(uri, FileAccess.Read));
                        }
                        catch(Exception) {
                            try {
                                if (onlyFacts) ie.LoadFacts(new RuleML086DatalogAdapter(uri, FileAccess.Read));
                                else ie.LoadRuleBase(new RuleML086DatalogAdapter(uri, FileAccess.Read));
                            }
                            catch(Exception) {
                                try {
                                    if (onlyFacts) ie.LoadFacts(new RuleML08DatalogAdapter(uri, FileAccess.Read));
                                    else ie.LoadRuleBase(new RuleML08DatalogAdapter(uri, FileAccess.Read));
                                } catch(Exception) {
                                    // the fall-back policy failed, hence throw the original exception
                                    throw firstAttemptException;
                                }
                            }
                        }
                    }
                    break;

                case ".hrf":
                    if (onlyFacts) ie.LoadFacts(new HRF086Adapter(uri, FileAccess.Read));
                    else ie.LoadRuleBase(new HRF086Adapter(uri, FileAccess.Read));
                    break;

                case ".vdx":
                    string[] selectedPages = mf.PromptForVisioPageNameSelection(Visio2003Adapter.GetPageNames(uri));
                    if (selectedPages != null) {
                        if (onlyFacts) ie.LoadFacts(new Visio2003Adapter(uri, FileAccess.Read, selectedPages));
                        else ie.LoadRuleBase(new Visio2003Adapter(uri, FileAccess.Read, (DialogResult.Yes == MessageBox.Show(mf,
                                                                                    "Is your Visio rule base using strict syntax?",
                                                                                    "Visio strictness",
                                                                                    MessageBoxButtons.YesNo,
                                                                                    MessageBoxIcon.Question,
                                                            MessageBoxDefaultButton.Button2)), selectedPages));
                    }
                    break;

                default:
                    throw new Exception(Path.GetExtension(uri) + " is an unknown extension.");
            }
        }