public UncResource(CustomUri resource) { CreateStream = delegate { return(CreateStreamFromUri(resource, DefaultBasePath)); }; }
public UncResource(CustomUri resource, string basePath) { CreateStream = delegate { return(CreateStreamFromUri(resource, basePath)); }; }
public static IResource File(string name) { var fullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XmlFiles/" + name); var uri = new CustomUri(fullPath); var resource = new FileResource(uri); return resource; }
public AssemblyResource(CustomUri resource) { CreateStream = delegate { return CreateResourceFromUri(resource, null); }; }
private Stream CreateStreamFromUri(CustomUri resource, string rootPath) { if (resource == null) { throw new ArgumentNullException(nameof(resource)); } if (!resource.IsUnc) { throw new ArgumentException("Resource must be an Unc", nameof(resource)); } if (!resource.IsFile) { throw new ArgumentException("The specified resource is not a file", nameof(resource)); } string resourcePath = resource.Path; if (!File.Exists(resourcePath) && rootPath != null) { resourcePath = Path.Combine(rootPath, resourcePath); } filePath = Path.GetFileName(resourcePath); basePath = Path.GetDirectoryName(resourcePath); CheckFileExists(resourcePath); return(File.OpenRead(resourcePath)); }
private Stream CreateResourceFromUri(CustomUri resourcex, String path) { if (resourcex == null) throw new ArgumentNullException("resourcex"); assemblyName = resourcex.Host; resourcePath = ConvertToResourceName(assemblyName, resourcex.Path, path); Assembly assembly = ObtainAssembly(assemblyName); String[] names = assembly.GetManifestResourceNames(); String nameFound = GetNameFound(names); if (nameFound == null) { resourcePath = resourcex.Path.Replace('/', '.').Substring(1); nameFound = GetNameFound(names); } if (nameFound == null) { String message = String.Format(CultureInfo.InvariantCulture, "The assembly resource {0} could not be located", resourcePath); throw new ResourceException(message); } basePath = ConvertToPath(resourcePath); return assembly.GetManifestResourceStream(nameFound); }
public IResource Create(CustomUri uri, String basePath) { if (basePath != null) return new FileResource(uri, basePath); else return new FileResource(uri); }
public AssemblyResource(CustomUri resource, String basePath) { CreateStream = delegate { return CreateResourceFromUri(resource, basePath); }; }
public FileResource(CustomUri resource) { CreateStream = delegate { return CreateStreamFromUri(resource, DefaultBasePath); }; }
public FileResource(CustomUri resource, String basePath) { CreateStream = delegate { return CreateStreamFromUri(resource, basePath); }; }
private static IComponentsInstaller CreateInterpreter(Castle.Core.Resource.CustomUri uri, IEnvironmentInfo env) { if (IsBoo(uri)) { return(new BooComponentInstaller(uri, env)); } return(new DefaultComponentInstaller()); }
public IResource Create(CustomUri uri, String basePath) { if (basePath == null) { return new AssemblyResource(uri); } return new AssemblyResource(uri, basePath); }
public IResource Create(CustomUri uri, String basePath) { if (basePath == null) { return(new AssemblyResource(uri)); } return(new AssemblyResource(uri, basePath)); }
public void FileUris2() { CustomUri uri1 = new CustomUri("file://Config/properties.config"); Assert.AreEqual("Config/properties.config", uri1.Path); Assert.AreEqual(null, uri1.Host); Assert.AreEqual("file", uri1.Scheme); Assert.AreEqual(true, uri1.IsFile); Assert.AreEqual(false, uri1.IsUnc); }
private Stream CreateStreamFromUri(CustomUri resource, String rootPath) { if (resource == null) throw new ArgumentNullException("resource"); if (rootPath == null) throw new ArgumentNullException("rootPath"); if (!resource.IsFile) throw new ArgumentException("The specified resource is not a file", "resource"); return CreateStreamFromPath(resource.Path, rootPath); }
public void CreateWithRelativePathAndContext() { CustomUri uri = new CustomUri("file://file1.txt"); IResource resource = resFactory.Create( uri, basePath ); Assert.IsNotNull(resource); String line = resource.GetStreamReader().ReadLine(); Assert.AreEqual("Something", line); }
public void FileUris3() { CustomUri uri1 = new CustomUri("e:\\somedir\\somefile.extension"); Assert.AreEqual("e:/somedir/somefile.extension", uri1.Path); Assert.AreEqual(null, uri1.Host); Assert.AreEqual("file", uri1.Scheme); Assert.AreEqual(true, uri1.IsFile); Assert.AreEqual(false, uri1.IsUnc); }
public void CreateWithAbsolutePath() { CustomUri uri = new CustomUri(@"\\hammet\C$\file.txt"); IResource resource = resFactory.Create(uri, null); Assert.IsNotNull(resource); String line = resource.GetStreamReader().ReadLine(); Assert.AreEqual("The long and winding road", line); }
public void AssemblyUri() { CustomUri uri1 = new CustomUri("assembly://Assembly.Name/properties.config"); Assert.AreEqual("/properties.config", uri1.Path); Assert.AreEqual("Assembly.Name", uri1.Host); Assert.AreEqual("assembly", uri1.Scheme); Assert.AreEqual(false, uri1.IsFile); Assert.AreEqual(false, uri1.IsUnc); }
public IResource Create(CustomUri uri, String basePath) { if (basePath != null) { return(new FileResource(uri, basePath)); } else { return(new FileResource(uri)); } }
public void CreateRelative() { CustomUri uri = new CustomUri(@"\\hammet\C$\file.txt"); IResource resource = resFactory.Create( uri, null ); resource = resource.CreateRelative("file2.txt"); Assert.IsNotNull(resource); String line = resource.GetStreamReader().ReadLine(); Assert.AreEqual("Something", line); }
public void With_config_section() { var sectionName = "config://castle/";//trailing slash is required var uri = new CustomUri(sectionName); Assert.AreEqual("config", uri.Scheme); Assert.AreEqual("castle", uri.Host); var container = new WindsorContainer(sectionName); container.Resolve<ICalcService>("calcservice"); }
public void UriWithEnvironmentVariable() { string path = Environment.GetEnvironmentVariable("PATH"); Assert.IsNotEmpty(path); CustomUri uri1 = new CustomUri("file://%PATH%"); Assert.AreEqual(path, uri1.Path); Assert.AreEqual(null, uri1.Host); Assert.AreEqual("file", uri1.Scheme); Assert.AreEqual(true, uri1.IsFile); Assert.AreEqual(false, uri1.IsUnc); }
public void CreateWithAbsolutePath() { String file = Path.Combine(basePath, "file1.txt"); FileInfo fileInfo = new FileInfo(file); CustomUri uri = new CustomUri(fileInfo.FullName); IResource resource = resFactory.Create(uri, null); Assert.IsNotNull(resource); String line = resource.GetStreamReader().ReadLine(); Assert.AreEqual("Something", line); }
public IResource CreateResource(CustomUri uri) { if (uri == null) throw new ArgumentNullException("uri"); foreach(IResourceFactory resFactory in resourceFactories) { if (resFactory.Accept(uri)) { return resFactory.Create(uri); } } throw new KernelException("No Resource factory was able to " + "deal with Uri " + uri.ToString()); }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyResourceEx"/> class. /// </summary> /// <param name="resource">The resource.</param> /// <param name="cultureInfo">The culture info.</param> public AssemblyResourceEx( CustomUri resource, CultureInfo cultureInfo ) { _ResourceUri = resource; _CultureInfo = cultureInfo; AbstractStreamResource.StreamFactory factory = null; if ( factory == null ) { factory = delegate { return CreateResourceFromUri( resource, null ); }; } base.CreateStream = factory; }
private Stream CreateStreamFromUri(CustomUri resource, string rootPath) { if (resource == null) { throw new ArgumentNullException(nameof(resource)); } if (rootPath == null) { throw new ArgumentNullException(nameof(rootPath)); } if (!resource.IsFile) { throw new ArgumentException("The specified resource is not a file", nameof(resource)); } return(CreateStreamFromPath(resource.Path, rootPath)); }
public IResource CreateResource(CustomUri uri, String basePath) { if (uri == null) { throw new ArgumentNullException("uri"); } if (basePath == null) { throw new ArgumentNullException("basePath"); } foreach (var resFactory in resourceFactories) { if (resFactory.Accept(uri)) { return resFactory.Create(uri, basePath); } } throw new KernelException("No Resource factory was able to " + "deal with Uri " + uri); }
private Stream CreateStreamFromUri(CustomUri resource, String rootPath) { if (resource == null) throw new ArgumentNullException("resource"); if (!resource.IsUnc) throw new ArgumentException("Resource must be an Unc", "resource"); if (!resource.IsFile) throw new ArgumentException("The specified resource is not a file", "resource"); String resourcePath = resource.Path; if (!File.Exists(resourcePath) && rootPath != null) { resourcePath = Path.Combine(rootPath, resourcePath); } filePath = Path.GetFileName(resourcePath); basePath = Path.GetDirectoryName(resourcePath); CheckFileExists(resourcePath); return File.OpenRead(resourcePath); }
private Stream CreateResourceFromUri(CustomUri resourcex, string path) { if (resourcex == null) { throw new ArgumentNullException(nameof(resourcex)); } assemblyName = resourcex.Host; resourcePath = ConvertToResourceName(assemblyName, resourcex.Path); Assembly assembly = ObtainAssembly(assemblyName); string[] names = assembly.GetManifestResourceNames(); string nameFound = GetNameFound(names); if (nameFound == null) { resourcePath = resourcex.Path.Replace('/', '.').Substring(1); nameFound = GetNameFound(names); } if (nameFound == null) { string message = string.Format( CultureInfo.InvariantCulture, "The assembly resource {0} could not be located", resourcePath ); throw new ResourceException(message); } basePath = ConvertToPath(resourcePath); return(assembly.GetManifestResourceStream(nameFound)); }
public IResource Create(CustomUri uri) { return(new UncResource(uri)); }
public IResource Create(CustomUri uri) { return Create(uri, null); }
public bool Accept(CustomUri uri) { return "file".Equals(uri.Scheme); }
public IResource Create(CustomUri uri, string basePath) { return(new UncResource(uri, basePath)); }
public IResource Create(CustomUri uri, String basePath) { return new UncResource(uri, basePath); }
public IResource Create(CustomUri uri, String basePath) { return Create(uri); }
public AssemblyBundleResource(CustomUri resource) { this.resource = resource; }
public IResource Create(CustomUri uri) { return(new ConfigResource(uri)); }
public AssemblyResource(CustomUri resource) { CreateStream = () => CreateResourceFromUri(resource, null); }
public AssemblyResource(CustomUri resource, string basePath) { CreateStream = () => CreateResourceFromUri(resource, basePath); }
public ConfigResource(CustomUri uri) : this(uri.Host) { }
public IResource Create(CustomUri uri) { return(Create(uri, null)); }
public bool Accept(CustomUri uri) { return("assembly".Equals(uri.Scheme)); }
public bool Accept(CustomUri uri) { return(uri.IsUnc); }
public IResource Create(CustomUri uri) { return new UncResource(uri); }
public bool Accept(CustomUri uri) { return("config".Equals(uri.Scheme)); }
public bool Accept(CustomUri uri) { return "config".Equals(uri.Scheme); }
public IResource Create(CustomUri uri, String basePath) { return(Create(uri)); }
public IResource Create(CustomUri uri) { return new ConfigResource(uri); }