Example #1
2
        public Type[] Execute(System.Reflection.Assembly assembly)
        {
            var targetNamespaces = new HashSet<string>();
            var resourceNames = assembly.GetManifestResourceNames().Where(n => n.EndsWith("VenusIoc.config"));
            foreach (var resourceName in resourceNames)
            {
                var xmlDoc = new XmlDocument();
                using (var sr = new StreamReader(assembly.GetManifestResourceStream(resourceName)))
                {
                    xmlDoc.Load(sr);
                    foreach (var node in xmlDoc.DocumentElement.SelectNodes("components/assemblyScan/namespace"))
                    {
                        var name = ((XmlElement)node).GetAttribute("name");
                        if (!string.IsNullOrWhiteSpace(name))
                        {
                            targetNamespaces.Add(name.Trim());
                        }
                    }
                }
            }

            var types = new List<Type>();
            foreach (var type in assembly.GetTypes())
            {
                if (targetNamespaces.Contains(type.Namespace) && !type.IsAbstract && type.IsDefined(typeof(NamedAttribute), false))
                {
                    types.Add(type);
                }
            }

            return types.ToArray();
        }
Example #2
0
        private System.Collections.Specialized.NameValueCollection GetAssemblyEventMapping(System.Reflection.Assembly assembly, Hl7Package package)
        {
            System.Collections.Specialized.NameValueCollection structures = new System.Collections.Specialized.NameValueCollection();
            using (System.IO.Stream inResource = assembly.GetManifestResourceStream(package.EventMappingResourceName))
            {
                if (inResource != null)
                {
                    using (System.IO.StreamReader sr = new System.IO.StreamReader(inResource))
                    {
                        string line = sr.ReadLine();
                        while (line != null)
                        {
                            if ((line.Length > 0) && ('#' != line[0]))
                            {
                                string[] lineElements = line.Split(' ', '\t');
                                structures.Add(lineElements[0], lineElements[1]);
                            }
                            line = sr.ReadLine();

                        }
                    }
                }
            }
            return structures;
        }
Example #3
0
        public SVGImage(System.Reflection.Assembly _assembly, string resource)
        {
            try {
                byte[] array;
                Stream stream;
                int error = 0;

                stream =  _assembly.GetManifestResourceStream (resource);
                array = new byte [stream.Length];

                stream.Read (array, 0, (int) stream.Length);

                handle = rsvg_handle_new_from_data (array, array.Length, out error);
                rsvg_handle_get_dimensions (handle, ref dimension);
            }
            catch (Exception e)
            {
                Console.WriteLine ("SVGImage. SVGImage (assembly). Exception: {0}", e);
            }
            finally
            {
                if (handle == IntPtr.Zero)
                    throw new System.IO.IOException ("SVGImage. SVGImage (assembly). Could not load resource: " + resource);
            }
        }
 public System.IO.Stream GetManifestResourceStream(System.Reflection.Assembly assembly, string resourceName)
 {
     var name = resourceName;
     using (new CodeWatch("GetManifestResourceStream", 1000, new Action<string, LoggerStrategyBase, int?, long>((tag, currentLog, wcount, execms) => currentLog.LogFormat(LoggerLevels.Warn, "\t{0}:资源({3})请求时间为({1})ms.已超过阀值({2})ms.", tag, execms, wcount, name))))
     {
         return assembly.GetManifestResourceStream(resourceName);
     }
 }
Example #5
0
 public static Pixbuf LoadFromAssembly(System.Reflection.Assembly assembly, string resource)
 {
     System.IO.Stream s = assembly.GetManifestResourceStream (resource);
     if (s == null)
         return null;
     else
         return LoadFromStream (s);
 }
Example #6
0
        public static SchemaInfo GetSchemaFromAssembly(System.Reflection.Assembly ass)
        {
            SchemaInfo schemaInfo = (SchemaInfo) assembly2SchemaInfo[ass];

            if (schemaInfo == null)
            {
                lock (typeof(SchemaLoader))
                {
                    schemaInfo = (SchemaInfo) assembly2SchemaInfo[ass];
                    if (schemaInfo == null)
                    {
                        foreach (string name in ass.GetManifestResourceNames())
                        {
                            if (name.EndsWith("_DBSchema.bin"))
                            {
                                System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                                using (Stream resourceStream = ass.GetManifestResourceStream(name))
                                {
                                    schemaInfo = (SchemaInfo) bf.Deserialize(resourceStream);
                                    schemaInfo.Resolve();
                                }
                                break;
                            }
                            if (name.EndsWith("_DBSchema.xml"))
                            {
                                using (Stream resourceStream = ass.GetManifestResourceStream(name))
                                {
                                    XmlSerializer ser = new XmlSerializer(typeof(SchemaInfo));
                                    XmlTextReader reader = new XmlTextReader(resourceStream);

                                    schemaInfo = (SchemaInfo) ser.Deserialize(reader);
                                    schemaInfo.Resolve();
                                }
                                break;
                            }
                        }
                        if (schemaInfo == null)
                        {
                            throw new InvalidOperationException("_DBSchema.xml not embedded in " + ass.CodeBase);
                        }
                        assembly2SchemaInfo[ass] = schemaInfo;
                    }
                }
            }
            return schemaInfo;
        }
		public static StreamReader GetStream(System.Reflection.Assembly assembly, string name)
		{
			foreach (string resName in assembly.GetManifestResourceNames())
			{
				if (resName.EndsWith(name))
					return new StreamReader(assembly.GetManifestResourceStream(resName));
			}
			return null;
		}
