// And messages we send out or the responses sent out // are recorded in the context messages sent table public bool SendContextMessage(ContextMsg ctxMsg) { // Quick error checks if (ctxMsg == null) { throw new ArgumentNullException("ctxMsg", "Invalid context message"); } // Put the destination data in the Sender, SenderUrl fields of // the context message bool bRetVal = false; try { StringBuilder strQueryBuilder = new StringBuilder(); strQueryBuilder.Append(" INSERT INTO "); strQueryBuilder.Append(Constants.CONTEXT_MSGS_SENT_TABLENAME); strQueryBuilder.Append("("); strQueryBuilder.Append(Constants.MTG_ID); strQueryBuilder.Append(","); strQueryBuilder.Append(Constants.CTXMSG_ID); strQueryBuilder.Append(","); strQueryBuilder.Append(Constants.CONTACT_ID); strQueryBuilder.Append(","); strQueryBuilder.Append(Constants.CTXMSG_TYPE); strQueryBuilder.Append(","); strQueryBuilder.Append(Constants.CONTACT_LOC); strQueryBuilder.Append(","); strQueryBuilder.Append(Constants.CTXMSG); strQueryBuilder.Append(")"); strQueryBuilder.Append(" VALUES "); strQueryBuilder.Append("("); strQueryBuilder.Append("'" + QueryService.MakeQuotesafe(ctxMsg.MeetingID) + "'"); strQueryBuilder.Append(","); strQueryBuilder.Append("'" + QueryService.MakeQuotesafe(ctxMsg.MessageID) + "'"); strQueryBuilder.Append(","); strQueryBuilder.Append("'" + QueryService.MakeQuotesafe(ctxMsg.Dest) + "'"); strQueryBuilder.Append(","); strQueryBuilder.Append("'" + QueryService.MakeQuotesafe(ctxMsg.Type.ToString()) + "'"); strQueryBuilder.Append(","); strQueryBuilder.Append("'" + QueryService.MakeQuotesafe(ctxMsg.DestUrl) + "'"); strQueryBuilder.Append(","); strQueryBuilder.Append("'" + QueryService.MakeQuotesafe(ctxMsg.ToXml()) + "'"); strQueryBuilder.Append(")"); int nRowsAffected = QueryService.ExecuteNonQuery(this.DBConnect, strQueryBuilder.ToString()); if (nRowsAffected == 1) { bRetVal = true; } } catch (Exception /*e*/) { } finally { } return(bRetVal); }
// A context message goes into the responses table if there is // a sent message with a matching message id. Otherwise it goes into the // context messages received table public bool ReceiveContextMessage(ContextMsg ctxMsg, bool bMarkAsNewMsg) { // Quick error checks if (ctxMsg == null) { throw new ArgumentNullException("ctxMsg", "Invalid context message"); } bool bRetVal = false; bool bIsResponse = false; string strTablename = Constants.CONTEXT_MSGS_RECEIVED_TABLENAME; if (IsContextMessageResponse(ctxMsg)) { strTablename = Constants.CONTEXT_MSG_RESPONSES_TABLENAME; bIsResponse = true; } // If a context message is not a response then it is a regular // received message if (!bIsResponse) { // Check whether we have received this context message twice if (this.IsContextMessageReceivedTwice(ctxMsg)) { return(true); } } try { StringBuilder strQueryBuilder = new StringBuilder(); strQueryBuilder.Append(" INSERT INTO "); strQueryBuilder.Append(strTablename); strQueryBuilder.Append("("); strQueryBuilder.Append(Constants.MTG_ID); strQueryBuilder.Append(","); strQueryBuilder.Append(Constants.CTXMSG_ID); strQueryBuilder.Append(","); strQueryBuilder.Append(Constants.CONTACT_ID); strQueryBuilder.Append(","); strQueryBuilder.Append(Constants.CTXMSG_TYPE); strQueryBuilder.Append(","); strQueryBuilder.Append(Constants.CONTACT_LOC); strQueryBuilder.Append(","); strQueryBuilder.Append(Constants.CTXMSG); if (!bIsResponse) { strQueryBuilder.Append(","); strQueryBuilder.Append(Constants.NEWMSG); } strQueryBuilder.Append(")"); strQueryBuilder.Append(" VALUES "); strQueryBuilder.Append("("); strQueryBuilder.Append("'" + QueryService.MakeQuotesafe(ctxMsg.MeetingID) + "'"); strQueryBuilder.Append(","); strQueryBuilder.Append("'" + QueryService.MakeQuotesafe(ctxMsg.MessageID) + "'"); strQueryBuilder.Append(","); strQueryBuilder.Append("'" + QueryService.MakeQuotesafe(ctxMsg.Sender) + "'"); strQueryBuilder.Append(","); strQueryBuilder.Append("'" + QueryService.MakeQuotesafe(ctxMsg.Type.ToString()) + "'"); strQueryBuilder.Append(","); strQueryBuilder.Append("'" + QueryService.MakeQuotesafe(ctxMsg.SenderUrl) + "'"); strQueryBuilder.Append(","); strQueryBuilder.Append("'" + QueryService.MakeQuotesafe(ctxMsg.ToXml()) + "'"); if (!bIsResponse) { strQueryBuilder.Append(","); if (bMarkAsNewMsg == true) { strQueryBuilder.Append(1); } else { strQueryBuilder.Append(0); } } strQueryBuilder.Append(")"); int nRowsAffected = QueryService.ExecuteNonQuery(this.DBConnect, strQueryBuilder.ToString()); if (nRowsAffected == 1) { bRetVal = true; } } catch (Exception /*e*/) { } finally { } return(bRetVal); }