All pastes #716575 Raw Edit

Someone

public text v1 · immutable
#716575 ·published 2007-09-26 23:16 UTC
rendered paste body
using System;
using System.Threading;

using libsecondlife;

namespace libsecondlife
{
    class InventoryTools
    {
        InventoryManager iManager = null;

        public InventoryTools(SecondLife client)
        {
            iManager = client.Inventory;
            iManager.RequestFolderContents(iManager.Store.RootFolder, client.Network.AgentID, true, false, false, InventorySortOrder.ByName);
        }

        public void CreateNotecard(string name, string desc, string body)
        {
            iManager.BeginCreateItemFromAsset(CreateNotecardAsset(body), name, desc, AssetType.Notecard, InventoryType.Notecard, iManager.FindFolderForType(AssetType.Notecard), this.ItemCreatedCallback);

        }

        public void ItemCreatedCallback(bool success, InventoryItem item)
        {
            
        }

        /// <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((string)lindenText);
			byte[] assetData = new byte[stringBytes.Length + 1];
			Array.Copy(stringBytes, 0, assetData, 0, stringBytes.Length);

            return assetData;
		}

    }
}