-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCatalog.cs
169 lines (153 loc) · 5.26 KB
/
Catalog.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using System;
using System.Collections.Generic;
namespace AllegroGraphCSharpClient
{
// NOTE: If you change the class name "Catalog" here, you must also update the reference to "Catalog" in App.config.
/// <summary>
/// Catalog class handles all interaction with the catalog object
/// Please note that if you use wcf, you will always need to pass the url and potentially username/password
/// Otherwise you can set it using the constructor
/// </summary>
public class Catalog : ICatalog
{
#region ICatalog Members
private string _url;
private string _username;
private string _password;
private string _curl;
/// <summary>
/// Initializes the catalog class
/// </summary>
/// <param name="url"></param>
/// <param name="username"></param>
/// <param name="password"></param>
/// <returns></returns>
public bool InitializeCatalogClass(string url, string username, string password)
{
_url = url;
_username = username;
_password = password;
return true;
}
/// <summary>
/// return url for the service
/// </summary>
/// <returns></returns>
public string getUrl()
{
return this._url;
}
/// <summary>
/// List the triple stores at the current url
/// </summary>
/// <returns></returns>
public List<string> listTripleStores(string url)
{
if (url != string.Empty)
{
this._url = url;
}
List<string> stores = new List<string>();
try
{
Request request = new Request();
List<Results> rs = new List<Results>();
rs = request.StandardRequest("GET", this._url + @"/repositories", null, null);
foreach (Results result in rs)
{
stores.Add(result.Result.ToString());
}
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine("Error in listTripleStores : " + ex.Message);
}
return stores;
}
/// <summary>
/// Initialize new triple store
/// </summary>
/// <param name="name"></param>
/// <param name="url"></param>
/// <returns></returns>
public bool createTripleStore(string name, string url)
{
try
{
if (url != string.Empty)
{
this._url = url;
}
Request request = new Request();
request.StandardRequest("PUT", this._url + @"/repositories/" + legalizeName(name,this._url), null, null);
return true;
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine("Error in create triple store : " + ex.Message);
return false;
}
}
/// <summary>
/// Federate the triple store, untested at this time
/// </summary>
/// <param name="name"></param>
/// <param name="storeNames"></param>
/// <param name="url"></param>
/// <returns></returns>
public bool federateTripleStores(string name, List<string> storeNames, string url)
{
try
{
if (url != string.Empty)
{
this._url = url;
}
Request request = new Request();
List<NameValuePairs> nvp = new List<NameValuePairs>();
NameValuePairs np = new NameValuePairs();
np.Name = "federate";
np.Value = (object)storeNames;
nvp.Add(np);
request.StandardRequest("PUT", this._url + @"/repositories/" + legalizeName(name,this._url), nvp, string.Empty);
return true;
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine("Error in federateTripleStores: " + ex.Message);
return false;
}
}
public bool deleteTripleStore(string storeName, string url)
{
try
{
if (url != string.Empty)
{
this._url = url;
}
Request request = new Request();
request.StandardRequest("DELETE", this._url + @"/repositories/" + legalizeName(storeName,this._url), null, null);
return true;
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine("Error in deleteTripleStore: " + ex.Message);
return false;
}
}
public Repository getRepository(string name, string url)
{
if (url != string.Empty)
{
this._url = url;
}
return new Repository(this._url + @"/repositories/" + legalizeName(name,this._url));
}
public string legalizeName(string name, string url)
{
return name;
}
#endregion
}
}