From 5df851761aa796cba70a3b6d8b36d119502c1de2 Mon Sep 17 00:00:00 2001 From: MW Date: Sat, 1 Dec 2007 18:49:17 +0000 Subject: Initial working Grid Inventory server. Only been tested on a very small grid, so likely to have problems on a larger grid with more people? To use , both the user server and Inventory server need to be running this latest revision. (older regions should be able to still be used, just the user won't have inventory on them). Also and HERE IS THE BIG BREAK ISSUE, currently, so that the initial inventory details for a user are added to the inventory db , you need to recreate the accounts using the user server "create user" feature. It should be quite easy to manual populate the inventory database instead but I someone else will need to look into that) Also I've only tested using SQLite as the database provider, there is a Mysql inventory provider but I don't know if it works (SQLite is set as default, so you will need to change it in the inventory server config.xml) --- OpenSim/Framework/Servers/RestObjectPoster.cs | 92 +++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) (limited to 'OpenSim/Framework/Servers') diff --git a/OpenSim/Framework/Servers/RestObjectPoster.cs b/OpenSim/Framework/Servers/RestObjectPoster.cs index b77cbcc..07095f3 100644 --- a/OpenSim/Framework/Servers/RestObjectPoster.cs +++ b/OpenSim/Framework/Servers/RestObjectPoster.cs @@ -8,8 +8,11 @@ using System.Xml.Serialization; namespace OpenSim.Framework.Servers { + public delegate void ReturnResponse(T reponse); + public class RestObjectPoster { + public static void BeginPostObject(string requestUrl, TRequest obj) { Type type = typeof(TRequest); @@ -46,4 +49,93 @@ namespace OpenSim.Framework.Servers } } } + + public class RestObjectPosterResponse + { + public ReturnResponse ReturnResponseVal; + + public void BeginPostObject(string requestUrl, TRequest obj) + { + Type type = typeof(TRequest); + + WebRequest request = WebRequest.Create(requestUrl); + request.Method = "POST"; + request.ContentType = "text/xml"; + + MemoryStream buffer = new MemoryStream(); + + XmlWriterSettings settings = new XmlWriterSettings(); + settings.Encoding = Encoding.UTF8; + + using (XmlWriter writer = XmlWriter.Create(buffer, settings)) + { + XmlSerializer serializer = new XmlSerializer(type); + serializer.Serialize(writer, obj); + writer.Flush(); + } + + int length = (int)buffer.Length; + request.ContentLength = length; + + Stream requestStream = request.GetRequestStream(); + requestStream.Write(buffer.ToArray(), 0, length); + IAsyncResult result = request.BeginGetResponse(AsyncCallback, request); + } + + private void AsyncCallback(IAsyncResult result) + { + WebRequest request = (WebRequest)result.AsyncState; + using (WebResponse resp = request.EndGetResponse(result)) + { + TResponse deserial; + XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); + deserial = (TResponse)deserializer.Deserialize(resp.GetResponseStream()); + + if (deserial != null && ReturnResponseVal != null) + { + ReturnResponseVal(deserial); + } + } + } + } + + public class SyncRestObjectPoster + { + + public static TResponse BeginPostObject(string requestUrl, TRequest obj) + { + Type type = typeof(TRequest); + + WebRequest request = WebRequest.Create(requestUrl); + request.Method = "POST"; + request.ContentType = "text/xml"; + + MemoryStream buffer = new MemoryStream(); + + XmlWriterSettings settings = new XmlWriterSettings(); + settings.Encoding = Encoding.UTF8; + + using (XmlWriter writer = XmlWriter.Create(buffer, settings)) + { + XmlSerializer serializer = new XmlSerializer(type); + serializer.Serialize(writer, obj); + writer.Flush(); + } + + int length = (int)buffer.Length; + request.ContentLength = length; + + Stream requestStream = request.GetRequestStream(); + requestStream.Write(buffer.ToArray(), 0, length); + TResponse deserial = default(TResponse); + using (WebResponse resp = request.GetResponse()) + { + + XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); + deserial = (TResponse)deserializer.Deserialize(resp.GetResponseStream()); + } + return deserial; + } + + } } \ No newline at end of file -- cgit v1.1