public ArchiveMonkeySettings GetSettings() { if (File.Exists(this.SettingsPath)) { ArchiveMonkeySettings settings = null; var serializer = new DataContractJsonSerializer(typeof(ArchiveMonkeySettings)); using (var fileStream = new FileStream(this.SettingsPath, FileMode.Open)) { try { using (var jsonReader = JsonReaderWriterFactory.CreateJsonReader(fileStream, Encoding.GetEncoding("utf-8"), XmlDictionaryReaderQuotas.Max, null)) { settings = (ArchiveMonkeySettings)serializer.ReadObject(jsonReader); } } catch (Exception ex) { settings = null; logger.Error(ex, "Could not deserialize settings."); } } return(settings ?? new ArchiveMonkeySettings()); } return(new ArchiveMonkeySettings()); }
public void SaveSettings(ArchiveMonkeySettings settings) { var serializer = new DataContractJsonSerializer(typeof(ArchiveMonkeySettings)); using (var fileStream = new FileStream(this.SettingsPath, FileMode.Create)) { using (var jsonWriter = JsonReaderWriterFactory.CreateJsonWriter(fileStream, Encoding.GetEncoding("utf-8"))) { serializer.WriteObject(jsonWriter, settings); jsonWriter.Flush(); } } }
public Worker(ArchiveMonkeySettings settings, Queue <ArchivingAction> queue, IArchiver archiver, UnityContainer iocContainer) { this.settings = settings; this.queue = queue; this.iocContainer = iocContainer; this.archiveWatchers = new List <IArchiveWatcher>(); this.archiver = archiver; this.filterService = iocContainer.Resolve <IFilterService>(); this.Processing = false; foreach (var action in this.settings.ArchivingActionTemplates.OrderBy(x => x.InputArchive.FullNetworkPath).ThenBy(y => y.Sequence)) { // create one queue entry for every archiving action to ensure changes are processed that might have been missed since last program run this.queue.Enqueue(ArchivingAction.FromTemplate(action, this.filterService)); } }