public void UpdateManifest(Manifest manifest) { if (manifest == null) { throw new ArgumentNullException("manifest"); } try { string manifestFilename = GetManifestFilename(manifest.Id); using (IsolatedStorageDirectory dir = GetStorageDirectory()) dir.WriteFile(manifestFilename, manifest); } catch (Exception ex) { LogAccessor.Log.FormattedError(typeof(IsolatedStorageQueueStore), ex, "Problem updating manifest '{0}' in isolated storage", manifest.Id); throw; } }
public void ReadCorruptedConfiguration() { Assert.False(String.IsNullOrEmpty(DEFAULT_STORE)); var client = new ExceptionlessClient(); using (var dir = new IsolatedStorageDirectory(DEFAULT_STORE)) dir.WriteFile(CONFIG_FILENAME, "<blah/>>>"); Exception exception = Record.Exception(() => { client.IsConfigurationUpdateNeeded(); LocalConfigurationDictionary localConfiguration = LocalConfigurationDictionary.Create(DEFAULT_STORE, client); Assert.NotNull(localConfiguration); }); Assert.Null(exception); }
public bool Save() { if (!IsDirty) { return(true); } try { using (new SingleGlobalInstance(String.Concat(StoreId, FileName).GetHashCode().ToString(), 500)) { if (!IsDirty) { return(true); } LogAccessor.Log.Trace("Saving local configuration.", "LocalConfigurationDictionary"); // retry loop for (int retry = 0; retry < 2; retry++) { using (var dir = new IsolatedStorageDirectory(StoreId)) { try { dir.WriteFile(FileName, this); // Only mark configuration as not dirty if everything was saved. IsDirty = false; LogAccessor.Log.Trace("Done saving local configuration.", "LocalConfigurationDictionary"); return(true); } catch (IsolatedStorageException ex) { // File is being used by another process or thread or the file does not exist. LogAccessor.Log.FormattedError(ex, "Unable to save data to local storage: {0}", ex.Message); Thread.Sleep(50); } catch (IOException ex) { // File is being used by another process or thread or the file does not exist. LogAccessor.Log.FormattedError(ex, "Unable to save data to local storage: {0}", ex.Message); Thread.Sleep(50); } } // using } // retry } } catch (Exception ex) { LogAccessor.Log.Error(ex, "An error occurred while saving local configuration"); } return(false); }
internal static void ProcessServerConfigResponse(IConfigurationAndLogAccessor accessors, ConfigurationDictionary serverConfig, string storeId) { if (serverConfig == null) { return; } try { // only allow one save at a time using (new SingleGlobalInstance(String.Concat(storeId, CachedServerConfigFile).GetHashCode().ToString(), 500)) { // retry loop for (int retry = 0; retry < 2; retry++) { using (var dir = new IsolatedStorageDirectory(storeId)) { try { dir.WriteFile(CachedServerConfigFile, serverConfig); break; } catch (Exception ex) { // File is being used by another process or thread or the file does not exist. accessors.Log.FormattedError(ex, "Unable to save server config to local storage: {0}", ex.Message); Thread.Sleep(50); } } } } } catch (Exception ex) { accessors.Log.Error(ex, "An error occurred while saving client configuration"); } // apply the config values from the server to the current client configuration foreach (string k in serverConfig.Keys) { accessors.Configuration[k] = serverConfig[k]; } // if a set of data exclusions are not sent down, then it means that there aren't any exclusions. if (!serverConfig.ContainsKey("@@DataExclusions")) { accessors.Configuration["@@DataExclusions"] = String.Empty; } }
internal static void ProcessServerConfigResponse(IConfigurationAndLogAccessor accessors, ConfigurationDictionary serverConfig, string storeId) { if (serverConfig == null) return; try { // only allow one save at a time using (new SingleGlobalInstance(String.Concat(storeId, CachedServerConfigFile).GetHashCode().ToString(), 500)) { // retry loop for (int retry = 0; retry < 2; retry++) { using (var dir = new IsolatedStorageDirectory(storeId)) { try { dir.WriteFile(CachedServerConfigFile, serverConfig); break; } catch (Exception ex) { // File is being used by another process or thread or the file does not exist. accessors.Log.FormattedError(ex, "Unable to save server config to local storage: {0}", ex.Message); Thread.Sleep(50); } } } } } catch (Exception ex) { accessors.Log.Error(ex, "An error occurred while saving client configuration"); } // apply the config values from the server to the current client configuration foreach (string k in serverConfig.Keys) accessors.Configuration[k] = serverConfig[k]; // if a set of data exclusions are not sent down, then it means that there aren't any exclusions. if (!serverConfig.ContainsKey("@@DataExclusions")) accessors.Configuration["@@DataExclusions"] = String.Empty; }
public void CanHandleInvalidCachedServerConfig() { using (var dir = new IsolatedStorageDirectory(DEFAULT_STORE)) { dir.WriteFile(CONFIG_FILENAME, "sadf<sdf>"); Assert.True(dir.FileExists(CONFIG_FILENAME)); var client = new ExceptionlessClient(); ClientConfiguration config = ClientConfiguration.Create(client); // file should get deleted if it's invalid Assert.False(dir.FileExists(CONFIG_FILENAME)); Assert.NotNull(config); Assert.True(config.ContainsKey("AttributeOnly")); Assert.Equal(config["AttributeOnly"], "Attribute"); Assert.True(config.ContainsKey("UserNamespaces")); Assert.Equal(config["UserNamespaces"], "Exceptionless,FromConfig"); Assert.True(config.ContainsKey("ConfigAndAttribute")); Assert.Equal(config["ConfigAndAttribute"], "Config"); Assert.True(config.ContainsKey("AppConfigOnly")); Assert.Equal(config["AppConfigOnly"], "Config"); } }