Beispiel #1
0
 protected void OnForwardedNotificationCallback(Growl.Connector.Response response, Growl.Connector.CallbackData callbackData)
 {
     if (this.ForwardedNotificationCallback != null)
     {
         this.ForwardedNotificationCallback(response, callbackData);
     }
 }
Beispiel #2
0
 private static void growl_notification_callback(Growl.Connector.Response response, Growl.Connector.CallbackData callbackData, object state)
 {
     if ((callbackData.Result == Growl.CoreLibrary.CallbackResult.CLICK) && callbackData.Type.Contains("Cannot hear anything"))
     {
         OnOperation(Operation.Show);
     }
 }
Beispiel #3
0
        void growl_NotificationCallback(Growl.Connector.Response response, Growl.Connector.CallbackData callbackData)

        {
            CallbackData cd = new CallbackData(callbackData);

            OnCallback(cd);
        }
 /// <summary>
 /// Called when a notification that has been forwarded triggers a callback from the forwarded destination.
 /// </summary>
 /// <param name="response">The <see cref="Response"/> from the forwarded destination</param>
 /// <param name="callbackData">The <see cref="CallbackData"/></param>
 protected void OnForwardNotificationCallback(Response response, CallbackData callbackData)
 {
     if (this.ForwardedNotificationCallback != null)
     {
         this.ForwardedNotificationCallback(response, callbackData);
     }
 }
        void growl_NotificationCallback(Response response, CallbackData callbackData, object state)
        {
            if (callbackData != null)
            {
                if (callbackData.Result == Growl.CoreLibrary.CallbackResult.CLICK)
                {
                    string[] data = callbackData.Data.Split(CALLBACK_DATA_SEPARATOR.ToCharArray());
                    IntPtr hWnd = new IntPtr(Convert.ToInt32(data[0]));
                    uint msg = Convert.ToUInt32(data[1]);
                    IntPtr wparam = new IntPtr(Convert.ToInt32(data[2]));
                    IntPtr lparam = new IntPtr(Convert.ToInt32(data[3]));

                    Win32.SendMessage(hWnd, msg, wparam, lparam);
                }
            }
        }
        /// <summary>
        /// Creates a new <see cref="SubscriptionResponse"/> from a base <see cref="Response"/> and a list of headers
        /// </summary>
        /// <param name="response">The base <see cref="Response"/></param>
        /// <param name="headers">The <see cref="HeaderCollection"/> used to populate the response</param>
        /// <returns><see cref="SubscriptionResponse"/></returns>
        internal static SubscriptionResponse FromResponse(Response response, HeaderCollection headers)
        {
            SubscriptionResponse sr = null;
            if (response.IsOK)
            {
                int ttl = headers.GetHeaderIntValue(Header.SUBSCRIPTION_TTL, true);

                sr = new SubscriptionResponse(ttl);
            }
            else
            {
                sr = new SubscriptionResponse(response.ErrorCode, response.ErrorDescription);
                sr.ttl = 0;
            }

            SetInhertiedAttributesFromHeaders(sr, headers);
            return sr;
        }
Beispiel #7
0
 private void GrowlOKResponse(Response response, object state)
 {
     var requestState = state as GrowlRequestState;
     if (requestState != null)
     {
         requestState.Update();
     }
 }
Beispiel #8
0
 private void GrowlErrorResponse(Response response, object state)
 {
     var requestState = state as GrowlRequestState;
     if (requestState != null)
     {
         requestState.Update(response.ErrorCode, response.ErrorDescription);
     }
 }
Beispiel #9
0
 private static void ConnectorOnNotificationCallback(Response response, CallbackData callbackData, object state)
 {
     Process.Start(callbackData.Data);
 }
Beispiel #10
0
 private void growl_NotificationCallback(Response response, CallbackData callbackData, object state)
 {
     _isNotificationActive = false;
     //string text = String.Format("Response Type: {0}\r\nNotification ID: {1}\r\nCallback Data: {2}\r\nCallback Data Type: {3}\r\n", callbackData.Result, callbackData.NotificationID, callbackData.Data, callbackData.Type);
     //MessageBox.Show(text, "Callback received", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
 }
