Exemple #1
0
        public int CompareTo(object o)
        {
            RecentItem item = o as RecentItem;

            if (item == null)
            {
                throw new ArgumentException("Can only compare items of " + typeof(RecentItem) + " item was: " + o);
            }
            return(item.Timestamp.CompareTo(this.Timestamp));
        }
Exemple #2
0
        public override bool Equals(object obj)
        {
            RecentItem item = obj as RecentItem;

            if (item == null)
            {
                return(false);
            }
            return(uri == item.uri);
        }
Exemple #3
0
        void Add(string grp, string fileName, string displayName)
        {
            var mime       = "text/plain";      //DesktopService.GetMimeTypeForUri (fileName);
            var uri        = RecentFileStorage.ToUri(fileName);
            var recentItem = new RecentItem(uri, mime, grp)
            {
                Private = displayName
            };

            recentFiles.AddWithLimit(recentItem, grp, ItemLimit);
        }
Exemple #4
0
 public void AddWithLimit(RecentItem item, string group, int limit)
 {
     lock (writerLock) {
         RemoveItem(item.Uri);
         List <RecentItem> store = ReadStore(0);
         if (store != null)
         {
             store.Add(item);
             WriteStore(store);
             CheckLimit(group, limit);
         }
     }
 }
Exemple #5
0
        List <RecentItem> ReadStore(int numberOfTry)
        {
            List <RecentItem> result = new List <RecentItem> ();

            if (!File.Exists(filePath))
            {
                return(result);
            }
            var reader = new XmlTextReader(filePath);

            try {
                while (true)
                {
                    bool read = false;
                    try {
                        // seems to crash on empty files ?
                        read = reader.Read();
                    } catch (Exception) {
                        read = false;
                    }
                    if (!read)
                    {
                        break;
                    }
                    if (reader.IsStartElement() && reader.LocalName == RecentItem.Node)
                    {
                        result.Add(RecentItem.Read(reader));
                    }
                }
            }  catch {           // (Exception e) {
                //MonoDevelop.Core.LoggingService.LogError ("Exception while reading the store", e);
                if (numberOfTry < MAX_TRIES)
                {
                    Thread.Sleep(200);
                    return(ReadStore(numberOfTry + 1));
                }
                return(null);
            } finally {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            return(result);
        }
Exemple #6
0
 public bool RemoveItem(RecentItem item)
 {
     return item != null && RemoveItem (item.Uri);
 }
Exemple #7
0
 public void AddWithLimit(RecentItem item, string group, int limit)
 {
     lock (writerLock) {
         RemoveItem (item.Uri);
         List<RecentItem> store = ReadStore (0);
         if (store != null) {
             store.Add (item);
             WriteStore (store);
             CheckLimit (group, limit);
         }
     }
 }
Exemple #8
0
 public static RecentItem Read(XmlReader reader)
 {
     Debug.Assert (reader.LocalName == Node);
     RecentItem result = new RecentItem ();
     bool readGroup = false;
     while (reader.Read ()) {
         switch (reader.NodeType) {
         case XmlNodeType.EndElement:
             if (reader.LocalName == GroupsNode) {
                 readGroup = false;
                 break;
             }
             if (reader.LocalName == Node)
                 return result;
             throw new XmlException ("Found unknown end element:" + reader.LocalName);
         case XmlNodeType.Element:
             if (readGroup) {
                 result.AddGroup (reader.ReadElementString ());
                 break;
             }
             switch (reader.LocalName) {
             case "Uri":
             case UriNode:
                 result.uri = reader.ReadElementString ();
                 break;
             case "MimeType":
             case MimeTypeNode:
                 result.mimeType = reader.ReadElementString ();
                 break;
             case TimestampNode:
                 result.timestamp = ToDateTime (Int32.Parse (reader.ReadElementString ()));
                 break;
             case PrivateNode:
                 result.privateData = reader.ReadElementString ();
                 break;
             case GroupsNode:
                 readGroup = true;
                 break;
             default:
                 throw new XmlException ("Found unknown start element:" + reader.LocalName);
             }
             break;
         }
     }
     return null;
 }
Exemple #9
0
 void Add(string grp, string fileName, string displayName)
 {
     var mime = "text/plain";//DesktopService.GetMimeTypeForUri (fileName);
     var uri = RecentFileStorage.ToUri (fileName);
     var recentItem = new RecentItem (uri, mime, grp) { Private = displayName };
     recentFiles.AddWithLimit (recentItem, grp, ItemLimit);
 }
Exemple #10
0
 public bool RemoveItem(RecentItem item)
 {
     return(item != null && RemoveItem(item.Uri));
 }