source: trunk/eraser6/Eraser.Manager/ManagerLibrary.cs @ 1359

Revision 1359, 3.3 KB checked in by lowjoel, 4 years ago (diff)

Set svn:eol-style to native

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1/*
2 * $Id$
3 * Copyright 2008 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
22using System;
23using System.Collections.Generic;
24using System.Text;
25using System.Runtime.Serialization;
26
27namespace 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 EntropySourceManager();
45            PRNGManager = new PrngManager();
46            ErasureMethodManager = new ErasureMethodManager();
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 (disposing)
60            {
61                EntropySourceManager.Poller.Abort();
62                Host.Dispose();
63                SettingsManager.Save();
64            }
65
66            SettingsManager = null;
67            Instance = null;
68        }
69
70        public void Dispose()
71        {
72            Dispose(true);
73            GC.SuppressFinalize(this);
74        }
75
76        /// <summary>
77        /// The global library instance.
78        /// </summary>
79        public static ManagerLibrary Instance { get; private set; }
80
81        /// <summary>
82        /// The global instance of the EntropySource Manager
83        /// </summary>
84        internal EntropySourceManager EntropySourceManager;
85
86        /// <summary>
87        /// The global instance of the PRNG Manager.
88        /// </summary>
89        internal PrngManager PRNGManager;
90
91        /// <summary>
92        /// The global instance of the Erasure method manager.
93        /// </summary>
94        internal ErasureMethodManager ErasureMethodManager;
95
96        /// <summary>
97        /// The global instance of the File System manager.
98        /// </summary>
99        internal FileSystemManager FileSystemManager;
100
101        /// <summary>
102        /// Global instance of the Settings manager.
103        /// </summary>
104        public SettingsManager SettingsManager { get; set; }
105
106        /// <summary>
107        /// Gets the settings object representing the settings for the Eraser
108        /// Manager. This is just shorthand for the local classes.
109        /// </summary>
110        public static ManagerSettings Settings
111        {
112            get
113            {
114                if (settingsInstance == null)
115                    settingsInstance = new ManagerSettings();
116                return settingsInstance;
117            }
118        }
119
120        /// <summary>
121        /// The singleton instance for <see cref="Settings"/>.
122        /// </summary>
123        private static ManagerSettings settingsInstance;
124
125        /// <summary>
126        /// The global instance of the Plugin host.
127        /// </summary>
128        internal Plugin.DefaultHost Host;
129    }
130}
Note: See TracBrowser for help on using the repository browser.