2008-03-12 22:46:53 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
2008-07-21 21:12:59 +00:00
|
|
|
using OpenMetaverse;
|
2008-03-12 22:46:53 +00:00
|
|
|
|
2008-07-21 21:12:59 +00:00
|
|
|
namespace OpenMetaverse.TestClient
|
2008-03-12 22:46:53 +00:00
|
|
|
{
|
|
|
|
|
public class CreateNotecardCommand : Command
|
|
|
|
|
{
|
|
|
|
|
public CreateNotecardCommand(TestClient testClient)
|
|
|
|
|
{
|
|
|
|
|
Name = "createnotecard";
|
|
|
|
|
Description = "Creates a notecard from a local text file.";
|
2008-07-25 08:55:36 +00:00
|
|
|
Category = CommandCategory.Inventory;
|
2008-03-12 22:46:53 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
void OnNoteUpdate(bool success, string status, UUID itemID, UUID assetID)
|
2008-03-12 22:46:53 +00:00
|
|
|
{
|
|
|
|
|
if (success)
|
|
|
|
|
Console.WriteLine("Notecard successfully uploaded, ItemID {0} AssetID {1}", itemID, assetID);
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
public override string Execute(string[] args, UUID fromAgentID)
|
2008-03-12 22:46:53 +00:00
|
|
|
{
|
|
|
|
|
if(args.Length < 1)
|
|
|
|
|
return "Usage: createnotecard filename.txt";
|
|
|
|
|
|
|
|
|
|
string file = String.Empty;
|
|
|
|
|
for (int ct = 0; ct < args.Length; ct++)
|
|
|
|
|
file = file + args[ct] + " ";
|
|
|
|
|
file = file.TrimEnd();
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("Filename: {0}", file);
|
|
|
|
|
if (!File.Exists(file))
|
|
|
|
|
return String.Format("Filename '{0}' does not exist", file);
|
|
|
|
|
|
|
|
|
|
System.IO.StreamReader reader = new StreamReader(file);
|
|
|
|
|
string body = reader.ReadToEnd();
|
|
|
|
|
|
2008-04-30 22:30:41 +00:00
|
|
|
// FIXME: Upload the notecard asset first. When that completes, call RequestCreateItem
|
2008-03-12 22:46:53 +00:00
|
|
|
try
|
|
|
|
|
{
|
2008-07-21 21:12:59 +00:00
|
|
|
string desc = String.Format("{0} created by OpenMetaverse TestClient {1}", file, DateTime.Now);
|
2008-03-12 22:46:53 +00:00
|
|
|
// create the asset
|
2008-05-04 07:43:02 +00:00
|
|
|
|
|
|
|
|
Client.Inventory.RequestCreateItem(Client.Inventory.FindFolderForType(AssetType.Notecard),
|
2008-07-25 05:15:05 +00:00
|
|
|
file, desc, AssetType.Notecard, UUID.Random(), InventoryType.Notecard, PermissionMask.All,
|
2008-07-29 21:36:53 +00:00
|
|
|
delegate(bool success, ItemData item) {
|
2008-03-12 22:46:53 +00:00
|
|
|
if(success) // upload the asset
|
|
|
|
|
Client.Inventory.RequestUploadNotecardAsset(CreateNotecardAsset(body), item.UUID, new InventoryManager.NotecardUploadedAssetCallback(OnNoteUpdate));
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
return "Done";
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (System.Exception e)
|
|
|
|
|
{
|
2008-05-06 23:57:26 +00:00
|
|
|
Logger.Log(e.ToString(), Helpers.LogLevel.Error, Client);
|
2008-03-12 22:46:53 +00:00
|
|
|
return "Error creating notecard.";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="body"></param>
|
|
|
|
|
public static byte[] CreateNotecardAsset(string body)
|
|
|
|
|
{
|
|
|
|
|
// Format the string body into Linden text
|
|
|
|
|
string lindenText = "Linden text version 1\n";
|
|
|
|
|
lindenText += "{\n";
|
|
|
|
|
lindenText += "LLEmbeddedItems version 1\n";
|
|
|
|
|
lindenText += "{\n";
|
|
|
|
|
lindenText += "count 0\n";
|
|
|
|
|
lindenText += "}\n";
|
|
|
|
|
lindenText += "Text length " + body.Length + "\n";
|
|
|
|
|
lindenText += body;
|
|
|
|
|
lindenText += "}\n";
|
|
|
|
|
|
|
|
|
|
// Assume this is a string, add 1 for the null terminator
|
|
|
|
|
byte[] stringBytes = System.Text.Encoding.UTF8.GetBytes(lindenText);
|
|
|
|
|
byte[] assetData = new byte[stringBytes.Length]; //+ 1];
|
|
|
|
|
Array.Copy(stringBytes, 0, assetData, 0, stringBytes.Length);
|
|
|
|
|
|
|
|
|
|
return assetData;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-07-29 21:36:53 +00:00
|
|
|
}
|