Files
libremetaverse/Programs/examples/TestClient/Commands/Inventory/ViewNotecardCommand.cs

77 lines
2.6 KiB
C#
Raw Normal View History

2025-01-13 07:44:05 -06:00
using System;
using OpenMetaverse.Assets;
namespace OpenMetaverse.TestClient
{
public class ViewNotecardCommand : Command
{
/// <summary>
/// TestClient command to download and display a notecard asset
/// </summary>
/// <param name="testClient"></param>
public ViewNotecardCommand(TestClient testClient)
{
Name = "viewnote";
Description = "Downloads and displays a notecard asset";
Category = CommandCategory.Inventory;
}
/// <summary>
2022-11-16 08:39:23 -06:00
/// Execute the command
/// </summary>
/// <param name="args"></param>
/// <param name="fromAgentID"></param>
/// <returns></returns>
public override string Execute(string[] args, UUID fromAgentID)
{
if (args.Length < 1)
{
return "Usage: viewnote [notecard asset uuid]";
}
UUID note;
if (!UUID.TryParse(args[0], out note))
{
return "First argument expected agent UUID.";
}
System.Threading.AutoResetEvent waitEvent = new System.Threading.AutoResetEvent(false);
System.Text.StringBuilder result = new System.Text.StringBuilder();
// verify asset is loaded in store
if (Client.Inventory.Store.Contains(note))
{
// retrieve asset from store
InventoryItem ii = (InventoryItem)Client.Inventory.Store[note];
// make request for asset
var transferID = UUID.Random();
Client.Assets.RequestInventoryAsset(ii, true, transferID,
delegate(AssetDownload transfer, Asset asset)
{
if (transfer.Success)
{
result.AppendFormat("Raw Notecard Data: " + System.Environment.NewLine + " {0}", Utils.BytesToString(asset.AssetData));
waitEvent.Set();
}
}
);
// wait for reply or timeout
2025-01-13 07:44:05 -06:00
if (!waitEvent.WaitOne(TimeSpan.FromSeconds(10), false))
{
result.Append("Timeout waiting for notecard to download.");
}
}
else
{
result.Append("Cannot find asset in inventory store, use 'i' to populate store");
}
// return results
return result.ToString();
}
}
}