Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LocalAssetProxy{T}"/> class.
        /// </summary>
        /// <param name="manager">
        /// The manager.
        /// </param>
        /// <param name="networkAsset">
        /// The network asset.
        /// </param>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="instance">
        /// The instance.
        /// </param>
        public LocalAssetProxy(LocalAssetManager manager, LocalAsset networkAsset, string name, IAsset instance)
            : base(instance.GetType())
        {
            this.m_Instance   = instance;
            this.m_Manager    = manager;
            this.m_LocalAsset = networkAsset;
            this.m_AssetName  = name;
            this.m_Dirty      = false;

            this.m_LocalAsset.Dirtied += this.MarkDirty;
        }
Exemplo n.º 2
0
        /// <summary>
        /// The invoke.
        /// </summary>
        /// <param name="msg">
        /// The msg.
        /// </param>
        /// <returns>
        /// The <see cref="IMessage"/>.
        /// </returns>
        /// <exception cref="InvalidOperationException">
        /// </exception>
        public override IMessage Invoke(IMessage msg)
        {
            if (this.m_Dirty)
            {
                this.m_LocalAsset.Dirtied -= this.MarkDirty;
                this.m_LocalAsset          = this.m_Manager.GetUnresolved(this.m_AssetName) as LocalAsset;
                var proxy = this.m_LocalAsset.Resolve <IAsset>();
                if (!RemotingServices.IsTransparentProxy(proxy))
                {
                    throw new InvalidOperationException("Object retrieved was not transparent proxy.");
                }

                var realProxy            = RemotingServices.GetRealProxy(proxy);
                var newNetworkAssetProxy = realProxy as LocalAssetProxy;
                if (newNetworkAssetProxy == null)
                {
                    throw new InvalidOperationException("Unable to cast real proxy back to NetworkAssetProxy<>.");
                }

                this.m_Instance            = newNetworkAssetProxy.m_Instance;
                this.m_Dirty               = false;
                this.m_LocalAsset.Dirtied += this.MarkDirty;
            }

            var methodCall = (IMethodCallMessage)msg;
            var method     = (MethodInfo)methodCall.MethodBase;

            try
            {
                var result = method.Invoke(this.m_Instance, methodCall.InArgs);
                return(new ReturnMessage(result, null, 0, methodCall.LogicalCallContext, methodCall));
            }
            catch (Exception e)
            {
                if (e is TargetInvocationException && e.InnerException != null)
                {
                    return(new ReturnMessage(e.InnerException, msg as IMethodCallMessage));
                }

                return(new ReturnMessage(e, msg as IMethodCallMessage));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// The get unresolved.
        /// </summary>
        /// <param name="asset">
        /// The asset.
        /// </param>
        /// <returns>
        /// The <see cref="IAsset"/>.
        /// </returns>
        /// <exception cref="AssetNotFoundException">
        /// </exception>
        /// <exception cref="AssetNotCompiledException">
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// </exception>
        public IAsset GetUnresolved(string asset)
        {
            if (this.m_Assets.ContainsKey(asset))
            {
                if (this.m_Assets[asset] == null)
                {
                    throw new AssetNotFoundException(asset);
                }

                return(this.m_Assets[asset]);
            }

            var candidatesWithTimes       = this.m_RawAssetLoader.LoadRawAssetCandidatesWithModificationDates(asset);
            var loaders                   = this.m_AssetLoaders.ToArray();
            var failedDueToCompilation    = false;
            var hasMoreThanZeroCandidates = false;

            var candidates = candidatesWithTimes.OrderByDescending(x => x.Value).Select(x => x.Key).ToList();

            foreach (var candidate in candidates)
            {
                hasMoreThanZeroCandidates = true;

                foreach (var loader in loaders)
                {
                    var canLoad = false;
                    try
                    {
                        canLoad = loader.CanHandle(candidate);
                    }
                    catch (Exception)
                    {
                    }

                    if (canLoad)
                    {
                        var result = loader.Handle(this, asset, candidate);
                        if (!this.SkipCompilation)
                        {
                            this.m_TransparentAssetCompiler.Handle(result);

                            if (result.SourceOnly && (!this.AllowSourceOnly || asset == "font.Default"))
                            {
                                // We can't have source only assets past this point.  The compilation
                                // failed, but we definitely do have a source representation, so let's
                                // keep that around if we need to throw an exception.
                                failedDueToCompilation = true;
                                Console.WriteLine(
                                    "WARNING: Unable to compile " + asset
                                    + " at runtime (a compiled version may be used).");
                                break;
                            }
                        }

                        this.m_ProxiesLocked = true;
                        if (this.GenerateRuntimeProxies)
                        {
                            var local = new LocalAsset(asset, result, this);
                            this.m_Assets.Add(asset, local);
                            return(local);
                        }

                        this.m_Assets.Add(asset, result);
                        return(result);
                    }
                }
            }

            if (failedDueToCompilation)
            {
                throw new AssetNotCompiledException(asset);
            }

            if (!hasMoreThanZeroCandidates)
            {
                this.m_Assets[asset] = null;

                throw new AssetNotFoundException(asset);
            }

            // NOTE: We don't use asset defaults with the local asset manager, if it
            // doesn't exist, the load fails.
            throw new InvalidOperationException(
                      "Unable to load asset '" + asset + "'.  " + "No loader for this asset could be found.");
        }