public void HandleXfer(IClientAPI client, ulong xferID, uint packetID, byte[] data)
        {
            AssetXferUploader foundUploader = null;

            lock (XferUploaders)
            {
                foreach (AssetXferUploader uploader in XferUploaders.Values)
                {
                    //                    MainConsole.Instance.DebugFormat(
                    //                        "[AGENT ASSETS TRANSACTIONS]: In HandleXfer, inspect xfer upload with xfer id {0}",
                    //                        uploader.XferID);

                    if (uploader.XferID == xferID)
                    {
                        foundUploader = uploader;
                        break;
                    }
                }
            }

            if (foundUploader != null)
            {
                //                MainConsole.Instance.DebugFormat(
                //                    "[AGENT ASSETS TRANSACTIONS]: Found xfer uploader for xfer id {0}, packet id {1}, data length {2}",
                //                    xferID, packetID, data.Length);

                foundUploader.HandleXferPacket(xferID, packetID, data);
            }
        }
        /// <summary>
        ///     Request that a client (agent) begin an asset transfer.
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="assetID"></param>
        /// <param name="transaction"></param>
        /// <param name="type"></param>
        /// <param name="data"></param>
        /// <param name="storeLocal"></param>
        /// <param name="tempFile"></param>
        public void HandleUDPUploadRequest(IClientAPI remoteClient, UUID assetID, UUID transaction, sbyte type,
                                           byte[] data, bool storeLocal, bool tempFile)
        {
//            MainConsole.Instance.Debug("HandleUDPUploadRequest - assetID: " + assetID.ToString() + " transaction: " + transaction.ToString() + " type: " + type.ToString() + " storelocal: " + storeLocal + " tempFile: " + tempFile);

            if (((AssetType)type == AssetType.Texture ||
                 (AssetType)type == AssetType.Sound ||
                 (AssetType)type == AssetType.TextureTGA ||
                 (AssetType)type == AssetType.Animation) &&
                tempFile == false)
            {
                IScene       scene = remoteClient.Scene;
                IMoneyModule mm    = scene.RequestModuleInterface <IMoneyModule>();

                if (mm != null)
                {
                    if (!mm.Charge(remoteClient.AgentId, mm.UploadCharge, "", TransactionType.UploadCharge))
                    {
                        remoteClient.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false);
                        return;
                    }
                }
            }

            AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);

            AssetXferUploader uploader = transactions.RequestXferUploader(transaction);

            if (uploader != null)
            {
                uploader.StartUpload(remoteClient, assetID, transaction, type, data, storeLocal, tempFile);
            }
        }
        /// <summary>
        ///     Return the xfer uploader for the given transaction.
        /// </summary>
        /// <remarks>
        ///     If an uploader does not already exist for this transaction then it is created, otherwise the existing
        ///     uploader is returned.
        /// </remarks>
        /// <param name="transactionID"></param>
        /// <returns>The asset xfer uploader</returns>
        public AssetXferUploader RequestXferUploader(UUID transactionID)
        {
            AssetXferUploader uploader;

            lock (XferUploaders)
            {
                if (!XferUploaders.ContainsKey(transactionID))
                {
                    uploader = new AssetXferUploader(this, m_Scene, transactionID, m_dumpAssetsToFile);

                    //                    MainConsole.Instance.DebugFormat(
                    //                        "[AGENT ASSETS TRANSACTIONS]: Adding asset xfer uploader {0} since it didn't previously exist", transactionID);

                    XferUploaders.Add(transactionID, uploader);
                }
                else
                {
                    uploader = XferUploaders[transactionID];
                }
            }

            IMonitorModule monitorModule = m_Scene.RequestModuleInterface <IMonitorModule>();

            if (monitorModule != null)
            {
                INetworkMonitor networkMonitor = monitorModule.GetMonitor <INetworkMonitor>(m_Scene);
                networkMonitor.AddPendingUploads(1);
            }

            return(uploader);
        }
        public void RequestUpdateInventoryItem(IClientAPI remoteClient,
                                               UUID transactionID, InventoryItemBase item)
        {
            AssetXferUploader uploader = RequestXferUploader(transactionID);

            uploader.RequestUpdateInventoryItem(remoteClient, item);
        }
        public void RequestUpdateTaskInventoryItem(IClientAPI remoteClient,
                                                   ISceneChildEntity part, UUID transactionID,
                                                   TaskInventoryItem item)
        {
            AssetXferUploader uploader = RequestXferUploader(transactionID);

            uploader.RequestUpdateTaskInventoryItem(remoteClient, item);
        }
        public void RequestCreateInventoryItem(IClientAPI remoteClient,
                                               UUID transactionID, UUID folderID, uint callbackID,
                                               string description, string name, sbyte invType,
                                               sbyte type, byte wearableType, uint nextOwnerMask)
        {
            AssetXferUploader uploader = RequestXferUploader(transactionID);

            uploader.RequestCreateInventoryItem(
                remoteClient, folderID, callbackID,
                description, name, invType, type, wearableType, nextOwnerMask);
        }
        /// <summary>
        ///     Return the xfer uploader for the given transaction.
        /// </summary>
        /// <remarks>
        ///     If an uploader does not already exist for this transaction then it is created, otherwise the existing
        ///     uploader is returned.
        /// </remarks>
        /// <param name="transactionID"></param>
        /// <returns>The asset xfer uploader</returns>
        public AssetXferUploader RequestXferUploader(UUID transactionID)
        {
            AssetXferUploader uploader;

            lock (XferUploaders)
            {
                if (!XferUploaders.ContainsKey(transactionID))
                {
                    uploader = new AssetXferUploader(this, m_Scene, transactionID, m_dumpAssetsToFile);

                    //                    MainConsole.Instance.DebugFormat(
                    //                        "[AGENT ASSETS TRANSACTIONS]: Adding asset xfer uploader {0} since it didn't previously exist", transactionID);

                    XferUploaders.Add(transactionID, uploader);
                }
                else
                {
                    uploader = XferUploaders[transactionID];
                }
            }

            IMonitorModule monitorModule = m_Scene.RequestModuleInterface<IMonitorModule>();
            if (monitorModule != null)
            {
                INetworkMonitor networkMonitor = monitorModule.GetMonitor<INetworkMonitor>(m_Scene);
                networkMonitor.AddPendingUploads(1);
            }

            return uploader;
        }