Beispiel #11
0
        /// <summary>
        /// Creates a new <see cref="Response"/> from a list of headers
        /// </summary>
        /// <param name="headers">The <see cref="HeaderCollection"/> used to populate the response</param>
        /// <returns><see cref="Response"/></returns>
        public new static Response FromHeaders(HeaderCollection headers)
        {
            int errorCode = headers.GetHeaderIntValue(Header.ERROR_CODE, true);
            string description = headers.GetHeaderStringValue(Header.ERROR_DESCRIPTION, false);

            Response response = new Response(errorCode, description);
            SetInhertiedAttributesFromHeaders(response, headers);
            return response;
        }
Beispiel #12
0
        void growl_OKResponse(Response response, object state)
        {
            if (state != null) InvokeWrite(state.ToString());

            InvokeWrite("OK - " + response.MachineName);
        }
Beispiel #13
0
 void growl_ErrorResponse(Response response, object state)
 {
     InvokeWrite("Error - " + response.ErrorCode + " : " + response.ErrorDescription);
 }
Beispiel #14
0
        Response server_RegisterReceived(Growl.Connector.Application application, List<NotificationType> notificationTypes, Growl.Connector.RequestInfo requestInfo)
        {
            if (requestInfo.PreviousReceivedHeaders.Count < 0)  // change to a positive number to forward
            {
                Forwarder fwd = new Forwarder(password, "127.0.0.1", Growl.Connector.GrowlConnector.TCP_PORT, requestInfo);
                fwd.EncryptionAlgorithm = Cryptography.SymmetricAlgorithmType.AES;
                fwd.Register(application, notificationTypes.ToArray());
            }

            Response response = new Response();
            return response;
        }
Beispiel #15
0
        Response server_NotifyReceived(Notification notification, Growl.Daemon.CallbackInfo callbackInfo, Growl.Connector.RequestInfo requestInfo)
        {
            Response response = new Response();

            if (callbackInfo != null)
            {
                if (callbackInfo.ShouldKeepConnectionOpen())
                {
                    response.SetCallbackData(notification.ID, callbackInfo.Context, Growl.CoreLibrary.CallbackResult.CLICK);

                    // simulate a wait
                    System.Threading.Thread.Sleep(5000);
                }
                else
                {
                    string url = callbackInfo.Context.CallbackUrl;
                    server_ServerMessage(null, Growl.Daemon.GrowlServer.LogMessageType.Information, url);
                }
            }

            //Console.WriteLine("notification response");
            return response;
        }
Beispiel #16
0
        static void growl_Response(Response response, object state)
        {
            if (!silent)
            {
                if (response.IsOK)
                {
                    r = 0;
                    Console.WriteLine("Notification sent successfully");
                }
                else
                {
                    r = response.ErrorCode;
                    Console.WriteLine(String.Format("Notification failed: {0} - {1}", response.ErrorCode, response.ErrorDescription));
                }
            }

            // signal that a response was received
            ewh.Set();
        }
Beispiel #17
0
        void growl_NotificationCallback(Response response, CallbackData callbackContext, object state)
        {
            switch (callbackContext.Result)
            {
                case Growl.CoreLibrary.CallbackResult.CLICK:
                    if (callbackContext.Data == "OPEN_URL")
                    {
                        Notification notification = state as Notification;

                        string url = notification.CustomTextAttributes["url"];
                        if (url != null && url.Substring(0, 4) == "http")
                        {
                            Process.Start(url);
                        }
                    }
                    break;

                case Growl.CoreLibrary.CallbackResult.CLOSE:
                    break;
                case Growl.CoreLibrary.CallbackResult.TIMEDOUT:
                    break;
            }
        }
