public void AddLastFile (string name, string project) { RecentItem recentItem = new RecentItem (RecentFileStorage.ToUri (name), DesktopService.GetMimeTypeForUri (name), fileGroup); recentItem.Private = project != null ? string.Format ("{0} [{1}]", Path.GetFileName (name), project) : Path.GetFileName (name); recentFiles.AddWithLimit (recentItem, fileGroup, ItemLimit); OnRecentFileChange(); }
static List <RecentItem> ReadStore(FileStream file) { var result = new List <RecentItem> (); if (file.Length == 0) { return(result); } try { using (var reader = XmlReader.Create(file, new XmlReaderSettings { CloseInput = false })) { while (reader.Read()) { if (reader.IsStartElement() && reader.LocalName == RecentItem.Node) { result.Add(RecentItem.Read(reader)); } } } } catch (Exception e) { LoggingService.LogError("Error while reading recent file store.", e); } return(result); }
public void AddLastProject(string name, string projectName) { RecentItem recentItem = new RecentItem(RecentFileStorage.ToUri(name), DesktopService.GetMimeTypeForUri(name), projectGroup); recentItem.Private = projectName; recentFiles.AddWithLimit(recentItem, projectGroup, ItemLimit); OnRecentProjectChange(); }
public void AddLastFile(string name, string project) { RecentItem recentItem = new RecentItem(RecentFileStorage.ToUri(name), DesktopService.GetMimeTypeForUri(name), fileGroup); recentItem.Private = project != null?string.Format("{0} [{1}]", Path.GetFileName(name), project) : Path.GetFileName(name); recentFiles.AddWithLimit(recentItem, fileGroup, ItemLimit); OnRecentFileChange(); }
public void AddWithLimit(RecentItem item, string group, int limit) { ModifyStore(list => { RemoveMatches(list, i => i.Uri == item.Uri); list.Add(item); CheckLimit(list, group, limit); return(true); }); }
public override bool Equals(object obj) { RecentItem item = obj as RecentItem; if (item == null) { return(false); } return(uri == item.uri); }
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)); }
void Add(string grp, string fileName, string displayName) { var mime = 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); } } }
void Add(string grp, string fileName, string displayName) { var mime = DesktopService.GetMimeTypeForUri(fileName); try { var uri = RecentFileStorage.ToUri(fileName); var recentItem = new RecentItem(uri, mime, grp) { Private = displayName }; recentFiles.AddWithLimit(recentItem, grp, ItemLimit); } catch (Exception e) { LoggingService.LogError("Failed to add item to recent files list.", e); } }
List <RecentItem> ReadStore(int numberOfTry) { //Debug.Assert (IsLocked); List <RecentItem> result = new List <RecentItem> (); if (!File.Exists(RecentFileStorage.RecentFileFullPath)) { return(result); } XmlTextReader reader = new XmlTextReader(RecentFileStorage.RecentFileFullPath); 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 void AddWithLimit(RecentItem item, string group, int limit) { lock (writerLock) { /*ObtainLock (); * try {*/ RemoveItem(item.Uri); List <RecentItem> store = ReadStore(0); if (store != null) { store.Add(item); WriteStore(store); CheckLimit(group, limit); } /*} finally { * ReleaseLock (); * }*/ } }
static List <RecentItem> ReadStore(FileStream file) { var result = new List <RecentItem> (); if (file.Length == 0) { return(result); } using (var reader = XmlReader.Create(file, new XmlReaderSettings { CloseInput = false })) { while (reader.Read()) { if (reader.IsStartElement() && reader.LocalName == RecentItem.Node) { result.Add(RecentItem.Read(reader)); } } } return(result); }
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; }
public void RemoveItem (RecentItem item) { if (item != null) RemoveItem (item.Uri); }
public void AddLastProject (string name, string projectName) { RecentItem recentItem = new RecentItem (RecentFileStorage.ToUri (name), DesktopService.GetMimeTypeForUri (name), projectGroup); recentItem.Private = projectName; recentFiles.AddWithLimit (recentItem, projectGroup, ItemLimit); OnRecentProjectChange(); }
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 bool RemoveItem (RecentItem item) { return item != null && RemoveItem (item.Uri); }
void Add (string grp, string fileName, string displayName) { var mime = 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)); }
void Add (string grp, string fileName, string displayName) { var mime = DesktopService.GetMimeTypeForUri (fileName); System.Threading.ThreadPool.QueueUserWorkItem (_ => { try { var uri = RecentFileStorage.ToUri (fileName); var recentItem = new RecentItem (uri, mime, grp) { Private = displayName }; recentFiles.AddWithLimit (recentItem, grp, ItemLimit); } catch (Exception e) { LoggingService.LogError ("Failed to add item to recent files list.", e); } }); }
public void AddWithLimit (RecentItem item, string group, int limit) { lock (writerLock) { /*ObtainLock (); try {*/ RemoveItem (item.Uri); List<RecentItem> store = ReadStore (0); if (store != null) { store.Add (item); WriteStore (store); CheckLimit (group, limit); } /*} finally { ReleaseLock (); }*/ } }