Пример #1
0
        public virtual RequestID Prepare(string resType, string name, string group, bool isManual,
                                         IManualResourceLoader loader, NameValuePairList loadParams,
                                         OnOperationCompleted listener)
#endif
        {
#if AXIOM_THREAD_SUPPORT
            // queue a request
            ResourceRequest req = new ResourceRequest();
            req.Type         = RequestType.PrepareResource;
            req.ResourceType = resType;
            req.ResourceName = name;
            req.GroupName    = group;
            req.IsManual     = isManual;
            req.Loader       = loader;
            // Make instance copy of loadParams for thread independence
            req.LoadParams = (loadParams != null ? new NameValuePairList(loadParams) : null);
            req.Listener   = listener;
            return(AddRequest(req));
#else
            // synchronous
            ResourceManager rm = ResourceGroupManager.Instance.ResourceManagers[resType];
            rm.Prepare(name, group, isManual, loader, loadParams);
            return(0);
#endif
        }
Пример #2
0
        /// <see cref="WorkQueue.IRequestHandler.HandleRequest"/>
        //[OgreVersion(1, 7, 2)]
        public WorkQueue.Response HandleRequest(WorkQueue.Request req, WorkQueue srcQ)
        {
            var resreq = (ResourceRequest)req.Data;

            if (req.Aborted)
            {
                if (resreq.Type == RequestType.PrepareResource || resreq.Type == RequestType.LoadResource)
                {
                    resreq.LoadParams.Clear();
                    resreq.LoadParams = null;
                }

                resreq.Result.Error = false;
                var resresp = new ResourceResponse(null, resreq);
                return(new WorkQueue.Response(req, true, resresp));
            }

            ResourceManager rm       = null;
            Resource        resource = null;

            try {
                switch (resreq.Type)
                {
                case RequestType.InitializeGroup:
                    ResourceGroupManager.Instance.InitializeResourceGroup(resreq.GroupName);
                    break;

                case RequestType.InitializeAllGroups:
                    ResourceGroupManager.Instance.InitializeAllResourceGroups();
                    break;

                case RequestType.PrepareGroup:
                    ResourceGroupManager.Instance.PrepareResourceGroup(resreq.GroupName);
                    break;

                case RequestType.LoadGroup:
#if AXIOM_THREAD_SUPPORT
                    if (Axiom.Configuration.Config.AxiomThreadLevel == 2)
                    {
                        ResourceGroupManager.Instance.PrepareResourceGroup(resreq.GroupName);
                    }
                    else
                    {
                        ResourceGroupManager.Instance.LoadResourceGroup(resreq.GroupName);
                    }
#endif
                    break;

                case RequestType.UnloadGroup:
                    ResourceGroupManager.Instance.UnloadResourceGroup(resreq.GroupName);
                    break;

                case RequestType.PrepareResource:
                    rm       = ResourceGroupManager.Instance.ResourceManagers[resreq.ResourceType];
                    resource = rm.Prepare(resreq.ResourceName, resreq.GroupName, resreq.IsManual, resreq.Loader, resreq.LoadParams,
                                          true);
                    break;

                case RequestType.LoadResource:
#if AXIOM_THREAD_SUPPORT
                    rm = ResourceGroupManager.Instance.ResourceManagers[resreq.ResourceType];
                    if (Axiom.Configuration.Config.AxiomThreadLevel == 2)
                    {
                        resource = rm.Prepare(resreq.ResourceName, resreq.GroupName, resreq.IsManual, resreq.Loader, resreq.LoadParams, true);
                    }
                    else
                    {
                        resource = rm.Load(resreq.ResourceName, resreq.GroupName, resreq.IsManual, resreq.Loader, resreq.LoadParams, true);
                    }
#endif
                    break;

                case RequestType.UnloadResource:
                    rm = ResourceGroupManager.Instance.ResourceManagers[resreq.ResourceType];
                    if (string.IsNullOrEmpty(resreq.ResourceName))
                    {
                        rm.Unload(resreq.ResourceHandle);
                    }
                    else
                    {
                        rm.Unload(resreq.ResourceName);
                    }
                    break;
                }
            }
            catch (Exception e) {
                if (resreq.Type == RequestType.PrepareResource || resreq.Type == RequestType.LoadResource)
                {
                    resreq.LoadParams.Clear();
                    resreq.LoadParams = null;
                }
                resreq.Result.Error   = true;
                resreq.Result.Message = e.Message;

                //return error response
                var resresp = new ResourceResponse(resource, resreq);
                return(new WorkQueue.Response(req, false, resresp, e.Message));
            }

            //success
            if (resreq.Type == RequestType.PrepareResource || resreq.Type == RequestType.LoadResource)
            {
                resreq.LoadParams.Clear();
                resreq.LoadParams = null;
            }

            resreq.Result.Error = false;
            var resp = new ResourceResponse(resource, resreq);
            return(new WorkQueue.Response(req, true, resp));
        }