/// <summary>接收数据</summary>
        /// <returns></returns>
        public override IMessageObject Receive()
        {
            // 阻塞方式
            IMessageObject data = null;

            lock (lockObject)
            {
                if (queue == null)
                {
                    this.queue = this.GetQueueInstance();
                }

                try
                {
                    data = new TaskWorkInfo();

                    // 如果消息队列为空时, 将会导致无限期占用线程, 设置等待10秒钟Receive()函数无响应,则返回空值。
                    Message message = queue.Receive(new TimeSpan(0, 0, 10));

                    XmlDocument doc = new XmlDocument();

                    doc.LoadXml(message.Body.ToString());

                    data.Deserialize(doc.DocumentElement);

                    return(data);
                }
                catch (MessageQueueException messageQueueException)
                {
                    if (messageQueueException.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout)
                    {
                        // 等待10秒钟Receive()函数无响应,则返回空值。
                        return(null);
                    }

                    throw;
                }
                catch
                {
                    this.Close();
                    throw;
                }
            }
        }
Exemplo n.º 2
0
        private string Process(string securityToken, string xml, string actionType)
        {
            try
            {
                /*
                 *
                 * Xml数据示例
                 *
                 * <?xml version="1.0" encoding="utf-8"?>
                 *
                 * <root>
                 *     <task>
                 *         <taskCode>T00001</taskCode>
                 *         <title>Some Title</title>
                 *         <url>http://www.google.com</url>
                 *         <category>Document</category>
                 *         <senderId>administrator</senderId>
                 *         <receiver>0#test1,1#test2#2008-1-1 08:08:08</receiver>
                 *         <createDate>2008-01-01</createDate>
                 *     </task>
                 *     <task>
                 *         <taskCode>T00002</taskCode>
                 *         <title>Some Title</title>
                 *         <url>http://www.google.com</url>
                 *         <category>Document</category>
                 *         <senderId>administrator</senderId>
                 *         <receiver>0#test1,1#test2#2008-1-1 08:08:08</receiver>
                 *         <createDate>2008-01-01</createDate>
                 *     </task>
                 * </root>
                 *
                 * (*) 接收者信息说明 格式:{0}#{1}#{2} , {0}代表代办状态 1 完成 0 未完成, {1}相关的帐号, {2}{任务完成时间}
                 *
                 *
                 *
                 */

                string result = null;

                string applicationId = SecurityTokenManager.Authenticate(securityToken);

                TaskWorkInfo param = null;

                XmlDocument doc = new XmlDocument();

                doc.LoadXml(xml);

                XmlNodeList list = doc.GetElementsByTagName("ajaxStorage")[0].ChildNodes;

                foreach (XmlNode item in list)
                {
                    param = new TaskWorkInfo(applicationId);

                    param.Deserialize((XmlElement)item);

                    if (param.ReceiverGroup.Count == 0)
                    {
                        result += string.Format("任务【{0}】没有指派给任何用户请重新设置,", param.TaskCode);
                    }
                    else
                    {
                        if (actionType == "发送" &&
                            TasksContext.Instance.TaskService.IsExistTaskCode(param.ApplicationId, param.TaskCode))
                        {
                            result += string.Format("发送失败(任务【{0}】已存在),", param.TaskCode);
                        }
                        else if (actionType == "更新" &&
                                 !TasksContext.Instance.TaskService.IsExistTaskCode(param.ApplicationId, param.TaskCode))
                        {
                            result += string.Format("更新失败(任务【{0}】不存在),", param.TaskCode);
                        }
                        else
                        {
                            param = TasksContext.Instance.TaskService.Save(param);

                            if (param == null)
                            {
                                result += string.Format("任务【{0}】" + actionType + "失败请重新" + actionType + ",", param.TaskCode);
                            }
                        }
                    }
                }

                if (string.IsNullOrEmpty(result))
                {
                    return("任务全部" + actionType + "成功。");
                }
                else
                {
                    return(result.TrimEnd(new char[] { ',' }) + "。");
                }
            }
            catch (Exception ex)
            {
                return(string.Format("SecurityToken:{0}\r\nXml:{1}\r\nException:{2}", securityToken, xml, ex.ToString()));
            }
        }