RequestAsset() public method

Request an asset download
public RequestAsset ( UUID assetID, AssetType type, bool priority, AssetReceivedCallback callback ) : void
assetID UUID Asset UUID
type AssetType Asset type, must be correct for the transfer to succeed
priority bool Whether to give this transfer an elevated priority
callback AssetReceivedCallback The callback to fire when the simulator responds with the asset data
return void
        public static void SaveSimAssets(AssetManager assetManager, AssetType assetType, UUID assetID, UUID itemID, UUID primID, string assetsPath)
        {
            int count = 0;

            AutoResetEvent AllPropertiesReceived = new AutoResetEvent(false);
            assetManager.RequestAsset(assetID, itemID, primID, assetType, false, SourceType.SimInventoryItem, UUID.Random(), (transfer, asset) =>
            {
                string extension = string.Empty;

                if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.ContainsKey(assetType))
                    extension = ArchiveConstants.ASSET_TYPE_TO_EXTENSION[assetType];

                if (asset == null)
                {
                    AllPropertiesReceived.Set();
                    return;
                }
                File.WriteAllBytes(Path.Combine(assetsPath, assetID.ToString() + extension), asset.AssetData);
                ++count;
                AllPropertiesReceived.Set();
            });
            AllPropertiesReceived.WaitOne(5000);

            Logger.Log("Copied " + count + " textures to the asset archive folder", Helpers.LogLevel.Info);
        }
        public static void SaveAssets(AssetManager assetManager, AssetType assetType, IList<UUID> assets, string assetsPath)
        {
            int count = 0;

            List<UUID> remainingTextures = new List<UUID>(assets);
            AutoResetEvent AllPropertiesReceived = new AutoResetEvent(false);
            for (int i = 0; i < assets.Count; i++)
            {
                UUID texture = assets[i];
                if(assetType == AssetType.Texture)
                {
                    assetManager.RequestImage(texture, (state, assetTexture) =>
                    {
                        string extension = string.Empty;

                        if (assetTexture == null)
                        {
                            Console.WriteLine("Missing asset " + texture);
                            return;
                        }

                        if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.ContainsKey(assetType))
                            extension = ArchiveConstants.ASSET_TYPE_TO_EXTENSION[assetType];

                        File.WriteAllBytes(Path.Combine(assetsPath, texture.ToString() + extension), assetTexture.AssetData);
                        remainingTextures.Remove(assetTexture.AssetID);
                        if (remainingTextures.Count == 0)
                            AllPropertiesReceived.Set();
                        ++count;
                    });
                }
                else
                {
                    assetManager.RequestAsset(texture, assetType, false, (transfer, asset) =>
                    {
                        string extension = string.Empty;

                        if (asset == null)
                        {
                            Console.WriteLine("Missing asset " + texture);
                            return;
                        }

                        if (ArchiveConstants.ASSET_TYPE_TO_EXTENSION.ContainsKey(assetType))
                            extension = ArchiveConstants.ASSET_TYPE_TO_EXTENSION[assetType];

                        File.WriteAllBytes(Path.Combine(assetsPath, texture.ToString() + extension), asset.AssetData);
                        remainingTextures.Remove(asset.AssetID);
                        if (remainingTextures.Count == 0)
                            AllPropertiesReceived.Set();
                        ++count;
                    });
                }

                Thread.Sleep(200);
                if (i % 5 == 0)
                    Thread.Sleep(250);
            }
            AllPropertiesReceived.WaitOne(5000 + 350 * assets.Count);

            Logger.Log("Copied " + count + " textures to the asset archive folder", Helpers.LogLevel.Info);
        }