public void CanEnableLoggingFromConfig()
        {
            var client = new ExceptionlessClient();
            ClientConfiguration config = ClientConfiguration.Create(client);
            string logPath             = config.LogPath;

            Assert.NotNull(config);

            Assert.True(config.EnableLogging);
            //Assert.Equal(logPath, config.LogPath); // TODO: Should this even be set to a value?? It's Isolated storage?
            Assert.NotNull(client.Log);
            Assert.NotNull(client);

            Assert.Equal(typeof(SafeExceptionlessLog), client.Log.GetType());

            client.ProcessQueue();
            client.Shutdown();

            var dir = new IsolatedStorageDirectory(DEFAULT_STORE);

            Assert.True(dir.FileExists(logPath));
            string content = dir.ReadFileAsString(logPath);

            Assert.True(content.Length > 10);
        }
        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);
        }
        public bool VerifyStoreIsUsable()
        {
            if (_verified.HasValue)
            {
                return(_verified.Value);
            }

            _verified = false;

            try {
                if (String.IsNullOrEmpty(SubDirectory))
                {
                    return(false);
                }

                string filename = Path.GetRandomFileName();

                using (IsolatedStorageDirectory dir = GetStorageDirectory()) {
                    dir.WriteFile(filename, "test");
                    dir.DeleteFile(filename);
                }
            } catch (Exception ex) {
                LogAccessor.Log.FormattedError(typeof(IsolatedStorageQueueStore), "Problem verifing isolated storage store: {0}", ex.Message);
                return(false);
            }

            _verified = true;
            return(true);
        }
        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");
            }
        }
Exemplo n.º 5
0
 private void DeleteConfig(string storeId = DEFAULT_STORE)
 {
     using (var dir = new IsolatedStorageDirectory(storeId)) {
         if (dir.FileExists(CONFIG_FILENAME))
         {
             dir.DeleteFile(CONFIG_FILENAME);
         }
     }
 }
Exemplo n.º 6
0
        public void CreateNewConfiguration() {
            DeleteConfig();

            var client = new ExceptionlessClient();
            LocalConfigurationDictionary localConfiguration = LocalConfigurationDictionary.Create(DEFAULT_STORE, client);
            Assert.NotNull(localConfiguration);
            Assert.False(localConfiguration.IsDirty);
            Assert.NotEqual(Guid.Empty, localConfiguration.InstallIdentifier);

            using (var store = new IsolatedStorageDirectory(DEFAULT_STORE)) {
                Assert.True(store.FileExists(CONFIG_FILENAME));
                Console.WriteLine(store.ReadFileAsString(CONFIG_FILENAME));
            }
        }
        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);
            }
        }
Exemplo n.º 8
0
        public void CreateNewConfiguration()
        {
            DeleteConfig();

            var client = new ExceptionlessClient();
            LocalConfigurationDictionary localConfiguration = LocalConfigurationDictionary.Create(DEFAULT_STORE, client);

            Assert.NotNull(localConfiguration);
            Assert.False(localConfiguration.IsDirty);
            Assert.NotEqual(Guid.Empty, localConfiguration.InstallIdentifier);

            using (var store = new IsolatedStorageDirectory(DEFAULT_STORE)) {
                Assert.True(store.FileExists(CONFIG_FILENAME));
                Console.WriteLine(store.ReadFileAsString(CONFIG_FILENAME));
            }
        }
        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(FolderQueueStore), ex, "Problem updating manifest '{0}' in isolated storage", manifest.Id);
                throw;
            }
        }
        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);
        }
