aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers/RestObjectPoster.cs
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/RestObjectPoster.cs
parentNew Inventory folder should now be stored to the inventory server/database. T... (diff)
downloadopensim-SC_OLD-80609c2b1572d9b946675db486fc46e327171cfa.zip
opensim-SC_OLD-80609c2b1572d9b946675db486fc46e327171cfa.tar.gz
opensim-SC_OLD-80609c2b1572d9b946675db486fc46e327171cfa.tar.bz2
opensim-SC_OLD-80609c2b1572d9b946675db486fc46e327171cfa.tar.xz
Some refactoring , mainly on Inventory code.
Diffstat (limited to 'OpenSim/Framework/Servers/RestObjectPoster.cs')
-rw-r--r--OpenSim/Framework/Servers/RestObjectPoster.cs93
1 files changed, 0 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