/// <summary> /// Execute the current transaction with the reason specified to obtain /// the next user command. /// </summary> private void GetNextUserCommand(KmodTransactionReason reason) { Debug.Assert(IsTransactionExecuting()); Debug.Assert(IsThreadReadyForUserCommand()); // Remember the previous command posted by the user. KmodThreadCommand prevCmd = m_curCommand; try { // Call Run(). Note that the transaction may be cancelled // or finished during that time. m_curTransaction.Run(reason); // If the transaction is still executing and the user hasn't // posted another command or if the transaction has explicitly // been marked finished, the transaction is completed. if ((IsTransactionExecuting() && (m_curCommand == null || m_curCommand == prevCmd)) || (m_curTransaction != null && m_curTransaction.Status == KmodTransactionStatus.Finished)) { EndCurrentTransaction(); RequestRun(); } } // The transaction has failed. Kill everything and request a run. catch (Exception ex) { Killall(ex); RequestRun(); } }
public override void Run(KmodTransactionReason reason) { if (reason == KmodTransactionReason.Start) { PostCommand(new K3p.k3p_beg_session(), false); for (int i = 0; i < InCmdArray.Length - 1; i++) { PostCommand(InCmdArray[i], false); } PostCommand(InCmdWithRes, true); } else if (reason == KmodTransactionReason.CommandResult) { // Important: let Slurp() throw. GetSlurper().Slurp(InCmdWithRes, out OutDesc, out OutMsg); // Post the end session command. PostCommand(new K3p.k3p_end_session(), false); // Mark the query as finished to allow the callback to cancel // the query without killing KMOD. Finish(); // Call the callback. CallCallback(); } else { OutDesc = Ex.Message; CallCallback(); } }
/// <summary> /// This method is called by the KMOD broker in UI context when the /// first command is ready to be sent, when the current command results /// are ready and also when an error occurs in KMOD. If no command is posted /// during the call to Run(), the KMOD broker will assume that the /// transaction is completed. /// /// IMPORTANT NOTES: /// - The Run() method may not reenter the UI. /// - All the exceptions raised due to a communication error with KMOD /// must be allowed to escape to the caller. The KMOD broker must /// trap these exceptions to update its status correctly. /// </summary> /// <param name="reason">Reason why this method is being called</param> public abstract void Run(KmodTransactionReason reason);
public override void Run(KmodTransactionReason reason) { if (reason == KmodTransactionReason.Start) { PostCommand(new K3p.k3p_beg_session(), false); for (int i = 0; i < InCmdArray.Length - 1; i++) PostCommand(InCmdArray[i], false); PostCommand(InCmdWithRes, true); } else if (reason == KmodTransactionReason.CommandResult) { // Important: let Slurp() throw. GetSlurper().Slurp(InCmdWithRes, out OutDesc, out OutMsg); // Post the end session command. PostCommand(new K3p.k3p_end_session(), false); // Mark the query as finished to allow the callback to cancel // the query without killing KMOD. Finish(); // Call the callback. CallCallback(); } else { OutDesc = Ex.Message; CallCallback(); } }