コード例 #1
0
        public void MousebuttonHasBeenClicked(string button, Int32 NotificationId)
        {
            IncomingRequest request = Requests.Where(r => r.SnarlNotificationId == NotificationId).FirstOrDefault();

            if (request != null)
            {
                switch (button)
                {
                case "left":
                    if (request.LeftClickUrl != null)
                    {
                        try
                        {
                            System.Diagnostics.Process.Start(request.LeftClickUrl);
                        }
                        catch { }
                    }
                    break;

                case "right":
                    if (request.RightClickUrl != null)
                    {
                        try {
                            System.Diagnostics.Process.Start(request.RightClickUrl);
                        }
                        catch { }
                    }
                    break;

                case "middle":
                    if (request.RightClickUrl != null)
                    {
                        try {
                            System.Diagnostics.Process.Start(request.MiddleClickUrl);
                        }
                        catch { }
                    }
                    break;

                default:
                    break;
                }
            }
        }
コード例 #2
0
        public void FetchNotifications()
        {
            string rawData = "";
            if (Properties.Settings.Default.UrlOrUnc.ToLower().StartsWith("http"))
            {
                rawData = GetHttpContent(Properties.Settings.Default.UrlOrUnc);
            }
            else
            {
                if (File.Exists(Properties.Settings.Default.UrlOrUnc))
                {
                    rawData = File.ReadAllText(Properties.Settings.Default.UrlOrUnc);
                }
                else
                {
                    if (ShowDebug)
                    {
                        Notifier.EZNotify("Debug", "File not found", Properties.Settings.Default.UrlOrUnc, 10, Properties.Settings.Default.AppIcon);
                    }
                    UpdateTimer.Start();
                    return;
                }
            }
            if (rawData == "")
            {
                if (ShowDebug)
                {
                    Notifier.EZNotify("Debug", "Empty Response", Properties.Settings.Default.UrlOrUnc, 10, Properties.Settings.Default.AppIcon);
                }
                UpdateTimer.Start();
                return;
            }
            XmlDocument xmlDoc = new XmlDocument();
            try
            {
                xmlDoc.LoadXml(rawData);
            }
            catch (Exception exp)
            {
                if (ShowDebug)
                {
                    Notifier.EZNotify("Debug", "XML general parsing error", exp.Message, 10, Properties.Settings.Default.AppIcon);
                }
                UpdateTimer.Start();
                return;
            }

            if (xmlDoc.DocumentElement.Name != "alerts")
            {
                if (ShowDebug)
                {
                    Notifier.EZNotify("Debug", "Invalid XML", "XML open tag is not \"alerts\"", 10, Properties.Settings.Default.AppIcon);
                }
                UpdateTimer.Start();
                return;
            }

            try
            {
                bool alreadyShown = false;
                foreach (XmlNode alert in xmlDoc.GetElementsByTagName("alert"))
                {
                    alreadyShown = false;
                    IncomingRequest currentAlert = new IncomingRequest();
                    foreach (XmlNode childNode in alert.ChildNodes)
                    {
                        if (alreadyShown)
                        {
                            break;
                        }
                        switch (childNode.Name.ToLower())
                        {
                            case "id":
                                currentAlert.Id = Convert.ToInt64(childNode.InnerText);
                                if (currentAlert.Id > Properties.Settings.Default.LastIdShown)
                                {

                                    if (Requests.Where(r => r.Id == currentAlert.Id).Count() > 0)
                                    {
                                        alreadyShown = true;
                                        continue;
                                    }
                                }
                                else
                                {
                                    alreadyShown = true;
                                    continue;
                                }

                                break;

                            case "title":
                                currentAlert.Title = childNode.InnerText;
                                break;

                            case "text":
                                currentAlert.Text = childNode.InnerText;
                                break;

                            case "icon":
                                currentAlert.Icon = childNode.InnerText;
                                break;

                            case "displaytime":
                                currentAlert.DisplayTime = Convert.ToInt32(childNode.InnerXml);
                                break;

                            case "app":
                                currentAlert.AppName = childNode.InnerText;
                                break;

                            case "class":
                                currentAlert.ClassName = childNode.InnerText;
                                break;

                            case "leftclickurl":
                                currentAlert.LeftClickUrl = childNode.InnerText;
                                break;

                            case "middleclickurl":
                                currentAlert.MiddleClickUrl = childNode.InnerText;
                                break;

                            case "rightclickurl":
                                currentAlert.RightClickUrl = childNode.InnerText;
                                break;

                            default:
                                break;
                        }

                    }
                    if (!alreadyShown && SnarlConnector.GetSnarlWindow() != IntPtr.Zero)
                    {
                        if (currentAlert.Icon == null)
                        {
                            currentAlert.Icon = Properties.Settings.Default.DefaultNotificationIcon;
                        }
                        if (currentAlert.DisplayTime == null)
                        {
                            currentAlert.DisplayTime = Properties.Settings.Default.DefaultDisplayTime;
                        }
                        if (currentAlert.ClassName == null)
                        {
                            currentAlert.ClassName = Properties.Settings.Default.DefaultNotificationClass;
                        }

                        currentAlert.SnarlNotificationId = Notifier.EZNotify(currentAlert.ClassName, currentAlert.Title, currentAlert.Text, 10, currentAlert.Icon);

                        if (currentAlert.SnarlNotificationId != 0)
                        {
                            currentAlert.AlreadyShown = true;
                            if (Properties.Settings.Default.LastIdShown < currentAlert.Id)
                            {
                                Properties.Settings.Default.LastIdShown = currentAlert.Id;
                                Properties.Settings.Default.Save();
                            }
                            Requests.Add(currentAlert);
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                if (ShowDebug)
                {
                    Notifier.EZNotify("Debug", "XML Parsing error", exp.Message, 10, Properties.Settings.Default.AppIcon);
                }
            }
            UpdateTimer.Start();
        }
コード例 #3
0
        public void FetchNotifications()
        {
            string rawData = "";

            if (Properties.Settings.Default.UrlOrUnc.ToLower().StartsWith("http"))
            {
                rawData = GetHttpContent(Properties.Settings.Default.UrlOrUnc);
            }
            else
            {
                if (File.Exists(Properties.Settings.Default.UrlOrUnc))
                {
                    rawData = File.ReadAllText(Properties.Settings.Default.UrlOrUnc);
                }
                else
                {
                    if (ShowDebug)
                    {
                        Notifier.EZNotify("Debug", "File not found", Properties.Settings.Default.UrlOrUnc, 10, Properties.Settings.Default.AppIcon);
                    }
                    UpdateTimer.Start();
                    return;
                }
            }
            if (rawData == "")
            {
                if (ShowDebug)
                {
                    Notifier.EZNotify("Debug", "Empty Response", Properties.Settings.Default.UrlOrUnc, 10, Properties.Settings.Default.AppIcon);
                }
                UpdateTimer.Start();
                return;
            }
            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.LoadXml(rawData);
            }
            catch (Exception exp)
            {
                if (ShowDebug)
                {
                    Notifier.EZNotify("Debug", "XML general parsing error", exp.Message, 10, Properties.Settings.Default.AppIcon);
                }
                UpdateTimer.Start();
                return;
            }

            if (xmlDoc.DocumentElement.Name != "alerts")
            {
                if (ShowDebug)
                {
                    Notifier.EZNotify("Debug", "Invalid XML", "XML open tag is not \"alerts\"", 10, Properties.Settings.Default.AppIcon);
                }
                UpdateTimer.Start();
                return;
            }

            try
            {
                bool alreadyShown = false;
                foreach (XmlNode alert in xmlDoc.GetElementsByTagName("alert"))
                {
                    alreadyShown = false;
                    IncomingRequest currentAlert = new IncomingRequest();
                    foreach (XmlNode childNode in alert.ChildNodes)
                    {
                        if (alreadyShown)
                        {
                            break;
                        }
                        switch (childNode.Name.ToLower())
                        {
                        case "id":
                            currentAlert.Id = Convert.ToInt64(childNode.InnerText);
                            if (currentAlert.Id > Properties.Settings.Default.LastIdShown)
                            {
                                if (Requests.Where(r => r.Id == currentAlert.Id).Count() > 0)
                                {
                                    alreadyShown = true;
                                    continue;
                                }
                            }
                            else
                            {
                                alreadyShown = true;
                                continue;
                            }

                            break;

                        case "title":
                            currentAlert.Title = childNode.InnerText;
                            break;

                        case "text":
                            currentAlert.Text = childNode.InnerText;
                            break;

                        case "icon":
                            currentAlert.Icon = childNode.InnerText;
                            break;

                        case "displaytime":
                            currentAlert.DisplayTime = Convert.ToInt32(childNode.InnerXml);
                            break;

                        case "app":
                            currentAlert.AppName = childNode.InnerText;
                            break;

                        case "class":
                            currentAlert.ClassName = childNode.InnerText;
                            break;

                        case "leftclickurl":
                            currentAlert.LeftClickUrl = childNode.InnerText;
                            break;

                        case "middleclickurl":
                            currentAlert.MiddleClickUrl = childNode.InnerText;
                            break;

                        case "rightclickurl":
                            currentAlert.RightClickUrl = childNode.InnerText;
                            break;

                        default:
                            break;
                        }
                    }
                    if (!alreadyShown && SnarlConnector.GetSnarlWindow() != IntPtr.Zero)
                    {
                        if (currentAlert.Icon == null)
                        {
                            currentAlert.Icon = Properties.Settings.Default.DefaultNotificationIcon;
                        }
                        if (currentAlert.DisplayTime == null)
                        {
                            currentAlert.DisplayTime = Properties.Settings.Default.DefaultDisplayTime;
                        }
                        if (currentAlert.ClassName == null)
                        {
                            currentAlert.ClassName = Properties.Settings.Default.DefaultNotificationClass;
                        }

                        currentAlert.SnarlNotificationId = Notifier.EZNotify(currentAlert.ClassName, currentAlert.Title, currentAlert.Text, 10, currentAlert.Icon);

                        if (currentAlert.SnarlNotificationId != 0)
                        {
                            currentAlert.AlreadyShown = true;
                            if (Properties.Settings.Default.LastIdShown < currentAlert.Id)
                            {
                                Properties.Settings.Default.LastIdShown = currentAlert.Id;
                                Properties.Settings.Default.Save();
                            }
                            Requests.Add(currentAlert);
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                if (ShowDebug)
                {
                    Notifier.EZNotify("Debug", "XML Parsing error", exp.Message, 10, Properties.Settings.Default.AppIcon);
                }
            }
            UpdateTimer.Start();
        }