public ResourceWebResponse(Uri uri, IDictionary<String, Assembly> assemblyMap, IDictionary<string, string> pluginAliasMap, String staticFileFolder)
        {
            this.uri = uri;
            var pluginName = uri.Host;
            if (pluginName == "0")
                pluginName = ".";

            if (pluginAliasMap != null && pluginAliasMap.ContainsKey(pluginName))
                pluginName = pluginAliasMap[pluginName];
            pluginName = pluginName.ToLower();

            resourceName = uri.LocalPath;
            while (resourceName.StartsWith("/"))
                resourceName = resourceName.Substring(1);

            String fullFilePath = Path.Combine(staticFileFolder, pluginName, resourceName);
            if (File.Exists(fullFilePath))
                fileInfo = new FileInfo(fullFilePath);
            else if (pluginName == ".") { }
            else
            {
                if (!assemblyMap.ContainsKey(pluginName))
                    return;
                assembly = assemblyMap[pluginName];
                String assemblyName = assembly.GetName().Name;

                resourceName = resourceName.Replace("/", ".");
                resourceName = $"{assemblyName}.{resourceName}";
                resourceInfo = assembly.GetManifestResourceInfo(resourceName);
            }
        }
Exemplo n.º 2
0
        public void TestResourceLocation()
        {
            Assembly assembly1 = typeof(FieldInfoManifestResourceInfoTests).GetTypeInfo().Assembly;

            System.Reflection.ManifestResourceInfo manifestresourceinfo = assembly1.GetManifestResourceInfo("ResourceTextFile.txt");
            Assert.Equal("Embedded, ContainedInManifestFile", manifestresourceinfo.ResourceLocation.ToString());
        }
Exemplo n.º 3
0
        public void TestReferencedAssembly()
        {
            Assembly assembly1 = typeof(FieldInfoManifestResourceInfoTests).GetTypeInfo().Assembly;

            System.Reflection.ManifestResourceInfo manifestresourceinfo = assembly1.GetManifestResourceInfo("ResourceTextFile.txt");
            Assert.Null(manifestresourceinfo.ReferencedAssembly);
        }
Exemplo n.º 4
0
 private extern bool GetManifestResourceInfoInternal(String name, ManifestResourceInfo info);
Exemplo n.º 5
0
		public virtual ManifestResourceInfo GetManifestResourceInfo (String resourceName)
		{
			if (resourceName == null)
				throw new ArgumentNullException ("resourceName");
			if (resourceName.Length == 0)
				throw new ArgumentException ("String cannot have zero length.");
			ManifestResourceInfo result = new ManifestResourceInfo ();
			bool found = GetManifestResourceInfoInternal (resourceName, result);
			if (found)
				return result;
			else
				return null;
		}
Exemplo n.º 6
0
		private extern bool GetManifestResourceInfoInternal (String name, ManifestResourceInfo info);
Exemplo n.º 7
0
        public virtual Stream GetManifestResourceStream(String name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw new ArgumentException("String cannot have zero length.",
                                            "name");
            }

            ManifestResourceInfo info = GetManifestResourceInfo(name);

            if (info == null)
            {
                return(null);
            }

            if (info.ReferencedAssembly != null)
            {
                return(info.ReferencedAssembly.GetManifestResourceStream(name));
            }
            if ((info.FileName != null) && (info.ResourceLocation == 0))
            {
                if (fromByteArray)
                {
                    throw new FileNotFoundException(info.FileName);
                }

                string location = Path.GetDirectoryName(Location);
                string filename = Path.Combine(location, info.FileName);
#if MOONLIGHT
                // we don't control the content of 'info.FileName' so we want to make sure we keep to ourselves
                filename = Path.GetFullPath(filename);
                if (!filename.StartsWith(location))
                {
                    throw new SecurityException("non-rooted access to manifest resource");
                }
#endif
                return(new FileStream(filename, FileMode.Open, FileAccess.Read));
            }

            int    size;
            Module module;
            IntPtr data = GetManifestResourceInternal(name, out size, out module);
            if (data == (IntPtr)0)
            {
                return(null);
            }
            else
            {
                UnmanagedMemoryStream stream;
                unsafe {
                    stream = new UnmanagedMemoryStream((byte *)data, size);
                }

                /*
                 * The returned pointer points inside metadata, so
                 * we have to increase the refcount of the module, and decrease
                 * it when the stream is finalized.
                 */
                stream.Closed += new EventHandler(new ResourceCloseHandler(module).OnClose);
                return(stream);
            }
        }
Exemplo n.º 8
0
 private bool GetManifestResourceInfoInternal(String name, ManifestResourceInfo info)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 9
