forked from HalcyonGrid/AIS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InventoryAPI.cs
145 lines (129 loc) · 6.62 KB
/
InventoryAPI.cs
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System;
using System.Net;
using log4net;
using OpenMetaverse;
using OpenSim.Data;
using InWorldz.Data.Inventory.Cassandra;
using SimpleAPIServer;
using Nini.Config;
namespace AIS
{
class InventoryAPI
{
private static readonly ILog m_log = LogManager.GetLogger(typeof(InventoryAPI));
static private string _cluster = Properties.Settings.Default.cassandraCluster;
static private string _connstring = Properties.Settings.Default.coreConnStr;
private UUID _Id;
private InventoryStorage _cassandraStorage;
private CassandraMigrationProviderSelector _selector;
private LegacyMysqlInventoryStorage _legacy;
private IInventoryStorage _storage; // per-user specific storage reference
public InventoryAPI(ArgvConfigSource options)
{
options.AddSwitch("Inventory", "local", "l");
string useLocal = options.Configs["Inventory"].Get("local");
if (useLocal != null) // any value include "" will do
{
_cluster = Properties.LocalSettings.Default.cassandraCluster;
_connstring = Properties.LocalSettings.Default.coreConnStr;
m_log.Warn("Using LOCAL settings.");
}
try
{
_cassandraStorage = new InventoryStorage(_cluster);
_legacy = new LegacyMysqlInventoryStorage(_connstring);
_selector = new CassandraMigrationProviderSelector(true, _connstring, _cassandraStorage, _legacy);
m_log.InfoFormat("Cassandra support on '{0}' enabled and ready.", _cluster);
}
catch (Exception e)
{
m_log.ErrorFormat("Unable to connect to cassandra cluster: {0}", e);
}
}
public void AddRoutes(APIRouter router)
{
APIRoute[] inventoryRoutes =
{
new APIRoute("ALL", "/category/{category}", HandleCategory),
new APIRoute("ALL", "/category/{category}/children", HandleCategoryChildren),
new APIRoute("ALL", "/category/{category}/links", HandleCategoryLinks),
new APIRoute("ALL", "/category/{category}/items", HandleCategoryItems),
new APIRoute("ALL", "/category/{category}/categories", HandleCategoryCategories),
new APIRoute("ALL", "/item/{item}", HandleItem),
};
router.AddRoutes(inventoryRoutes);
}
// "GET", "/category/{category}", HandleGetCategory
public void HandleGetCategory(HttpListenerRequest request, string[] requestParts, HttpListenerResponse response)
{
APIServer.SetResponse(response, HttpStatusCode.OK, "OK " + request.RawUrl);
}
public void HandleCategory(HttpListenerRequest request, string[] requestParts, HttpListenerResponse response)
{
if (string.Compare(request.HttpMethod, "GET", true) == 0)
HandleGetCategory(request, requestParts, response);
else
APIServer.SetResponse(response, HttpStatusCode.MethodNotAllowed, request.RawUrl);
}
// "GET", "/category/{category}/children", HandleGetCategoryChildren
public void HandleGetCategoryChildren(HttpListenerRequest request, string[] requestParts, HttpListenerResponse response)
{
APIServer.SetResponse(response, HttpStatusCode.OK, "OK " + request.RawUrl);
}
public void HandleCategoryChildren(HttpListenerRequest request, string[] requestParts, HttpListenerResponse response)
{
if (string.Compare(request.HttpMethod, "GET", true) == 0)
HandleGetCategoryChildren(request, requestParts, response);
else
APIServer.SetResponse(response, HttpStatusCode.MethodNotAllowed, request.RawUrl);
}
// "GET", "/category/{category}/links", HandleGetCategoryLinks
public void HandleGetCategoryLinks(HttpListenerRequest request, string[] requestParts, HttpListenerResponse response)
{
APIServer.SetResponse(response, HttpStatusCode.OK, "OK " + request.RawUrl);
}
public void HandleCategoryLinks(HttpListenerRequest request, string[] requestParts, HttpListenerResponse response)
{
if (string.Compare(request.HttpMethod, "GET", true) == 0)
HandleGetCategory(request, requestParts, response);
else
APIServer.SetResponse(response, HttpStatusCode.MethodNotAllowed, request.RawUrl);
}
// "GET", "/category/{category}/items", HandleGetCategoryItems
public void HandleGetCategoryItems(HttpListenerRequest request, string[] requestParts, HttpListenerResponse response)
{
APIServer.SetResponse(response, HttpStatusCode.OK, "OK " + request.RawUrl);
}
public void HandleCategoryItems(HttpListenerRequest request, string[] requestParts, HttpListenerResponse response)
{
if (string.Compare(request.HttpMethod, "GET", true) == 0)
HandleGetCategory(request, requestParts, response);
else
APIServer.SetResponse(response, HttpStatusCode.MethodNotAllowed, request.RawUrl);
}
// "GET", "/category/{category}/categories",HandleGetCategoryCategories
public void HandleGetCategoryCategories(HttpListenerRequest request, string[] requestParts, HttpListenerResponse response)
{
APIServer.SetResponse(response, HttpStatusCode.OK, "OK " + request.RawUrl);
}
public void HandleCategoryCategories(HttpListenerRequest request, string[] requestParts, HttpListenerResponse response)
{
if (string.Compare(request.HttpMethod, "GET", true) == 0)
HandleGetCategory(request, requestParts, response);
else
APIServer.SetResponse(response, HttpStatusCode.MethodNotAllowed, request.RawUrl);
}
// "GET", "/item/{item}", HandleGetItem
public void HandleGetItem(HttpListenerRequest request, string[] requestParts, HttpListenerResponse response)
{
APIServer.SetResponse(response, HttpStatusCode.OK, "OK " + request.RawUrl);
}
public void HandleItem(HttpListenerRequest request, string[] requestParts, HttpListenerResponse response)
{
if (string.Compare(request.HttpMethod, "GET", true) == 0)
HandleGetCategory(request, requestParts, response);
else
APIServer.SetResponse(response, HttpStatusCode.MethodNotAllowed, request.RawUrl);
}
}
}