/// <summary> /// Retrieve a resourceinstance from MountedResourceContainer from container storage /// </summary> /// <param name="path"></param> /// <returns></returns> protected override Pair<ResourceInstance, object[]> retrieveResource(string path, RESTMethod method) { string rootPath = path; string relativePath = path; int pathSeperatorIndex = path.IndexOf('/', 1); if (pathSeperatorIndex >= 0) { rootPath = path.Substring(0, pathSeperatorIndex); relativePath = path.Substring(pathSeperatorIndex); } GlobalConfiguration.GetInstance().Logger.DebugFormat("Retrieving resource: rootPath={{{0}}}, relativePath={{{1}}}", rootPath, relativePath); if (_mountedResourceContainers.ContainsKey(rootPath)) { ResourceInstance directMatchInstance = _mountedResourceContainers[rootPath].RetrieveResource(relativePath); if (directMatchInstance == null) { Pair<Match, ResourceInstance> methodMatchedResource = _mountedResourceContainers[rootPath].RetrieveResourceByMethodMatching(relativePath, method); if (methodMatchedResource != null) { var methodMatchedResourceMethod = methodMatchedResource.V2.GetResourceMethod(method); if (methodMatchedResourceMethod != null) return new Pair<ResourceInstance, object[]>(methodMatchedResource.V2, methodMatchedResourceMethod.MatchParameters(relativePath)); } } return new Pair<ResourceInstance, object[]>(directMatchInstance, new object[0]); } return null; }
/// <summary> /// Retrieve a relative resource to the mount path /// </summary> public Pair<Match, ResourceInstance> RetrieveResourceByMethodMatching(string path, RESTMethod method) { // regex match foreach (KeyValuePair<string, ResourceInstance> resourcePair in _resources) { Match match = resourcePair.Value.GetResourceMethod(method).MatchRoute(path); if (match.Success) return new Pair<Match, ResourceInstance>(match, resourcePair.Value); } return null; }
/// <summary> /// Retrieve a resourceh by path /// </summary> protected virtual Pair<ResourceInstance, object[]> retrieveResource(string path, RESTMethod method) { return _resources.ContainsKey(path) ? new Pair<ResourceInstance, object[]>(_resources[path], new object[0]) : null; }