Example #8
0
		static public Font FromResource(System.Reflection.Assembly asm, string resourceName)
		{
			System.IO.Stream s = asm.GetManifestResourceStream(resourceName);
			byte[] bytedata = new byte[s.Length];
			s.Read(bytedata, 0, (int)s.Length);
			UInt32[] data = new UInt32[s.Length/4];
			for (int i = 0; i != s.Length/4; ++i)
				data[i] = BitConverter.ToUInt32(bytedata, i*4);
			return new Font(data);
		}
Example #9
0
        public Image(System.Reflection.Assembly assembly, string resource)
            : this()
        {
            if (assembly == null)
                assembly = System.Reflection.Assembly.GetCallingAssembly ();

            System.IO.Stream s = assembly.GetManifestResourceStream (resource);
            if (s == null)
                throw new ArgumentException ("'" + resource + "' is not a valid resource name of assembly '" + assembly + "'.");

            LoadFromStream (s);
        }
Example #10
0
        private static Stream GetStream(string resourceName, System.Reflection.Assembly containingAssembly)
        {
            #if DEBUG
            string filePath = null;
            if (ResRepo.TryGetPath(containingAssembly.GetName().FullName, resourceName, out filePath))
                return new FileStream(filePath, FileMode.Open);

            return null;
            #else
            return containingAssembly.GetManifestResourceStream(resourceName);
            #endif
        }
 public string GetWebResourceAsString(System.Reflection.Assembly assembly, string resourceName)
 {
     string content;
     if (assembly == null) return null;
     var stream = assembly.GetManifestResourceStream(resourceName);
     if (stream == null) return null;
     using (var reader = new System.IO.StreamReader(stream))
     {
         content = reader.ReadToEnd();
     }
     return content;
 }
Example #12
0
 public AlphaImage(string resourceName, System.Reflection.Assembly assembly)
 {
     try
     {
         var iconStream = new OpenNETCF.Drawing.Imaging.StreamOnFile(assembly.GetManifestResourceStream(resourceName));
         var factory = new OpenNETCF.Drawing.Imaging.ImagingFactoryClass();
         factory.CreateImageFromStream(iconStream, out _img);
     }
     catch (Exception e)
     {
         //!! write to log  (e.StackTrace, "SetBtnImg")
     }
 }
Example #13
0
        public SVGImage(System.Reflection.Assembly _assembly, string resource)
        {
            try {
                byte[] array;
                Stream stream;
                int error = 0;

                stream =  _assembly.GetManifestResourceStream (resource);
                array = new byte [stream.Length];

                stream.Read (array, 0, (int) stream.Length);

                handle = rsvg_handle_new_from_data (array, array.Length, out error);
                rsvg_handle_get_dimensions (handle, ref dimension);
            }
            finally
            {
                if (handle == IntPtr.Zero)
                    throw new System.IO.IOException ("Resource not found: " + resource);
            }
        }
Example #14
0
        public AlphaImage(string resourceName, System.Reflection.Assembly assembly)
        {
            try
            {
                var factory = (IImagingFactory)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("327ABDA8-072B-11D3-9D7B-0000F81EF32E")));
                IImage img;

                IImage imagingResource;
                using (var strm = (MemoryStream)assembly.GetManifestResourceStream(resourceName))
                {
                    var pbBuf = strm.GetBuffer();
                    var cbBuf = (uint)strm.Length;
                    factory.CreateImageFromBuffer(pbBuf, cbBuf, BufferDisposalFlag.BufferDisposalFlagNone, out imagingResource);
                }
                _img = new IImageWrapper(imagingResource);
            }
            catch (Exception e)
            {
                //!! write to log  (e.StackTrace, "SetBtnImg")
            }
        }
