Пример #1
0
        protected void HandleForwarding(Growl.Connector.Notification notification, Growl.Daemon.CallbackInfo callbackInfo, Growl.Connector.RequestInfo requestInfo, List<string> limitToTheseComputers)
        {
            bool limit = (limitToTheseComputers != null);
            foreach (ForwardDestination fc in this.forwards.Values)
            {
                if ((!limit || limitToTheseComputers.Contains(fc.Key)) && (fc.EnabledAndAvailable))
                {
                    try
                    {
                        Growl.Connector.CallbackContext context = null;
                        ForwardDestination.ForwardedNotificationCallbackHandler callback = null;
                        if (callbackInfo != null)
                        {
                            context = callbackInfo.Context;
                            callbackInfo.ForwardedNotificationCallback += new Growl.Daemon.CallbackInfo.ForwardedNotificationCallbackHandler(growl_ForwardedNotificationCallback);
                            callback = new ForwardDestination.ForwardedNotificationCallbackHandler(callbackInfo.HandleCallbackFromForwarder);
                        }

                        requestInfo.SaveHandlingInfo(String.Format("Forwarding to {0} ({1})", fc.Description, fc.AddressDisplay));
                        fc.ForwardNotification(notification, context, requestInfo, this.activityMonitor.IsIdle, callback);
                    }
                    catch
                    {
                        // swallow any exceptions and move on to the next forwarded computer in the list
                        // this way, if one computer configuration is bad (invalid port or whatever), the rest are not affected
                    }
                }
                else
                {
                    requestInfo.SaveHandlingInfo(String.Format("Not forwarded to {0} ({1}) - ({2})", fc.Description, fc.AddressDisplay, (limit ? "disallowed by preferences" : (fc.Enabled ? "offline" : "disabled"))));
                }
            }
        }
Пример #2
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));
            }
        }