コード例 #1
0
        /// <summary>
        /// http://www.23card.net
        /// </summary>
        private static void ProcessNotify()
        {
            TimeSpan tsTimeout = TimeSpan.FromSeconds(Convert.ToDouble(NotifyTransactionTimeout * NotifybatchSize));

            for (int j = 0; j < NotifybatchSize; j++)
            {
                try
                {
                    var apiNotify = new APINotification();

                    OrderCardInfo order = apiNotify.ReceiveFromQueue(NotifyqueueTimeout);
                    if (order != null)
                    {
                        order.notifycount = 0;
                        var notifyInfo = new OrderCardNotify {
                            orderInfo = order
                        };


                        var tmr = new Timer(apiNotify.NotifyCheckStatus, notifyInfo, 0, 1000);
                        notifyInfo.tmr = tmr;
                    }
                    else
                    {
                        break;
                    }
                }
                catch (Exception exception)
                {
                    ExceptionHandler.HandleException(exception);
                }
            }
        }
コード例 #2
0
        public void StartTask(OrderCardNotify info)
        {
            Thread threadHand1 = new Thread(() => Process(info));

            threadHand1.IsBackground = true;
            threadHand1.SetApartmentState(ApartmentState.STA);

            threadHand1.Start();
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="info"></param>
        private void Process(OrderCardNotify info)
        {
            try
            {
                string notifyUrl = info.NotifyUrl;

                if (string.IsNullOrEmpty(notifyUrl))
                {
                    return;
                }

                string callback   = string.Empty;
                string status     = string.Empty;
                string message    = string.Empty;
                string statusCode = string.Empty;
                string statusDesc = string.Empty;

                bool isOk = false;

                try
                {
                    callback = viviLib.Web.WebClientHelper.GetString(notifyUrl
                                                                     , string.Empty
                                                                     , "GET"
                                                                     , Encoding.GetEncoding("GB2312")
                                                                     , 1 * 60 * 1000);

                    isOk = Utility.CheckCallBackIsSuccess(info.orderInfo.version, callback);
                }
                catch (WebException e)
                {
                    message = e.Message;
                    status  = e.Status.ToString();

                    if (e.Status == WebExceptionStatus.ProtocolError)
                    {
                        statusCode = ((HttpWebResponse)e.Response).StatusCode.ToString();
                        statusDesc = ((HttpWebResponse)e.Response).StatusDescription;
                    }
                }
                catch (Exception e)
                {
                    message = e.Message;
                }

                int notifystat = isOk ? 2 : 4;

                var notifyInfo = new Model.Order.Card.CardNotify()
                {
                    orderid           = info.orderInfo.orderid,
                    status            = status,
                    message           = message,
                    httpStatusCode    = statusCode,
                    StatusDescription = statusDesc,
                    againNotifyUrl    = notifyUrl,
                    notifystat        = notifystat,
                    notifycontext     = callback,
                    notifytime        = DateTime.Now
                };

                CardNotify.Instance.Insert(notifyInfo);

                if (isOk)
                {
                    if (info.tmr != null)
                    {
                        info.tmr.Dispose();
                        info.tmr = null;
                    }
                }
            }
            catch (Exception exception)
            {
                ExceptionHandler.HandleException(exception);
            }
        }