diff options
Re-imported OpenGridServices from trunk
Diffstat (limited to '')
-rw-r--r-- | OpenGridServices/OpenUser.Config/UserConfigDb4o/DbUserConfig.cs | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/OpenGridServices/OpenUser.Config/UserConfigDb4o/DbUserConfig.cs b/OpenGridServices/OpenUser.Config/UserConfigDb4o/DbUserConfig.cs new file mode 100644 index 0000000..fe0e7aa --- /dev/null +++ b/OpenGridServices/OpenUser.Config/UserConfigDb4o/DbUserConfig.cs | |||
@@ -0,0 +1,96 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenSim.Framework.Console; | ||
31 | using OpenSim.Framework.Interfaces; | ||
32 | using Db4objects.Db4o; | ||
33 | |||
34 | namespace OpenUser.Config.UserConfigDb4o | ||
35 | { | ||
36 | public class Db4oConfigPlugin: IUserConfig | ||
37 | { | ||
38 | public UserConfig GetConfigObject() | ||
39 | { | ||
40 | OpenSim.Framework.Console.MainConsole.Instance.Verbose("Loading Db40Config dll"); | ||
41 | return ( new DbUserConfig()); | ||
42 | } | ||
43 | } | ||
44 | |||
45 | public class DbUserConfig : UserConfig | ||
46 | { | ||
47 | private IObjectContainer db; | ||
48 | |||
49 | public void LoadDefaults() { | ||
50 | OpenSim.Framework.Console.MainConsole.Instance.Notice("Config.cs:LoadDefaults() - Please press enter to retain default or enter new settings"); | ||
51 | |||
52 | this.DefaultStartupMsg = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Default startup message", "Welcome to OGS"); | ||
53 | |||
54 | this.GridServerURL = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Grid server URL","http://127.0.0.1:8001/"); | ||
55 | this.GridSendKey = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Key to send to grid server","null"); | ||
56 | this.GridRecvKey = OpenSim.Framework.Console.MainConsole.Instance.CmdPrompt("Key to expect from grid server","null"); | ||
57 | } | ||
58 | |||
59 | public override void InitConfig() { | ||
60 | try { | ||
61 | db = Db4oFactory.OpenFile("openuser.yap"); | ||
62 | IObjectSet result = db.Get(typeof(DbUserConfig)); | ||
63 | if(result.Count==1) { | ||
64 | OpenSim.Framework.Console.MainConsole.Instance.Verbose("Config.cs:InitConfig() - Found a UserConfig object in the local database, loading"); | ||
65 | foreach (DbUserConfig cfg in result) { | ||
66 | this.GridServerURL=cfg.GridServerURL; | ||
67 | this.GridSendKey=cfg.GridSendKey; | ||
68 | this.GridRecvKey=cfg.GridRecvKey; | ||
69 | this.DefaultStartupMsg=cfg.DefaultStartupMsg; | ||
70 | } | ||
71 | } else { | ||
72 | OpenSim.Framework.Console.MainConsole.Instance.Verbose("Config.cs:InitConfig() - Could not find object in database, loading precompiled defaults"); | ||
73 | LoadDefaults(); | ||
74 | OpenSim.Framework.Console.MainConsole.Instance.Verbose("Writing out default settings to local database"); | ||
75 | db.Set(this); | ||
76 | db.Close(); | ||
77 | } | ||
78 | } catch(Exception e) { | ||
79 | OpenSim.Framework.Console.MainConsole.Instance.Warn("Config.cs:InitConfig() - Exception occured"); | ||
80 | OpenSim.Framework.Console.MainConsole.Instance.Warn(e.ToString()); | ||
81 | } | ||
82 | |||
83 | OpenSim.Framework.Console.MainConsole.Instance.Verbose("User settings loaded:"); | ||
84 | OpenSim.Framework.Console.MainConsole.Instance.Verbose("Default startup message: " + this.DefaultStartupMsg); | ||
85 | OpenSim.Framework.Console.MainConsole.Instance.Verbose("Grid server URL: " + this.GridServerURL); | ||
86 | OpenSim.Framework.Console.MainConsole.Instance.Verbose("Key to send to grid: " + this.GridSendKey); | ||
87 | OpenSim.Framework.Console.MainConsole.Instance.Verbose("Key to expect from grid: " + this.GridRecvKey); | ||
88 | } | ||
89 | |||
90 | |||
91 | public void Shutdown() { | ||
92 | db.Close(); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | } | ||