public int Cleanup(DateTime target)
        {
            int counter = 0;

            using (IsolatedStorageDirectory dir = GetStorageDirectory()) {
                // first delete all files older than the target date
                IEnumerable <IsolatedStorageFileInfo> files = dir.GetFilesWithTimes().Where(m => m.CreationTime < target && !m.FileName.EndsWith(".config", StringComparison.OrdinalIgnoreCase));

                foreach (IsolatedStorageFileInfo file in files)
                {
                    try {
                        if (dir.DeleteFile(file.FileName))
                        {
                            counter++;
                        }
                    } catch (Exception ex) {
                        LogAccessor.Log.FormattedError(typeof(IsolatedStorageQueueStore), ex, "Error deleting file '{0}' from isolated storage", file);
                    }
                }

                // check to see if we have an excessive amount of manifests
                List <IsolatedStorageFileInfo> manifests = GetManifestsSortedByNewestCreateFirst(dir);
                if (manifests.Count <= 250)
                {
                    return(counter);
                }

                // delete all but the newest 250
                foreach (IsolatedStorageFileInfo file in manifests.Skip(250))
                {
                    try {
                        var manifest = dir.ReadFile <Manifest>(file.FileName);
                        if (manifest == null || !manifest.CanDiscard)
                        {
                            continue;
                        }

                        Delete(dir, manifest.Id);
                        counter++;
                    } catch (Exception ex) {
                        LogAccessor.Log.FormattedError(typeof(IsolatedStorageQueueStore), ex, "Error deleting manifest file '{0}' from isolated storage", file);
                    }
                }
            }

            return(counter);
        }
 private List <IsolatedStorageFileInfo> GetManifestsSortedByNewestCreateFirst(IsolatedStorageDirectory dir)
 {
     return(dir.GetFilesWithTimes("*" + QueueManager.MANIFEST_EXTENSION).OrderByDescending(m => m.CreationTime).ToList());
 }
        private List <IsolatedStorageFileInfo> GetManifestsSortedByOldestWriteFirst(IsolatedStorageDirectory dir, DateTime?manifestsLastWriteTimeOlderThan = null)
        {
            DateTime lastWriteTimeFilter = manifestsLastWriteTimeOlderThan.HasValue ? manifestsLastWriteTimeOlderThan.Value : DateTime.Now;

            return(dir.GetFilesWithTimes("*" + QueueManager.MANIFEST_EXTENSION).Where(m => m.LastWriteTime.DateTime <= lastWriteTimeFilter).OrderBy(m => m.LastWriteTime).ToList());
        }
 private List<IsolatedStorageFileInfo> GetManifestsSortedByNewestCreateFirst(IsolatedStorageDirectory dir) {
     return dir.GetFilesWithTimes("*" + QueueManager.MANIFEST_EXTENSION).OrderByDescending(m => m.CreationTime).ToList();
 }
 private List<IsolatedStorageFileInfo> GetManifestsSortedByOldestWriteFirst(IsolatedStorageDirectory dir, DateTime? manifestsLastWriteTimeOlderThan = null) {
     DateTime lastWriteTimeFilter = manifestsLastWriteTimeOlderThan.HasValue ? manifestsLastWriteTimeOlderThan.Value : DateTime.Now;
     return dir.GetFilesWithTimes("*" + QueueManager.MANIFEST_EXTENSION).Where(m => m.LastWriteTime.DateTime <= lastWriteTimeFilter).OrderBy(m => m.LastWriteTime).ToList();
 }