aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/StorageManager.cs
blob: a7d67d3cfb0645414812884fa6cafcc5e60c263f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.Text;

using OpenSim.Framework;
using OpenSim.Framework.Communications;
using OpenSim.Framework.Servers;
using OpenSim.Region.Capabilities;
using OpenSim.Region.Environment.Scenes;
using OpenSim.Region.Interfaces;

using System.Reflection;

namespace OpenSim.Region.Environment
{
    public class StorageManager
    {
        private IRegionDataStore m_dataStore;

        public IRegionDataStore DataStore
        {
            get
            {
                return m_dataStore;
            }
        }

        public StorageManager(IRegionDataStore storage)
        {
            m_dataStore = storage;
        }

        public StorageManager(string dllName, string dataStoreFile, string dataStoreDB)
        {
            OpenSim.Framework.Console.MainLog.Instance.Verbose("DATASTORE", "Attempting to load " + dllName);
            Assembly pluginAssembly = Assembly.LoadFrom(dllName);

            foreach (Type pluginType in pluginAssembly.GetTypes())
            {
                if (pluginType.IsPublic)
                {
                    Type typeInterface = pluginType.GetInterface("IRegionDataStore", true);

                    if (typeInterface != null)
                    {
                        IRegionDataStore plug = (IRegionDataStore)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
                        plug.Initialise(dataStoreFile, dataStoreDB);

                        m_dataStore = plug;

                        OpenSim.Framework.Console.MainLog.Instance.Verbose("DATASTORE", "Added IRegionDataStore Interface");
                    }

                    typeInterface = null;
                }
            }

            pluginAssembly = null;

            //TODO: Add checking and warning to make sure it initialised.
        }
    }
}