| 1 | /* |
|---|
| 2 | * $Id$ |
|---|
| 3 | * Copyright 2008-2010 The Eraser Project |
|---|
| 4 | * Original Author: Joel Low <lowjoel@users.sourceforge.net> |
|---|
| 5 | * Modified By: |
|---|
| 6 | * |
|---|
| 7 | * This file is part of Eraser. |
|---|
| 8 | * |
|---|
| 9 | * Eraser is free software: you can redistribute it and/or modify it under the |
|---|
| 10 | * terms of the GNU General Public License as published by the Free Software |
|---|
| 11 | * Foundation, either version 3 of the License, or (at your option) any later |
|---|
| 12 | * version. |
|---|
| 13 | * |
|---|
| 14 | * Eraser is distributed in the hope that it will be useful, but WITHOUT ANY |
|---|
| 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
|---|
| 16 | * A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
|---|
| 17 | * |
|---|
| 18 | * A copy of the GNU General Public License can be found at |
|---|
| 19 | * <http://www.gnu.org/licenses/>. |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | using System; |
|---|
| 23 | using System.Collections.Generic; |
|---|
| 24 | using System.Text; |
|---|
| 25 | using System.Runtime.Serialization; |
|---|
| 26 | |
|---|
| 27 | namespace Eraser.Manager |
|---|
| 28 | { |
|---|
| 29 | /// <summary> |
|---|
| 30 | /// The library instance which initializes and cleans up data required for the |
|---|
| 31 | /// library to function. |
|---|
| 32 | /// </summary> |
|---|
| 33 | public class ManagerLibrary : IDisposable |
|---|
| 34 | { |
|---|
| 35 | public ManagerLibrary(SettingsManager settings) |
|---|
| 36 | { |
|---|
| 37 | if (Instance != null) |
|---|
| 38 | throw new InvalidOperationException("Only one ManagerLibrary instance can " + |
|---|
| 39 | "exist at any one time"); |
|---|
| 40 | |
|---|
| 41 | Instance = this; |
|---|
| 42 | SettingsManager = settings; |
|---|
| 43 | |
|---|
| 44 | EntropySourceManager = new EntropySourceRegistrar(); |
|---|
| 45 | PRNGManager = new PrngManager(); |
|---|
| 46 | ErasureMethodManager = new ErasureMethodRegistrar(); |
|---|
| 47 | FileSystemManager = new FileSystemManager(); |
|---|
| 48 | Host = new Plugin.DefaultHost(); |
|---|
| 49 | Host.Load(); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | ~ManagerLibrary() |
|---|
| 53 | { |
|---|
| 54 | Dispose(false); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | protected virtual void Dispose(bool disposing) |
|---|
| 58 | { |
|---|
| 59 | if (SettingsManager == null) |
|---|
| 60 | return; |
|---|
| 61 | |
|---|
| 62 | if (disposing) |
|---|
| 63 | { |
|---|
| 64 | EntropySourceManager.Poller.Abort(); |
|---|
| 65 | Host.Dispose(); |
|---|
| 66 | SettingsManager.Save(); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | SettingsManager = null; |
|---|
| 70 | Instance = null; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | public void Dispose() |
|---|
| 74 | { |
|---|
| 75 | Dispose(true); |
|---|
| 76 | GC.SuppressFinalize(this); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | /// <summary> |
|---|
| 80 | /// The global library instance. |
|---|
| 81 | /// </summary> |
|---|
| 82 | public static ManagerLibrary Instance { get; private set; } |
|---|
| 83 | |
|---|
| 84 | /// <summary> |
|---|
| 85 | /// The global instance of the EntropySource Manager |
|---|
| 86 | /// </summary> |
|---|
| 87 | public EntropySourceRegistrar EntropySourceManager { get; private set; } |
|---|
| 88 | |
|---|
| 89 | /// <summary> |
|---|
| 90 | /// The global instance of the PRNG Manager. |
|---|
| 91 | /// </summary> |
|---|
| 92 | public PrngManager PRNGManager { get; private set; } |
|---|
| 93 | |
|---|
| 94 | /// <summary> |
|---|
| 95 | /// The global instance of the Erasure method manager. |
|---|
| 96 | /// </summary> |
|---|
| 97 | public ErasureMethodRegistrar ErasureMethodManager { get; private set; } |
|---|
| 98 | |
|---|
| 99 | /// <summary> |
|---|
| 100 | /// The global instance of the File System manager. |
|---|
| 101 | /// </summary> |
|---|
| 102 | public FileSystemManager FileSystemManager { get; private set; } |
|---|
| 103 | |
|---|
| 104 | /// <summary> |
|---|
| 105 | /// Global instance of the Settings manager. |
|---|
| 106 | /// </summary> |
|---|
| 107 | public SettingsManager SettingsManager { get; set; } |
|---|
| 108 | |
|---|
| 109 | /// <summary> |
|---|
| 110 | /// Gets the settings object representing the settings for the Eraser |
|---|
| 111 | /// Manager. This is just shorthand for the local classes. |
|---|
| 112 | /// </summary> |
|---|
| 113 | public static ManagerSettings Settings |
|---|
| 114 | { |
|---|
| 115 | get |
|---|
| 116 | { |
|---|
| 117 | if (settingsInstance == null) |
|---|
| 118 | settingsInstance = new ManagerSettings(); |
|---|
| 119 | return settingsInstance; |
|---|
| 120 | } |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | /// <summary> |
|---|
| 124 | /// The singleton instance for <see cref="Settings"/>. |
|---|
| 125 | /// </summary> |
|---|
| 126 | private static ManagerSettings settingsInstance; |
|---|
| 127 | |
|---|
| 128 | /// <summary> |
|---|
| 129 | /// The global instance of the Plugin host. |
|---|
| 130 | /// </summary> |
|---|
| 131 | internal Plugin.DefaultHost Host; |
|---|
| 132 | } |
|---|
| 133 | } |
|---|