/// <summary> /// 添加接收者 /// </summary> /// <param name="userId">接收者标识,例如用户ID、会员ID等</param> /// <param name="userName">接收者姓名</param> /// <param name="postTo">邮件消息该属性指定接收者邮箱地址,短信消息该属性指定接收者手机号码</param> /// <returns></returns> public Notification AddReceiver(string userId, string userName, string postTo) { NotificationReceiver receiver = new NotificationReceiver(this.NotifyID, userId, userName, postTo); receiver.Create(this._session); return(this); }
/// <summary> /// <para>����֮ǰ������ø÷��������췢�ͱ��⡢���ݣ���ȡ�������б�Ȳ���</para> /// <para>ʹ��Title, Content, Receivers���ԾͿ��Ի�÷�����Ҫ��������Ϣ</para> /// </summary> /// <param name="session"></param> /// <returns>����������</returns> public int ReadyToSend() { this._title = ""; this._content = ""; //������ IList<NotificationSubscriber> subscribers = NotificationSubscriber.GetList(this._session, this.CatID); foreach (NotificationSubscriber subscriber in subscribers) { NotificationReceiver receiver = NotificationReceiver.Retrieve(this._session, this.NotifyID, subscriber.UserID); if (receiver == null) { //��ǰ�������Ƿ��Ѿ���ӵ��������б����ˣ� receiver = new NotificationReceiver(this.NotifyID, subscriber.UserID, subscriber.UserName, subscriber.PostCode); receiver.Create(this._session); } } //��ȡ�������б� this._receiver = NotificationReceiver.ToSendList(this._session, this.NotifyID); if (this._receiver.Count <= 0) return 0; //���� this._param = new Dictionary<string, object>(); IList<NotificationParam> paramList = this._session.CreateEntityQuery<NotificationParam>() .Where(Exp.Eq("NotifyID", this.NotifyID) & Exp.Eq("ParentID", 0)) .List<NotificationParam>(); foreach (NotificationParam p in paramList) this._param.Add(p.ParamName, this.BuildParam(p)); NotificationCategory category = Notification.GetCategory(this._session, this.CatID); //��Ϣ���⣨�����ʼ���Ϣ�� if (category.Type == NotificationType.Mail && !string.IsNullOrEmpty(category.TitleTemplate) && category.TitleTemplate.Trim().Length > 0) { StringTemplate st = new StringTemplate(category.TitleTemplate); SetAttribute(st, this._param); this._title = st.ToString(); } //��Ϣ���� if (!System.IO.File.Exists(category.TemplateFile)) { log.ErrorFormat("category {0}: template file {1} not exists", category.CatID, category.TemplateFile); return this._receiver.Count; } string templateContent = null; using (System.IO.StreamReader reader = new System.IO.StreamReader(category.TemplateFile, System.Text.Encoding.UTF8)) { templateContent = reader.ReadToEnd(); } if (string.IsNullOrEmpty(templateContent) || templateContent.Length <= 0) return this._receiver.Count; StringTemplate stContent = new StringTemplate(templateContent); SetAttribute(stContent, this._param); this._content = stContent.ToString(); return this._receiver.Count; }
/// <summary> /// ��ӽ����� /// </summary> /// <param name="userId">�����߱�ʶ�������û�ID����ԱID��</param> /// <param name="userName">����������</param> /// <param name="postTo">�ʼ���Ϣ������ָ�������������ַ��������Ϣ������ָ���������ֻ�����</param> /// <returns></returns> public Notification AddReceiver(string userId, string userName, string postTo) { NotificationReceiver receiver = new NotificationReceiver(this.NotifyID, userId, userName, postTo); receiver.Create(this._session); return this; }
/// <summary> /// <para>发送之前必须调用该方法,构造发送标题、内容,读取接收者列表等操作</para> /// <para>使用Title, Content, Receivers属性就可以获得发送需要的完整信息</para> /// </summary> /// <param name="session"></param> /// <returns>待发送数量</returns> public int ReadyToSend() { this._title = ""; this._content = ""; //接收者 IList <NotificationSubscriber> subscribers = NotificationSubscriber.GetList(this._session, this.CatID); foreach (NotificationSubscriber subscriber in subscribers) { NotificationReceiver receiver = NotificationReceiver.Retrieve(this._session, this.NotifyID, subscriber.UserID); if (receiver == null) { //当前订阅者是否已经添加到接收者列表中了? receiver = new NotificationReceiver(this.NotifyID, subscriber.UserID, subscriber.UserName, subscriber.PostCode); receiver.Create(this._session); } } //获取接收者列表 this._receiver = NotificationReceiver.ToSendList(this._session, this.NotifyID); if (this._receiver.Count <= 0) { return(0); } //参数 this._param = new Dictionary <string, object>(); IList <NotificationParam> paramList = this._session.CreateEntityQuery <NotificationParam>() .Where(Exp.Eq("NotifyID", this.NotifyID) & Exp.Eq("ParentID", 0)) .List <NotificationParam>(); foreach (NotificationParam p in paramList) { this._param.Add(p.ParamName, this.BuildParam(p)); } NotificationCategory category = Notification.GetCategory(this._session, this.CatID); //消息标题(对于邮件消息) if (category.Type == NotificationType.Mail && !string.IsNullOrEmpty(category.TitleTemplate) && category.TitleTemplate.Trim().Length > 0) { StringTemplate st = new StringTemplate(category.TitleTemplate); SetAttribute(st, this._param); this._title = st.ToString(); } //消息内容 if (!System.IO.File.Exists(category.TemplateFile)) { log.ErrorFormat("category {0}: template file {1} not exists", category.CatID, category.TemplateFile); return(this._receiver.Count); } string templateContent = null; using (System.IO.StreamReader reader = new System.IO.StreamReader(category.TemplateFile, System.Text.Encoding.UTF8)) { templateContent = reader.ReadToEnd(); } if (string.IsNullOrEmpty(templateContent) || templateContent.Length <= 0) { return(this._receiver.Count); } StringTemplate stContent = new StringTemplate(templateContent); SetAttribute(stContent, this._param); this._content = stContent.ToString(); return(this._receiver.Count); }