Beispiel #18
0
 private static void growl_Response(Response response, object state)
 {
     if (!Program.silent)
     {
         if (response.IsOK)
         {
             Program.r = 0;
             Console.WriteLine("Notification sent successfully");
         }
         else
         {
             Program.r = response.ErrorCode;
             Console.WriteLine(string.Format("Notification failed: {0} - {1}", (object)response.ErrorCode, (object)response.ErrorDescription));
         }
     }
     Program.ewh.Set();
 }
Beispiel #19
0
 void Forwarder_NotificationCallback(Response response, CallbackData callbackData, object state)
 {
     this.OnForwardedNotificationCallback(response, callbackData);
 }
Beispiel #20
0
 void growl_ErrorResponse(Response response)
 {
     Error error = new Error(response.ErrorCode, response.ErrorDescription);
     OnError(error);
 }
Beispiel #21
0
 void growl_NotificationCallback(Response response, CallbackData callbackContext, object state)
 {
     string s = String.Format("CALLBACK RECEIVED: {0} - {1} - {2} - {3}", callbackContext.NotificationID, callbackContext.Data, callbackContext.Type, callbackContext.Result);
     InvokeWrite(s);
 }
Beispiel #22
0
 void growl_OKResponse(Response response)
 {
     OnOK();
 }
Beispiel #23
0
 private static void GrowlNotificationCallback(Response response, CallbackData callbackdata)
 {
     SaveChangesToFile(String.Format("Response Type: {0}\r\nNotification ID: {1}\r\nCallback Data: {2}\r\nCallback Data Type: {3}\r\n", callbackdata.Result, callbackdata.NotificationID, callbackdata.Data, callbackdata.Type));
 }
Beispiel #24
0
        private void connector_ErrorResponse(Response response)
        {
            if (m_logger.IsInfoEnabled)
             {
            m_logger.InfoFormat("Notification response error: {0}/{1} {2}",
               response.ErrorCode, response.ErrorDescription, response.InResponseTo);
             }

             if (m_lastNotification != null && (
            response.ErrorCode == 401 || response.ErrorCode == 402 ) ) // Application and/or type not registered
             {
            // The Sql2Growl service is designed to loop forever :) so if someone deletes our registered
            // applications and types we want to register them again.

            m_lastNotification.ClearCachedObjects = true;
            Notify(m_lastNotification);
             }
        }
        /// <summary>
        /// Parses a response message and returns the corresponding <see cref="Response"/> object
        /// </summary>
        /// <param name="message">The entire GNTP response message</param>
        /// <param name="headers">The <see cref="HeaderCollection"/> of parsed header values</param>
        /// <returns><see cref="Response"/></returns>
        private Response Parse(string message, out HeaderCollection headers)
        {
            ResponseType responseType = ResponseType.ERROR;
            Response response = null;
            headers = new HeaderCollection();

            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(message);
            System.IO.MemoryStream stream = new System.IO.MemoryStream(bytes);
            using (stream)
            {
                GNTPStreamReader reader = new GNTPStreamReader(stream);
                using (reader)
                {
                    bool isError = false;
                    bool isFirstLine = true;
                    while (!reader.EndOfStream)
                    {
                        string line = reader.ReadLine();

                        if (isFirstLine)
                        {
                            Match match = ParseGNTPHeaderLine(line);
                            if (match.Success)
                            {
                                this.version = match.Groups["Version"].Value;
                                this.directive = match.Groups["Directive"].Value;
                                if (this.directive.StartsWith("-", StringComparison.InvariantCulture)) this.directive = this.directive.Remove(0, 1);

                                if (version == GNTP_SUPPORTED_VERSION)
                                {
                                    if (Enum.IsDefined(typeof(ResponseType), this.directive))
                                    {
                                        responseType = (ResponseType)Enum.Parse(typeof(ResponseType), this.directive, false);
                                        response = new Response();
                                        if (responseType == ResponseType.ERROR) isError = true;
                                        isFirstLine = false;
                                    }
                                    else
                                    {
                                        // invalid directive
                                        response = new Response(ErrorCode.INVALID_REQUEST, "Unrecognized response type");
                                        break;
                                    }
                                }
                                else
                                {
                                    // invalid version
                                    response = new Response(ErrorCode.UNKNOWN_PROTOCOL_VERSION, "Unsupported version");
                                    break;
                                }
                            }
                            else
                            {
                                // invalid message header
                                response = new Response(ErrorCode.UNKNOWN_PROTOCOL, "Unrecognized response");
                                break;
                            }
                        }
                        else
                        {
                            Header header = Header.ParseHeader(line);
                            headers.AddHeader(header);
                        }
                    }

                    if (response != null)
                    {
                        if (isError)
                        {
                            int errorCode = headers.GetHeaderIntValue(Header.ERROR_CODE, false);
                            string errorDescription = headers.GetHeaderStringValue(Header.ERROR_DESCRIPTION, false);
                            if (errorCode > 0 && errorDescription != null)
                                response = new Response(errorCode, errorDescription);
                            else
                                response = new Response(ErrorCode.INTERNAL_SERVER_ERROR, ErrorDescription.INTERNAL_SERVER_ERROR);
                        }
                        else
                        {
                            string inResponseTo = headers.GetHeaderStringValue(Header.RESPONSE_ACTION, false);
                            response.InResponseTo = inResponseTo;
                        }

                        response.SetAttributesFromHeaders(headers, (responseType == ResponseType.CALLBACK));
                    }
                    else
                    {
                        // if we got here, that is bad.
                        response = new Response(ErrorCode.INTERNAL_SERVER_ERROR, ErrorDescription.INTERNAL_SERVER_ERROR);
                    }
                }
            }

            return response;
        }
 /// <summary>
 /// Occurs when any of the following network conditions occur:
 /// 1. Unable to connect to target host for any reason
 /// 2. Write request fails
 /// 3. Read request fails
 /// </summary>
 /// <param name="response">The <see cref="Response"/> that contains information about the failure</param>
 /// <param name="state">An optional state object that will be passed into the response events associated with this request</param>
 protected override void OnCommunicationFailure(Response response, object state)
 {
     SubscriptionResponse sr = SubscriptionResponse.FromResponse(response, null);
     ResetTimerBasedOnResponse(sr);
     this.OnErrorResponse(sr);
 }