Exemplo n.º 11
0
        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);
        }
        private void Delete(IsolatedStorageDirectory dir, string id)
        {
            // retry delete up to 3 times
            for (int retry = 0; retry < 3; retry++)
            {
                try {
                    string manifestFilename = GetManifestFilename(id);
                    dir.DeleteFile(manifestFilename);

                    string errorFilename = GetErrorFilename(id);
                    dir.DeleteFile(errorFilename);

                    return;
                } catch (IOException ex) {
                    LogAccessor.Log.FormattedError(typeof(FolderQueueStore), ex, "Problem deleting id '{0}' from isolated storage", id);
                    Thread.Sleep(50);
                }
            }
        }
        public void Enqueue(Error error)
        {
            if (error == null)
            {
                throw new ArgumentNullException("error");
            }

            try {
                using (IsolatedStorageDirectory dir = GetStorageDirectory()) {
                    string   manifestFilename = GetManifestFilename(error.Id);
                    string   errorFilename    = GetErrorFilename(error.Id);
                    Manifest manifest         = Manifest.FromError(error);
                    dir.WriteFile(manifestFilename, manifest);
                    dir.WriteFile(errorFilename, error);
                }
            } catch (Exception ex) {
                LogAccessor.Log.FormattedError(typeof(FolderQueueStore), ex, "Problem enqueuing error '{0}' to isolated storage", error.Id);
                throw;
            }
        }
        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);
        }
Exemplo n.º 16
0
        public void MultiThreadedSaveLocalConfiguration()
        {
            DeleteConfig();
            var client = new ExceptionlessClient();

            Parallel.For(0, 200, i => {
                Exception exception = Record.Exception(() => {
                    LocalConfigurationDictionary localConfiguration = LocalConfigurationDictionary.Create(DEFAULT_STORE, client);
                    Assert.NotNull(localConfiguration);

                    localConfiguration.IsDirty            = true;
                    localConfiguration["ExpireTokenDate"] = DateTime.Now.AddMinutes(i).ToString();
                    localConfiguration.StartCount++;
                    Task.Factory.StartNew(() => localConfiguration["ExpireTokenDate"] = DateTime.Now.AddMinutes(i + 1).ToString());
                    localConfiguration.Save();

                    Assert.NotNull(LocalConfigurationDictionary.Create(DEFAULT_STORE, client));

                    localConfiguration.IsDirty            = true;
                    localConfiguration["ExpireTokenDate"] = DateTime.Now.AddMinutes(i).ToString();
                    Task.Factory.StartNew(() => localConfiguration.Remove("ExpireTokenDate"));
                    localConfiguration.Save();

                    Assert.NotNull(LocalConfigurationDictionary.Create(DEFAULT_STORE, client));

                    localConfiguration.StartCount++;
                    localConfiguration.IsDirty = true;
                    Assert.True(localConfiguration.Save(), "Saved");

                    Assert.NotNull(LocalConfigurationDictionary.Create(DEFAULT_STORE, client));
                });

                Assert.Null(exception);
            });

            using (var store = new IsolatedStorageDirectory(DEFAULT_STORE)) {
                Console.WriteLine(store.GetFullPath(CONFIG_FILENAME));
                Assert.True(store.FileExists(CONFIG_FILENAME));
                Console.WriteLine(store.ReadFileAsString(CONFIG_FILENAME));
            }
        }
Exemplo n.º 17
0
        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 CanEnableLoggingFromConfig() {
            var client = new ExceptionlessClient();
            ClientConfiguration config = ClientConfiguration.Create(client);
            string logPath = config.LogPath;
            Assert.NotNull(config);

            Assert.True(config.EnableLogging);
            //Assert.Equal(logPath, config.LogPath); // TODO: Should this even be set to a value?? It's Isolated storage?
            Assert.NotNull(client.Log);
            Assert.NotNull(client);

            Assert.Equal(typeof(SafeExceptionlessLog), client.Log.GetType());

            client.ProcessQueue();
            client.Shutdown();

            var dir = new IsolatedStorageDirectory(DEFAULT_STORE);
            Assert.True(dir.FileExists(logPath));
            string content = dir.ReadFileAsString(logPath);
            Assert.True(content.Length > 10);
        }
Exemplo n.º 19
0
        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);
            }
        }
