diff options
author | gareth | 2007-04-30 03:08:05 +0000 |
---|---|---|
committer | gareth | 2007-04-30 03:08:05 +0000 |
commit | d9d301c9d9d8e08485c74af0798ca02beb84bc7d (patch) | |
tree | 977ab4f0e0cf54662ea014a380ed8d6effee2594 /OpenGridServices.AssetServer/Main.cs | |
parent | Oops! I done an AdamZaius (forgot to test build before submit (diff) | |
download | opensim-SC_OLD-d9d301c9d9d8e08485c74af0798ca02beb84bc7d.zip opensim-SC_OLD-d9d301c9d9d8e08485c74af0798ca02beb84bc7d.tar.gz opensim-SC_OLD-d9d301c9d9d8e08485c74af0798ca02beb84bc7d.tar.bz2 opensim-SC_OLD-d9d301c9d9d8e08485c74af0798ca02beb84bc7d.tar.xz |
W00t! It loads a DB!
Diffstat (limited to '')
-rw-r--r-- | OpenGridServices.AssetServer/Main.cs | 142 |
1 files changed, 132 insertions, 10 deletions
diff --git a/OpenGridServices.AssetServer/Main.cs b/OpenGridServices.AssetServer/Main.cs index 3fab84b..887bf07 100644 --- a/OpenGridServices.AssetServer/Main.cs +++ b/OpenGridServices.AssetServer/Main.cs | |||
@@ -32,11 +32,13 @@ using System.IO; | |||
32 | using System.Text; | 32 | using System.Text; |
33 | using System.Timers; | 33 | using System.Timers; |
34 | using System.Net; | 34 | using System.Net; |
35 | using System.Reflection; | 35 | using System.Reflection; |
36 | using System.Threading; | ||
36 | using libsecondlife; | 37 | using libsecondlife; |
37 | using OpenSim.Framework; | 38 | using OpenSim.Framework; |
38 | using OpenSim.Framework.Sims; | 39 | using OpenSim.Framework.Sims; |
39 | using OpenSim.Framework.Console; | 40 | using OpenSim.Framework.Console; |
41 | using OpenSim.Framework.Types; | ||
40 | using OpenSim.Framework.Interfaces; | 42 | using OpenSim.Framework.Interfaces; |
41 | using OpenSim.GridInterfaces.Local; // REFACTORING IS NEEDED!!!!!!!!!!! | 43 | using OpenSim.GridInterfaces.Local; // REFACTORING IS NEEDED!!!!!!!!!!! |
42 | using OpenSim.Servers; | 44 | using OpenSim.Servers; |
@@ -83,19 +85,13 @@ namespace OpenGridServices.AssetServer | |||
83 | } | 85 | } |
84 | 86 | ||
85 | public void Startup() | 87 | public void Startup() |
86 | { | 88 | { m_console.WriteLine("Main.cs:Startup() - Setting up asset DB"); |
87 | /*m_console.WriteLine("Main.cs:Startup() - Loading configuration"); | 89 | setupDB(); |
88 | Cfg = this.LoadConfigDll(this.ConfigDll); | ||
89 | Cfg.InitConfig(); */ | ||
90 | 90 | ||
91 | |||
92 | m_console.WriteLine("Main.cs:Startup() - Starting HTTP process"); | 91 | m_console.WriteLine("Main.cs:Startup() - Starting HTTP process"); |
93 | BaseHttpServer httpServer = new BaseHttpServer(8003); | 92 | BaseHttpServer httpServer = new BaseHttpServer(8003); |
94 | 93 | ||
95 | /*httpServer.AddRestHandler("GET", "/sims/", m_simProfileManager.RestGetSimMethod); | 94 | |
96 | httpServer.AddRestHandler("POST", "/sims/", m_simProfileManager.RestSetSimMethod); | ||
97 | httpServer.AddRestHandler("GET", "/regions/", m_simProfileManager.RestGetRegionMethod); | ||
98 | httpServer.AddRestHandler("POST", "/regions/", m_simProfileManager.RestSetRegionMethod); */ | ||
99 | httpServer.AddRestHandler("GET", "/assets/", this.assetGetMethod); | 95 | httpServer.AddRestHandler("GET", "/assets/", this.assetGetMethod); |
100 | 96 | ||
101 | 97 | ||
@@ -107,6 +103,132 @@ namespace OpenGridServices.AssetServer | |||
107 | return ""; | 103 | return ""; |
108 | } | 104 | } |
109 | 105 | ||
106 | public void setupDB() { | ||
107 | bool yapfile=System.IO.File.Exists("assets.yap"); | ||
108 | try | ||
109 | { | ||
110 | db = Db4oFactory.OpenFile("assets.yap"); | ||
111 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:setupDB() - creation"); | ||
112 | } | ||
113 | catch (Exception e) | ||
114 | { | ||
115 | db.Close(); | ||
116 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Main.cs:setupDB() - Exception occured"); | ||
117 | OpenSim.Framework.Console.MainConsole.Instance.WriteLine(e.ToString()); | ||
118 | } | ||
119 | if (!yapfile) | ||
120 | { | ||
121 | this.LoadDB(); | ||
122 | } | ||
123 | } | ||
124 | |||
125 | public void LoadDB() { | ||
126 | try | ||
127 | { | ||
128 | |||
129 | Console.WriteLine("setting up Asset database"); | ||
130 | |||
131 | AssetBase Image = new AssetBase(); | ||
132 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000001"); | ||
133 | Image.Name = "Bricks"; | ||
134 | this.LoadAsset(Image, true, "bricks.jp2"); | ||
135 | AssetStorage store = new AssetStorage(); | ||
136 | store.Data = Image.Data; | ||
137 | store.Name = Image.Name; | ||
138 | store.UUID = Image.FullID; | ||
139 | db.Set(store); | ||
140 | db.Commit(); | ||
141 | |||
142 | Image = new AssetBase(); | ||
143 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000002"); | ||
144 | Image.Name = "Plywood"; | ||
145 | this.LoadAsset(Image, true, "plywood.jp2"); | ||
146 | store = new AssetStorage(); | ||
147 | store.Data = Image.Data; | ||
148 | store.Name = Image.Name; | ||
149 | store.UUID = Image.FullID; | ||
150 | db.Set(store); | ||
151 | db.Commit(); | ||
152 | |||
153 | Image = new AssetBase(); | ||
154 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000003"); | ||
155 | Image.Name = "Rocks"; | ||
156 | this.LoadAsset(Image, true, "rocks.jp2"); | ||
157 | store = new AssetStorage(); | ||
158 | store.Data = Image.Data; | ||
159 | store.Name = Image.Name; | ||
160 | store.UUID = Image.FullID; | ||
161 | db.Set(store); | ||
162 | db.Commit(); | ||
163 | |||
164 | Image = new AssetBase(); | ||
165 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000004"); | ||
166 | Image.Name = "Granite"; | ||
167 | this.LoadAsset(Image, true, "granite.jp2"); | ||
168 | store = new AssetStorage(); | ||
169 | store.Data = Image.Data; | ||
170 | store.Name = Image.Name; | ||
171 | store.UUID = Image.FullID; | ||
172 | db.Set(store); | ||
173 | db.Commit(); | ||
174 | |||
175 | Image = new AssetBase(); | ||
176 | Image.FullID = new LLUUID("00000000-0000-0000-9999-000000000005"); | ||
177 | Image.Name = "Hardwood"; | ||
178 | this.LoadAsset(Image, true, "hardwood.jp2"); | ||
179 | store = new AssetStorage(); | ||
180 | store.Data = Image.Data; | ||
181 | store.Name = Image.Name; | ||
182 | store.UUID = Image.FullID; | ||
183 | db.Set(store); | ||
184 | db.Commit(); | ||
185 | |||
186 | Image = new AssetBase(); | ||
187 | Image.FullID = new LLUUID("00000000-0000-0000-5005-000000000005"); | ||
188 | Image.Name = "Prim Base Texture"; | ||
189 | this.LoadAsset(Image, true, "plywood.jp2"); | ||
190 | store = new AssetStorage(); | ||
191 | store.Data = Image.Data; | ||
192 | store.Name = Image.Name; | ||
193 | store.UUID = Image.FullID; | ||
194 | db.Set(store); | ||
195 | db.Commit(); | ||
196 | |||
197 | Image = new AssetBase(); | ||
198 | Image.FullID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73"); | ||
199 | Image.Name = "Shape"; | ||
200 | this.LoadAsset(Image, false, "base_shape.dat"); | ||
201 | store = new AssetStorage(); | ||
202 | store.Data = Image.Data; | ||
203 | store.Name = Image.Name; | ||
204 | store.UUID = Image.FullID; | ||
205 | db.Set(store); | ||
206 | db.Commit(); | ||
207 | } | ||
208 | catch (Exception e) | ||
209 | { | ||
210 | Console.WriteLine(e.Message); | ||
211 | } | ||
212 | } | ||
213 | |||
214 | private void LoadAsset(AssetBase info, bool image, string filename) | ||
215 | { | ||
216 | |||
217 | |||
218 | string dataPath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "assets"); //+ folder; | ||
219 | string fileName = Path.Combine(dataPath, filename); | ||
220 | FileInfo fInfo = new FileInfo(fileName); | ||
221 | long numBytes = fInfo.Length; | ||
222 | FileStream fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); | ||
223 | byte[] idata = new byte[numBytes]; | ||
224 | BinaryReader br = new BinaryReader(fStream); | ||
225 | idata = br.ReadBytes((int)numBytes); | ||
226 | br.Close(); | ||
227 | fStream.Close(); | ||
228 | info.Data = idata; | ||
229 | //info.loaded=true; | ||
230 | } | ||
231 | |||
110 | /*private GridConfig LoadConfigDll(string dllName) | 232 | /*private GridConfig LoadConfigDll(string dllName) |
111 | { | 233 | { |
112 | Assembly pluginAssembly = Assembly.LoadFrom(dllName); | 234 | Assembly pluginAssembly = Assembly.LoadFrom(dllName); |