private static void SetControllerForLoadedTask(TaskCache task) { try { // DO NOT USE CURRENT CACHED CONTROLLER: could have changed parts from the task's one. Also, controllers should be stateless task.Context.Controller = ControllerBuilder.Build(task.Context.Resource); } catch (Exception buildEx) { Log.Warn(String.Format("Could not build controller for loaded task {0}: {1}", task.Context.TaskId, buildEx )); } task.Context.Controller = null; }
public static void ReloadResources(IEnumerable <Resource> resources) { lock (_globalLock) { while (_cache.Any()) { var elem = _cache.First(); lock (elem.Value.StateLock) { elem.Value.Save(); _cache.Remove(elem.Key); } } var resourceNames = resources.Select(r => r.ResourceName); var nodeStates = LoadStates(resourceNames); var gcCollector = CacheCollectorFactory.GetInstance().GetResourceCacheCollector(resources); foreach (var resource in resources) { var controller = ControllerBuilder.Build(resource); var resourceCache = new ResourceCache(resource, controller, gcCollector); foreach (var node in resourceCache.NodeStateInfo) { var savedNodeState = nodeStates.FirstOrDefault(s => s.ResourceName == node.ResourceName && s.NodeName == node.NodeName); if (savedNodeState != null) { node.ApplyState(savedNodeState); } else { node.State = NodeState.Busy; // to prevent node usage before actual state update, which is async } } _cache[resource.ResourceName] = resourceCache; } /* * //foreach (string name in resourceNames) * PFX.Parallel.ForEach(resourceNames, (name) => * { * UpdateNodesState(name); * }); */ } }