public IEnumerable <Manifest> GetManifests(int?limit = null, bool includePostponed = true, DateTime?manifestsLastWriteTimeOlderThan = null) { var manifests = new List <Manifest>(); using (IsolatedStorageDirectory dir = GetStorageDirectory()) { List <IsolatedStorageFileInfo> files = GetManifestsSortedByOldestWriteFirst(dir, manifestsLastWriteTimeOlderThan); foreach (IsolatedStorageFileInfo file in files) { try { var manifest = dir.ReadFile <Manifest>(file.FileName); if (manifest != null && (includePostponed || manifest.ShouldRetry())) { manifests.Add(manifest); } if (limit.HasValue && manifests.Count == limit.Value) { break; } } catch (Exception ex) { LogAccessor.Log.FormattedError(typeof(IsolatedStorageQueueStore), ex, "Error reading manifest file '{0}' from isolated storage", file); } } } return(manifests); }
internal static LocalConfigurationDictionary Create(string storeId, IExceptionlessLogAccessor logAccessor) { var localStorage = new LocalConfigurationDictionary { LogAccessor = logAccessor, StoreId = storeId, CurrentConfigurationVersion = 0, NextConfigurationUpdate = DateTime.MinValue }; try { using (new SingleGlobalInstance(String.Concat(storeId, FileName).GetHashCode().ToString(), 500)) { // retry loop for (int retry = 0; retry < 2; retry++) { using (var dir = new IsolatedStorageDirectory(storeId)) { try { if (!dir.FileExists(FileName)) { break; } var config = dir.ReadFile <LocalConfigurationDictionary>(FileName); foreach (string key in config.Keys) { localStorage[key] = config[key]; } localStorage.IsDirty = false; break; } catch (Exception ex) { // File is being used by another process or thread or the file does not exist. logAccessor.Log.FormattedError(typeof(LocalConfigurationDictionary), ex, "Unable to read data from local storage: {0}", ex.Message); Thread.Sleep(50); } } // using stream } // retry // TODO: Why are we doing this even if the configuration couldn't be read or didn't exist?? localStorage.LoadDefaults(); localStorage.Save(); return(localStorage); } // lock } catch (Exception ex) { logAccessor.Log.Error(ex, "An error occurred while saving local configuration"); localStorage.LoadDefaults(); return(localStorage); } }
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); }
public Error GetError(string id) { if (String.IsNullOrEmpty(id)) { throw new ArgumentException("The id must be specified.", "id"); } Error error = null; using (IsolatedStorageDirectory dir = GetStorageDirectory()) { string errorFilename = GetErrorFilename(id); try { error = dir.ReadFile <Error>(errorFilename); } catch (Exception ex) { LogAccessor.Log.FormattedError(typeof(FolderQueueStore), ex, "Problem deserializing error '{0}' from isolated storage", errorFilename); } } return(error); }
private static void ReadSavedConfiguration(ClientConfiguration configuration, IExceptionlessLogAccessor logAccessor) { try { for (int retry = 0; retry < 2; retry++) { using (var dir = new IsolatedStorageDirectory(configuration.StoreId)) { try { if (!dir.FileExists(ClientConfiguration.CachedServerConfigFile)) { return; } var savedConfig = dir.ReadFile <Dictionary <string, string> >(ClientConfiguration.CachedServerConfigFile); if (savedConfig == null) { return; } foreach (string key in savedConfig.Keys) { configuration[key] = savedConfig[key]; } return; } catch (JsonReaderException) { // try deleting the invalid config file so we don't keep trying to read it. try { dir.DeleteFile(ClientConfiguration.CachedServerConfigFile); } catch {} } catch (Exception ex) { // File is being used by another process or thread or the file does not exist. logAccessor.Log.FormattedError(typeof(ClientConfigurationReader), ex, "Error while reading settings from the configuration file: {0}", ex.Message); Thread.Sleep(50); } } // storage } // retry } catch (Exception ex) { logAccessor.Log.FormattedError(typeof(ClientConfigurationReader), ex, "Error while reading settings from the configuration file: {0}", ex.Message); } }
private static void ReadSavedConfiguration(ClientConfiguration configuration, IExceptionlessLogAccessor logAccessor) { try { for (int retry = 0; retry < 2; retry++) { using (var dir = new IsolatedStorageDirectory(configuration.StoreId)) { try { if (!dir.FileExists(ClientConfiguration.CachedServerConfigFile)) return; var savedConfig = dir.ReadFile<Dictionary<string, string>>(ClientConfiguration.CachedServerConfigFile); if (savedConfig == null) return; foreach (string key in savedConfig.Keys) configuration[key] = savedConfig[key]; return; } catch (JsonReaderException) { // try deleting the invalid config file so we don't keep trying to read it. try { dir.DeleteFile(ClientConfiguration.CachedServerConfigFile); } catch {} } catch (Exception ex) { // File is being used by another process or thread or the file does not exist. logAccessor.Log.FormattedError(typeof(ClientConfigurationReader), ex, "Error while reading settings from the configuration file: {0}", ex.Message); Thread.Sleep(50); } } // storage } // retry } catch (Exception ex) { logAccessor.Log.FormattedError(typeof(ClientConfigurationReader), ex, "Error while reading settings from the configuration file: {0}", ex.Message); } }