public override void ForwardNotification(Growl.Connector.Notification notification, Growl.Connector.CallbackContext callbackContext, Growl.Connector.RequestInfo requestInfo, bool isIdle, ForwardedNotificationCallbackHandler callbackFunction) { bool send = true; if (requestInfo == null) { requestInfo = new Growl.Connector.RequestInfo(); } // if a minimum priority is set, check that if (this.MinimumPriority != null && this.MinimumPriority.HasValue && notification.Priority < this.MinimumPriority.Value) { requestInfo.SaveHandlingInfo(String.Format("Forwarding to Prowl ({0}) cancelled - Notification priority must be at least '{1}' (was actually '{2}').", this.Description, this.MinimumPriority.Value.ToString(), notification.Priority.ToString())); send = false; } // if only sending when idle, check that if (send && this.OnlyWhenIdle && !isIdle) { requestInfo.SaveHandlingInfo(String.Format("Forwarding to Prowl ({0}) cancelled - Currently only configured to forward when idle", this.Description)); send = false; } if (send) { requestInfo.SaveHandlingInfo(String.Format("Forwarded to Prowl '{0}' - Minimum Priority:'{1}', Actual Priority:'{2}'", this.Description, (this.MinimumPriority != null && this.MinimumPriority.HasValue ? this.MinimumPriority.Value.ToString() : "<any>"), notification.Priority.ToString())); string text = notification.Text; /* NOT YET * // this appends the url from a url callback to the Prowl message (if specified) * // this allows the user to click the url right from their Prowl app * if (callbackInfo != null && callbackInfo.Context != null) * { * string url = callbackInfo.Context.CallbackUrl; * if (!String.IsNullOrEmpty(url)) * { * text += String.Format(" - {0}", url); * } * } * */ Send(notification.ApplicationName, notification.Title, text, notification.Priority); } }
public virtual void ProcessNotification(DisplayStyle.Notification notification, Growl.Daemon.CallbackInfo cbInfo, Growl.Connector.RequestInfo requestInfo) { try { bool done = this.display.ProcessNotification(notification, this.ActualName); // for any notifications that remain open (essentially, any visual notifications), add them to a list so we // can handle their callbacks later if (!done) { this.notificationsAwaitingCallback.Add(notification.UUID, cbInfo); } } catch (Exception ex) { // suppress any exceptions here (in case the display fails for some reason) Utility.WriteDebugInfo(String.Format("Display failed to process notification: '{0}' - {1}", ex.Message, ex.StackTrace)); } }
public override void ForwardNotification(Growl.Connector.Notification notification, Growl.Connector.CallbackContext callbackContext, Growl.Connector.RequestInfo requestInfo, bool isIdle, ForwardedNotificationCallbackHandler callbackFunction) { bool send = true; if (requestInfo == null) { requestInfo = new Growl.Connector.RequestInfo(); } // if this notification originated from Toasty in the first place, dont re-forward it if (((notification.ApplicationName == "Toasty") && notification.CustomTextAttributes.ContainsKey("ToastyDeviceID")) && notification.CustomTextAttributes["ToastyDeviceID"].Equals(this.DeviceID, StringComparison.InvariantCultureIgnoreCase)) { requestInfo.HandlingInfo.Add(String.Format("Aborted forwarding due to circular notification (deviceID:{0})", this.DeviceID)); send = false; } // if a minimum priority is set, check that if (send && this.MinimumPriority != null && this.MinimumPriority.HasValue && notification.Priority < this.MinimumPriority.Value) { requestInfo.SaveHandlingInfo(String.Format("Forwarding to Toasty ({0}) cancelled - Notification priority must be at least '{1}' (was actually '{2}').", this.Description, this.MinimumPriority.Value.ToString(), notification.Priority.ToString())); send = false; } // if only sending when idle, check that if (send && this.OnlyWhenIdle && !isIdle) { requestInfo.SaveHandlingInfo(String.Format("Forwarding to Toasty ({0}) cancelled - Currently only configured to forward when idle", this.Description)); send = false; } // if quiet hours enabled, check that if (send && DuringQuietHours()) { requestInfo.SaveHandlingInfo(String.Format("Forwarding to Toasty ({0}) cancelled - Quiet hours enabled on {1} from {2} to {3}. Current time: {4} {5}", this.Description, this.QuietHoursDaysChoice, this.QuietHoursStart.ToShortTimeString(), this.QuietHoursEnd.ToShortTimeString(), DateTime.Now.DayOfWeek, DateTime.Now.ToShortTimeString())); send = false; } if (send) { requestInfo.SaveHandlingInfo(String.Format("Forwarded to Toasty '{0}' - Minimum Priority:'{1}', Actual Priority:'{2}'", this.Description, (this.MinimumPriority != null && this.MinimumPriority.HasValue ? this.MinimumPriority.Value.ToString() : "<any>"), notification.Priority.ToString())); string url = BuildUrl(NOTIFY_URL_FORMAT, this.DeviceID); System.Collections.Specialized.NameValueCollection data = new System.Collections.Specialized.NameValueCollection(); data.Add("target", this.DeviceID); data.Add("sender", notification.ApplicationName); data.Add("title", notification.Title); data.Add("text", notification.Text); byte[] bytes = null; if (notification.Icon != null && notification.Icon.IsSet) { System.Drawing.Image image = (System.Drawing.Image)notification.Icon; using (image) { bytes = GenerateThumbnail(image, 128, 128); } } APIRequestInfo info = new APIRequestInfo(); info.RequestInfo = requestInfo; info.Url = url; info.Data = data; info.ImageBytes = bytes; System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(SendAsync), info); } }
public override void ForwardRegistration(Growl.Connector.Application application, List <Growl.Connector.NotificationType> notificationTypes, Growl.Connector.RequestInfo requestInfo, bool isIdle) { // IGNORE REGISTRATION NOTIFICATIONS (since we have no way of filtering out already-registered apps at this point) //Send(application.Name, Properties.Resources.SystemNotification_AppRegistered_Title, String.Format(Properties.Resources.SystemNotification_AppRegistered_Text, application.Name)); requestInfo.SaveHandlingInfo("Forwarding to Toasty cancelled - Application Registrations are not forwarded."); }
public override void ForwardNotification(Growl.Connector.Notification notification, Growl.Connector.CallbackContext callbackContext, Growl.Connector.RequestInfo requestInfo, bool isIdle, ForwardedNotificationCallbackHandler callbackFunction) { Growl.UDPLegacy.NotificationType nt = new Growl.UDPLegacy.NotificationType(notification.Name, true); Growl.UDPLegacy.MessageSender netgrowl = new Growl.UDPLegacy.MessageSender(this.IPAddress, this.Port, notification.ApplicationName, this.Password); netgrowl.Notify(nt, notification.Title, notification.Text, notification.Priority, notification.Sticky); }
public override void ForwardRegistration(Growl.Connector.Application application, List <Growl.Connector.NotificationType> notificationTypes, Growl.Connector.RequestInfo requestInfo, bool isIdle) { Growl.UDPLegacy.NotificationType[] types = new Growl.UDPLegacy.NotificationType[notificationTypes.Count]; for (int i = 0; i < notificationTypes.Count; i++) { Growl.Connector.NotificationType notificationType = notificationTypes[i]; Growl.UDPLegacy.NotificationType nt = new Growl.UDPLegacy.NotificationType(notificationType.Name, notificationType.Enabled); types[i] = nt; } Growl.UDPLegacy.MessageSender netgrowl = new Growl.UDPLegacy.MessageSender(this.IPAddress, this.Port, application.Name, this.Password); netgrowl.Register(ref types); }
internal void SendSystemNotification(string title, string text, Display display) { Growl.Connector.RequestInfo requestInfo = new Growl.Connector.RequestInfo(); // this is not used, but needed as a placeholder DisplayStyle.Notification n = new Growl.DisplayStyle.Notification(); n.UUID = requestInfo.RequestID; n.ApplicationName = Properties.Resources.SystemNotification_ApplicationName; n.Description = text; n.Name = "Growl System Message"; n.Priority = (int)Growl.Connector.Priority.Normal; n.Sticky = false; // system notifications are never sticky n.Title = title; n.Image = Growl.FormResources.growl; ShowNotification(n, display, null, false, requestInfo); }
/// <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)); } }
public List<string> ProcessNotification(Growl.UDPLegacy.NotificationPacket np, string receivedFrom) { /* THIS METHOD RESENDS THE UDP MESSAGE AS A LOCAL GNTP MESSAGE Growl.Connector.Application application = new Growl.Connector.Application(np.ApplicationName); Growl.Connector.Notification notification = new Growl.Connector.Notification(np.ApplicationName, np.NotificationType.Name, String.Empty, np.Title, np.Description, null, np.Sticky, np.Priority, null); Growl.Connector.GrowlConnector udpToGNTPForwarder = new Growl.Connector.GrowlConnector(); udpToGNTPForwarder.Password = np.Password; udpToGNTPForwarder.EncryptionAlgorithm = Growl.Connector.Cryptography.SymmetricAlgorithmType.PlainText; udpToGNTPForwarder.Notify(application, notification); * */ /* THIS METHOD AVOIDS SENDING ANOTHER MESSAGE, BUT TRADES THE DETAILED GNTP LOGGING */ Growl.Connector.Notification notification = new Growl.Connector.Notification(np.ApplicationName, np.NotificationType.Name, String.Empty, np.Title, np.Description, null, np.Sticky, np.Priority, null); Growl.Connector.RequestInfo requestInfo = new Growl.Connector.RequestInfo(); gntpListener_NotifyReceived(notification, null, requestInfo); List<string> extraLogInfo = (requestInfo != null ? requestInfo.HandlingInfo : null); return extraLogInfo; }
public override void ForwardNotification(Growl.Connector.Notification notification, Growl.Connector.CallbackContext callbackContext, Growl.Connector.RequestInfo requestInfo, bool isIdle, ForwardedNotificationCallbackHandler callbackFunction) { bool send = true; // if a minimum priority is set, check that if (this.MinimumPriority != null && this.MinimumPriority.HasValue && notification.Priority < this.MinimumPriority.Value) { requestInfo.SaveHandlingInfo(String.Format("Forwarding to Twitter ({0}) cancelled - Notification priority must be at least '{1}' (was actually '{2}').", this.Username, this.MinimumPriority.Value.ToString(), notification.Priority.ToString())); send = false; } // if only sending when idle, check that if (this.OnlyWhenIdle && !isIdle) { requestInfo.SaveHandlingInfo(String.Format("Forwarding to Twitter ({0}) cancelled - Currently only configured to forward when idle", this.Username)); send = false; } if (send) { requestInfo.SaveHandlingInfo(String.Format("Forwarded to Twitter '{0}' - Minimum Priority:'{1}', Actual Priority:'{2}'", this.Description, (this.MinimumPriority != null && this.MinimumPriority.HasValue ? this.MinimumPriority.Value.ToString() : "<any>"), notification.Priority.ToString())); string message = this.format; message = message.Replace(PLACEHOLDER_APPNAME, notification.ApplicationName); message = message.Replace(PLACEHOLDER_TITLE, notification.Title); message = message.Replace(PLACEHOLDER_TEXT, notification.Text); message = message.Replace(PLACEHOLDER_PRIORITY, PrefPriority.GetFriendlyName(notification.Priority)); message = message.Replace(PLACEHOLDER_SENDER, notification.MachineName); //Utility.WriteLine(message); // trim if (message.Length > 140) { message = message.Substring(0, 140); } //byte[] bytes = System.Text.Encoding.UTF8.GetBytes("status=" + message); string data = "status=" + message; // send async (using threads instead of async WebClient/HttpWebRequest methods since they seem to have a bug with KeepAlives in infrequent cases) System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(SendAsync), data); } }
public override void ForwardRegistration(Growl.Connector.Application application, List <Growl.Connector.NotificationType> notificationTypes, Growl.Connector.RequestInfo requestInfo, bool isIdle) { // IGNORE REGISTRATION NOTIFICATIONS requestInfo.SaveHandlingInfo("Forwarding to Twitter cancelled - Application Registrations are not forwarded."); }
public override void ForwardNotification(Growl.Connector.Notification notification, Growl.Connector.CallbackContext callbackContext, Growl.Connector.RequestInfo requestInfo, bool isIdle, ForwardedNotificationCallbackHandler callbackFunction) { bool send = true; // if a minimum priority is set, check that if (this.MinimumPriority != null && this.MinimumPriority.HasValue && notification.Priority < this.MinimumPriority.Value) { requestInfo.SaveHandlingInfo(String.Format("Forwarding to Email ({0}) cancelled - Notification priority must be at least '{1}' (was actually '{2}').", this.Description, this.MinimumPriority.Value.ToString(), notification.Priority.ToString())); send = false; } // if only sending when idle, check that if (this.OnlyWhenIdle && !isIdle) { requestInfo.SaveHandlingInfo(String.Format("Forwarding to Email ({0}) cancelled - Currently only configured to forward when idle", this.Description)); send = false; } if (send) { requestInfo.SaveHandlingInfo(String.Format("Forwarded to Email '{0}' - Minimum Priority:'{1}', Actual Priority:'{2}'", this.Description, (this.MinimumPriority != null && this.MinimumPriority.HasValue ? this.MinimumPriority.Value.ToString() : "<any>"), notification.Priority.ToString())); string format = "Application: {0}\r\n\r\n{1}\r\n\r\n{2}\r\n\r\nSent From: {3} - {4}"; string message = String.Format(format, notification.ApplicationName, notification.Title, notification.Text, notification.MachineName, DateTime.Now.ToString()); Send(notification.ApplicationName, notification.Title, notification.Priority, message); } }
public override void ForwardNotification(Growl.Connector.Notification notification, Growl.Connector.CallbackContext callbackContext, Growl.Connector.RequestInfo requestInfo, bool isIdle, ForwardedNotificationCallbackHandler callbackFunction) { bool send = true; if (requestInfo == null) requestInfo = new Growl.Connector.RequestInfo(); // if a minimum priority is set, check that if (this.MinimumPriority != null && this.MinimumPriority.HasValue && notification.Priority < this.MinimumPriority.Value) { requestInfo.SaveHandlingInfo(String.Format("Forwarding to Prowl ({0}) cancelled - Notification priority must be at least '{1}' (was actually '{2}').", this.Description, this.MinimumPriority.Value.ToString(), notification.Priority.ToString())); send = false; } // if only sending when idle, check that if (send && this.OnlyWhenIdle && !isIdle) { requestInfo.SaveHandlingInfo(String.Format("Forwarding to Prowl ({0}) cancelled - Currently only configured to forward when idle", this.Description)); send = false; } if (send) { requestInfo.SaveHandlingInfo(String.Format("Forwarded to Prowl '{0}' - Minimum Priority:'{1}', Actual Priority:'{2}'", this.Description, (this.MinimumPriority != null && this.MinimumPriority.HasValue ? this.MinimumPriority.Value.ToString() : "<any>"), notification.Priority.ToString())); string text = notification.Text; /* NOT YET // this appends the url from a url callback to the Prowl message (if specified) // this allows the user to click the url right from their Prowl app if (callbackInfo != null && callbackInfo.Context != null) { string url = callbackInfo.Context.CallbackUrl; if (!String.IsNullOrEmpty(url)) { text += String.Format(" - {0}", url); } } * */ Send(notification.ApplicationName, notification.Title, text, notification.Priority); } }
public override void ProcessNotification(Growl.DisplayStyle.Notification notification, Growl.Daemon.CallbackInfo cbInfo, Growl.Connector.RequestInfo requestInfo) { this.realDisplay.ProcessNotification(notification, cbInfo, requestInfo); }
public List<string> ProcessRegistration(Growl.UDPLegacy.RegistrationPacket rp, string receivedFrom) { /* THIS METHOD RESENDS THE UDP MESSAGE AS A LOCAL GNTP MESSAGE Growl.Connector.Application application = new Growl.Connector.Application(rp.ApplicationName); List<Growl.Connector.NotificationType> notificationTypes = new List<Growl.Connector.NotificationType>(); foreach (Growl.UDPLegacy.NotificationType nt in rp.NotificationTypes) { Growl.Connector.NotificationType notificationType = new Growl.Connector.NotificationType(nt.Name, nt.Name, null, nt.Enabled); notificationTypes.Add(notificationType); } Growl.Connector.GrowlConnector udpToGNTPForwarder = new Growl.Connector.GrowlConnector(); udpToGNTPForwarder.Password = rp.Password; udpToGNTPForwarder.EncryptionAlgorithm = Growl.Connector.Cryptography.SymmetricAlgorithmType.PlainText; udpToGNTPForwarder.Register(application, notificationTypes.ToArray()); * */ /* THIS METHOD AVOIDS SENDING ANOTHER MESSAGE, BUT TRADES THE DETAILED GNTP LOGGING */ Growl.Connector.Application application = new Growl.Connector.Application(rp.ApplicationName); List<Growl.Connector.NotificationType> notificationTypes = new List<Growl.Connector.NotificationType>(); foreach (Growl.UDPLegacy.NotificationType nt in rp.NotificationTypes) { Growl.Connector.NotificationType notificationType = new Growl.Connector.NotificationType(nt.Name, nt.Name, null, nt.Enabled); notificationTypes.Add(notificationType); } Growl.Connector.RequestInfo requestInfo = new Growl.Connector.RequestInfo(); gntpListener_RegisterReceived(application, notificationTypes, requestInfo); List<string> extraLogInfo = (requestInfo != null ? requestInfo.HandlingInfo : null); return extraLogInfo; }
public override void ForwardNotification(Growl.Connector.Notification notification, Growl.Connector.CallbackContext callbackContext, Growl.Connector.RequestInfo requestInfo, bool isIdle, ForwardedNotificationCallbackHandler callbackFunction) { bool send = true; if (requestInfo == null) requestInfo = new Growl.Connector.RequestInfo(); // if this notification originated from Toasty in the first place, dont re-forward it if (((notification.ApplicationName == "Toasty") && notification.CustomTextAttributes.ContainsKey("ToastyDeviceID")) && notification.CustomTextAttributes["ToastyDeviceID"].Equals(this.DeviceID, StringComparison.InvariantCultureIgnoreCase)) { requestInfo.HandlingInfo.Add(String.Format("Aborted forwarding due to circular notification (deviceID:{0})", this.DeviceID)); send = false; } // if a minimum priority is set, check that if (send && this.MinimumPriority != null && this.MinimumPriority.HasValue && notification.Priority < this.MinimumPriority.Value) { requestInfo.SaveHandlingInfo(String.Format("Forwarding to Toasty ({0}) cancelled - Notification priority must be at least '{1}' (was actually '{2}').", this.Description, this.MinimumPriority.Value.ToString(), notification.Priority.ToString())); send = false; } // if only sending when idle, check that if (send && this.OnlyWhenIdle && !isIdle) { requestInfo.SaveHandlingInfo(String.Format("Forwarding to Toasty ({0}) cancelled - Currently only configured to forward when idle", this.Description)); send = false; } // if quiet hours enabled, check that if (send && DuringQuietHours()) { requestInfo.SaveHandlingInfo(String.Format("Forwarding to Toasty ({0}) cancelled - Quiet hours enabled on {1} from {2} to {3}. Current time: {4} {5}", this.Description, this.QuietHoursDaysChoice, this.QuietHoursStart.ToShortTimeString(), this.QuietHoursEnd.ToShortTimeString(), DateTime.Now.DayOfWeek, DateTime.Now.ToShortTimeString())); send = false; } if (send) { requestInfo.SaveHandlingInfo(String.Format("Forwarded to Toasty '{0}' - Minimum Priority:'{1}', Actual Priority:'{2}'", this.Description, (this.MinimumPriority != null && this.MinimumPriority.HasValue ? this.MinimumPriority.Value.ToString() : "<any>"), notification.Priority.ToString())); string url = BuildUrl(NOTIFY_URL_FORMAT, this.DeviceID); System.Collections.Specialized.NameValueCollection data = new System.Collections.Specialized.NameValueCollection(); data.Add("target", this.DeviceID); data.Add("sender", notification.ApplicationName); data.Add("title", notification.Title); data.Add("text", notification.Text); byte[] bytes = null; if (notification.Icon != null && notification.Icon.IsSet) { System.Drawing.Image image = (System.Drawing.Image)notification.Icon; using (image) { bytes = GenerateThumbnail(image, 128, 128); } } APIRequestInfo info = new APIRequestInfo(); info.RequestInfo = requestInfo; info.Url = url; info.Data = data; info.ImageBytes = bytes; System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(SendAsync), info); } }
/// <summary> /// Called when an application registration is received by GfW. /// </summary> /// <param name="application">The application.</param> /// <param name="notificationTypes">The notification types.</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> /// <remarks> /// Many types of forwarders can just ignore this event. /// </remarks> public override void ForwardRegistration(Growl.Connector.Application application, List <Growl.Connector.NotificationType> notificationTypes, Growl.Connector.RequestInfo requestInfo, bool isIdle) { // do nothing }