Beispiel #27
0
 static void GrowlNotificationCallback(Response response, CallbackData callbackData)
 {
     //string text = String.Format("Response Type: {0}\r\nNotification ID: {1}\r\nCallback Data: {2}\r\nCallback Data Type: {3}\r\n", callbackData.Result, callbackData.NotificationID, callbackData.Data, callbackData.Type);
     //MessageBox.Show(text, "Callback received", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
 }
Beispiel #28
0
        /*
        /// <summary>
        /// Gets the url-formatted callback data that is to be sent for url callbacks.
        /// </summary>
        /// <param name="result">The <see cref="CallbackResult"/> indicating the user action</param>
        /// <returns>string - querystring/post format</returns>
        public string GetUrlCallbackData(CallbackResult result)
        {
            string data = null;
            if (this.Context != null)
            {
                UrlCallbackTarget target = this.Context.GetUrlCallbackTarget();
                if (target != null)
                {
                    data = String.Format("notification-id={0}&notification-callback-result={1}&notification-callback-context={2}&notification-callback-context-type={3}", HttpUtility.UrlEncode(this.notificationID), HttpUtility.UrlEncode(result.ToString()), HttpUtility.UrlEncode(this.Context.Data), HttpUtility.UrlEncode(this.Context.Type));
                }
            }
            return data;
        }
         * */

        /// <summary>
        /// Handles the callback from a forwarder.
        /// </summary>
        /// <param name="response">The <see cref="Response"/> from the forwarder</param>
        /// <param name="callbackData">The <see cref="CallbackData"/></param>
        public void HandleCallbackFromForwarder(Response response, CallbackData callbackData)
        {
            this.RequestInfo.SaveHandlingInfo(String.Format("Was responded to on {0} - Action: {1}", response.MachineName, callbackData.Result));

            if (this.ForwardedNotificationCallback != null)
            {
                this.ForwardedNotificationCallback(response, callbackData, this);
            }
        }