예제 #1
0
 public void Notify(Story story)
 {
     var frontpageItem = story.Item;
     var notification = new Notification(ApplicationName, NotificationTypeName, "ID", frontpageItem.Title, frontpageItem.Link);
     var callback = new CallbackContext(frontpageItem.Link);
     _growl.Notify(notification, callback);
 }
예제 #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            CallbackContext callbackContext = new CallbackContext("some fake information", "fake data");

            Notification notification = new Notification(this.application.Name, this.notificationType.Name, DateTime.Now.Ticks.ToString(), this.textBox2.Text, this.textBox3.Text);
            this.growl.Notify(notification, callbackContext);
        }
        /// <summary>
        /// Creates a new <see cref="CallbackContext"/> from a list of headers
        /// </summary>
        /// <param name="headers">The <see cref="HeaderCollection"/> used to populate the object</param>
        /// <returns><see cref="CallbackContext"/></returns>
        public static new CallbackContext FromHeaders(HeaderCollection headers)
        {
            CallbackDataBase baseObj = CallbackDataBase.FromHeaders(headers);

            CallbackContext context = new CallbackContext(baseObj.Data, baseObj.Type);

            return context;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GNTPRequest"/> class.
 /// </summary>
 /// <param name="version">The version of the GNTP request.</param>
 /// <param name="directive">The type of GNTP request.</param>
 /// <param name="key">The key used to validate and encrypt the message.</param>
 /// <param name="headers">The collection of headers parsed from the current request.</param>
 /// <param name="applicationName">The name of the application sending the request.</param>
 /// <param name="notificationsToBeRegistered">A collection of the groups of headers for each notification type to be registered.</param>
 /// <param name="callbackContext">The callback context associated with the request.</param>
 public GNTPRequest(string version, RequestType directive, Key key, HeaderCollection headers, string applicationName, List<HeaderCollection> notificationsToBeRegistered, CallbackContext callbackContext)
 {
     this.version = version;
     this.directive = directive;
     this.key = key;
     this.headers = headers;
     this.applicationName = applicationName;
     this.notificationsToBeRegistered = notificationsToBeRegistered;
     this.callbackContext = callbackContext;
 }
예제 #5
0
        /// <summary>

        /// Sets the <see cref="CallbackData"/> for this response

        /// </summary>

        /// <param name="notificationID">The ID of the notification making the callback</param>

        /// <param name="callbackContext">The <see cref="CallbackContext"/> of the request</param>

        /// <param name="callbackResult">The <see cref="CallbackResult"/> (clicked, closed)</param>

        public void SetCallbackData(string notificationID, CallbackContext callbackContext, CallbackResult callbackResult)

        {
            if (callbackContext != null)

            {
                CallbackData cd = new CallbackData(callbackContext.Data, callbackContext.Type, callbackResult, notificationID);

                this.callbackData = cd;
            }
        }
예제 #6
0
        /// <summary>

        /// Creates a new <see cref="CallbackContext"/> from a list of headers

        /// </summary>

        /// <param name="headers">The <see cref="HeaderCollection"/> used to populate the object</param>

        /// <returns><see cref="CallbackContext"/></returns>

        public new static CallbackContext FromHeaders(HeaderCollection headers)

        {
            CallbackDataBase baseObj = CallbackDataBase.FromHeaders(headers);



            CallbackContext context = new CallbackContext(baseObj.Data, baseObj.Type);



            return(context);
        }
예제 #7
0
        public void SendNotification()
        {
            // TODO: deal with the situation when Growl is not running by adding a timeout for every notification.
            if (!_isNotificationActive)
            {
                CallbackContext callbackContext = new CallbackContext("some fake information", "fake data");

                Notification notification = new Notification(this.application.Name, this.notificationType.Name,
                                                             DateTime.Now.Ticks.ToString(), "usb",
                                                             "Knock, Knock");
                _isNotificationActive = true;
                this.growl.Notify(notification, callbackContext);
            }
        }
예제 #8
0
        public void Notify(string applicationName, Notification notification, CallbackContext callbackContext)
        {
            if (String.IsNullOrEmpty(applicationName))
            {
                throw new ArgumentException("The application name cannot be null or empty", "applicationName");
            }
            if (notification == null)
            {
                throw new ArgumentException("The notification cannot be null");
            }

            Growl.Connector.Notification    n   = notification.UnderlyingNotification;
            Growl.Connector.CallbackContext cbc = (callbackContext != null ? callbackContext.UnderlyingCallbackContext : null);
            this.growl.Notify(n, cbc);
        }
        /// <summary>
        /// Sends a notification to Growl that specifies callback information and allows for additional request data.
        /// </summary>
        /// <param name="notification">The <see cref="Notification"/> to send.</param>
        /// <param name="callbackContext">The <see cref="CallbackContext"/> containing the callback information.</param>
        /// <param name="requestData">The <see cref="RequestData"/> containing the additional information.</param>
        /// <param name="state">An optional state object that will be passed into the response events associated with this request</param>
        public virtual void Notify(Notification notification, CallbackContext callbackContext, RequestData requestData, object state)
        {
            bool             waitForCallback     = false;
            HeaderCollection notificationHeaders = notification.ToHeaders();
            MessageBuilder   mb = new MessageBuilder(RequestType.NOTIFY, this.GetKey());

            foreach (Header header in notificationHeaders)
            {
                mb.AddHeader(header);
            }

            if (callbackContext != null)
            {
                string url = callbackContext.CallbackUrl;
                if (!String.IsNullOrEmpty(url))
                {
                    mb.AddHeader(new Header(Header.NOTIFICATION_CALLBACK_TARGET, url));
                }
                else
                {
                    mb.AddHeader(new Header(Header.NOTIFICATION_CALLBACK_CONTEXT, callbackContext.Data));
                    mb.AddHeader(new Header(Header.NOTIFICATION_CALLBACK_CONTEXT_TYPE, callbackContext.Type.ToString()));
                    waitForCallback = true;
                }
            }

            // handle any additional request data
            if (requestData != null)
            {
                HeaderCollection requestDataHeaders = requestData.ToHeaders();
                foreach (Header header in requestDataHeaders)
                {
                    mb.AddHeader(header);
                }
            }

            Send(mb, OnResponseReceived, waitForCallback, state);
        }
예제 #10
0
        private void button5_Click(object sender, EventArgs e)
        {
            Growl.Connector.Application app = new Growl.Connector.Application("SurfWriter");
            //app.Icon = "http://atomicbride.com/Apple.gif";
            //app.Icon = "http://www.thetroyers.com/images/Apple_Logo.jpg";
            app.Icon = @"c:\apple.png";
            app.CustomTextAttributes.Add("Creator", "Apple Software");
            app.CustomTextAttributes.Add("Application-ID", "08d6c05a21512a79a1dfeb9d2a8f262f");

            NotificationType nt1 = new NotificationType("Download Complete", "Download completed");
            nt1.Icon = new BinaryData(new byte[] { 65, 66, 67, 68 });
            nt1.CustomTextAttributes.Add("Language", "English");
            nt1.CustomTextAttributes.Add("Timezone", "PST");

            Notification notification = new Notification(app.Name, nt1.Name, "123456", "\u2605 Your document was published", @"File 'c:\file.txt' was successfully published at 8:57pm.");
            notification.Sticky = false;
            notification.Priority = Priority.Emergency;
            //notification.Icon = "http://atomicbride.com/Apple.gif";
            app.Icon = @"c:\apple.png";
            notification.CustomTextAttributes.Add("Filename", @"c:\file.txt");
            notification.CustomTextAttributes.Add("Timestamp", "8:57pm");
            notification.CustomBinaryAttributes.Add("File", new BinaryData(new byte[] { 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78 }));

            string data = "this is my context\nthis is after a line break";
            string type = typeof(string).ToString();
            CallbackContext context = new CallbackContext(data, type);

            Growl.Connector.RequestData rd = new RequestData();
            rd.Add("Return-To-Me", "some text value");
            rd.Add("Return-To-Me2", "another value");

            growl.Notify(notification, context, rd);
            this.textBox1.Text = "NOTIFY sent";
        }
예제 #11
0
        private void button2_Click(object sender, EventArgs e)
        {
            Growl.Connector.Application app = new Growl.Connector.Application("SurfWriter");
            //app.Icon = "http://atomicbride.com/Apple.gif";
            //app.Icon = "http://www.thetroyers.com/images/Apple_Logo.jpg";
            app.Icon = @"c:\apple.png";
            app.CustomTextAttributes.Add("Creator", "Apple Software");
            app.CustomTextAttributes.Add("Application-ID", "08d6c05a21512a79a1dfeb9d2a8f262f");

            NotificationType nt1 = new NotificationType("Download Complete", "Download completed");
            //nt1.Icon = new BinaryData(new byte[] { 65, 66, 67, 68 });
            nt1.CustomTextAttributes.Add("Language", "English");
            nt1.CustomTextAttributes.Add("Timezone", "PST");

            Notification notification = new Notification(app.Name, nt1.Name, "123456", "\u2065 Your docu;ment\nwas publi&shed", "File 'c:\\file.txt' was successfully published at 8:57pm.\n\nClick this notification to open the file.\n\nThis is a test of the expanding displays.");
            notification.Sticky = false;
            notification.Priority = Priority.Emergency;
            notification.Icon = "http://atomicbride.com/Apple.gif";
            //notification.Icon = "http://haxe.org/favicon.ico";
            notification.CustomTextAttributes.Add("Filename", @"c:\file.txt");
            notification.CustomTextAttributes.Add("Timestamp", "8:57pm");
            notification.CustomBinaryAttributes.Add("File", new BinaryData(new byte[] { 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78, 78 }));
            notification.CoalescingID = "secretfaketest";

            //string url = "http://localhost/growl-callback.aspx";
            //string url = "mailto:[email protected]";
            string url = "itpc:http://www.npr.org/rss/podcast.php?id=35";
            CallbackContext callback = new CallbackContext(url);

            Growl.Connector.RequestData rd = new RequestData();
            rd.Add("Return-To-Me", "some text value");
            rd.Add("Return-To-Me2", "this is some longer value, including a \n few \n line \n breaks");
            rd.Add("Can I have spaces?", "dont know");

            growl.Notify(notification, callback, rd);
            this.textBox1.Text = "NOTIFY sent";
        }
예제 #12
0
 public QueuedNotification(Notification notification, CallbackContext context)
 {
     this.Notification = notification;
     this.Context = context;
 }
예제 #13
0
 public static void Enqueue(Notification notification, CallbackContext context)
 {
     QueuedNotification qn = new QueuedNotification(notification, context);
     queue.Enqueue(qn);
     timer.Start();
 }
예제 #14
0
        void feed_FeedUpdated(object sender, FeedUpdatedEventArgs e)
        {
            if (e != null && e.NewItems != null)
            {
                foreach (FeedItem item in e.NewItems)
                {
                    //this.notifyIcon.ShowBalloonTip(1000, item.SourceFeed.Title.Text, item.Title.Text, ToolTipIcon.Info);

                    Notification n = new Notification(this.app.Name, this.ntNewFeedItem.Name, String.Empty, item.SourceFeed.Title, item.Title);

                    CallbackContext c = null;
                    if (!String.IsNullOrEmpty(item.Link))
                    {
                        c = new CallbackContext(item.Link);
                    }

                    this.growl.Notify(n, c);
                }
            }
        }
예제 #15
0
 /// <summary>
 /// Sets the <see cref="CallbackData"/> for this response
 /// </summary>
 /// <param name="notificationID">The ID of the notification making the callback</param>
 /// <param name="callbackContext">The <see cref="CallbackContext"/> of the request</param>
 /// <param name="callbackResult">The <see cref="CallbackResult"/> (clicked, closed)</param>
 public void SetCallbackData(string notificationID, CallbackContext callbackContext, CallbackResult callbackResult)
 {
     if (callbackContext != null)
     {
         CallbackData cd = new CallbackData(callbackContext.Data, callbackContext.Type, callbackResult, notificationID);
         this.callbackData = cd;
     }
 }
예제 #16
0
        private void SendGrowl(string title, string message)
        {
            CallbackContext callbackContext = new CallbackContext("", "");

            Notification notification = new Notification(application.Name, notificationType.Name, DateTime.Now.Ticks.ToString(), title, message);
            growl.Notify(notification, callbackContext);
        }
예제 #17
0
        private void ShowMessageBox(string caption, string message)
        {
            if (!_showmess) return;
            var callbackContext = new CallbackContext(caption, message);

            var notification = new Notification(_application.Name, _notificationType.Name, DateTime.Now.Ticks.ToString(), caption, message);
            _growl.Notify(notification, callbackContext);
        }
예제 #18
0
        private void ProcessFeed(FeedInfo feed)
        {
            DateTimeOffset mostRecentItem = this.feedLastUpdated;
            if (mostRecentItem == DateTimeOffset.MaxValue) mostRecentItem = DateTimeOffset.MinValue;

            Growl.CoreLibrary.DebugInfo.WriteLine(String.Format("Feed Retrieved: {0} - Last Most Recent Item: {1}", this.Description, mostRecentItem));

            foreach (FeedItem item in feed.Items)
            {
                DateTimeOffset itemDate = item.PubDate;

                if (itemDate > mostRecentItem)
                    mostRecentItem = itemDate;

                if (itemDate > this.feedLastUpdated)
                {
                    Growl.CoreLibrary.DebugInfo.WriteLine(String.Format("{0} - New Feed Item - Published at: {1} - (last update at: {2})", this.Description, itemDate, this.feedLastUpdated));

                    item.SourceFeed = feed;

                    Notification n = new Notification(this.AppName, this.ntNewFeedItem.Name, String.Empty, this.AppName, item.Title);
                    n.Icon = feed.Icon;

                    CallbackContext c = null;
                    if (!String.IsNullOrEmpty(item.Link))
                    {
                        c = new CallbackContext(item.Link);
                    }

                    // the NotificationQueue provides some simple throttling so that the screen is not flooded with new items
                    // (especially important at load time when there could be lots of new items)
                    NotificationQueue.Enqueue(n, c);
                }
            }

            this.feedLastUpdated = mostRecentItem;  // feed.LastUpdatedTime is not always set =(
        }
 /// <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);
예제 #20
0
파일: UiCommands.cs 프로젝트: jlami/mutefm
        public static void SetNotification(string text, bool useBgMusicIcon)
        {
            try
            {
                // Don't send the same message multiple times over a short interval
                if ((text == _prevNotifyText) && (TimeSpan.Compare(DateTime.Now.Subtract(_prevNotifyDateTime).Duration(), new TimeSpan(0, 0, 0, 5, 0)) < 0))
                {
                    return;
                }
                _prevNotifyDateTime = DateTime.Now;
                _prevNotifyText = text;

                if (mPlayerForm != null)
                {
                    mPlayerForm.Invoke((System.Windows.Forms.MethodInvoker)delegate
                    {
                        mPlayerForm.SetStatusText(text);
                    });
                }

                if (GrowlInstallHelper.GrowlInstallHelper.GetForceGrowl())
                {
                    _growlApp = new Growl.Connector.Application(Constants.ProgramName);
                    _growl.Register(_growlApp, new NotificationType[] { _notificationType });

                    CallbackContext callbackContext = new CallbackContext("setNotification", text);
                    Notification notification = new Notification(_growlApp.Name, _notificationType.Name, DateTime.Now.Ticks.ToString(), Constants.ProgramName, text);
                    _growl.Notify(notification, callbackContext);
                }
                else if (SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GeneralSettings.ShowBalloonNotifications)
                {
                    MuteFm.UiPackage.WinSoundServerSysTray.Instance.ShowBalloonTip(3000, Constants.ProgramName, text, ToolTipIcon.Info);
                }

                //OLDNOTIFY
                /*
                TopForm.Instance.Invoke((System.Windows.Forms.MethodInvoker)delegate
                {
                    //TODO: the below isn't actually working (it seems to sometimes though)
                    //            TopForm.Instance.BeginInvoke(new Action(() => TopForm.Instance.Opacity = 0.99)); // via http://stackoverflow.com/questions/10452740/remove-black-flicker-on-first-show-of-winform-with-transparencykey-set to remove initial flicker
                    TopForm.Instance.Opacity = 0.99;
                    TopForm.Instance.SetText(text, useBgMusicIcon);
                    MuteApp.SmartVolManagerPackage.SoundEventLogger.LogMsg("Top text: " + text);
                }); */
            }
            catch (Exception ex)
            {
                MuteFm.SmartVolManagerPackage.SoundEventLogger.LogException(ex);
            }
        }
        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( Notification notification, CallbackContext callbackContext, RequestInfo requestInfo, bool isIdle, ForwardedNotificationCallbackHandler callbackFunction )
 {
     //notify.ShowBalloonTip ( 4000, notification.Title, notification.Text, ToolTipIcon.Info );
 }
 /// <summary>
 /// Sends a notification to Growl that specifies callback information.
 /// </summary>
 /// <param name="notification">The <see cref="Notification"/> to send.</param>
 /// <param name="callbackContext">The <see cref="CallbackContext"/> containing the callback information.</param>
 /// <param name="state">An optional state object that will be passed into the response events associated with this request</param>
 public virtual void Notify(Notification notification, CallbackContext callbackContext, object state)
 {
     Notify(notification, callbackContext, null, state);
 }
예제 #24
0
        /// <summary>

        /// Sends a notification to Growl that specifies callback information.

        /// </summary>

        /// <param name="notification">The <see cref="Notification"/> to send.</param>

        /// <param name="callbackContext">The <see cref="CallbackContext"/> containing the callback information.</param>

        public virtual void Notify(Notification notification, CallbackContext callbackContext)

        {
            Notify(notification, callbackContext, null, null);
        }
        /// <summary>
        /// Sends a notification to Growl that specifies callback information and allows for additional request data.
        /// </summary>
        /// <param name="notification">The <see cref="Notification"/> to send.</param>
        /// <param name="callbackContext">The <see cref="CallbackContext"/> containing the callback information.</param>
        /// <param name="requestData">The <see cref="RequestData"/> containing the additional information.</param>
        /// <param name="state">An optional state object that will be passed into the response events associated with this request</param>
        public virtual void Notify(Notification notification, CallbackContext callbackContext, RequestData requestData, object state)
        {
            bool waitForCallback = false;
            HeaderCollection notificationHeaders = notification.ToHeaders();
            MessageBuilder mb = new MessageBuilder(RequestType.NOTIFY, this.GetKey());
            foreach (Header header in notificationHeaders)
            {
                mb.AddHeader(header);
            }

            if (callbackContext != null)
            {
                string url = callbackContext.CallbackUrl;
                if (!String.IsNullOrEmpty(url))
                {
                    mb.AddHeader(new Header(Header.NOTIFICATION_CALLBACK_TARGET, url));
                }
                else
                {
                    mb.AddHeader(new Header(Header.NOTIFICATION_CALLBACK_CONTEXT, callbackContext.Data));
                    mb.AddHeader(new Header(Header.NOTIFICATION_CALLBACK_CONTEXT_TYPE, callbackContext.Type.ToString()));
                    waitForCallback = true;
                }
            }

            // handle any additional request data
            if (requestData != null)
            {
                HeaderCollection requestDataHeaders = requestData.ToHeaders();
                foreach (Header header in requestDataHeaders)
                {
                    mb.AddHeader(header);
                }
            }

            Send(mb, OnResponseReceived, waitForCallback, state);
        }
예제 #26
0
        private static void InitDatabase()
        {
            var config = ActiveRecordSectionHandler.Instance;
            var assemblyLibrary = Assembly.Load("FileProccesor");

            ActiveRecordStarter.Initialize(assemblyLibrary, config);

            switch (ConfigurationManager.AppSettings["Enviroment"])
            {
                case "Development":
                    ActiveRecordStarter.DropSchema();
                    ActiveRecordStarter.CreateSchema();
                    break;
                case "Testing":
                    ActiveRecordStarter.UpdateSchema();
                    break;
                default:
                    break;
            }
           

            var callbackContext = new CallbackContext("Conectado a la Base de Datos", ActiveRecordStarter.ConfigurationSource.ToString());

            var notification = new Notification(_application.Name, _notificationType.Name, DateTime.Now.Ticks.ToString(), "InitDatabase", "OK");
            _growl.Notify(notification, callbackContext);
        }
예제 #27
0
        /// <summary>

        /// Sends a notification to Growl that specifies callback information.

        /// </summary>

        /// <param name="notification">The <see cref="Notification"/> to send.</param>

        /// <param name="callbackContext">The <see cref="CallbackContext"/> containing the callback information.</param>

        /// <param name="state">An optional state object that will be passed into the response events associated with this request</param>

        public virtual void Notify(Notification notification, CallbackContext callbackContext, object state)

        {
            Notify(notification, callbackContext, null, state);
        }
 /// <summary>
 /// Sends a notification to Growl that specifies callback information.
 /// </summary>
 /// <param name="notification">The <see cref="Notification"/> to send.</param>
 /// <param name="callbackContext">The <see cref="CallbackContext"/> containing the callback information.</param>
 public virtual void Notify(Notification notification, CallbackContext callbackContext)
 {
     Notify(notification, callbackContext, null, null);
 }
예제 #29
0
        /// <summary>

        /// Sends a notification to Growl that specifies callback information.

        /// </summary>

        /// <param name="notification">The <see cref="Notification"/> to send.</param>

        /// <param name="callbackContext">The <see cref="CallbackContext"/> containing the callback information.</param>

        /// <param name="requestData">The <see cref="RequestData"/> containing the additional information.</param>

        public virtual void Notify(Notification notification, CallbackContext callbackContext, RequestData requestData)

        {
            Notify(notification, callbackContext, requestData, null);
        }
 /// <summary>
 /// Sends a notification to Growl that specifies callback information.
 /// </summary>
 /// <param name="notification">The <see cref="Notification"/> to send.</param>
 /// <param name="callbackContext">The <see cref="CallbackContext"/> containing the callback information.</param>
 /// <param name="requestData">The <see cref="RequestData"/> containing the additional information.</param>
 public virtual void Notify(Notification notification, CallbackContext callbackContext, RequestData requestData)
 {
     Notify(notification, callbackContext, requestData, null);
 }
        void listener_NotificationReceived(object sender, NotifyIOListener.NotificationReceivedEventArgs e)
        {
            // register first (TODO: maybe keep a list of already-registered sources?)
            Growl.Connector.Application app = new Growl.Connector.Application(e.Source);
            app.Icon = (String.IsNullOrEmpty(e.Icon) ? e.SourceIcon : e.Icon);
            Register(app, new NotificationType[] { this.nt });

            // wait just a bit to make sure the registration went through (we are on another thread here, so it is ok)
            System.Threading.Thread.Sleep(500);

            // send notification
            Notification n = new Notification(app.Name, this.nt.Name, "", Fixup(e.Title, Properties.Resources.NotifyIO_NotificationType), Fixup(e.Text));
            n.Icon = e.Icon;
            n.Sticky = e.Sticky;
            CallbackContext c = null;
            if (!String.IsNullOrEmpty(e.Link))
            {
                c = new CallbackContext(e.Link);
            }
            Notify(n, c);
        }
        /// <summary>
        /// Called when the request is successfully parsed.
        /// </summary>
        private void OnMessageParsed()
        {
            // handle callback context
            CallbackContext context = null;
            if (!String.IsNullOrEmpty(this.callbackData) && !String.IsNullOrEmpty(this.callbackDataType) && String.IsNullOrEmpty(this.callbackUrl))
                context = new CallbackContext(this.callbackData, this.callbackDataType);
            else if (!String.IsNullOrEmpty(this.callbackUrl))
                context = new CallbackContext(this.callbackUrl);

            if (this.MessageParsed != null)
            {
                GNTPRequest request = new GNTPRequest(this.version, this.directive, this.key, this.headers, this.applicationName, this.notificationsToBeRegistered, context);
                this.MessageParsed(request);
            }
            else
            {
                // no handler - return some kind of error? (this should never really happen)
                OnError(ErrorCode.INTERNAL_SERVER_ERROR, ErrorDescription.INTERNAL_SERVER_ERROR);
            }
        }
예제 #33
0
 public static int Main(string[] args)
 {
     if (args == null || args.Length == 0)
     {
         Console.WriteLine("Invalid arguments. See /? for usage.");
         return -1;
     }
     else if (args[0] == "/?")
     {
         Console.WriteLine();
         Console.WriteLine(Resources.usage);
         return 0;
     }
     else
     {
         Dictionary<string, Program.Parameter> dictionary = new Dictionary<string, Program.Parameter>();
         try
         {
             foreach (string str in args)
             {
                 Program.Parameter parameterValue = Program.GetParameterValue(str);
                 dictionary.Add(parameterValue.Argument, parameterValue);
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine("Bad arguments : " + ex.Message);
             return -1;
         }
         string title = "growlnotify";
         string id = "";
         string coalescingID = (string)null;
         bool sticky = false;
         int num = 0;
         string str1 = (string)null;
         string str2 = "growlnotify";
         string uriString = (string)null;
         string[] strArray1 = (string[])null;
         string notificationName = "General Notification";
         string url = (string)null;
         string str3 = "GNTP";
         string hostname = "localhost";
         string password = (string)null;
         Cryptography.SymmetricAlgorithmType symmetricAlgorithmType = Cryptography.SymmetricAlgorithmType.PlainText;
         Cryptography.HashAlgorithmType hashAlgorithmType = Cryptography.HashAlgorithmType.MD5;
         int port = 23053;
         if (!dictionary.ContainsKey("messagetext"))
         {
             Console.WriteLine("Missing 'messagetext' argument. See /? for usage");
             return -1;
         }
         else
         {
             string text = dictionary["messagetext"].Value;
             if (dictionary.ContainsKey("/t"))
                 title = dictionary["/t"].Value;
             if (dictionary.ContainsKey("/id"))
                 id = dictionary["/id"].Value;
             if (dictionary.ContainsKey("/s") && dictionary["/s"].Value.ToLower() == "true")
                 sticky = true;
             if (dictionary.ContainsKey("/p"))
                 num = Convert.ToInt32(dictionary["/p"].Value);
             if (dictionary.ContainsKey("/i"))
             {
                 str1 = dictionary["/i"].Value;
                 if (str1.StartsWith("."))
                     str1 = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), str1);
             }
             if (dictionary.ContainsKey("/c"))
                 coalescingID = dictionary["/c"].Value;
             if (dictionary.ContainsKey("/a"))
                 str2 = dictionary["/a"].Value;
             if (dictionary.ContainsKey("/ai"))
             {
                 uriString = dictionary["/ai"].Value;
                 if (uriString.StartsWith("."))
                     uriString = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), str1);
             }
             if (dictionary.ContainsKey("/r"))
             {
                 string[] strArray2 = dictionary["/r"].Value.Split(new char[1]
     {
       ','
     });
                 if (strArray2 != null && strArray2.Length > 0)
                 {
                     strArray1 = new string[strArray2.Length];
                     for (int index = 0; index < strArray2.Length; ++index)
                     {
                         string str4 = strArray2[index];
                         if (str4.StartsWith("\""))
                             str4 = str4.Substring(1, str4.Length - 1);
                         if (str4.EndsWith("\""))
                             str4 = str4.Substring(0, str4.Length - 1);
                         strArray1[index] = str4;
                     }
                 }
             }
             if (dictionary.ContainsKey("/n"))
                 notificationName = dictionary["/n"].Value;
             if (dictionary.ContainsKey("/cu"))
                 url = dictionary["/cu"].Value;
             if (dictionary.ContainsKey("/protocol"))
                 str3 = dictionary["/protocol"].Value;
             if (dictionary.ContainsKey("/host"))
                 hostname = dictionary["/host"].Value;
             if (dictionary.ContainsKey("/port"))
                 port = Convert.ToInt32(dictionary["/port"].Value);
             else if (str3 == "UDP")
                 port = 9887;
             if (dictionary.ContainsKey("/pass"))
                 password = dictionary["/pass"].Value;
             if (dictionary.ContainsKey("/enc"))
             {
                 switch (dictionary["/enc"].Value.ToUpper())
                 {
                     case "DES":
                         symmetricAlgorithmType = Cryptography.SymmetricAlgorithmType.DES;
                         break;
                     case "3DES":
                         symmetricAlgorithmType = Cryptography.SymmetricAlgorithmType.TripleDES;
                         break;
                     case "AES":
                         symmetricAlgorithmType = Cryptography.SymmetricAlgorithmType.AES;
                         break;
                     default:
                         symmetricAlgorithmType = Cryptography.SymmetricAlgorithmType.PlainText;
                         break;
                 }
             }
             if (dictionary.ContainsKey("/hash"))
             {
                 switch (dictionary["/hash"].Value.ToUpper())
                 {
                     case "SHA1":
                         hashAlgorithmType = Cryptography.HashAlgorithmType.SHA1;
                         break;
                     case "SHA256":
                         hashAlgorithmType = Cryptography.HashAlgorithmType.SHA256;
                         break;
                     case "SHA512":
                         hashAlgorithmType = Cryptography.HashAlgorithmType.SHA512;
                         break;
                     default:
                         hashAlgorithmType = Cryptography.HashAlgorithmType.MD5;
                         break;
                 }
             }
             if (dictionary.ContainsKey("/silent") && dictionary["/silent"].Value.ToLower() == "true")
                 Program.silent = true;
             Program.ewh = new EventWaitHandle(false, EventResetMode.ManualReset);
             Program.growl = new GrowlConnector(password, hostname, port);
             Program.growl.EncryptionAlgorithm = symmetricAlgorithmType;
             Program.growl.KeyHashAlgorithm = hashAlgorithmType;
             Program.growl.OKResponse += new GrowlConnector.ResponseEventHandler(Program.growl_Response);
             Program.growl.ErrorResponse += new GrowlConnector.ResponseEventHandler(Program.growl_Response);
             if (strArray1 != null || str2 == "growlnotify")
             {
                 Resource resource = (Resource)null;
                 if (!string.IsNullOrEmpty(uriString))
                 {
                     Uri uri = new Uri(uriString);
                     resource = !uri.IsFile || !File.Exists(uri.LocalPath) ? (Resource)uriString : (Resource) ImageConverter.ImageFromUrl(uri.LocalPath);
                 }
                 if (strArray1 == null)
                     strArray1 = new string[1]
       {
         "General Notification"
       };
                 NotificationType[] notificationTypes = new NotificationType[strArray1.Length];
                 for (int index = 0; index < notificationTypes.Length; ++index)
                 {
                     NotificationType notificationType = new NotificationType(strArray1[index]);
                     notificationTypes[index] = notificationType;
                 }
                 Program.growl.Register(new Application(str2)
                 {
                     Icon = resource
                 }, notificationTypes);
                 Program.ewh.WaitOne();
             }
             CallbackContext callbackContext = (CallbackContext)null;
             if (!string.IsNullOrEmpty(url))
                 callbackContext = new CallbackContext(url);
             Program.ewh.Reset();
             Resource icon = (Resource)null;
             if (!string.IsNullOrEmpty(str1))
             {
                 Uri uri = new Uri(str1);
                 icon = !uri.IsFile || !File.Exists(uri.LocalPath) ? (Resource)str1 : (Resource)ImageConverter.ImageFromUrl(uri.LocalPath);
             }
             Priority priority = Enum.IsDefined(typeof(Priority), (object)num) ? (Priority)num : Priority.Normal;
             Notification notification = new Notification(str2, notificationName, id, title, text, icon, sticky, priority, coalescingID);
             Program.growl.Notify(notification, callbackContext);
             Program.ewh.WaitOne();
             Console.WriteLine();
             return Program.r;
         }
     }
 }