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)); }
public override bool Equals(object obj) { RecentItem item = obj as RecentItem; if (item == null) { return(false); } return(uri == item.uri); }
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); }
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); } } }
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); }
public bool RemoveItem(RecentItem item) { return item != null && RemoveItem (item.Uri); }
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); } } }
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; }
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); }
public bool RemoveItem(RecentItem item) { return(item != null && RemoveItem(item.Uri)); }