Example #1
0
 public UncResource(CustomUri resource)
 {
     CreateStream = delegate
     {
         return(CreateStreamFromUri(resource, DefaultBasePath));
     };
 }
Example #2
0
 public UncResource(CustomUri resource, string basePath)
 {
     CreateStream = delegate
     {
         return(CreateStreamFromUri(resource, basePath));
     };
 }
Example #3
0
		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;
		}
Example #4
0
		public AssemblyResource(CustomUri resource)
		{
			CreateStream = delegate
			{
				return CreateResourceFromUri(resource, null);
			};
		}
Example #5
0
        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));
        }
Example #6
0
		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);
		}
Example #7
0
		public IResource Create(CustomUri uri, String basePath)
		{
			if (basePath != null)
				return new FileResource(uri, basePath);
			else
				return new FileResource(uri);
		}
Example #8
0
		public AssemblyResource(CustomUri resource, String basePath)
		{
			CreateStream = delegate
			{
				return CreateResourceFromUri(resource, basePath);
			};
		}
Example #9
0
		public FileResource(CustomUri resource)
		{
			CreateStream = delegate
			{
				return CreateStreamFromUri(resource, DefaultBasePath);
			};
		}
Example #10
0
		public FileResource(CustomUri resource, String basePath)
		{
			CreateStream = delegate
			{
				return CreateStreamFromUri(resource, basePath);
			};
		}
Example #11
0
 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);
		}
Example #13
0
        public IResource Create(CustomUri uri, String basePath)
        {
            if (basePath == null)
            {
                return(new AssemblyResource(uri));
            }

            return(new AssemblyResource(uri, basePath));
        }
Example #14
0
		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);
		}
Example #15
0
		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);
		}
Example #17
0
		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);
		}
Example #19
0
		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);
		}
Example #20
0
 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");
		}
Example #23
0
		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;
		}
Example #27
0
        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);
		}
Example #29
0
		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);
		}
Example #30
0
        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));
        }
Example #31
0
 public IResource Create(CustomUri uri)
 {
     return(new UncResource(uri));
 }
Example #32
0
		public IResource Create(CustomUri uri)
		{
			return Create(uri, null);
		}
Example #33
0
		public bool Accept(CustomUri uri)
		{
			return "file".Equals(uri.Scheme);
		}
Example #34
0
 public IResource Create(CustomUri uri, string basePath)
 {
     return(new UncResource(uri, basePath));
 }
		public IResource Create(CustomUri uri, String basePath)
		{
			return new UncResource(uri, basePath);
		}
Example #36
0
		public IResource Create(CustomUri uri, String basePath)
		{
			return Create(uri);
		}
 public AssemblyBundleResource(CustomUri resource)
 {
     this.resource = resource;
 }
Example #38
0
 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);
 }
Example #41
0
 public ConfigResource(CustomUri uri) : this(uri.Host)
 {
 }
Example #42
0
 public IResource Create(CustomUri uri)
 {
     return(Create(uri, null));
 }
Example #43
0
 public bool Accept(CustomUri uri)
 {
     return("assembly".Equals(uri.Scheme));
 }
Example #44
0
 public bool Accept(CustomUri uri)
 {
     return(uri.IsUnc);
 }
Example #45
0
		public ConfigResource(CustomUri uri) : this(uri.Host)
		{
		}
		public IResource Create(CustomUri uri)
		{
			return new UncResource(uri);
		}
Example #47
0
 public bool Accept(CustomUri uri)
 {
     return("config".Equals(uri.Scheme));
 }
Example #48
0
		public bool Accept(CustomUri uri)
		{
			return "config".Equals(uri.Scheme);
		}
Example #49
0
 public IResource Create(CustomUri uri, String basePath)
 {
     return(Create(uri));
 }
Example #50
0
		public IResource Create(CustomUri uri)
		{
			return new ConfigResource(uri);
		}