protected override ResourcePath ExpandResourcePathFromString(string pathStr) { ResourceProviderMetadata rpm = BaseResourceProvider; IBaseResourceProvider rp = GetResourceProvider(rpm.ResourceProviderId); return(rp.ExpandResourcePathFromString(pathStr)); }
public MockFileSystemAccessor(ResourcePath path, IBaseResourceProvider provider, ICollection <IFileSystemResourceAccessor> files) { _path = path; _provider = provider; _files = files; _isFile = files == null; }
/// <summary> /// Checks if a resource provider chain for this resource path can be created in the local system. /// This method only checks the availability of providers; it doesn't check if the given path is available /// in the providers. /// </summary> public void CheckValidLocalPath() { IMediaAccessor mediaAccessor = ServiceRegistration.Get <IMediaAccessor>(); if (!IsAbsolute) // This will check the path itself. Below, we will check if the referenced resource providers implement the correct interfaces { throw new ArgumentException(string.Format( "Can only access media files at an absolute resource path (given relative path is '{0}')", Serialize())); } IEnumerator <ProviderPathSegment> enumer = _pathSegments.GetEnumerator(); if (!enumer.MoveNext()) { throw new UnexpectedStateException("Cannot build resource accessor for an empty resource path"); } bool baseSegment = true; do { ProviderPathSegment pathSegment = enumer.Current; IResourceProvider resourceProvider; if (!mediaAccessor.LocalResourceProviders.TryGetValue(pathSegment.ProviderId, out resourceProvider)) { throw new IllegalCallException("The resource provider with id '{0}' is not accessible in the current system", pathSegment.ProviderId); } if (baseSegment) { IBaseResourceProvider baseProvider = resourceProvider as IBaseResourceProvider; if (baseProvider == null) { throw new IllegalCallException("The resource provider with id '{0}' does not implement the {1} interface", pathSegment.ProviderId, typeof(IBaseResourceProvider).Name); } baseSegment = false; } else { IChainedResourceProvider chainedProvider = resourceProvider as IChainedResourceProvider; if (chainedProvider == null) { throw new IllegalCallException("The resource provider with id '{0}' does not implement the {1} interface", pathSegment.ProviderId, typeof(IChainedResourceProvider).Name); } } } while (enumer.MoveNext()); }
/// <summary> /// Creates a local resource provider chain for this resource path, if it is a local path /// (see <see cref="CheckValidLocalPath"/>), and returns its result in a <see cref="IResourceAccessor"/> instance. /// </summary> /// <param name="result">Returns the resource accessor to access the resource represented by this path, if the /// return value is <c>true</c>. Else, this parameter doesn't return a meaningful value.</param> /// <returns><c>true</c>, if a resource accessor could successfully be built for this path.</returns> /// <exception cref="IllegalCallException">If one of the referenced resource providers is not available in the system or /// has the wrong type.</exception> /// <exception cref="UnexpectedStateException">If this path is empty.</exception> public bool TryCreateLocalResourceAccessor(out IResourceAccessor result) { IResourceAccessor resourceAccessor = null; if (USE_RA_CACHE) { if (TryGetCloneFromCache(this, out resourceAccessor)) { result = resourceAccessor; return(true); } } IMediaAccessor mediaAccessor = ServiceRegistration.Get <IMediaAccessor>(); IEnumerator <ProviderPathSegment> enumer = _pathSegments.GetEnumerator(); if (!enumer.MoveNext()) { throw new UnexpectedStateException("Cannot build resource accessor for an empty resource path"); } try { do { ProviderPathSegment pathSegment = enumer.Current; IResourceProvider resourceProvider; if (!mediaAccessor.LocalResourceProviders.TryGetValue(pathSegment.ProviderId, out resourceProvider)) { throw new IllegalCallException("The resource provider with id '{0}' is not accessible in the current system", pathSegment.ProviderId); } if (resourceAccessor == null) { IBaseResourceProvider baseProvider = resourceProvider as IBaseResourceProvider; if (baseProvider == null) { throw new IllegalCallException("The resource provider with id '{0}' does not implement the {1} interface", pathSegment.ProviderId, typeof(IBaseResourceProvider).Name); } if (!baseProvider.TryCreateResourceAccessor(pathSegment.Path, out resourceAccessor)) { result = null; return(false); } } else { IChainedResourceProvider chainedProvider = resourceProvider as IChainedResourceProvider; if (chainedProvider == null) { throw new IllegalCallException("The resource provider with id '{0}' does not implement the {1} interface", pathSegment.ProviderId, typeof(IChainedResourceProvider).Name); } IResourceAccessor chainedRa; if (!chainedProvider.TryChainUp(resourceAccessor, pathSegment.Path, out chainedRa)) { resourceAccessor.Dispose(); result = null; return(false); } resourceAccessor = chainedRa; } } while (enumer.MoveNext()); } catch (Exception) { if (resourceAccessor != null) { resourceAccessor.Dispose(); } throw; } if (USE_RA_CACHE) { AddToCache(this, resourceAccessor); } result = resourceAccessor; return(true); }