aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers
diff options
context:
space:
mode:
authorMW2007-12-02 13:59:15 +0000
committerMW2007-12-02 13:59:15 +0000
commit80609c2b1572d9b946675db486fc46e327171cfa (patch)
tree85a623c1a75255d74883c3f9ba11e5f66a053a18 /OpenSim/Framework/Servers
parentNew Inventory folder should now be stored to the inventory server/database. T... (diff)
downloadopensim-SC-80609c2b1572d9b946675db486fc46e327171cfa.zip
opensim-SC-80609c2b1572d9b946675db486fc46e327171cfa.tar.gz
opensim-SC-80609c2b1572d9b946675db486fc46e327171cfa.tar.bz2
opensim-SC-80609c2b1572d9b946675db486fc46e327171cfa.tar.xz
Some refactoring , mainly on Inventory code.
Diffstat (limited to 'OpenSim/Framework/Servers')
-rw-r--r--OpenSim/Framework/Servers/RestObjectPoster.cs93
-rw-r--r--OpenSim/Framework/Servers/RestObjectPosterResponse.cs60
-rw-r--r--OpenSim/Framework/Servers/SynchronousRestObjectPoster.cs48
3 files changed, 108 insertions, 93 deletions
diff --git a/OpenSim/Framework/Servers/RestObjectPoster.cs b/OpenSim/Framework/Servers/RestObjectPoster.cs
index 07095f3..9bcfcca 100644
--- a/OpenSim/Framework/Servers/RestObjectPoster.cs
+++ b/OpenSim/Framework/Servers/RestObjectPoster.cs
@@ -5,14 +5,10 @@ using System.Text;
5using System.Xml; 5using System.Xml;
6using System.Xml.Serialization; 6using System.Xml.Serialization;
7 7
8
9namespace OpenSim.Framework.Servers 8namespace OpenSim.Framework.Servers
10{ 9{
11 public delegate void ReturnResponse<T>(T reponse);
12
13 public class RestObjectPoster 10 public class RestObjectPoster
14 { 11 {
15
16 public static void BeginPostObject<TRequest>(string requestUrl, TRequest obj) 12 public static void BeginPostObject<TRequest>(string requestUrl, TRequest obj)
17 { 13 {
18 Type type = typeof(TRequest); 14 Type type = typeof(TRequest);
@@ -49,93 +45,4 @@ namespace OpenSim.Framework.Servers
49 } 45 }
50 } 46 }
51 } 47 }
52
53 public class RestObjectPosterResponse<TResponse>
54 {
55 public ReturnResponse<TResponse> ReturnResponseVal;
56
57 public void BeginPostObject<TRequest>(string requestUrl, TRequest obj)
58 {
59 Type type = typeof(TRequest);
60
61 WebRequest request = WebRequest.Create(requestUrl);
62 request.Method = "POST";
63 request.ContentType = "text/xml";
64
65 MemoryStream buffer = new MemoryStream();
66
67 XmlWriterSettings settings = new XmlWriterSettings();
68 settings.Encoding = Encoding.UTF8;
69
70 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
71 {
72 XmlSerializer serializer = new XmlSerializer(type);
73 serializer.Serialize(writer, obj);
74 writer.Flush();
75 }
76
77 int length = (int)buffer.Length;
78 request.ContentLength = length;
79
80 Stream requestStream = request.GetRequestStream();
81 requestStream.Write(buffer.ToArray(), 0, length);
82 IAsyncResult result = request.BeginGetResponse(AsyncCallback, request);
83 }
84
85 private void AsyncCallback(IAsyncResult result)
86 {
87 WebRequest request = (WebRequest)result.AsyncState;
88 using (WebResponse resp = request.EndGetResponse(result))
89 {
90 TResponse deserial;
91 XmlSerializer deserializer = new XmlSerializer(typeof(TResponse));
92 deserial = (TResponse)deserializer.Deserialize(resp.GetResponseStream());
93
94 if (deserial != null && ReturnResponseVal != null)
95 {
96 ReturnResponseVal(deserial);
97 }
98 }
99 }
100 }
101
102 public class SyncRestObjectPoster
103 {
104
105 public static TResponse BeginPostObject<TRequest, TResponse>(string requestUrl, TRequest obj)
106 {
107 Type type = typeof(TRequest);
108
109 WebRequest request = WebRequest.Create(requestUrl);
110 request.Method = "POST";
111 request.ContentType = "text/xml";
112
113 MemoryStream buffer = new MemoryStream();
114
115 XmlWriterSettings settings = new XmlWriterSettings();
116 settings.Encoding = Encoding.UTF8;
117
118 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
119 {
120 XmlSerializer serializer = new XmlSerializer(type);
121 serializer.Serialize(writer, obj);
122 writer.Flush();
123 }
124
125 int length = (int)buffer.Length;
126 request.ContentLength = length;
127
128 Stream requestStream = request.GetRequestStream();
129 requestStream.Write(buffer.ToArray(), 0, length);
130 TResponse deserial = default(TResponse);
131 using (WebResponse resp = request.GetResponse())
132 {
133
134 XmlSerializer deserializer = new XmlSerializer(typeof(TResponse));
135 deserial = (TResponse)deserializer.Deserialize(resp.GetResponseStream());
136 }
137 return deserial;
138 }
139
140 }
141} \ No newline at end of file 48} \ No newline at end of file
diff --git a/OpenSim/Framework/Servers/RestObjectPosterResponse.cs b/OpenSim/Framework/Servers/RestObjectPosterResponse.cs
new file mode 100644
index 0000000..eeae285
--- /dev/null
+++ b/OpenSim/Framework/Servers/RestObjectPosterResponse.cs
@@ -0,0 +1,60 @@
1using System;
2using System.IO;
3using System.Net;
4using System.Text;
5using System.Xml;
6using System.Xml.Serialization;
7
8namespace OpenSim.Framework.Servers
9{
10 public delegate void ReturnResponse<T>(T reponse);
11
12 public class RestObjectPosterResponse<TResponse>
13 {
14 public ReturnResponse<TResponse> ResponseCallback;
15
16 public void BeginPostObject<TRequest>(string requestUrl, TRequest obj)
17 {
18 Type type = typeof(TRequest);
19
20 WebRequest request = WebRequest.Create(requestUrl);
21 request.Method = "POST";
22 request.ContentType = "text/xml";
23
24 MemoryStream buffer = new MemoryStream();
25
26 XmlWriterSettings settings = new XmlWriterSettings();
27 settings.Encoding = Encoding.UTF8;
28
29 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
30 {
31 XmlSerializer serializer = new XmlSerializer(type);
32 serializer.Serialize(writer, obj);
33 writer.Flush();
34 }
35
36 int length = (int)buffer.Length;
37 request.ContentLength = length;
38
39 Stream requestStream = request.GetRequestStream();
40 requestStream.Write(buffer.ToArray(), 0, length);
41 IAsyncResult result = request.BeginGetResponse(AsyncCallback, request);
42 }
43
44 private void AsyncCallback(IAsyncResult result)
45 {
46 WebRequest request = (WebRequest)result.AsyncState;
47 using (WebResponse resp = request.EndGetResponse(result))
48 {
49 TResponse deserial;
50 XmlSerializer deserializer = new XmlSerializer(typeof(TResponse));
51 deserial = (TResponse)deserializer.Deserialize(resp.GetResponseStream());
52
53 if (deserial != null && ResponseCallback != null)
54 {
55 ResponseCallback(deserial);
56 }
57 }
58 }
59 }
60}
diff --git a/OpenSim/Framework/Servers/SynchronousRestObjectPoster.cs b/OpenSim/Framework/Servers/SynchronousRestObjectPoster.cs
new file mode 100644
index 0000000..dde4c02
--- /dev/null
+++ b/OpenSim/Framework/Servers/SynchronousRestObjectPoster.cs
@@ -0,0 +1,48 @@
1using System;
2using System.IO;
3using System.Net;
4using System.Text;
5using System.Xml;
6using System.Xml.Serialization;
7
8namespace OpenSim.Framework.Servers
9{
10 public class SynchronousRestObjectPoster
11 {
12 public static TResponse BeginPostObject<TRequest, TResponse>(string requestUrl, TRequest obj)
13 {
14 Type type = typeof(TRequest);
15
16 WebRequest request = WebRequest.Create(requestUrl);
17 request.Method = "POST";
18 request.ContentType = "text/xml";
19
20 MemoryStream buffer = new MemoryStream();
21
22 XmlWriterSettings settings = new XmlWriterSettings();
23 settings.Encoding = Encoding.UTF8;
24
25 using (XmlWriter writer = XmlWriter.Create(buffer, settings))
26 {
27 XmlSerializer serializer = new XmlSerializer(type);
28 serializer.Serialize(writer, obj);
29 writer.Flush();
30 }
31
32 int length = (int)buffer.Length;
33 request.ContentLength = length;
34
35 Stream requestStream = request.GetRequestStream();
36 requestStream.Write(buffer.ToArray(), 0, length);
37 TResponse deserial = default(TResponse);
38 using (WebResponse resp = request.GetResponse())
39 {
40
41 XmlSerializer deserializer = new XmlSerializer(typeof(TResponse));
42 deserial = (TResponse)deserializer.Deserialize(resp.GetResponseStream());
43 }
44 return deserial;
45 }
46
47 }
48}