Inheritance: System.EventArgs
Esempio n. 1
0
 /// <summary>
 /// Occurs when LongPoll server received some data
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnReceivedData(LongPollServerEventArgs e)
 {
     if (this.ReceivedData != null)
     {
         this.ReceivedData(this, e);
     }
 }
Esempio n. 2
0
        private void run(object state)
        {
            //try
            {
                SynchronizationContext context = state as SynchronizationContext;
                context.Send(this.doGetLongPollServerConnectionData, null);
                context.Send(this.doGetSendRequest, null);
                while (!this.stopPending)
                {
                    this.lastLongPollMessage = ApiRequest.Send("http://" + this.Server + "?act=a_check&key=" + this.Key + "&ts=" + this.LastEventId.ToString() + "&wait=" + this.WaitTime.ToString());
                    if (this.lastLongPollMessage == "")
                    {
                        continue;
                    }
                    // {"ts":727820493,"updates":[[8,-696076,0]]}
                    if (new Regex("\\\"?failed\\\"?\\s*?\\:\\s*?\\d+").Match(this.lastLongPollMessage).Success)
                    {
                        Console.WriteLine(this.lastLongPollMessage);
                        context.Send(this.doGetLongPollServerConnectionData, null);
                    }
                    else
                    {
                        this.LastEventId = Convert.ToInt32(new Regex("\\{[\\s]*?\\\"ts\\\"[\\s]*?\\:[\\s]*?(\\d+)[\\s]*?").Match(this.lastLongPollMessage).Groups[1].Value);
                        if (this.lastLongPollMessage != "" && this.lastLongPollMessage != null)
                        {
                            if (!new Regex("\\\"updates\\\"\\:\\[\\]").Match(this.lastLongPollMessage).Success)
                            {
                                this.longPollMessages.Add(this.lastLongPollMessage);
                                LongPollServerEventArgs args = new LongPollServerEventArgs();
                                args.LastEventId     = this.LastEventId;
                                args.EventSourceCode = this.lastLongPollMessage;

                                context.Post(this.doOnDataReceived, args);
                            }
                        }
                    }
                }
            }
            //catch
            //{ }
            //finally
            {
            }
        }
        private void run(object state)
        {
            try
            {
                SynchronizationContext context = state as SynchronizationContext;
                context.Send(this.doGetLongPollServerConnectionData, null);
                context.Send(this.doGetSendRequest, null);
                if (this.request == null)
                {
                    this.request = new ApiRequest();
                    this.request.Timeout = this.WaitTime;
                }
                while (!this.stopPending)
                {
                    this.lastLongPollMessage = this.request.Send("http://" + this.Server + "?act=a_check&key=" + this.Key + "&ts=" + this.LastEventId.ToString() + "&wait=" + this.WaitTime.ToString() + "&mode=0");
                    if (this.lastLongPollMessage == "")
                    {
                        continue;
                    }
                    // {"ts":727820493,"updates":[[8,-696076,0]]}
                    if (new Regex("\\\"?failed\\\"?\\s*?\\:\\s*?\\d+").Match(this.lastLongPollMessage).Success)
                    {
                        Console.WriteLine(this.lastLongPollMessage);
                        context.Send(this.doGetLongPollServerConnectionData, null);

                    }
                    else
                    {
                        this.LastEventId = Convert.ToInt32(new Regex("\\{[\\s]*?\\\"ts\\\"[\\s]*?\\:[\\s]*?(\\d+)[\\s]*?").Match(this.lastLongPollMessage).Groups[1].Value);
                        if (this.lastLongPollMessage != "" && this.lastLongPollMessage != null)
                        {
                            if (!new Regex("\\\"updates\\\"\\:\\[\\]").Match(this.lastLongPollMessage).Success)
                            {
                                this.longPollMessages.Add(this.lastLongPollMessage);
                                LongPollServerEventArgs args = new LongPollServerEventArgs();
                                args.LastEventId = this.LastEventId;
                                args.EventSourceCode = this.lastLongPollMessage;

                                context.Post(this.doOnDataReceived, args);
                            }
                        }

                    }
                }
            }
            catch(System.Net.WebException e)
            {
                switch (e.Status)
                {
                    case System.Net.WebExceptionStatus.Timeout:
                        {
                            if (!this.stopPending)
                            {
                                this.run(state);
                            }
                            break;
                        }
                }
            }
            //finally
            {
            }
        }
 /// <summary>
 /// Occurs when LongPoll server received some data
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnReceivedData(LongPollServerEventArgs e)
 {
     if (this.ReceivedData != null)
     {
         this.ReceivedData(this, e);
     }
 }