OpenMetaverse.AppearanceManager.DownloadWearables C# (CSharp) Метод

DownloadWearables() приватный Метод

Blocking method to download and parse currently worn wearable assets
private DownloadWearables ( ) : bool
Результат bool
        private bool DownloadWearables()
        {
            bool success = true;

            // Make a copy of the wearables dictionary to enumerate over
            Dictionary<WearableType, WearableData> wearables;
            lock (Wearables)
                wearables = new Dictionary<WearableType, WearableData>(Wearables);

            // We will refresh the textures (zero out all non bake textures)
            for (int i = 0; i < Textures.Length; i++)
            {
                bool isBake = false;
                for (int j = 0; j < BakeIndexToTextureIndex.Length; j++)
                {
                    if (BakeIndexToTextureIndex[j] == i)
                    {
                        isBake = true;
                        break;
                    }
                }
                if (!isBake)
                    Textures[i] = new TextureData();
            }

            int pendingWearables = wearables.Count;
            foreach (WearableData wearable in wearables.Values)
            {
                if (wearable.Asset != null)
                {
                    DecodeWearableParams(wearable);
                    --pendingWearables;
                }
            }

            if (pendingWearables == 0)
                return true;

            Logger.DebugLog("Downloading " + pendingWearables + " wearable assets");

            Parallel.ForEach<WearableData>(Math.Min(pendingWearables, MAX_CONCURRENT_DOWNLOADS), wearables.Values,
                delegate(WearableData wearable)
                {
                    if (wearable.Asset == null)
                    {
                        AutoResetEvent downloadEvent = new AutoResetEvent(false);

                        // Fetch this wearable asset
                        Client.Assets.RequestAsset(wearable.AssetID, wearable.AssetType, true,
                            delegate(AssetDownload transfer, Asset asset)
                            {
                                if (transfer.Success && asset is AssetWearable)
                                {
                                    // Update this wearable with the freshly downloaded asset 
                                    wearable.Asset = (AssetWearable)asset;

                                    if (wearable.Asset.Decode())
                                    {
                                        DecodeWearableParams(wearable);
                                        Logger.DebugLog("Downloaded wearable asset " + wearable.WearableType + " with " + wearable.Asset.Params.Count +
                                            " visual params and " + wearable.Asset.Textures.Count + " textures", Client);

                                    }
                                    else
                                    {
                                        wearable.Asset = null;
                                        Logger.Log("Failed to decode asset:" + Environment.NewLine +
                                            Utils.BytesToString(asset.AssetData), Helpers.LogLevel.Error, Client);
                                    }
                                }
                                else
                                {
                                    Logger.Log("Wearable " + wearable.AssetID + "(" + wearable.WearableType + ") failed to download, " +
                                        transfer.Status, Helpers.LogLevel.Warning, Client);
                                }

                                downloadEvent.Set();
                            }
                        );

                        if (!downloadEvent.WaitOne(WEARABLE_TIMEOUT, false))
                        {
                            Logger.Log("Timed out downloading wearable asset " + wearable.AssetID + " (" + wearable.WearableType + ")",
                                Helpers.LogLevel.Error, Client);
                            success = false;
                        }

                        --pendingWearables;
                    }
                }
            );

            return success;
        }