Some refactoring , mainly on Inventory code.

afrisby
MW 2007-12-02 13:59:15 +00:00
parent b92df4aaaf
commit 80609c2b15
10 changed files with 169 additions and 236 deletions

View File

@ -49,8 +49,8 @@ namespace OpenSim.Framework.Communications.Cache
folderID = new LLUUID("00000112-000f-0000-0000-000100bba000");
name = "OpenSim Library";
parentID = LLUUID.Zero;
type = (short) -1;
version = (ushort) 1;
type = (short)-1;
version = (ushort)1;
InventoryFolderImpl folderInfo = new InventoryFolderImpl();
folderInfo.agentID = libOwner;
@ -67,7 +67,7 @@ namespace OpenSim.Framework.Communications.Cache
string filePath = Path.Combine(Util.configDir(), "OpenSimLibrary.xml");
if (File.Exists(filePath))
{
try
try
{
XmlConfigSource source = new XmlConfigSource(filePath);
ReadItemsFromFile(source);
@ -80,142 +80,60 @@ namespace OpenSim.Framework.Communications.Cache
}
private void CreateLibraryItems()
{
InventoryItemBase item = CreateItem(LLUUID.Random(), new LLUUID("00000000-0000-0000-9999-000000000002"), "Plywood", "Plywood texture", (int)AssetType.Texture, (int)InventoryType.Texture, m_textureFolder.folderID);
m_textureFolder.Items.Add(item.inventoryID, item);
item = CreateItem(LLUUID.Random(), new LLUUID("00000000-0000-0000-9999-000000000003"), "Rocks", "Rocks texture", (int)AssetType.Texture, (int)InventoryType.Texture, m_textureFolder.folderID);
m_textureFolder.Items.Add(item.inventoryID, item);
item = CreateItem(LLUUID.Random(), new LLUUID("00000000-0000-0000-9999-000000000001"), "Bricks", "Bricks texture", (int)AssetType.Texture, (int)InventoryType.Texture, m_textureFolder.folderID);
m_textureFolder.Items.Add(item.inventoryID, item);
item = CreateItem(LLUUID.Random(), new LLUUID("00000000-0000-0000-9999-000000000004"), "Granite", "Granite texture", (int)AssetType.Texture, (int)InventoryType.Texture, m_textureFolder.folderID);
m_textureFolder.Items.Add(item.inventoryID, item);
item = CreateItem(LLUUID.Random(), new LLUUID("00000000-0000-0000-9999-000000000005"), "Hardwood", "Hardwood texture", (int)AssetType.Texture, (int)InventoryType.Texture, m_textureFolder.folderID);
m_textureFolder.Items.Add(item.inventoryID, item);
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);
item.inventoryCurrentPermissions = 0;
item.inventoryNextPermissions = 0;
Items.Add(item.inventoryID, item);
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);
item.inventoryCurrentPermissions = 0;
item.inventoryNextPermissions = 0;
Items.Add(item.inventoryID, item);
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);
item.inventoryCurrentPermissions = 0;
item.inventoryNextPermissions = 0;
Items.Add(item.inventoryID, item);
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);
item.inventoryCurrentPermissions = 0;
item.inventoryNextPermissions = 0;
Items.Add(item.inventoryID, item);
}
private InventoryItemBase CreateItem(LLUUID inventoryID, LLUUID assetID, string name, string description, int assetType, int invType, LLUUID parentFolderID)
{
InventoryItemBase item = new InventoryItemBase();
item.avatarID = libOwner;
item.creatorsID = libOwner;
item.inventoryID = LLUUID.Random();
item.assetID = new LLUUID("00000000-0000-0000-9999-000000000002");
item.inventoryDescription = "Plywood texture";
item.inventoryName = "Plywood";
item.assetType = (int) AssetType.Texture;
item.invType = (int) InventoryType.Texture;
item.parentFolderID = m_textureFolder.folderID;
item.assetID = assetID;
item.inventoryDescription = description;
item.inventoryName = name;
item.assetType = assetType;
item.invType = invType;
item.parentFolderID = parentFolderID;
item.inventoryBasePermissions = 0x7FFFFFFF;
item.inventoryEveryOnePermissions = 0x7FFFFFFF;
item.inventoryCurrentPermissions = 0x7FFFFFFF;
item.inventoryNextPermissions = 0x7FFFFFFF;
m_textureFolder.Items.Add(item.inventoryID, item);
item = new InventoryItemBase();
item.avatarID = libOwner;
item.creatorsID = libOwner;
item.inventoryID = LLUUID.Random();
item.assetID = new LLUUID("00000000-0000-0000-9999-000000000003");
item.inventoryDescription = "Rocks texture";
item.inventoryName = "Rocks";
item.assetType = (int) AssetType.Texture;
item.invType = (int) InventoryType.Texture;
item.parentFolderID = m_textureFolder.folderID;
item.inventoryBasePermissions = 0x7FFFFFFF;
item.inventoryEveryOnePermissions = 0x7FFFFFFF;
item.inventoryCurrentPermissions = 0x7FFFFFFF;
item.inventoryNextPermissions = 0x7FFFFFFF;
m_textureFolder.Items.Add(item.inventoryID, item);
item = new InventoryItemBase();
item.avatarID = libOwner;
item.creatorsID = libOwner;
item.inventoryID = LLUUID.Random();
item.assetID = new LLUUID("00000000-0000-0000-9999-000000000001");
item.inventoryDescription = "Bricks texture";
item.inventoryName = "Bricks";
item.assetType = (int) AssetType.Texture;
item.invType = (int) InventoryType.Texture;
item.parentFolderID = m_textureFolder.folderID;
item.inventoryBasePermissions = 0x7FFFFFFF;
item.inventoryEveryOnePermissions = 0x7FFFFFFF;
item.inventoryCurrentPermissions = 0x7FFFFFFF;
item.inventoryNextPermissions = 0x7FFFFFFF;
m_textureFolder.Items.Add(item.inventoryID, item);
item = new InventoryItemBase();
item.avatarID = libOwner;
item.creatorsID = libOwner;
item.inventoryID = LLUUID.Random();
item.assetID = new LLUUID("00000000-0000-0000-9999-000000000004");
item.inventoryDescription = "Granite texture";
item.inventoryName = "Granite";
item.assetType = (int) AssetType.Texture;
item.invType = (int) InventoryType.Texture;
item.parentFolderID = m_textureFolder.folderID;
item.inventoryBasePermissions = 0x7FFFFFFF;
item.inventoryEveryOnePermissions = 0x7FFFFFFF;
item.inventoryCurrentPermissions = 0x7FFFFFFF;
item.inventoryNextPermissions = 0x7FFFFFFF;
m_textureFolder.Items.Add(item.inventoryID, item);
item = new InventoryItemBase();
item.avatarID = libOwner;
item.creatorsID = libOwner;
item.inventoryID = LLUUID.Random();
item.assetID = new LLUUID("00000000-0000-0000-9999-000000000005");
item.inventoryDescription = "Hardwood texture";
item.inventoryName = "Hardwood";
item.assetType = (int) AssetType.Texture;
item.invType = (int) InventoryType.Texture;
item.parentFolderID = m_textureFolder.folderID;
item.inventoryBasePermissions = 0x7FFFFFFF;
item.inventoryEveryOnePermissions = 0x7FFFFFFF;
item.inventoryCurrentPermissions = 0x7FFFFFFF;
item.inventoryNextPermissions = 0x7FFFFFFF;
m_textureFolder.Items.Add(item.inventoryID, item);
item = new InventoryItemBase();
item.avatarID = libOwner;
item.creatorsID = libOwner;
item.inventoryID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfaba9");
item.assetID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73");
item.inventoryDescription = "Default Shape";
item.inventoryName = "Default Shape";
item.assetType = (int) AssetType.Bodypart;
item.invType = (int) InventoryType.Wearable;
item.parentFolderID = folderID;
item.inventoryCurrentPermissions = 0;
item.inventoryNextPermissions = 0;
Items.Add(item.inventoryID, item);
item = new InventoryItemBase();
item.avatarID = libOwner;
item.creatorsID = libOwner;
item.inventoryID = new LLUUID("77c41e39-38f9-f75a-024e-585989bfabc9");
item.assetID = new LLUUID("77c41e39-38f9-f75a-024e-585989bbabbb");
item.inventoryDescription = "Default Skin";
item.inventoryName = "Default Skin";
item.assetType = (int) AssetType.Bodypart;
item.invType = (int) InventoryType.Wearable;
item.parentFolderID = folderID;
item.inventoryCurrentPermissions = 0;
item.inventoryNextPermissions = 0;
Items.Add(item.inventoryID, item);
item = new InventoryItemBase();
item.avatarID = libOwner;
item.creatorsID = libOwner;
item.inventoryID = new LLUUID("77c41e39-38f9-f75a-0000-585989bf0000");
item.assetID = new LLUUID("00000000-38f9-1111-024e-222222111110");
item.inventoryDescription = "Default Shirt";
item.inventoryName = "Default Shirt";
item.assetType = (int) AssetType.Clothing;
item.invType = (int) InventoryType.Wearable;
item.parentFolderID = folderID;
item.inventoryCurrentPermissions = 0;
item.inventoryNextPermissions = 0;
Items.Add(item.inventoryID, item);
item = new InventoryItemBase();
item.avatarID = libOwner;
item.creatorsID = libOwner;
item.inventoryID = new LLUUID("77c41e39-38f9-f75a-0000-5859892f1111");
item.assetID = new LLUUID("00000000-38f9-1111-024e-222222111120");
item.inventoryDescription = "Default Pants";
item.inventoryName = "Default Pants";
item.assetType = (int) AssetType.Clothing;
item.invType = (int) InventoryType.Wearable;
item.parentFolderID = folderID;
item.inventoryCurrentPermissions = 0;
item.inventoryNextPermissions = 0;
Items.Add(item.inventoryID, item);
return item;
}
private void ReadItemsFromFile(IConfigSource source)
@ -232,10 +150,10 @@ namespace OpenSim.Framework.Communications.Cache
item.inventoryName = source.Configs[i].GetString("name", "");
item.assetType = source.Configs[i].GetInt("assetType", 0);
item.invType = source.Configs[i].GetInt("inventoryType", 0);
item.inventoryCurrentPermissions = (uint) source.Configs[i].GetLong("currentPermissions", 0x7FFFFFFF);
item.inventoryNextPermissions = (uint) source.Configs[i].GetLong("nextPermissions", 0x7FFFFFFF);
item.inventoryEveryOnePermissions = (uint) source.Configs[i].GetLong("everyonePermissions", 0x7FFFFFFF);
item.inventoryBasePermissions = (uint) source.Configs[i].GetLong("basePermissions", 0x7FFFFFFF);
item.inventoryCurrentPermissions = (uint)source.Configs[i].GetLong("currentPermissions", 0x7FFFFFFF);
item.inventoryNextPermissions = (uint)source.Configs[i].GetLong("nextPermissions", 0x7FFFFFFF);
item.inventoryEveryOnePermissions = (uint)source.Configs[i].GetLong("everyonePermissions", 0x7FFFFFFF);
item.inventoryBasePermissions = (uint)source.Configs[i].GetLong("basePermissions", 0x7FFFFFFF);
if (item.assetType == 0)
{
item.parentFolderID = m_textureFolder.folderID;

View File

@ -30,7 +30,7 @@ using libsecondlife;
namespace OpenSim.Framework.Communications.Cache
{
public class UserProfileCache
public class UserProfileCacheService
{
// Fields
private readonly CommunicationsManager m_parent;
@ -39,7 +39,7 @@ namespace OpenSim.Framework.Communications.Cache
public LibraryRootFolder libraryRoot = new LibraryRootFolder();
// Methods
public UserProfileCache(CommunicationsManager parent)
public UserProfileCacheService(CommunicationsManager parent)
{
m_parent = parent;
}

View File

@ -64,9 +64,9 @@ namespace OpenSim.Framework.Communications
get { return m_interRegion; }
}
protected UserProfileCache m_userProfileCache;
protected UserProfileCacheService m_userProfileCache;
public UserProfileCache UserProfileCache
public UserProfileCacheService UserProfileCache
{
get { return m_userProfileCache; }
}
@ -97,7 +97,7 @@ namespace OpenSim.Framework.Communications
{
m_networkServersInfo = serversInfo;
m_assetCache = assetCache;
m_userProfileCache = new UserProfileCache(this);
m_userProfileCache = new UserProfileCacheService(this);
m_transactionsManager = new AssetTransactionManager(this, dumpAssetsToFile);
}

View File

@ -5,14 +5,10 @@ using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace OpenSim.Framework.Servers
{
public delegate void ReturnResponse<T>(T reponse);
public class RestObjectPoster
{
public static void BeginPostObject<TRequest>(string requestUrl, TRequest obj)
{
Type type = typeof(TRequest);
@ -49,93 +45,4 @@ namespace OpenSim.Framework.Servers
}
}
}
public class RestObjectPosterResponse<TResponse>
{
public ReturnResponse<TResponse> ReturnResponseVal;
public void BeginPostObject<TRequest>(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<TRequest, TResponse>(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;
}
}
}

View File

@ -0,0 +1,60 @@
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace OpenSim.Framework.Servers
{
public delegate void ReturnResponse<T>(T reponse);
public class RestObjectPosterResponse<TResponse>
{
public ReturnResponse<TResponse> ResponseCallback;
public void BeginPostObject<TRequest>(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 && ResponseCallback != null)
{
ResponseCallback(deserial);
}
}
}
}
}

