public void AddUpload(LLUUID transactionID, AssetBase asset)
 {
     AssetTransaction upload = new AssetTransaction();
     lock (this.transactions)
     {
         upload.Asset = asset;
         upload.TransactionID = transactionID;
         this.transactions.Add(transactionID, upload);
     }
     if (upload.Asset.Data.Length > 2)
     {
         //is complete
         upload.UploadComplete = true;
         AssetUploadCompletePacket response = new AssetUploadCompletePacket();
         response.AssetBlock.Type = asset.Type;
         response.AssetBlock.Success = true;
         response.AssetBlock.UUID = transactionID.Combine(this.ourClient.SecureSessionID);
         this.ourClient.OutPacket(response);
         m_assetCache.AddAsset(asset);
     }
     else
     {
         upload.UploadComplete = false;
         upload.XferID = Util.GetNextXferID();
         RequestXferPacket xfer = new RequestXferPacket();
         xfer.XferID.ID = upload.XferID;
         xfer.XferID.VFileType = upload.Asset.Type;
         xfer.XferID.VFileID = transactionID.Combine(this.ourClient.SecureSessionID);
         xfer.XferID.FilePath = 0;
         xfer.XferID.Filename = new byte[0];
         this.ourClient.OutPacket(xfer);
     }
 }
예제 #2
0
        /// <summary>
        /// Initiate an asset upload
        /// </summary>
        /// <param name="transactionID">The ID this asset will have if the
        /// upload succeeds</param>
        /// <param name="type">Asset type to upload this data as</param>
        /// <param name="data">Raw asset data to upload</param>
        /// <param name="tempFile">Whether this is a temporary file or not</param>
        /// <param name="storeLocal">Whether to store this asset on the local
        /// simulator or the grid-wide asset server</param>
        /// <param name="isPriority">Give this upload a higher priority</param>
        /// <returns>The transaction ID of this transfer</returns>
        public LLUUID RequestUpload(out LLUUID assetID, AssetType type, byte[] data, bool tempFile, bool storeLocal, bool isPriority)
        {
            AssetUpload upload = new AssetUpload();

            upload.AssetData = data;
            upload.AssetType = type;
            upload.ID        = LLUUID.Random();
            assetID          = LLUUID.Combine(upload.ID, Client.Self.SecureSessionID);
            upload.AssetID   = assetID;
            upload.Size      = data.Length;
            upload.XferID    = 0;

            // Build and send the upload packet
            AssetUploadRequestPacket request = new AssetUploadRequestPacket();

            request.AssetBlock.StoreLocal    = storeLocal;
            request.AssetBlock.Tempfile      = tempFile;
            request.AssetBlock.TransactionID = upload.ID;
            request.AssetBlock.Type          = (sbyte)type;

            if (data.Length + 100 < Settings.MAX_PACKET_SIZE)
            {
                Client.Log(
                    String.Format("Beginning asset upload [Single Packet], ID: {0}, AssetID: {1}, Size: {2}",
                                  upload.ID.ToString(), upload.AssetID.ToString(), upload.Size),
                    Helpers.LogLevel.Info);

                // The whole asset will fit in this packet, makes things easy
                request.AssetBlock.AssetData = data;
                upload.Transferred           = data.Length;
            }
            else
            {
                Client.Log(
                    String.Format("Beginning asset upload [Multiple Packets], ID: {0}, AssetID: {1}, Size: {2}",
                                  upload.ID.ToString(), upload.AssetID.ToString(), upload.Size),
                    Helpers.LogLevel.Info);

                // Asset is too big, send in multiple packets
                request.AssetBlock.AssetData = new byte[0];
            }

            //Client.DebugLog(request.ToString());

            /*
             * // Add this upload to the Transfers dictionary using the assetID as the key.
             * // Once the simulator assigns an actual identifier for this upload it will be
             * // removed from Transfers and reinserted with the proper identifier
             * lock (Transfers) Transfers[upload.AssetID] = upload;
             */

            // Wait for the previous upload to receive a RequestXferPacket
            if (PendingUploadEvent.WaitOne(10000, false))
            {
                PendingUpload = upload;

                Client.Network.SendPacket(request);

                return(upload.ID);
            }
            else
            {
                throw new Exception("Timeout waiting for previous asset upload to begin");
            }
        }
예제 #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="transactionID">Usually a randomly generated UUID</param>
        /// <param name="type"></param>
        /// <param name="data"></param>
        /// <param name="tempFile"></param>
        /// <param name="storeLocal"></param>
        /// <param name="isPriority"></param>
        public void RequestUpload(LLUUID transactionID, AssetType type, byte[] data, bool tempFile, bool storeLocal, 
            bool isPriority)
        {
            if (!Transfers.ContainsKey(transactionID))
            {
                AssetUpload upload = new AssetUpload();
                upload.AssetData = data;
                upload.ID = transactionID;
                upload.AssetID = ((transactionID == LLUUID.Zero) ? transactionID : transactionID.Combine(Client.Network.SecureSessionID));
                upload.Size = data.Length;
                upload.XferID = 0;

                // Build and send the upload packet
                AssetUploadRequestPacket request = new AssetUploadRequestPacket();
                request.AssetBlock.StoreLocal = storeLocal;
                request.AssetBlock.Tempfile = tempFile;
                request.AssetBlock.TransactionID = upload.ID;
                request.AssetBlock.Type = (sbyte)type;

                if (data.Length + 100 < Settings.MAX_PACKET_SIZE)
                {
                    Client.Log(
                        String.Format("Beginning asset upload [Single Packet], ID: {0}, AssetID: {1}, Size: {2}",
                        upload.ID.ToStringHyphenated(), upload.AssetID.ToStringHyphenated(), upload.Size),
                        Helpers.LogLevel.Info);

                    // The whole asset will fit in this packet, makes things easy
                    request.AssetBlock.AssetData = data;
                    upload.Transferred = data.Length;
                }
                else
                {
                    Client.Log(
                        String.Format("Beginning asset upload [Multiple Packets], ID: {0}, AssetID: {1}, Size: {2}",
                        upload.ID.ToStringHyphenated(), upload.AssetID.ToStringHyphenated(), upload.Size),
                        Helpers.LogLevel.Info);

                    // Asset is too big, send in multiple packets
                    request.AssetBlock.AssetData = new byte[0];
                }

                //Client.DebugLog(request.ToString());

                // Add this upload to the Transfers dictionary using the assetID as the key.
                // Once the simulator assigns an actual identifier for this upload it will be
                // removed from Transfers and reinserted with the proper identifier
                lock (Transfers) Transfers[upload.AssetID] = upload;

                Client.Network.SendPacket(request);
            }
            else
            {
                Client.Log("RequestUpload() called for an asset we are already uploading, ignoring",
                    Helpers.LogLevel.Info);
            }
        }