// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. using System.Collections.Generic; using System.Linq; namespace Google.Play.AssetDelivery.Internal { /// /// Repository for active requests related to Play Asset Delivery. /// internal class PlayRequestRepository { /// /// Contains all active requests, including the contained within active /// . /// private Dictionary _requestsByName = new Dictionary(); /// /// Contains all active asset bundle requests. Every entry should have a corresponding entry in _requestsByName /// for assetBundleRequest.PackRequest. /// private Dictionary _assetBundleRequestsByName = new Dictionary(); public void AddAssetBundleRequest(PlayAssetBundleRequestImpl assetBundleRequest) { AddRequest(assetBundleRequest.PackRequest); _assetBundleRequestsByName.Add(assetBundleRequest.PackRequest.AssetPackName, assetBundleRequest); } public void AddRequest(PlayAssetPackRequestImpl request) { _requestsByName.Add(request.AssetPackName, request); } public void RemoveRequest(string name) { _requestsByName.Remove(name); _assetBundleRequestsByName.Remove(name); } public bool TryGetAssetBundleRequest(string name, out PlayAssetBundleRequestImpl assetBundleRequest) { return _assetBundleRequestsByName.TryGetValue(name, out assetBundleRequest); } public bool TryGetRequest(string name, out PlayAssetPackRequestImpl request) { return _requestsByName.TryGetValue(name, out request); } public IList GetRequestsWithStatus(AssetDeliveryStatus status) { return _requestsByName.Values.Where(request => request.Status == status).ToList(); } public string[] GetActiveAssetPackNames() { return _requestsByName.Keys.ToArray(); } public bool ContainsAssetBundleRequest(string name) { return _assetBundleRequestsByName.ContainsKey(name); } public bool ContainsRequest(string name) { return _requestsByName.ContainsKey(name); } } }