Beispiel #1
0
        /// <summary>
        /// Called when a notification is received by GfW.
        /// </summary>
        /// <param name="notification">The notification information</param>
        /// <param name="callbackContext">The callback context.</param>
        /// <param name="requestInfo">The request info.</param>
        /// <param name="isIdle"><c>true</c> if the user is currently idle;<c>false</c> otherwise</param>
        /// <param name="callbackFunction">The function GfW will run if this notification is responded to on the forwarded computer</param>
        /// <remarks>
        /// Unless your forwarder is going to handle socket-style callbacks from the remote computer, you should ignore
        /// the <paramref name="callbackFunction"/> parameter.
        /// </remarks>
        public override void ForwardNotification(Growl.Connector.Notification notification, Growl.Connector.CallbackContext callbackContext, Growl.Connector.RequestInfo requestInfo, bool isIdle, ForwardDestination.ForwardedNotificationCallbackHandler callbackFunction)
        {
            try
            {
                QuerystringBuilder qsb = new QuerystringBuilder();
                qsb.Add("app", notification.ApplicationName);
                qsb.Add("id", notification.ID);
                qsb.Add("type", notification.Name);
                qsb.Add("title", notification.Title);
                qsb.Add("text", notification.Text);
                qsb.Add("sticky", notification.Sticky);
                qsb.Add("priority", (int)notification.Priority);
                qsb.Add("coalescingid", notification.CoalescingID);
                if (notification.CustomTextAttributes != null)
                {
                    foreach (KeyValuePair <string, string> item in notification.CustomTextAttributes)
                    {
                        qsb.Add(item.Key, item.Value);
                    }
                }

                string data = qsb.ToPostData();
                Growl.CoreLibrary.WebClientEx wc = new Growl.CoreLibrary.WebClientEx();
                using (wc)
                {
                    wc.Headers.Add(HttpRequestHeader.UserAgent, "Growl for Windows Webhook Plugin/1.0");
                    string result = wc.UploadString(this.url, data);
                    Console.WriteLine(result);
                }
            }
            catch (Exception ex)
            {
                // this is an example of writing to the main GfW debug log:
                Growl.CoreLibrary.DebugInfo.WriteLine(String.Format("Webhook forwarding failed: {0}", ex.Message));
            }
        }
        /// <summary>
        /// Called when a notification is received by GfW.
        /// </summary>
        /// <param name="notification">The notification information</param>
        /// <param name="callbackContext">The callback context.</param>
        /// <param name="requestInfo">The request info.</param>
        /// <param name="isIdle"><c>true</c> if the user is currently idle;<c>false</c> otherwise</param>
        /// <param name="callbackFunction">The function GfW will run if this notification is responded to on the forwarded computer</param>
        /// <remarks>
        /// Unless your forwarder is going to handle socket-style callbacks from the remote computer, you should ignore
        /// the <paramref name="callbackFunction"/> parameter.
        /// </remarks>
        public override void ForwardNotification(Growl.Connector.Notification notification, Growl.Connector.CallbackContext callbackContext, Growl.Connector.RequestInfo requestInfo, bool isIdle, ForwardDestination.ForwardedNotificationCallbackHandler callbackFunction)
        {
            try
            {
                QuerystringBuilder qsb = new QuerystringBuilder();
                qsb.Add("app", notification.ApplicationName);
                qsb.Add("id", notification.ID);
                qsb.Add("type", notification.Name);
                qsb.Add("title", notification.Title);
                qsb.Add("text", notification.Text);
                qsb.Add("sticky", notification.Sticky);
                qsb.Add("priority", (int)notification.Priority);
                qsb.Add("coalescingid", notification.CoalescingID);
                if (notification.CustomTextAttributes != null)
                {
                    foreach (KeyValuePair<string, string> item in notification.CustomTextAttributes)
                    {
                        qsb.Add(item.Key, item.Value);
                    }
                }

                string data = qsb.ToPostData();
                Growl.CoreLibrary.WebClientEx wc = new Growl.CoreLibrary.WebClientEx();
                using (wc)
                {
                    wc.Headers.Add(HttpRequestHeader.UserAgent, "Growl for Windows Webhook Plugin/1.0");
                    string result = wc.UploadString(this.url, data);
                    Console.WriteLine(result);
                }
            }
            catch (Exception ex)
            {
                // this is an example of writing to the main GfW debug log:
                Growl.CoreLibrary.DebugInfo.WriteLine(String.Format("Webhook forwarding failed: {0}", ex.Message));
            }
        }