protected override void DeleteLog(string path = LOG_FILE)
 {
     if (LogExists(path))
     {
         _directory.DeleteFile(path);
     }
 }
        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);
        }
Esempio n. 3
0
 private void DeleteConfig(string storeId = DEFAULT_STORE)
 {
     using (var dir = new IsolatedStorageDirectory(storeId)) {
         if (dir.FileExists(CONFIG_FILENAME))
         {
             dir.DeleteFile(CONFIG_FILENAME);
         }
     }
 }
        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 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);
        }
Esempio n. 6
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);
            }
        }
        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);
                }
            }
        }
        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 void DeleteConfig(string storeId = DEFAULT_STORE) {
     using (var dir = new IsolatedStorageDirectory(storeId)) {
         if (dir.FileExists(CONFIG_FILENAME))
             dir.DeleteFile(CONFIG_FILENAME);
     }
 }