diff options
author | MW | 2007-12-02 13:59:15 +0000 |
---|---|---|
committer | MW | 2007-12-02 13:59:15 +0000 |
commit | 80609c2b1572d9b946675db486fc46e327171cfa (patch) | |
tree | 85a623c1a75255d74883c3f9ba11e5f66a053a18 /OpenSim/Framework | |
parent | New Inventory folder should now be stored to the inventory server/database. T... (diff) | |
download | opensim-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')
-rw-r--r-- | OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs (renamed from OpenSim/Framework/Communications/Cache/InventoryFolder.cs) | 0 | ||||
-rw-r--r-- | OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs | 152 | ||||
-rw-r--r-- | OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs (renamed from OpenSim/Framework/Communications/Cache/UserProfileCache.cs) | 4 | ||||
-rw-r--r-- | OpenSim/Framework/Communications/CommunicationsManager.cs | 6 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/RestObjectPoster.cs | 93 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/RestObjectPosterResponse.cs | 60 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/SynchronousRestObjectPoster.cs | 48 |
7 files changed, 148 insertions, 215 deletions
diff --git a/OpenSim/Framework/Communications/Cache/InventoryFolder.cs b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs index fd029cd..fd029cd 100644 --- a/OpenSim/Framework/Communications/Cache/InventoryFolder.cs +++ b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs | |||
diff --git a/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs b/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs index 62251bc..33b4281 100644 --- a/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs +++ b/OpenSim/Framework/Communications/Cache/LibraryRootFolder.cs | |||
@@ -49,8 +49,8 @@ namespace OpenSim.Framework.Communications.Cache | |||
49 | folderID = new LLUUID("00000112-000f-0000-0000-000100bba000"); | 49 | folderID = new LLUUID("00000112-000f-0000-0000-000100bba000"); |
50 | name = "OpenSim Library"; | 50 | name = "OpenSim Library"; |
51 | parentID = LLUUID.Zero; | 51 | parentID = LLUUID.Zero; |
52 | type = (short) -1; | 52 | type = (short)-1; |
53 | version = (ushort) 1; | 53 | version = (ushort)1; |
54 | 54 | ||
55 | InventoryFolderImpl folderInfo = new InventoryFolderImpl(); | 55 | InventoryFolderImpl folderInfo = new InventoryFolderImpl(); |
56 | folderInfo.agentID = libOwner; | 56 | folderInfo.agentID = libOwner; |
@@ -67,7 +67,7 @@ namespace OpenSim.Framework.Communications.Cache | |||
67 | string filePath = Path.Combine(Util.configDir(), "OpenSimLibrary.xml"); | 67 | string filePath = Path.Combine(Util.configDir(), "OpenSimLibrary.xml"); |
68 | if (File.Exists(filePath)) | 68 | if (File.Exists(filePath)) |
69 | { | 69 | { |
70 | try | 70 | try |
71 | { | 71 | { |
72 | XmlConfigSource source = new XmlConfigSource(filePath); | 72 | XmlConfigSource source = new XmlConfigSource(filePath); |
73 | ReadItemsFromFile(source); | 73 | ReadItemsFromFile(source); |
@@ -81,143 +81,61 @@ namespace OpenSim.Framework.Communications.Cache | |||
81 | 81 | ||
82 | private void CreateLibraryItems() | 82 | private void CreateLibraryItems() |
83 | { | 83 | { |
84 | InventoryItemBase item = new InventoryItemBase(); | 84 | InventoryItemBase item = CreateItem(LLUUID.Random(), new LLUUID("00000000-0000-0000-9999-000000000002"), "Plywood", "Plywood texture", (int)AssetType.Texture, (int)InventoryType.Texture, m_textureFolder.folderID); |
85 | item.avatarID = libOwner; | ||
86 | item.creatorsID = libOwner; | ||
87 | item.inventoryID = LLUUID.Random(); | ||
88 | item.assetID = new LLUUID("00000000-0000-0000-9999-000000000002"); | ||
89 | item.inventoryDescription = "Plywood texture"; | ||
90 | item.inventoryName = "Plywood"; | ||
91 | item.assetType = (int) AssetType.Texture; | ||
92 | item.invType = (int) InventoryType.Texture; | ||
93 | item.parentFolderID = m_textureFolder.folderID; | ||
94 | item.inventoryBasePermissions = 0x7FFFFFFF; | ||
95 | item.inventoryEveryOnePermissions = 0x7FFFFFFF; | ||
96 | item.inventoryCurrentPermissions = 0x7FFFFFFF; | ||
97 | item.inventoryNextPermissions = 0x7FFFFFFF; | ||
98 | m_textureFolder.Items.Add(item.inventoryID, item); | 85 | m_textureFolder.Items.Add(item.inventoryID, item); |
99 | 86 | ||
100 | item = new InventoryItemBase(); | 87 | item = CreateItem(LLUUID.Random(), new LLUUID("00000000-0000-0000-9999-000000000003"), "Rocks", "Rocks texture", (int)AssetType.Texture, (int)InventoryType.Texture, m_textureFolder.folderID); |
101 | item.avatarID = libOwner; | ||
102 | item.creatorsID = libOwner; | ||
103 | item.inventoryID = LLUUID.Random(); | ||
104 | item.assetID = new LLUUID("00000000-0000-0000-9999-000000000003"); | ||
105 | item.inventoryDescription = "Rocks texture"; | ||
106 | item.inventoryName = "Rocks"; | ||
107 | item.assetType = (int) AssetType.Texture; | ||
108 | item.invType = (int) InventoryType.Texture; | ||
109 | item.parentFolderID = m_textureFolder.folderID; | ||
110 | item.inventoryBasePermissions = 0x7FFFFFFF; | ||
111 | item.inventoryEveryOnePermissions = 0x7FFFFFFF; | ||
112 | item.inventoryCurrentPermissions = 0x7FFFFFFF; | ||
113 | item.inventoryNextPermissions = 0x7FFFFFFF; | ||
114 | m_textureFolder.Items.Add(item.inventoryID, item); | 88 | m_textureFolder.Items.Add(item.inventoryID, item); |
115 | 89 | ||
116 | item = new InventoryItemBase(); | 90 | item = CreateItem(LLUUID.Random(), new LLUUID("00000000-0000-0000-9999-000000000001"), "Bricks", "Bricks texture", (int)AssetType.Texture, (int)InventoryType.Texture, m_textureFolder.folderID); |
117 | item.avatarID = libOwner; | ||
118 | item.creatorsID = libOwner; | ||
119 | item.inventoryID = LLUUID.Random(); | ||
120 | item.assetID = new LLUUID("00000000-0000-0000-9999-000000000001"); | ||
121 | item.inventoryDescription = "Bricks texture"; | ||
122 | item.inventoryName = "Bricks"; | ||
123 | item.assetType = (int) AssetType.Texture; | ||
124 | item.invType = (int) InventoryType.Texture; | ||
125 | item.parentFolderID = m_textureFolder.folderID; | ||
126 | item.inventoryBasePermissions = 0x7FFFFFFF; | ||
127 | item.inventoryEveryOnePermissions = 0x7FFFFFFF; | ||
128 | item.inventoryCurrentPermissions = 0x7FFFFFFF; | ||
129 | item.inventoryNextPermissions = 0x7FFFFFFF; | ||
130 | m_textureFolder.Items.Add(item.inventoryID, item); | 91 | m_textureFolder.Items.Add(item.inventoryID, item); |
131 | 92 | ||
132 | item = new InventoryItemBase(); | 93 | item = CreateItem(LLUUID.Random(), new LLUUID("00000000-0000-0000-9999-000000000004"), "Granite", "Granite texture", (int)AssetType.Texture, (int)InventoryType.Texture, m_textureFolder.folderID); |
133 | item.avatarID = libOwner; | ||
134 | item.creatorsID = libOwner; | ||
135 | item.inventoryID = LLUUID.Random(); | ||
136 | item.assetID = new LLUUID("00000000-0000-0000-9999-000000000004"); | ||
137 | item.inventoryDescription = "Granite texture"; | ||
138 | item.inventoryName = "Granite"; | ||
139 | item.assetType = (int) AssetType.Texture; | ||
140 | item.invType = (int) InventoryType.Texture; | ||
141 | item.parentFolderID = m_textureFolder.folderID; | ||
142 | item.inventoryBasePermissions = 0x7FFFFFFF; | ||
143 | item.inventoryEveryOnePermissions = 0x7FFFFFFF; | ||
144 | item.inventoryCurrentPermissions = 0x7FFFFFFF; | ||
145 | item.inventoryNextPermissions = 0x7FFFFFFF; | ||
146 | m_textureFolder.Items.Add(item.inventoryID, item); | 94 | m_textureFolder.Items.Add(item.inventoryID, item); |
147 | 95 | ||
148 | item = new InventoryItemBase(); | 96 | item = CreateItem(LLUUID.Random(), new LLUUID("00000000-0000-0000-9999-000000000005"), "Hardwood", "Hardwood texture", (int)AssetType.Texture, (int)InventoryType.Texture, m_textureFolder.folderID); |
149 | item.avatarID = libOwner; | ||
150 | item.creatorsID = libOwner; | ||
151 | item.inventoryID = LLUUID.Random(); | ||
152 | item.assetID = new LLUUID("00000000-0000-0000-9999-000000000005"); | ||
153 | item.inventoryDescription = "Hardwood texture"; | ||
154 | item.inventoryName = "Hardwood"; | ||
155 | item.assetType = (int) AssetType.Texture; | ||
156 | item.invType = (int) InventoryType.Texture; | ||
157 | item.parentFolderID = m_textureFolder.folderID; | ||
158 | item.inventoryBasePermissions = 0x7FFFFFFF; | ||
159 | item.inventoryEveryOnePermissions = 0x7FFFFFFF; | ||
160 | item.inventoryCurrentPermissions = 0x7FFFFFFF; | ||
161 | item.inventoryNextPermissions = 0x7FFFFFFF; | ||
162 | m_textureFolder.Items.Add(item.inventoryID, item); | 97 | m_textureFolder.Items.Add(item.inventoryID, item); |
163 | 98 | ||
164 | item = new InventoryItemBase(); | 99 | item = CreateItem(new LLUUID("66c41e39-38f9-f75a-024e-585989bfaba9"), new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73"), "Default Shape", "Default Shape", (int)AssetType.Bodypart, (int)InventoryType.Wearable, folderID); |
165 | item.avatarID = libOwner; | ||
166 | item.creatorsID = libOwner; | ||
167 | item.inventoryID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfaba9"); | ||
168 | item.assetID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73"); | ||
169 | item.inventoryDescription = "Default Shape"; | ||
170 | item.inventoryName = "Default Shape"; | ||
171 | item.assetType = (int) AssetType.Bodypart; | ||
172 | item.invType = (int) InventoryType.Wearable; | ||
173 | item.parentFolderID = folderID; | ||
174 | item.inventoryCurrentPermissions = 0; | 100 | item.inventoryCurrentPermissions = 0; |
175 | item.inventoryNextPermissions = 0; | 101 | item.inventoryNextPermissions = 0; |
176 | Items.Add(item.inventoryID, item); | 102 | Items.Add(item.inventoryID, item); |
177 | 103 | ||
178 | item = new InventoryItemBase(); | 104 | item = CreateItem(new LLUUID("77c41e39-38f9-f75a-024e-585989bfabc9"), new LLUUID("77c41e39-38f9-f75a-024e-585989bbabbb"), "Default Skin", "Default Skin", (int)AssetType.Bodypart, (int)InventoryType.Wearable, folderID); |
179 | item.avatarID = libOwner; | ||
180 | item.creatorsID = libOwner; | ||
181 | item.inventoryID = new LLUUID("77c41e39-38f9-f75a-024e-585989bfabc9"); | ||
182 | item.assetID = new LLUUID("77c41e39-38f9-f75a-024e-585989bbabbb"); | ||
183 | item.inventoryDescription = "Default Skin"; | ||
184 | item.inventoryName = "Default Skin"; | ||
185 | item.assetType = (int) AssetType.Bodypart; | ||
186 | item.invType = (int) InventoryType.Wearable; | ||
187 | item.parentFolderID = folderID; | ||
188 | item.inventoryCurrentPermissions = 0; | 105 | item.inventoryCurrentPermissions = 0; |
189 | item.inventoryNextPermissions = 0; | 106 | item.inventoryNextPermissions = 0; |
190 | Items.Add(item.inventoryID, item); | 107 | Items.Add(item.inventoryID, item); |
191 | 108 | ||
192 | item = new InventoryItemBase(); | 109 | item = CreateItem(new LLUUID("77c41e39-38f9-f75a-0000-585989bf0000"), new LLUUID("00000000-38f9-1111-024e-222222111110"), "Default Shirt", "Default Shirt", (int)AssetType.Clothing, (int)InventoryType.Wearable, folderID); |
193 | item.avatarID = libOwner; | ||
194 | item.creatorsID = libOwner; | ||
195 | item.inventoryID = new LLUUID("77c41e39-38f9-f75a-0000-585989bf0000"); | ||
196 | item.assetID = new LLUUID("00000000-38f9-1111-024e-222222111110"); | ||
197 | item.inventoryDescription = "Default Shirt"; | ||
198 | item.inventoryName = "Default Shirt"; | ||
199 | item.assetType = (int) AssetType.Clothing; | ||
200 | item.invType = (int) InventoryType.Wearable; | ||
201 | item.parentFolderID = folderID; | ||
202 | item.inventoryCurrentPermissions = 0; | 110 | item.inventoryCurrentPermissions = 0; |
203 | item.inventoryNextPermissions = 0; | 111 | item.inventoryNextPermissions = 0; |
204 | Items.Add(item.inventoryID, item); | 112 | Items.Add(item.inventoryID, item); |
205 | 113 | ||
206 | item = new InventoryItemBase(); | 114 | item = CreateItem(new LLUUID("77c41e39-38f9-f75a-0000-5859892f1111"), new LLUUID("00000000-38f9-1111-024e-222222111120"), "Default Pants", "Default Pants", (int)AssetType.Clothing, (int)InventoryType.Wearable, folderID); |
207 | item.avatarID = libOwner; | ||
208 | item.creatorsID = libOwner; | ||
209 | item.inventoryID = new LLUUID("77c41e39-38f9-f75a-0000-5859892f1111"); | ||
210 | item.assetID = new LLUUID("00000000-38f9-1111-024e-222222111120"); | ||
211 | item.inventoryDescription = "Default Pants"; | ||
212 | item.inventoryName = "Default Pants"; | ||
213 | item.assetType = (int) AssetType.Clothing; | ||
214 | item.invType = (int) InventoryType.Wearable; | ||
215 | item.parentFolderID = folderID; | ||
216 | item.inventoryCurrentPermissions = 0; | 115 | item.inventoryCurrentPermissions = 0; |
217 | item.inventoryNextPermissions = 0; | 116 | item.inventoryNextPermissions = 0; |
218 | Items.Add(item.inventoryID, item); | 117 | Items.Add(item.inventoryID, item); |
219 | } | 118 | } |
220 | 119 | ||
120 | private InventoryItemBase CreateItem(LLUUID inventoryID, LLUUID assetID, string name, string description, int assetType, int invType, LLUUID parentFolderID) | ||
121 | { | ||
122 | InventoryItemBase item = new InventoryItemBase(); | ||
123 | item.avatarID = libOwner; | ||
124 | item.creatorsID = libOwner; | ||
125 | item.inventoryID = LLUUID.Random(); | ||
126 | item.assetID = assetID; | ||
127 | item.inventoryDescription = description; | ||
128 | item.inventoryName = name; | ||
129 | item.assetType = assetType; | ||
130 | item.invType = invType; | ||
131 | item.parentFolderID = parentFolderID; | ||
132 | item.inventoryBasePermissions = 0x7FFFFFFF; | ||
133 | item.inventoryEveryOnePermissions = 0x7FFFFFFF; | ||
134 | item.inventoryCurrentPermissions = 0x7FFFFFFF; | ||
135 | item.inventoryNextPermissions = 0x7FFFFFFF; | ||
136 | return item; | ||
137 | } | ||
138 | |||
221 | private void ReadItemsFromFile(IConfigSource source) | 139 | private void ReadItemsFromFile(IConfigSource source) |
222 | { | 140 | { |
223 | for (int i = 0; i < source.Configs.Count; i++) | 141 | for (int i = 0; i < source.Configs.Count; i++) |
@@ -232,10 +150,10 @@ namespace OpenSim.Framework.Communications.Cache | |||
232 | item.inventoryName = source.Configs[i].GetString("name", ""); | 150 | item.inventoryName = source.Configs[i].GetString("name", ""); |
233 | item.assetType = source.Configs[i].GetInt("assetType", 0); | 151 | item.assetType = source.Configs[i].GetInt("assetType", 0); |
234 | item.invType = source.Configs[i].GetInt("inventoryType", 0); | 152 | item.invType = source.Configs[i].GetInt("inventoryType", 0); |
235 | item.inventoryCurrentPermissions = (uint) source.Configs[i].GetLong("currentPermissions", 0x7FFFFFFF); | 153 | item.inventoryCurrentPermissions = (uint)source.Configs[i].GetLong("currentPermissions", 0x7FFFFFFF); |
236 | item.inventoryNextPermissions = (uint) source.Configs[i].GetLong("nextPermissions", 0x7FFFFFFF); | 154 | item.inventoryNextPermissions = (uint)source.Configs[i].GetLong("nextPermissions", 0x7FFFFFFF); |
237 | item.inventoryEveryOnePermissions = (uint) source.Configs[i].GetLong("everyonePermissions", 0x7FFFFFFF); | 155 | item.inventoryEveryOnePermissions = (uint)source.Configs[i].GetLong("everyonePermissions", 0x7FFFFFFF); |
238 | item.inventoryBasePermissions = (uint) source.Configs[i].GetLong("basePermissions", 0x7FFFFFFF); | 156 | item.inventoryBasePermissions = (uint)source.Configs[i].GetLong("basePermissions", 0x7FFFFFFF); |
239 | if (item.assetType == 0) | 157 | if (item.assetType == 0) |
240 | { | 158 | { |
241 | item.parentFolderID = m_textureFolder.folderID; | 159 | item.parentFolderID = m_textureFolder.folderID; |
diff --git a/OpenSim/Framework/Communications/Cache/UserProfileCache.cs b/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs index 3c8ab51..b24d763 100644 --- a/OpenSim/Framework/Communications/Cache/UserProfileCache.cs +++ b/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs | |||
@@ -30,7 +30,7 @@ using libsecondlife; | |||
30 | 30 | ||
31 | namespace OpenSim.Framework.Communications.Cache | 31 | namespace OpenSim.Framework.Communications.Cache |
32 | { | 32 | { |
33 | public class UserProfileCache | 33 | public class UserProfileCacheService |
34 | { | 34 | { |
35 | // Fields | 35 | // Fields |
36 | private readonly CommunicationsManager m_parent; | 36 | private readonly CommunicationsManager m_parent; |
@@ -39,7 +39,7 @@ namespace OpenSim.Framework.Communications.Cache | |||
39 | public LibraryRootFolder libraryRoot = new LibraryRootFolder(); | 39 | public LibraryRootFolder libraryRoot = new LibraryRootFolder(); |
40 | 40 | ||
41 | // Methods | 41 | // Methods |
42 | public UserProfileCache(CommunicationsManager parent) | 42 | public UserProfileCacheService(CommunicationsManager parent) |
43 | { | 43 | { |
44 | m_parent = parent; | 44 | m_parent = parent; |
45 | } | 45 | } |
diff --git a/OpenSim/Framework/Communications/CommunicationsManager.cs b/OpenSim/Framework/Communications/CommunicationsManager.cs index a7280aa..d4ddead 100644 --- a/OpenSim/Framework/Communications/CommunicationsManager.cs +++ b/OpenSim/Framework/Communications/CommunicationsManager.cs | |||
@@ -64,9 +64,9 @@ namespace OpenSim.Framework.Communications | |||
64 | get { return m_interRegion; } | 64 | get { return m_interRegion; } |
65 | } | 65 | } |
66 | 66 | ||
67 | protected UserProfileCache m_userProfileCache; | 67 | protected UserProfileCacheService m_userProfileCache; |
68 | 68 | ||
69 | public UserProfileCache UserProfileCache | 69 | public UserProfileCacheService UserProfileCache |
70 | { | 70 | { |
71 | get { return m_userProfileCache; } | 71 | get { return m_userProfileCache; } |
72 | } | 72 | } |
@@ -97,7 +97,7 @@ namespace OpenSim.Framework.Communications | |||
97 | { | 97 | { |
98 | m_networkServersInfo = serversInfo; | 98 | m_networkServersInfo = serversInfo; |
99 | m_assetCache = assetCache; | 99 | m_assetCache = assetCache; |
100 | m_userProfileCache = new UserProfileCache(this); | 100 | m_userProfileCache = new UserProfileCacheService(this); |
101 | m_transactionsManager = new AssetTransactionManager(this, dumpAssetsToFile); | 101 | m_transactionsManager = new AssetTransactionManager(this, dumpAssetsToFile); |
102 | } | 102 | } |
103 | 103 | ||
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; | |||
5 | using System.Xml; | 5 | using System.Xml; |
6 | using System.Xml.Serialization; | 6 | using System.Xml.Serialization; |
7 | 7 | ||
8 | |||
9 | namespace OpenSim.Framework.Servers | 8 | namespace 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 @@ | |||
1 | using System; | ||
2 | using System.IO; | ||
3 | using System.Net; | ||
4 | using System.Text; | ||
5 | using System.Xml; | ||
6 | using System.Xml.Serialization; | ||
7 | |||
8 | namespace 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 @@ | |||
1 | using System; | ||
2 | using System.IO; | ||
3 | using System.Net; | ||
4 | using System.Text; | ||
5 | using System.Xml; | ||
6 | using System.Xml.Serialization; | ||
7 | |||
8 | namespace 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 | } | ||