public bool RequestUpdateTaskInventoryItem(
            IClientAPI remoteClient, SceneObjectPart part, UUID transactionID, TaskInventoryItem item)
        {
            AssetXferUploader uploader = GetTransactionUploader(transactionID);

            if (uploader == null)
            {
                m_log.WarnFormat("[ASSET TRANSACTIONS]: Transaction {0} NOT FOUND (duplicate removed?) for inventory item update {1}", transactionID, item.Name);
                return(false);
            }

            // This may complete now if upload complete, or later when the upload completes.
            uploader.TriggerWhenUploadComplete(delegate(AssetBase asset)
            {
                // This upload transaction is complete.
                XferUploaders.Remove(transactionID);

                if (asset == null)
                {
                    return;         // UpdateItem() not called
                }
                m_log.DebugFormat(
                    "[ASSET TRANSACTIONS]: Updating task item {0} in {1} with asset in transaction {2}",
                    item.Name, part.Name, transactionID);

                asset.Name        = item.Name;
                asset.Description = item.Description;
                asset.Type        = (sbyte)item.Type;

                try
                {
                    Manager.MyScene.CommsManager.AssetCache.AddAsset(asset, AssetRequestInfo.GenericNetRequest());
                    if (part.Inventory.UpdateTaskInventoryItemAsset(part.UUID, item.ItemID, asset.FullID))
                    {
                        part.GetProperties(remoteClient);
                    }
                }
                catch (AssetServerException e)
                {
                    remoteClient.SendAgentAlertMessage("Unable to upload asset. Please try again later.", false);

                    m_log.ErrorFormat("[ASSET TRANSACTIONS] Unable to update task item due to asset server error {0}", e);
                }
            });

            // We at least found an uploader with that transaction ID.
            return(true);
        }
        public bool RequestUpdateInventoryItem(IClientAPI remoteClient, UUID transactionID, InventoryItemBase item)
        {
            AssetXferUploader uploader = GetTransactionUploader(transactionID);

            if (uploader == null)
            {
                m_log.WarnFormat("[ASSET TRANSACTIONS]: Transaction {0} NOT FOUND (duplicate removed?) for inventory item update {1}", transactionID, item.Name);
                return(false);
            }

            CachedUserInfo userInfo = Manager.MyScene.CommsManager.UserService.GetUserDetails(remoteClient.AgentId);

            if (userInfo == null)
            {
                m_log.WarnFormat("[ASSET TRANSACTIONS]: Could not find user {0} for transaction {1} for inventory update {2}",
                                 remoteClient.AgentId, transactionID, item.Name);
                return(false);
            }

            // This may complete now if upload complete, or later when the upload completes.
            uploader.TriggerWhenUploadComplete(delegate(AssetBase asset)
            {
                // This upload transaction is complete.
                XferUploaders.Remove(transactionID);

                UUID assetID = UUID.Combine(transactionID, remoteClient.SecureSessionId);
                if (asset == null || asset.FullID != assetID)
                {
                    m_log.ErrorFormat("[ASSETS]: RequestUpdateInventoryItem wrong asset ID or not found {0}", asset == null ? "null" : asset.FullID.ToString());
                    return;
                }

                // Assets never get updated, new ones get created
                UUID oldID        = asset.FullID;
                asset.FullID      = UUID.Random();
                asset.Name        = item.Name;
                asset.Description = item.Description;
                asset.Type        = (sbyte)item.AssetType;

                try
                {
                    m_log.DebugFormat("[ASSETS]: RequestUpdateInventoryItem for transaction {0}, new asset {1} -> {2}", transactionID, oldID, asset.FullID);
                    Manager.MyScene.CommsManager.AssetCache.AddAsset(asset, AssetRequestInfo.GenericNetRequest());
                }
                catch (AssetServerException e)
                {
                    remoteClient.SendAgentAlertMessage("Unable to upload asset. Please try again later.", false);
                    m_log.ErrorFormat("[ASSET TRANSACTIONS] Creation of asset failed {0}", e);
                    return;
                }

                item.AssetID = asset.FullID;

                //wait for completion of the write to avoid reversion
                ManualResetEventSlim waitEvent = new ManualResetEventSlim();

                remoteClient.HandleWithInventoryWriteThread(() =>
                {
                    // Update the asset ID
                    userInfo.UpdateItem(item);
                    waitEvent.Set();
                });

                waitEvent.Wait();
                waitEvent.Dispose();
            });

            return(true);    // userInfo item was updated
        }