Example #15
0
        public Builder(System.Reflection.Assembly assembly, string resource_name, string translation_domain)
            : this()
        {
            if (GetType() != typeof (Builder))
                throw new InvalidOperationException ("Cannot chain to this constructor from subclasses.");

            if (assembly == null)
                assembly = System.Reflection.Assembly.GetCallingAssembly ();

            System.IO.Stream s = assembly.GetManifestResourceStream (resource_name);
            if (s == null)
                throw new ArgumentException ("Cannot get resource file '" + resource_name + "'",
                                             "resource_name");

            int size = (int) s.Length;
            byte[] buffer = new byte[size];
            s.Read (buffer, 0, size);
            s.Close ();

            AddFromString(System.Text.Encoding.UTF8.GetString (buffer));

            TranslationDomain = translation_domain;
        }
Example #16
0
		public static System.Windows.Forms.Cursor GetCursor( string FileName, System.Reflection.Assembly Assembly ) {
			System.Drawing.Bitmap bmp = System.Drawing.Bitmap.FromStream( Assembly.GetManifestResourceStream( FileName ) ) as System.Drawing.Bitmap;
			return Native.CreateCursor( bmp, 0, 0 );
		}
Example #17
0
 /// <summary>
 /// Load the specified cursor from the specified assembly and return it
 /// </summary>
 /// <param name="assembly">the assembly from which loading the cursor</param>
 /// <param name="cursorResourceName">the resource name of the embeded cursor</param>
 /// <returns>a new created cursor</returns>
 private Cursor LoadEmbededCustomCursors(System.Reflection.Assembly assembly, string cursorResourceName)
 {
     // get the stream from the assembly and create the cursor giving the stream
     System.IO.Stream stream = assembly.GetManifestResourceStream(cursorResourceName);
     Cursor cursor = new Cursor(stream);
     stream.Close();
     // return the created cursor
     return cursor;
 }
Example #18
0
		public static byte[] ReadBytesInternally(System.Reflection.Assembly assembly, string path)
		{
			System.IO.Stream stream = assembly.GetManifestResourceStream(assembly.GetName().Name + "." + path.Replace('/', '.'));
			if (stream == null)
			{
				throw new System.Exception(path + " not marked as an embedded resource.");
			}
			List<byte> output = new List<byte>();
			int bytesRead = 1;
			while (bytesRead > 0)
			{
				bytesRead = stream.Read(BUFFER, 0, BUFFER.Length);
				if (bytesRead == BUFFER.Length)
				{
					output.AddRange(BUFFER);
				}
				else
				{
					for (int i = 0; i < bytesRead; ++i)
					{
						output.Add(BUFFER[i]);
					}
					bytesRead = 0;
				}
			}

			return output.ToArray();
		}
        protected Texture LoadTextureFromAssembly(string fileName, ref System.Reflection.Assembly assembly)
        {
            try
            {
                Texture tex = null;
                System.IO.Stream stream = assembly.GetManifestResourceStream("VortexAnimatTools.Graphics." + fileName);

                //load texture from stream
                tex = TextureLoader.FromStream(Device,stream);

                return tex;

            }
            catch(Exception ex)
            {
                Util.DisplayError(ex);
            }

            return null;
        }
Example #20
0
		public static IByteDevice Open(System.Reflection.Assembly assembly, Uri.Path resource)
		{
			return new ByteDevice(assembly.GetManifestResourceStream(assembly.GetName().Name + ((string)resource).Replace('/', '.'))) {
				Resource = new Uri.Locator("assembly", assembly.GetName().Name, resource),
				FixedLength = true
			};
		}
Example #21
0
 //*********************************************************     
 //
 /// <summary>
 /// Load a EMF image
 /// </summary>
 /// <param name="assem">        Assembly from which the resource must be found</param>
 /// <param name="strName">      Partial name of the resource</param>
 /// <returns>
 /// EMF Image
 /// </returns>
 //  
 //*********************************************************     
 static private Metafile LoadMetaImage(System.Reflection.Assembly assem, string strName) {
     System.Drawing.Imaging.Metafile retVal;
     System.IO.Stream                stream;
     
     stream  = assem.GetManifestResourceStream(assem.GetName().Name + "." + strName);
     retVal  = new System.Drawing.Imaging.Metafile(stream);
     stream.Close();
     return(retVal);
 }
Example #22
0
 /// <summary>
 /// Loads an Embedded Resource file as a string, from the given source assembly.
 /// </summary>
 /// <param name="source">The assembly from which to load the file.</param>
 /// <param name="path">Path to the embedded file resource, starting with the root
 /// namespace of the assembly, up to and including the file name.
 /// (e.g. RootNs.Folders.FileName1.html)</param>
 /// <returns></returns>
 public static string ReadFile(System.Reflection.Assembly source, string path)
 {
     var stream = source.GetManifestResourceStream(path);
     using (var reader = new System.IO.StreamReader(stream))
     {
         return reader.ReadToEnd();
     }
 }
