private void HandleNotification(object state)
        {
            try
            {
                string response = (string)state;
                Utility.WriteDebugInfo(response);

                if (String.IsNullOrEmpty(response))
                {
                    return;                                  // empty response
                }
                int index = response.IndexOf("\r\n");
                if (index < 1)
                {
                    return;                                  // malformed response - missing \r\n
                }
                string l = response.Substring(0, index);
                if (String.IsNullOrEmpty(l))
                {
                    return;                                  // malformed response - no length specifier
                }
                int  length = 0;
                bool ok     = int.TryParse(l, System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture.NumberFormat, out length);
                if (!ok)
                {
                    return;             // malformed response - invalid length specifier
                }
                int start = index + 1;  // index plus one to account for \n
                int total = start + length;
                if (start >= response.Length)
                {
                    return;                                  // missing notification data
                }
                if (total > response.Length)
                {
                    return;                                  // truncated notification data
                }
                // ok - if we are here, we are good to go
                string json = response.Substring(start, length);

                /* DONT USE THIS - we cant control the JsonSerializer so we cant set the MissingMemberHandling property
                 * object obj = Newtonsoft.Json.JavaScriptConvert.DeserializeObject(json, typeof(NotificationReceivedEventArgs));
                 * NotificationReceivedEventArgs args = (NotificationReceivedEventArgs)obj;
                 * */

                System.IO.StringReader sr = new System.IO.StringReader(json);
                using (sr)
                {
                    Newtonsoft.Json.JsonSerializer js = new Newtonsoft.Json.JsonSerializer();
                    js.MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore;
                    js.NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore;
                    NotificationReceivedEventArgs args = (NotificationReceivedEventArgs)js.Deserialize(sr, typeof(NotificationReceivedEventArgs));
                    this.OnNotificationReceived(args);
                }
            }
            catch
            {
                // dont fail if the notification could not be handled properly
            }
        }
示例#2
0
        protected void OnNotificationReceived(NotificationReceivedEventArgs nrea)
        {
            if (this.NotificationReceived == null)
            {
                return;
            }

            if (this.synchronizingObject != null && this.synchronizingObject.InvokeRequired)
            {
                this.synchronizingObject.Invoke(new MethodInvoker(() => this.OnNotificationReceived(nrea)), null);
            }
            else
            {
                this.NotificationReceived(this, nrea);
            }
        }
 protected void OnNotificationReceived(NotificationReceivedEventArgs nrea)
 {
     if (this.NotificationReceived != null)
     {
         if (this.synchronizingObject != null && this.synchronizingObject.InvokeRequired)
         {
             this.synchronizingObject.Invoke(new MethodInvoker(delegate()
             {
                 OnNotificationReceived(nrea);
             }), null);
         }
         else
         {
             this.NotificationReceived(this, nrea);
         }
     }
 }
 protected void OnNotificationReceived(NotificationReceivedEventArgs nrea)
 {
     if (this.NotificationReceived != null)
     {
         if (this.synchronizingObject != null && this.synchronizingObject.InvokeRequired)
         {
             this.synchronizingObject.Invoke(new MethodInvoker(delegate()
             {
                 OnNotificationReceived(nrea);
             }), null);
         }
         else
         {
             this.NotificationReceived(this, nrea);
         }
     }
 }
示例#5
0
 private void OnNotificationReceived(Growl.DisplayStyle.Notification n)
 {
     if (this.synchronizingObject != null && this.synchronizingObject.InvokeRequired)
     {
         MethodInvoker invoker = new MethodInvoker(delegate()
         {
             OnNotificationReceived(n);
         });
         this.synchronizingObject.Invoke(invoker, null);
     }
     else
     {
         if (this.NotificationReceived != null)
         {
             NotificationReceivedEventArgs args = new NotificationReceivedEventArgs(n);
             this.NotificationReceived(this, args);
         }
     }
 }