Documented ModelUploader, added ability to just do price check

This commit is contained in:
Latif Khalifa
2014-06-27 09:01:47 +02:00
parent d2f63290f7
commit 49ad7e627a

View File

@@ -35,18 +35,38 @@ using OpenMetaverse.Http;
namespace OpenMetaverse.ImportExport
{
/// <summary>
/// Implements mesh upload communications with the simulator
/// </summary>
public class ModelUploader
{
/// <summary>
/// Inlcude stub convex hull physics, required for uploading to Second Life
/// </summary>
public bool IncludePhysicsStub;
/// <summary>
/// Use the same mesh used for geometry as the physical mesh upload
/// </summary>
public bool UseModelAsPhysics;
GridClient Client;
List<ModelPrim> Prims;
public delegate void ModelUploadCallback(OSD result);
/// <summary>
/// Creates instance of the mesh uploader
/// </summary>
/// <param name="client">GridClient instance to communicate with the simulator</param>
/// <param name="prims">List of ModelPrimitive objects to upload as a linkset</param>
public ModelUploader(GridClient client, List<ModelPrim> prims)
{
this.Client = client;
this.Prims = prims;
}
OSD AssetResources()
OSD AssetResources(bool includeImages)
{
OSDArray instanceList = new OSDArray();
List<byte[]> meshes = new List<byte[]>();
@@ -102,7 +122,37 @@ namespace OpenMetaverse.ImportExport
return resources;
}
public void PrepareUpload()
/// <summary>
/// Performs model upload in one go, without first checking for the price
/// </summary>
public void Upload()
{
Upload(null);
}
/// <summary>
/// Performs model upload in one go, without first checking for the price
/// </summary>
/// <param name="callback">Callback that will be invoke upon completion of the upload. Null is sent on request failure</param>
public void Upload(ModelUploadCallback callback)
{
PrepareUpload((result =>
{
if (result is OSDMap)
{
var res = (OSDMap)result;
Uri uploader = new Uri(res["uploader"]);
PerformUpload(uploader, callback);
}
}));
}
/// <summary>
/// Ask server for details of cost and impact of the mesh upload
/// </summary>
/// <param name="callback">Callback that will be invoke upon completion of the upload. Null is sent on request failure</param>
public void PrepareUpload(ModelUploadCallback callback)
{
Uri url = null;
if (Client.Network.CurrentSim == null ||
@@ -117,7 +167,7 @@ namespace OpenMetaverse.ImportExport
req["name"] = "Test upload object";
req["description"] = "Radegast mesh upload " + DateTime.Now.ToString();
req["asset_resources"] = AssetResources();
req["asset_resources"] = AssetResources(false);
req["asset_type"] = "mesh";
req["inventory_type"] = "object";
@@ -134,6 +184,7 @@ namespace OpenMetaverse.ImportExport
if (error != null || result == null || result.Type != OSDType.Map)
{
Logger.Log("Mesh upload request failure", Helpers.LogLevel.Error);
if (callback != null) callback(null);
return;
}
OSDMap res = (OSDMap)result;
@@ -141,19 +192,24 @@ namespace OpenMetaverse.ImportExport
if (res["state"] != "upload")
{
Logger.Log("Mesh upload failure: " + res["message"], Helpers.LogLevel.Error);
if (callback != null) callback(null);
return;
}
Logger.Log("Response from mesh upload prepare:\n" + OSDParser.SerializeLLSDNotationFormatted(result), Helpers.LogLevel.Debug);
Uri uploader = new Uri(res["uploader"]);
PerformUpload(uploader);
if (callback != null) callback(result);
};
request.BeginGetResponse(req, OSDFormat.Xml, 60 * 1000);
}
public void PerformUpload(Uri uploader)
/// <summary>
/// Performas actual mesh and image upload
/// </summary>
/// <param name="uploader">Uri recieved in the upload prepare stage</param>
/// <param name="callback">Callback that will be invoke upon completion of the upload. Null is sent on request failure</param>
public void PerformUpload(Uri uploader, ModelUploadCallback callback)
{
CapsClient request = new CapsClient(uploader);
request.OnComplete += (client, result, error) =>
@@ -161,13 +217,15 @@ namespace OpenMetaverse.ImportExport
if (error != null || result == null || result.Type != OSDType.Map)
{
Logger.Log("Mesh upload request failure", Helpers.LogLevel.Error);
if (callback != null) callback(null);
return;
}
OSDMap res = (OSDMap)result;
Logger.Log("Response from mesh upload perform:\n" + OSDParser.SerializeLLSDNotationFormatted(result), Helpers.LogLevel.Debug);
if (callback != null) callback(res);
};
request.BeginGetResponse(AssetResources(), OSDFormat.Xml, 60 * 1000);
request.BeginGetResponse(AssetResources(true), OSDFormat.Xml, 60 * 1000);
}