0
        public virtual Stream GetManifestResourceStream(String name)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (name.Length == 0)
            {
                throw new ArgumentException("String cannot have zero length.",
                                            "name");
            }

            ManifestResourceInfo info = GetManifestResourceInfo(name);

            if (info == null)
            {
                Assembly a = AppDomain.CurrentDomain.DoResourceResolve(name, this);
                if (a != null && a != this)
                {
                    return(a.GetManifestResourceStream(name));
                }
                else
                {
                    return(null);
                }
            }

            if (info.ReferencedAssembly != null)
            {
                return(info.ReferencedAssembly.GetManifestResourceStream(name));
            }
            if ((info.FileName != null) && (info.ResourceLocation == 0))
            {
                if (fromByteArray)
                {
                    throw new FileNotFoundException(info.FileName);
                }

                string location = Path.GetDirectoryName(Location);
                string filename = Path.Combine(location, info.FileName);
                return(new FileStream(filename, FileMode.Open, FileAccess.Read));
            }

            int    size;
            Module module;
            IntPtr data = GetManifestResourceInternal(name, out size, out module);

            if (data == (IntPtr)0)
            {
                return(null);
            }
            else
            {
                UnmanagedMemoryStream stream;
                unsafe {
                    stream = new UnmanagedMemoryStream((byte *)data, size);
                }

                /*
                 * The returned pointer points inside metadata, so
                 * we have to increase the refcount of the module, and decrease
                 * it when the stream is finalized.
                 */
                stream.Closed += new EventHandler(new ResourceCloseHandler(module).OnClose);
                return(stream);
            }
        }
Exemplo n.º 10
0
		public AManifestResource(ManifestResourceInfo mri, Assembly asm, string name)
		{
			_mri = mri;
			_name = name;
			_asm = asm;
		}
Exemplo n.º 11
0
		private bool GetManifestResourceInfoInternal (String name, ManifestResourceInfo info)
		{
			throw new System.NotImplementedException();
		}
Exemplo n.º 12
0
        public ResourceWebResponse(Uri uri, IDictionary<String, Assembly> assemblyMap, IDictionary<string, string> pluginAliasMap, String staticFileFolder)
        {
            this.uri = uri;
            //得到插件名
            var pluginName = uri.Host;
            if (pluginName == "0")
                pluginName = ".";
            //得到资源名
            resourceName = uri.LocalPath;

            //设置资源搜索目录
            List<String> searchFolderList = new List<string>();
            searchFolderList.Add(Path.Combine(staticFileFolder, pluginName));
            if (pluginAliasMap != null && pluginAliasMap.ContainsKey(pluginName))
            {
                pluginName = pluginAliasMap[pluginName];
                searchFolderList.Add(Path.Combine(staticFileFolder, pluginName));
            }
            pluginName = pluginName.ToLower();
            //获取到程序集
            if (assemblyMap.ContainsKey(pluginName))
                Assembly = assemblyMap[pluginName];

            //开始在文件系统上搜索资源
            String fullFilePath = null;
            foreach (var searchFolder in searchFolderList)
            {
                fullFilePath = ResourceUtils.findFilePath(searchFolder, resourceName);
                if (fullFilePath != null)
                    break;
            }
            if (fullFilePath != null)
                fileInfo = new FileInfo(fullFilePath);
            else if (pluginName == ".") { }
            else
            {
                if (Assembly == null)
                    return;
                String assemblyName = Assembly.GetName().Name;
                while (resourceName.StartsWith("/"))
                    resourceName = resourceName.Substring(1);
                resourceName = resourceName.Replace("/", ".");
                resourceName = $"{assemblyName}.{resourceName}";

                String[] resourceNames = new String[2];
                resourceNames[0] = resourceName;
                var dotIndex = resourceName.LastIndexOf('.');
                if (dotIndex < 0)
                    dotIndex = 0;
                resourceNames[1] = resourceName.Insert(dotIndex, ".");
                foreach (var currentResourceName in resourceNames)
                {
                    resourceInfo = Assembly.GetManifestResourceInfo(currentResourceName);
                    if (resourceInfo != null)
                    {
                        resourceName = currentResourceName;
                        break;
                    }   
                }
            }
        }
Exemplo n.º 13
0
 internal IResource GetResource(string resName, ManifestResourceInfo resInfo, System.IO.Stream bytes) {
   var data = new byte[bytes.Length];
   bytes.Read(data, 0, data.Length);
   var isInExternalFile = (resInfo.ResourceLocation & ResourceLocation.Embedded) != 0;
   var externalFile = Dummy.FileReference;
   var definingAssembly = this.GetAssembly(resInfo.ReferencedAssembly);
   if (isInExternalFile) externalFile = this.GetFileReference(resInfo.FileName, definingAssembly, false);
   var name = this.host.NameTable.GetNameFor(resName);
   return new ResourceWrapper(IteratorHelper.GetReadonly(data), isInExternalFile, externalFile, definingAssembly, name);
 }