Example #23
0
            private bool ExtractResourceToDisk(System.Reflection.Assembly ass, string s, string fileoutput)
            {
                bool gravaLista = false;
                using (StreamReader FileReader = new StreamReader(ass.GetManifestResourceStream(s)))
                {
                    if (!Directory.Exists(Path.GetDirectoryName(fileoutput)))
                        Directory.CreateDirectory(Path.GetDirectoryName(fileoutput));

                    using (StreamWriter FileWriter = new StreamWriter(fileoutput))
                    {
                        FileWriter.Write(FileReader.ReadToEnd());
                        FileWriter.Close();
                        gravaLista = true;
                    }
                }
                return gravaLista;
            }
        public static string GetEmbeddedResource(string resourceName, System.Reflection.Assembly assembly)
        {
            resourceName = FormatResourceName(assembly, resourceName);
            using (Stream resourceStream = assembly.GetManifestResourceStream(resourceName))
            {
                if (resourceStream == null)
                    return null;

                using (StreamReader reader = new StreamReader(resourceStream))
                {
                    return reader.ReadToEnd();
                }
            }
        }
        public Type[] Execute(System.Reflection.Assembly assembly)
        {
            var targetNamespaces = NamespaceList.Create();
            var resourceNames = assembly.GetManifestResourceNames().Where(n => n.EndsWith("VenusIoc.config"));
            foreach (var resourceName in resourceNames)
            {
                var xmlDoc = new XmlDocument();
                using (var sr = new StreamReader(assembly.GetManifestResourceStream(resourceName)))
                {
                    xmlDoc.Load(sr);
                    foreach (var node in xmlDoc.DocumentElement.SelectNodes("components/assemblyScan/namespace"))
                    {
                        var name = ((XmlElement)node).GetAttribute("name");
                        if (!string.IsNullOrWhiteSpace(name))
                        {
                            targetNamespaces.Add(name.Split('.'));
                        }
                    }
                }
            }

            if (targetNamespaces.Count == 0)
                return new Type[0];

            var types = new List<Type>();
            var checkList = new HashSet<string>();
            var ignoreList = new HashSet<string>();
            foreach (var type in assembly.GetTypes())
            {
                bool toCheck = false;
                if (!ignoreList.Contains(type.Namespace) && type.Namespace != null)
                {
                    if (checkList.Contains(type.Namespace))
                    {
                        toCheck = true;
                    }
                    else
                    {
                        if (targetNamespaces.Include(type.Namespace.Split('.')))
                        {
                            checkList.Add(type.Namespace);
                            toCheck = true;
                        }
                        else
                        {
                            ignoreList.Add(type.Namespace);
                        }
                    }
                }

                if (toCheck)
                {
                    if (!type.IsAbstract && type.IsDefined(typeof(NamedAttribute), false))
                    {
                        types.Add(type);
                    }
                }
            }

            return types.ToArray();
        }
Example #26
0
        private void LoadAssemblyResources(System.Reflection.Assembly asm, AddInAttribute addInAttribute)
        {
            using (var resource = asm.GetManifestResourceStream(addInAttribute.B1SResource))
            {
                if (resource != null)
                {
                    var doc = XDocument.Load(resource);
                    var key = asm.GetName().FullName;

                    Dictionary<string, XDocument> formDictionary;
                    if (!formSRFResource.ContainsKey(key))
                    {
                        formDictionary = new Dictionary<string, XDocument>();
                        formSRFResource.Add(key, formDictionary);
                    }
                    else
                    {
                        formDictionary = formSRFResource[key];
                    }

                    ParseB1SFormSRF(doc, addInAttribute, key, formDictionary);
                }
            }
        }
 private static ImageSource GetEmbeddedBmp(System.Reflection.Assembly app, string imageName)
 {
     var file = app.GetManifestResourceStream(imageName);
     var source = BmpBitmapDecoder.Create(file, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
     return source.Frames[0];
 }
Example #28
0
 protected virtual string GetResourceImageFile(System.Reflection.Assembly assembly, string image)
 {
     var img = System.Drawing.Bitmap.FromStream(assembly.GetManifestResourceStream(image));
     var result = ReportingHost.TempService.CreateWithExtension(".png");
     img.Save(result, ImageFormat.Png); // Always convert to a PNG
     return result.Replace('\\', '/');
 }
Example #29
0
        private ImageSource GetEmbeddedImage(System.Reflection.Assembly app, string imageName)
        {
            System.IO.Stream file = app.GetManifestResourceStream("BIMSource.NewSPWriter." + imageName);
             PngBitmapDecoder bd = new PngBitmapDecoder(file, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);

             return bd.Frames[0];
        }
 private static ImageSource GetEmbeddedPng(System.Reflection.Assembly app, string imageName)
 {
     var file = app.GetManifestResourceStream(imageName);
     var source = PngBitmapDecoder.Create(file, BitmapCreateOptions.None, BitmapCacheOption.None);
     return source.Frames[0];
 }