public bool TryChainUp(IFileSystemResourceAccessor potentialBaseResourceAccessor, string path, out IFileSystemResourceAccessor resultResourceAccessor) { resultResourceAccessor = null; string resourcePathName = potentialBaseResourceAccessor.ResourcePathName; if (string.IsNullOrEmpty(resourcePathName) || !potentialBaseResourceAccessor.IsFile || !".iso".Equals(DosPathHelper.GetExtension(resourcePathName), StringComparison.OrdinalIgnoreCase)) { return(false); } lock (_syncObj) { string key = potentialBaseResourceAccessor.CanonicalLocalResourcePath.Serialize(); try { IsoResourceProxy proxy; if (!_isoUsages.TryGetValue(key, out proxy)) { _isoUsages.Add(key, proxy = CreateIsoResourceProxy(key, potentialBaseResourceAccessor)); } resultResourceAccessor = new IsoResourceAccessor(this, proxy, path); } catch (Exception e) { ServiceRegistration.Get <ILogger>().Warn("IsoResourceProvider: Error chaining up to '{0}'", e, potentialBaseResourceAccessor.CanonicalLocalResourcePath); return(false); } return(true); } }
public bool IsResource(IFileSystemResourceAccessor baseResourceAccessor, string path) { string resourceName = baseResourceAccessor.ResourceName; if (string.IsNullOrEmpty(resourceName) || !baseResourceAccessor.IsFile) { return(false); } // Test if we have already an ISO proxy for that ISO file... lock (_syncObj) { string key = baseResourceAccessor.CanonicalLocalResourcePath.Serialize(); try { IsoResourceProxy proxy; if (_isoUsages.TryGetValue(key, out proxy)) { lock (proxy.SyncObj) return(IsoResourceAccessor.IsResource(proxy.DiskFileSystem, path)); } } catch (Exception) { return(false); } } // ... if not, test the resource in a new disk file system instance using (Stream underlayingStream = baseResourceAccessor.OpenRead()) { try { IFileSystem diskFileSystem = IsoResourceProxy.GetFileSystem(underlayingStream); using (diskFileSystem as IDisposable) return(IsoResourceAccessor.IsResource(diskFileSystem, path)); } catch { return(false); } } }
public bool TryChainUp(IResourceAccessor potentialBaseResourceAccessor, string path, out IResourceAccessor resultResourceAccessor) { resultResourceAccessor = null; string resourcePathName = potentialBaseResourceAccessor.ResourcePathName; if (string.IsNullOrEmpty(resourcePathName) || !potentialBaseResourceAccessor.IsFile || !".iso".Equals(DosPathHelper.GetExtension(resourcePathName), StringComparison.OrdinalIgnoreCase)) return false; lock (_syncObj) { string key = potentialBaseResourceAccessor.CanonicalLocalResourcePath.Serialize(); try { IsoResourceProxy proxy; if (!_isoUsages.TryGetValue(key, out proxy)) _isoUsages.Add(key, proxy = CreateIsoResourceProxy(key, potentialBaseResourceAccessor)); resultResourceAccessor = new IsoResourceAccessor(this, proxy, path); } catch (Exception e) { ServiceRegistration.Get<ILogger>().Warn("IsoResourceProvider: Error chaining up to '{0}'", e, potentialBaseResourceAccessor.CanonicalLocalResourcePath); return false; } return true; } }