Example #1
0
        private void GoButton_Click(object sender, System.EventArgs e)
        {
            LogicServer     ls;
            PrologPredicate prompt_pred;
            int             term;
            string          pet;

            ls          = new LogicServer();
            prompt_pred = new PrologPredicate(prompt);
            try
            {
                ls.Init("");
                ls.AddPred("prompt", 2, prompt_pred);
                ls.Load("pets.xpl");
                term = ls.ExecStr("pet(X)");
                if (term == 0)
                {
                    MessageBox.Show("Sound not found", "ERROR",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    pet          = ls.GetStrArg(term, 1);
                    PetText.Text = pet;
                }
                ls.Close();
            }
            catch (LSException ex)
            {
                MessageBox.Show(ex.GetMessage(), "ERROR",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #2
0
        private void GetPetButton_Click(object sender, System.EventArgs e)
        {
            LogicServer ls;
            long        term;

            term = 0;
            try
            {
                ls = new LogicServer();
                ls.Init("");
                ls.Load("pets.xpl");
                ls.AssertaStr("sound(" + SoundText.Text + ")");
                term = ls.ExecStr("pet(X)");
                if (term != 0)
                {
                    PetText.Text = ls.GetStrArg(term, 1);
                }
                else
                {
                    PetText.Text = "Unknown Pet";
                }
                ls.Close();
            }
            catch (LSException ex)
            {
                String message = ex.GetMessage();
                PetText.Text = message;
            }
        }
Example #3
0
    public void OpenRules(string rulesetfile, string arulespath)
    {
        string s;
        long   term;

        try
        {
            // Get our logicserver and initialize it
            ls = new LogicServer();
            ls.Init(DoubleSlashes(arulespath + "arulesrt.cfg"));

            // Load the arulesxl engine
            ls.Load(DoubleSlashes(arulespath + "arulesrt.xpl"));

            // Load the ruleset
            if (rulesetfile != null)
            {
                s    = "consult(`" + DoubleSlashes(rulesetfile) + "`)";
                term = ls.ExecStr(s);
                if (term == 0)
                {
                    throw new Exception("Unable to consult ruleset");
                }
            }
        }
        catch (LSException ex)
        {
            throw new Exception("OpenRules / " + FormatLSException(ex));
        }
    }
Example #4
0
 public void CloseRules()
 {
     if (ls != null)
     {
         ls.Close();
         ls = null;
     }
 }
Example #5
0
        public int TestSimple()
        {
            string binDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Bin");

            var obj = new LogicServer();

            obj.Init("");
            obj.Load(Path.Combine(binDir, "family.xpl"));
            obj.ExecStr("assert(house(1)).");

            var t = obj.ExecStr("house(1).");

            return(Convert.ToInt32(t));
        }
Example #6
0
        bool prompt(LogicServer ls)
        {
            string      prompt_text, answer;
            InputDialog dlg;

            prompt_text = ls.GetStrParm(1);
            dlg         = new InputDialog(prompt_text);
            dlg.ShowDialog();

            answer = dlg.GetInput();
            if (ls.UnifyStrParm(2, answer) == 0)
            {
                return(false);
            }
            return(true);
        }
Example #7
0
        // handle actions when button 'Get Result' is clicked
        private void GetResult_Click(object sender, System.EventArgs e)
        {
            LogicServer ls;
            int         term;

            try
            {
                // Initialize the logic server //
                ls = new LogicServer();
                ls.Init("");
                const string x = @"C:\Program Files\amzi\ide\workspace\cpe425\bin\cpe425.xpl";
                ls.Load(x);

                // get boarding station and alighting station input and execute corresponding command in Prolog //
                term = ls.ExecStr("shortest(" + (comboBox1.SelectedItem).ToString() + "," + (comboBox2.SelectedItem).ToString() + ", MinTime, MinRoute)");

                // analyse the return value, if return value != 0, means the command was successfully executed //
                if (term != 0)
                {
                    // show out the shortest travel time,
                    TimeResult.Text = (ls.GetIntArg(term, 3)).ToString();

                    // show out the shortest travel route, as return value is list, we must recursively get all elements in this list //
                    int    term1 = ls.GetArg(term, 4);
                    string s     = ls.GetStrHead(term1);
                    while (ls.GetTail(term1) != 0)
                    {
                        s    += " -> " + ls.GetStrHead(ls.GetTail(term1));
                        term1 = ls.GetTail(term1);
                    }
                    RouteResult.Text = s;
                }
                else
                {
                    TimeResult.Text  = "Invalid Request!";
                    RouteResult.Text = "Invalid Request!";
                }

                // close the logic server
                ls.Close();
            }
            catch (LSException ex)
            {
                String message = ex.GetMessage();
            }
        }
Example #8
0
        public static void Main(string[] args)
        {
            if (!ConfigManager.Load())
            {
                Console.WriteLine("Load config failed.");
                return;
            }

            LogicServer logic = new LogicServer();

            logic.Setup(ConfigManager.m_LogicServerPort);
            logic.Start();

            System.Console.WriteLine("Start server success.");
            while (true)
            {
            }
        }
Example #9
0
        private void ProcessReceive(AsyncClientArgs args)
        {
            // если данные получены
            if (args.SocketError == SocketError.Success)
            {
                if (args.BytesTransferred > 0)
                {
                    var message = args.UTF8Message;
                    Log.Debug("{0} > {1}", args.AcceptSocket.RemoteEndPoint, message);

                    // передаем сообщение логическому серверу и получаем ответ
                    message = LogicServer.GetResponse(message);

                    if (message == null)
                    {
                        CloseClientConnection(args);
                        return;
                    }

                    args.UTF8Message = message;

                    // посылаем сообщение обратно клиенту
                    if (!args.AcceptSocket.SendAsync(args))
                    {
                        ProcessSend(args);
                    }
                }
                else
                {
                    // клиент закончил передачу сообщения
                    CloseClientConnection(args);
                }
            }
            else
            {
                Log.Error("{0} > {1}", args.AcceptSocket.RemoteEndPoint, args.SocketError);
                CloseClientConnection(args);
            }
        }
Example #10
0
        private void ProcessReceive(AsyncClientArgs client)
        {
            switch (client.SocketError)
            {
            case SocketError.Success:
                if (client.BytesTransferred > 0)
                {
                    var request = client.UTF8Message;

                    // send request to logic server and get the response
                    var response = LogicServer.GetResponse(request);

                    // send response to client, if it is not empty
                    if (response != null)
                    {
                        client.UTF8Message = response;
                        if (!client.AcceptSocket.SendToAsync(client))
                        {
                            ProcessSend(client);
                        }
                    }

                    Log.Debug("{0}: {1} -> {2}", client.RemoteEndPoint, request, response);
                }
                break;

            case SocketError.OperationAborted:
                _clientPool.Release(client);
                return;

            default:
                Log.Error("{0}: {1}", client.RemoteEndPoint, client.SocketError);
                _clientPool.Release(client);
                break;
            }
            StartReceiving();
        }
Example #11
0
    // Dispose(bool disposing) executes in two distinct scenarios.
    // If disposing equals true, the method has been called directly
    // or indirectly by a user's code. Managed and unmanaged resources
    // can be disposed.
    // If disposing equals false, the method has been called by the
    // runtime from inside the finalizer and you should not reference
    // other objects. Only unmanaged resources can be disposed.
    private void Dispose(bool disposing)
    {
        // Check to see if Dispose has already been called.
        if (!this.disposed)
        {
            // If disposing equals true, dispose all managed
            // and unmanaged resources.
            if (disposing)
            {
                // Dispose managed resources.
            }

            // Call the appropriate methods to clean up
            // unmanaged resources here.
            // If disposing is false,
            // only the following code is executed.
            if (ls != null)
            {
                ls.Close();
                ls = null;
            }
        }
        disposed = true;
    }