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; } }
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); } }
// 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; }
// 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(); } }