Exemplo n.º 20
0
        public void IsolatedStorageFileSystem_AccessesIsolatedStorage()
        {
            using (var store = IsolatedStorageFile.GetMachineStoreForAssembly())
            {
                using (var writer = new StreamWriter(store.OpenFile("test.txt", FileMode.Create, FileAccess.Write)))
                {
                    writer.Write("test");
                    writer.Flush();
                }

                var directory = new IsolatedStorageDirectory(store);
                var file      = directory.GetFile("test.txt");
                file.Exists.ShouldBeTrue();
                using (var reader = new StreamReader(file.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
                {
                    reader.ReadToEnd().ShouldEqual("test");
                }

                file.Delete();
                store.FileExists("test.txt").ShouldBeFalse();
            }
        }
Exemplo n.º 21
0
        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;
        }
        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 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());
 }
Exemplo n.º 25
0
        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 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");
            }
        }
        private void Delete(IsolatedStorageDirectory dir, string id) {
            // retry delete up to 3 times
            for (int retry = 0; retry < 3; retry++) {
                try {
                    string manifestFilename = GetManifestFilename(id);
                    dir.DeleteFile(manifestFilename);

                    string errorFilename = GetErrorFilename(id);
                    dir.DeleteFile(errorFilename);

                    return;
                } catch (IOException ex) {
                    LogAccessor.Log.FormattedError(typeof(IsolatedStorageQueueStore), ex, "Problem deleting id '{0}' from isolated storage", id);
                    Thread.Sleep(50);
                }
            }
        }
Exemplo n.º 28
0
 private void DeleteConfig(string storeId = DEFAULT_STORE) {
     using (var dir = new IsolatedStorageDirectory(storeId)) {
         if (dir.FileExists(CONFIG_FILENAME))
             dir.DeleteFile(CONFIG_FILENAME);
     }
 }
 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();
 }
 public IsolatedStorageFileExceptionlessLogTests()
 {
     _directory = new IsolatedStorageDirectory("test");
 }
Exemplo n.º 32
0
        public void MultiThreadedSaveLocalConfiguration() {
            DeleteConfig();
            var client = new ExceptionlessClient();

            Parallel.For(0, 200, i => {
                Exception exception = Record.Exception(() => {
                    LocalConfigurationDictionary localConfiguration = LocalConfigurationDictionary.Create(DEFAULT_STORE, client);
                    Assert.NotNull(localConfiguration);

                    localConfiguration.IsDirty = true;
                    localConfiguration["ExpireTokenDate"] = DateTime.Now.AddMinutes(i).ToString();
                    localConfiguration.StartCount++;
                    Task.Factory.StartNew(() => localConfiguration["ExpireTokenDate"] = DateTime.Now.AddMinutes(i + 1).ToString());
                    localConfiguration.Save();

                    Assert.NotNull(LocalConfigurationDictionary.Create(DEFAULT_STORE, client));

                    localConfiguration.IsDirty = true;
                    localConfiguration["ExpireTokenDate"] = DateTime.Now.AddMinutes(i).ToString();
                    Task.Factory.StartNew(() => localConfiguration.Remove("ExpireTokenDate"));
                    localConfiguration.Save();

                    Assert.NotNull(LocalConfigurationDictionary.Create(DEFAULT_STORE, client));

                    localConfiguration.StartCount++;
                    localConfiguration.IsDirty = true;
                    Assert.True(localConfiguration.Save(), "Saved");

                    Assert.NotNull(LocalConfigurationDictionary.Create(DEFAULT_STORE, client));
                });

                Assert.Null(exception);
            });

            using (var store = new IsolatedStorageDirectory(DEFAULT_STORE)) {
                Console.WriteLine(store.GetFullPath(CONFIG_FILENAME));
                Assert.True(store.FileExists(CONFIG_FILENAME));
                Console.WriteLine(store.ReadFileAsString(CONFIG_FILENAME));
            }
        }
 public IsolatedStorageFileExceptionlessLog(string subDirectory, string filename, bool append = false) : base(filename, append)
 {
     _directory = new IsolatedStorageDirectory(subDirectory);
 }
 public IsolatedStorageFileExceptionlessLogTests() {
     _directory = new IsolatedStorageDirectory("test");
 }
 public IsolatedStorageFileExceptionlessLog(string subDirectory, string filename, bool append = false) : base(filename, append) {
     _directory = new IsolatedStorageDirectory(subDirectory);
 }