Example #1
0
        /// <summary>
        /// 创建新消息
        /// </summary>
        /// <param name="session"></param>
        /// <param name="tmplCode"></param>
        /// <param name="title"></param>
        /// <param name="content"></param>
        /// <param name="createBy"></param>
        /// <param name="sentAtOnce"></param>
        /// <param name="sentTime"></param>
        public static void NewMessage(ISession session, string tmplCode, string title, string content, string createBy, bool sentAtOnce, DateTime sentTime)
        {
            MsgTemplate tmpl = MsgTemplate.Retrieve(session, tmplCode);
            if (tmpl != null)
            {
                Message msg = new Message();
                msg._accessibility = tmpl.Accessibility;
                msg._source = tmpl.Source;
                msg._destination = "";
                if(tmpl.Expires > 0)
                    msg._expireTime = DateTime.Now.AddSeconds(tmpl.Expires);
                msg._createBy = createBy;
                msg._createTime = DateTime.Now;
                msg._msgTypeId = tmpl.MsgTypeId;
                msg._responseEntry = tmpl.ResponseEntry;
                if (!sentAtOnce)
                {
                    if (sentTime < DateTime.Now)
                        throw new Exception("发送时间不能小于当前时间");
                    msg._sendTime = sentTime;
                }
                msg._status = MessageStatus.New;
                msg._title = title;
                msg._content = content;
                msg._tmplCode = tmplCode;
                if (!msg.Create(session))
                {
                    logger.Info(string.Format("创建消息失败.模板代码:{0},标题:{1},内容:{2},创建人:{3}",tmplCode,title,content,createBy));
                }

            }
            else
            {
                throw new Exception(string.Format("指定的消息模板代码不存在;模板代码:{0}",tmplCode));
            }
        }
Example #2
0
        /// <summary>
        ///  Map a DataRow to a Message Entity.
        /// </summary>
        /// <returns></returns>
        public static Message Row2Entity(System.Data.DataRow row)
        {
            if(row == null) return null;

            Message entity = new Message();

            entity._messageId= Cast.Int(row["MSG_ID"]);
            entity._tmplCode= Cast.String(row["MSG_TMPL_CODE"]);
            entity._msgTypeId= Cast.Int(row["MSG_TYPE_ID"]);
            entity._title= Cast.String(row["MSG_TITLE"]);
            entity._content= Cast.String(row["MSG_CONTENT"]);
            entity._accessibility= Cast.Enum<MessageAccessibility>(row["MSG_ACCESS"]);
            entity._createTime= Cast.DateTime(row["CREATE_TIME"]);
            entity._viewEntry= Cast.String(row["MSG_URL"]);
            entity._sendTime= Cast.DateTime(row["MSG_SEND_TIME"]);
            entity._expireTime= Cast.DateTime(row["MSG_EXPIRE_TIME"]);
            entity._createBy= Cast.String(row["CREATE_BY"]);
            entity._lastResponseTime= Cast.DateTime(row["LAST_RESPONSE"]);
            entity._status= Cast.Enum<MessageStatus>(row["MSG_STATUS"]);
            entity._responseEntry= Cast.String(row["RESPONSE_URL"]);
            entity._source= Cast.String(row["MSG_SOURCE"]);
            entity._destination= Cast.String(row["MSG_TARGET"]);

               return entity;
        }