public int CompareTo(object obj)
        {
            PastNotification pn = obj as PastNotification;

            if (obj == null || pn == null)
            {
                return(-1);
            }
            return(-this.Timestamp.CompareTo(pn.Timestamp));
        }
Exemple #2
0
        /// <summary>
        /// Gets the specified from the cache
        /// </summary>
        /// <param name="applicationName">The application that owns the resource</param>
        /// <param name="resourceID">The resource ID</param>
        /// <returns>
        /// <see cref="Image"/> if the resource exists in the cache, <c>null</c> otherwise
        /// </returns>
        public static Image GetImage(PastNotification pn)
        {
            Image image = null;

            if (pn != null && pn.HasImage)
            {
                try
                {
                    image = Growl.CoreLibrary.ImageConverter.ImageFromUrl(pn.ImageFile);
                }
                catch
                {
                }
            }
            return(image);
        }
Exemple #3
0
        internal void ReloadPastNotifications()
        {
            if (this.pastNotifications == null)
            {
                this.pastNotifications = new List <PastNotification>();
            }
            this.pastNotifications.Clear();

            DateTime cutoffTime = DateTime.Now.Date.AddDays(-Properties.Settings.Default.HistoryDaysToSave);

            System.IO.DirectoryInfo d     = new System.IO.DirectoryInfo(HistoryFolder);
            System.IO.FileInfo[]    files = d.GetFiles("*.notification", System.IO.SearchOption.AllDirectories);

            foreach (System.IO.FileInfo file in files)
            {
                if (file.CreationTime < cutoffTime)
                {
                    file.Delete();
                    string imgFileName = file.FullName.Replace(".notification", ".img");
                    File.Delete(imgFileName);
                }
                else
                {
                    string data = System.IO.File.ReadAllText(file.FullName);
                    try
                    {
                        object obj = Serialization.DeserializeObject(data);
                        if (obj != null)
                        {
                            try
                            {
                                PastNotification pn = (PastNotification)obj;
                                this.pastNotifications.Add(pn);
                            }
                            catch
                            {
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Utility.WriteDebugInfo(String.Format("Deserialization of history item failed. {0} :: {1} :: {2}", ex.Message, ex.StackTrace, data));
                    }
                    data = null;
                }
            }
        }
Exemple #4
0
        public static PastNotification Save(Growl.DisplayStyle.Notification notification, string requestID, DateTime timestamp)
        {
            Growl.DisplayStyle.NotificationLite notificationLite = Growl.DisplayStyle.NotificationLite.Clone(notification);
            string path = Growl.CoreLibrary.PathUtility.Combine(historyFolder, Growl.CoreLibrary.PathUtility.GetSafeFolderName(notificationLite.ApplicationName));

            Growl.CoreLibrary.PathUtility.EnsureDirectoryExists(path);

            // save image data
            string imageFile = null;

            if (notification.Image != null && notification.Image.IsSet)
            {
                System.Drawing.Image image = (System.Drawing.Image)notification.Image;
                using (image)
                {
                    System.Drawing.Image thumbnail = GenerateThumbnail(image, 48, 48);
                    if (thumbnail != null)
                    {
                        using (thumbnail)
                        {
                            string imagefilename = String.Format(@"{0}.img", requestID);
                            imageFile = Growl.CoreLibrary.PathUtility.Combine(path, imagefilename);

                            thumbnail.Save(imageFile);
                        }
                    }
                }
            }

            PastNotification pn = new PastNotification(notificationLite, timestamp, imageFile);

            // save text data
            string filename = String.Format(@"{0}.notification", requestID);
            string filepath = Growl.CoreLibrary.PathUtility.Combine(path, filename);

            System.IO.StreamWriter w = System.IO.File.CreateText(filepath);
            using (w)
            {
                string data = Serialization.SerializeObject(pn);
                w.Write(data);
                data = null;
            }

            return(pn);
        }
Exemple #5
0
        public NotificationPastEventArgs(PastNotification pn)

        {
            this.pn = pn;
        }