View File

@ -0,0 +1,48 @@
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace OpenSim.Framework.Servers
{
public class SynchronousRestObjectPoster
{
public static TResponse BeginPostObject<TRequest, TResponse>(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;
}
}
}

View File

@ -155,7 +155,7 @@ namespace OpenSim.Grid.UserServer
// RestObjectPosterResponse<List<InventoryFolderBase>> requester = new RestObjectPosterResponse<List<InventoryFolderBase>>();
// requester.ReturnResponseVal = TestResponse;
// requester.BeginPostObject<LLUUID>(m_userManager._config.InventoryUrl + "RootFolders/", m_lastCreatedUser);
List<InventoryFolderBase> folders = SyncRestObjectPoster.BeginPostObject<LLUUID, List<InventoryFolderBase>>(m_userManager._config.InventoryUrl + "RootFolders/", m_lastCreatedUser);
List<InventoryFolderBase> folders = SynchronousRestObjectPoster.BeginPostObject<LLUUID, List<InventoryFolderBase>>(m_userManager._config.InventoryUrl + "RootFolders/", m_lastCreatedUser);
break;
}
}

View File

@ -197,12 +197,12 @@ namespace OpenSim.Grid.UserServer
protected override InventoryData CreateInventoryData(LLUUID userID)
{
List<InventoryFolderBase> folders = SyncRestObjectPoster.BeginPostObject<LLUUID, List<InventoryFolderBase>>(m_config.InventoryUrl + "RootFolders/", userID);
List<InventoryFolderBase> folders = SynchronousRestObjectPoster.BeginPostObject<LLUUID, List<InventoryFolderBase>>(m_config.InventoryUrl + "RootFolders/", userID);
if (folders ==null | folders.Count == 0)
{
RestObjectPoster.BeginPostObject<LLUUID>(m_config.InventoryUrl + "CreateInventory/", userID);
Thread.Sleep(1000);
folders = SyncRestObjectPoster.BeginPostObject<LLUUID, List<InventoryFolderBase>>(m_config.InventoryUrl + "RootFolders/", userID);
folders = SynchronousRestObjectPoster.BeginPostObject<LLUUID, List<InventoryFolderBase>>(m_config.InventoryUrl + "RootFolders/", userID);
}
if(folders.Count >0)

View File

@ -64,7 +64,7 @@ namespace OpenSim.Region.Communications.OGS1
try
{
RestObjectPosterResponse<InventoryCollection> requester = new RestObjectPosterResponse<InventoryCollection>();
requester.ReturnResponseVal = InventoryResponse;
requester.ResponseCallback = InventoryResponse;
requester.BeginPostObject<LLUUID>(_inventoryServerUrl + "/GetInventory/", userID);
}
catch (Exception)