Beispiel #1
0
        public virtual bool Get(string id, object sender, AssetRetrieved callBack)
        {
            AssetBase asset = null;

            if (m_Cache != null)
            {
                if (!m_Cache.GetFromMemory(id, out asset))
                {
                    callBack(id, sender, null);
                    return(false);
                }
            }

            if (asset == null)
            {
                if (id.Equals(Util.UUIDZeroString))
                {
                    callBack(id, sender, null);
                    return(false);
                }

                lock (m_AssetHandlers)
                {
                    SimpleAssetRetrieved handlerEx = new SimpleAssetRetrieved(delegate(AssetBase _asset) { callBack(id, sender, _asset); _asset = null; });

                    List <SimpleAssetRetrieved> handlers;
                    if (m_AssetHandlers.TryGetValue(id, out handlers))
                    {
                        // Someone else is already loading this asset. It will notify our handler when done.
                        handlers.Add(handlerEx);
                        return(true);
                    }

                    handlers = new List <SimpleAssetRetrieved>();
                    handlers.Add(handlerEx);

                    m_AssetHandlers.Add(id, handlers);
                    m_localRequestsQueue.Enqueue(id);
                }
            }
            else
            {
                if (asset != null && (asset.Data == null || asset.Data.Length == 0))
                {
                    asset = null;
                }
                callBack(id, sender, asset);
            }
            return(true);
        }
        public void Get(string id, string ForeignAssetService, bool StoreOnLocalGrid, SimpleAssetRetrieved callBack)
        {
            if (m_Cache != null)
            {
                AssetBase asset;
                if (!m_Cache.GetFromMemory(id, out asset))
                {
                    callBack(null);
                    return;
                }

                if (asset != null)
                {
                    callBack(asset);
                    return;
                }
            }

            if (id.Equals(Util.UUIDZeroString))
            {
                callBack(null);
                return;
            }

            m_AssetService.Get(id, null, delegate(string assetID, object s, AssetBase a)
            {
                if (m_Cache != null)
                {
                    if (a == null)
                    {
                        m_Cache.CacheNegative(assetID);
                    }
                    else
                    {
                        m_Cache.Cache(a);
                    }
                }
                //if (null == a)
                //.   m_log.WarnFormat("[LOCAL ASSET SERVICES CONNECTOR]: Could not asynchronously find asset with id {0}", id);

                Util.FireAndForget(o => callBack(a), null, "LocalAssetServiceConnector.GotFromServiceCallback");
            });
        }