Ejemplo n.º 1
0
        // 从 dp2mserver 获得消息
        // 每次最多获得 100 条
        List <MessageRecord> GetMessage()
        {
            string            strError     = "";
            CancellationToken cancel_token = new CancellationToken();

            string            id      = Guid.NewGuid().ToString();
            GetMessageRequest request = new GetMessageRequest(id,
                                                              "",
                                                              this.GroupName, // "" 表示默认群组
                                                              "",
                                                              "",             // strTimeRange,
                                                              "",             // sort
                                                              "",             //id
                                                              "",             // subject
                                                              0,
                                                              100);

            try
            {
                MessageConnection connection = this.Channels.GetConnectionTaskAsync(
                    this.Url,
                    "").Result;
#if NO
                GetMessageResult result = connection.GetMessage(
                    request,
                    new TimeSpan(0, 1, 0),
                    cancel_token).Result;
#endif
                GetMessageResult result = connection.GetMessage(
                    request,
                    new TimeSpan(0, 1, 0),
                    cancel_token);

                if (result.Value == -1)
                {
                    goto ERROR1;
                }
                return(result.Results);
            }
            catch (AggregateException ex)
            {
                strError = MessageConnection.GetExceptionText(ex);
                goto ERROR1;
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                goto ERROR1;
            }
ERROR1:
            WriteErrorLog("GetMessage() error: " + strError);
            return(new List <MessageRecord>());
        }
Ejemplo n.º 2
0
        // 从 dp2mserver 获得消息
        // 每次最多获得 100 条
        List <MessageRecord> GetMessage()
        {
            string            strError     = "";
            CancellationToken cancel_token = new CancellationToken();

            string            subjectCondition = "";
            string            id      = Guid.NewGuid().ToString();
            GetMessageRequest request = new GetMessageRequest(id,
                                                              "",
                                                              this.GroupName,    // "" 表示默认群组
                                                              "",
                                                              "",                // strTimeRange,
                                                              "publishTime|asc", //sortCondition 按发布时间正序排
                                                              "",
                                                              subjectCondition,
                                                              0,
                                                              100);

            try
            {
                MessageConnection connection = this.Channels.GetConnectionTaskAsync(
                    this.Url,
                    dp2WeiXinService.C_ConnName_TraceMessage).Result;
                GetMessageResult result = connection.GetMessage(request,
                                                                new TimeSpan(0, 1, 0),
                                                                cancel_token);
                if (result.Value == -1)
                {
                    goto ERROR1;
                }
                return(result.Results);
            }
            catch (AggregateException ex)
            {
                strError = MessageConnection.GetExceptionText(ex);
                goto ERROR1;
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                goto ERROR1;
            }

ERROR1:
            dp2WeiXinService.Instance.WriteErrorLog("GetMessage() error: " + strError);
            //this.WriteLog("GetMessage() error: " + strError,dp2WeiXinService.C_LogLevel_1);
            return(new List <MessageRecord>());
        }