/// <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(Notification notification, CallbackContext callbackContext, RequestInfo requestInfo, bool isIdle, ForwardedNotificationCallbackHandler callbackFunction) { try { Image img = null; var tempFile = ""; try { var iconType = IconType.ICON_NONE; img = GetImage(notification); if (img != null) { tempFile = Path.GetTempFileName(); iconType = IconType.ICON_PNG; img.Save(tempFile, ImageFormat.Png); } EventClient eventClient = new EventClient(); if (!eventClient.Connect(Server)) { Growl.CoreLibrary.DebugInfo.WriteLine("Could not connect to XBMC server at " + Server); return; } if ( !eventClient.SendNotification(ToSingleLine(notification.Title), ToSingleLine(notification.Text), iconType, tempFile)) { Growl.CoreLibrary.DebugInfo.WriteLine("Error sending notification"); } eventClient.Disconnect(); } finally { if (img != null) { img.Dispose(); } Delete(tempFile); } } catch (Exception ex) { Growl.CoreLibrary.DebugInfo.WriteLine("XBMC forwarding failed: " + ex.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 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 ForwardNotification(Growl.Connector.Notification notification, Growl.Connector.CallbackContext callbackContext, Growl.Connector.RequestInfo requestInfo, bool isIdle, ForwardedNotificationCallbackHandler callbackFunction) { Forwarder growl = new Forwarder(this.Password, this.IPAddress, this.Port, requestInfo); growl.KeyHashAlgorithm = this.HashAlgorithm; growl.EncryptionAlgorithm = this.EncryptionAlgorithm; #if DEBUG //growl.EncryptionAlgorithm = Cryptography.SymmetricAlgorithmType.PlainText; #endif growl.ForwardedNotificationCallback += callbackFunction; growl.Notify(notification, callbackContext); }
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 ForwardNotification( Notification notification, CallbackContext callbackContext, RequestInfo requestInfo, bool isIdle, ForwardedNotificationCallbackHandler callbackFunction ) { //notify.ShowBalloonTip ( 4000, notification.Title, notification.Text, ToolTipIcon.Info ); }
public override void ForwardNotification(Growl.Connector.Notification notification, Growl.Connector.CallbackContext callbackContext, Growl.Connector.RequestInfo requestInfo, bool isIdle, ForwardedNotificationCallbackHandler callbackFunction) { Forwarder growl = new Forwarder(this.Password, this.IPAddress, this.Port, requestInfo); growl.KeyHashAlgorithm = this.HashAlgorithm; growl.EncryptionAlgorithm = this.EncryptionAlgorithm; #if DEBUG //growl.EncryptionAlgorithm = Cryptography.SymmetricAlgorithmType.PlainText; #endif growl.ForwardedNotificationCallback += callbackFunction; growl.Notify(notification, callbackContext); }
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 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 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 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 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); } }
/// <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 <see cref="Growl.Connector.RequestInfo"/> associated with the notification request</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 abstract void ForwardNotification(Growl.Connector.Notification notification, Growl.Connector.CallbackContext callbackContext, Growl.Connector.RequestInfo requestInfo, bool isIdle, ForwardedNotificationCallbackHandler callbackFunction);
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); }
/// <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 <see cref="Growl.Connector.RequestInfo"/> associated with the notification request</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 abstract void ForwardNotification(Growl.Connector.Notification notification, Growl.Connector.CallbackContext callbackContext, Growl.Connector.RequestInfo requestInfo, bool isIdle, ForwardedNotificationCallbackHandler callbackFunction);