/// <summary>
        /// Attempts to resolve and open a resource from the specified name, which may be partially
        /// qualified or entirely unqualified, by searching the assemblies associated with this <see cref="ResourceResolver"/> in order.
        /// </summary>
        /// <param name="resourceName">A partially qualified or unqualified resource name.</param>
        /// <returns>A qualified resource name, if found, otherwise an exception is thrown.</returns>
        /// <exception cref="MissingManifestResourceException">if the resource name could not be resolved.</exception>
        public Stream OpenResource(string resourceName)
        {
            //resources are qualified internally in the manifest with '.' characters, so let's first try
            //to find a resource that matches 'exactly' by preceding the name with a '.'
            string exactMatch = String.Format(".{0}", resourceName);

            foreach (Assembly asm in _assemblies)
            {
                foreach (string match in GetResourcesEndingWith(asm, exactMatch))
                {
                    // Assembly type is thread-safe, so this call is ok
                    return(asm.GetManifestResourceStream(match));
                }

                //next we'll just try to find the first match ending with the resource name.
                foreach (string match in GetResourcesEndingWith(asm, resourceName))
                {
                    // Assembly type is thread-safe, so this call is ok
                    return(asm.GetManifestResourceStream(match));
                }
            }

            // try the fallback
            if (_fallbackResovler != null)
            {
                return(_fallbackResovler.OpenResource(resourceName));
            }

            // not found - throw exception
            throw new MissingManifestResourceException(string.Format(SR.ExceptionResourceNotFound, resourceName));
        }
        private static XmlDocument LoadDocumentFromResources()
        {
            XmlDocument document  = new XmlDocument();
            Stream      xmlStream = _resolver.OpenResource("StandardImageProperties.xml");

            document.Load(xmlStream);
            xmlStream.Close();
            return(document);
        }
		/// <summary>
		/// Instantiates an active template from an embedded resource.
		/// </summary>
		/// <param name="resource"></param>
		/// <param name="resolver"></param>
		/// <returns></returns>
		public static ActiveTemplate FromEmbeddedResource(string resource, IResourceResolver resolver)
		{
			using (var stream = resolver.OpenResource(resource))
			{
				using (var reader = new StreamReader(stream))
				{
					return new ActiveTemplate(reader);
				}
			}
		}
Exemple #4
0
 /// <summary>
 /// Instantiates an active template from an embedded resource.
 /// </summary>
 /// <param name="resource"></param>
 /// <param name="resolver"></param>
 /// <returns></returns>
 public static ActiveTemplate FromEmbeddedResource(string resource, IResourceResolver resolver)
 {
     using (var stream = resolver.OpenResource(resource))
     {
         using (var reader = new StreamReader(stream))
         {
             return(new ActiveTemplate(reader));
         }
     }
 }
        /// <summary>
        /// Constructs a controller that uses the 32-bit colour ARGB bitmap specified by the resource name and resource resolver.
        /// </summary>
        /// <param name="resourceName">The partially or fully qualified name of the resource to access.</param>
        /// <param name="resourceResolver">A resource resolver for the resource.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="resourceName"/> is empty or NULL, or <paramref name="resourceResolver"/> is NULL.</exception>
        public FlashOverlayController(string resourceName, IResourceResolver resourceResolver)
            : this()
        {
            Platform.CheckForEmptyString(resourceName, "resourceName");
            Platform.CheckForNullReference(resourceResolver, "resourceResolver");

            using (Bitmap bitmap = new Bitmap(resourceResolver.OpenResource(resourceName)))
            {
                _pixelData = ExtractBitmap(bitmap, out _rows, out _columns);
            }
        }
Exemple #6
0
 /// <summary>
 /// Creates an icon using the specified icon resource and resource resolver.
 /// </summary>
 /// <remarks>
 /// The base implementation resolves the specified image resource using the provided
 /// <paramref name="resourceResolver"/> and deserializes the resource stream into a <see cref="Bitmap"/>.
 /// </remarks>
 /// <param name="iconSize">The size of the desired icon.</param>
 /// <param name="resourceResolver">The resource resolver with which to resolve the requested icon resource.</param>
 /// <returns>An <see cref="Image"/> constructed from the requested resource.</returns>
 /// <exception cref="ArgumentNullException">Thrown if <paramref name="resourceResolver"/> is null.</exception>
 /// <exception cref="ArgumentException">Thrown if <paramref name="resourceResolver"/> was unable to resolve the requested icon resource.</exception>
 public virtual Image CreateIcon(IconSize iconSize, IResourceResolver resourceResolver)
 {
     Platform.CheckForNullReference(resourceResolver, "resourceResolver");
     try
     {
         return(new Bitmap(resourceResolver.OpenResource(this[iconSize])));
     }
     catch (MissingManifestResourceException ex)
     {
         throw new ArgumentException("The provided resource resolver was unable to resolve the requested icon resource.", ex);
     }
 }
Exemple #7
0
        private static CursorWrapper FromImageResource(string imageResource, IResourceResolver resolver)
        {
            Bitmap bitmap = new Bitmap(resolver.OpenResource(imageResource));
            IntPtr hIcon  = bitmap.GetHicon();

            //we can dispose of the bitmap right away because the icon is a separate resource.
            bitmap.Dispose();

            Cursor cursor = new Cursor(hIcon);

            return(new CursorWrapper(cursor, hIcon));
        }
		/// <summary>
		/// Constructs a controller that uses the 32-bit colour ARGB bitmap specified by the resource name and resource resolver.
		/// </summary>
		/// <param name="resourceName">The partially or fully qualified name of the resource to access.</param>
		/// <param name="resourceResolver">A resource resolver for the resource.</param>
		public FlashOverlayController(string resourceName, IResourceResolver resourceResolver) : this()
		{
			using (Bitmap bitmap = new Bitmap(resourceResolver.OpenResource(resourceName)))
			{
				BitmapData data = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
				try
				{
					int length = data.Stride*data.Height;
					_pixelData = new byte[length];
					_rows = data.Height;
					_columns = data.Width;
					Marshal.Copy(data.Scan0, _pixelData, 0, length);
				}
				finally
				{
					bitmap.UnlockBits(data);
				}
			}
		}
Exemple #9
0
 /// <summary>
 /// Constructs a controller that uses the 32-bit colour ARGB bitmap specified by the resource name and resource resolver.
 /// </summary>
 /// <param name="resourceName">The partially or fully qualified name of the resource to access.</param>
 /// <param name="resourceResolver">A resource resolver for the resource.</param>
 public FlashOverlayController(string resourceName, IResourceResolver resourceResolver) : this()
 {
     using (Bitmap bitmap = new Bitmap(resourceResolver.OpenResource(resourceName)))
     {
         BitmapData data = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
         try
         {
             int length = data.Stride * data.Height;
             _pixelData = new byte[length];
             _rows      = data.Height;
             _columns   = data.Width;
             Marshal.Copy(data.Scan0, _pixelData, 0, length);
         }
         finally
         {
             bitmap.UnlockBits(data);
         }
     }
 }
        /// <summary>
        /// Attempts to resolve and open a resource from the specified name, which may be partially
        /// qualified or entirely unqualified, by searching the assemblies associated with this <see cref="ResourceResolver"/> in order.
        /// </summary>
        /// <param name="resourceName">A partially qualified or unqualified resource name.</param>
        /// <returns>The loaded resource stream.</returns>
        /// <exception cref="MissingManifestResourceException">if the resource name could not be resolved.</exception>
        public Stream OpenResource(string resourceName)
        {
            Platform.CheckForEmptyString(resourceName, @"resourceName");

            foreach (var asm in _assemblies)
            {
                var result = ResolveResource(resourceName, asm);
                if (result != null)
                {
                    return(OpenResource(result, asm));
                }
            }

            // try the fallback
            if (_fallbackResolver != null)
            {
                return(_fallbackResolver.OpenResource(resourceName));
            }

            // not found - throw exception
            throw new MissingManifestResourceException(string.Format(SR.ExceptionResourceNotFound, resourceName));
        }
		private static CursorWrapper FromCursorResource(string cursorResource, IResourceResolver resolver)
		{
			return new CursorWrapper(new Cursor(resolver.OpenResource(cursorResource)), true);
		}
		private static CursorWrapper FromImageResource(string imageResource, IResourceResolver resolver)
		{
			Bitmap bitmap = new Bitmap(resolver.OpenResource(imageResource));
			IntPtr hIcon = bitmap.GetHicon();

			//we can dispose of the bitmap right away because the icon is a separate resource.
			bitmap.Dispose();

			Cursor cursor = new Cursor(hIcon);
			return new CursorWrapper(cursor, hIcon);
		}
Exemple #13
0
 /// <summary>
 /// Attempts to create an icon using the specified image resource and resource resolver.
 /// </summary>
 /// <param name="resource">The name of the image resource</param>
 /// <param name="resolver">A resource resolver</param>
 /// <returns>a bitmap constructed from the specified image resource</returns>
 public static Bitmap CreateIcon(string resource, IResourceResolver resolver)
 {
     return(new Bitmap(resolver.OpenResource(resource)));
 }
Exemple #14
0
 /// <summary>
 /// Attempts to create an icon using the specified image resource and resource resolver.
 /// </summary>
 /// <param name="resource">The name of the image resource</param>
 /// <param name="resolver">A resource resolver</param>
 /// <returns>a bitmap constructed from the specified image resource</returns>
 public static Bitmap CreateIcon(string resource, IResourceResolver resolver)
 {
     return new Bitmap(resolver.OpenResource(resource));
 }
Exemple #15
0
 private static CursorWrapper FromCursorResource(string cursorResource, IResourceResolver resolver)
 {
     return(new CursorWrapper(new Cursor(resolver.OpenResource(cursorResource)), true));
 }
		/// <summary>
		/// Constructs a controller that uses the 32-bit colour ARGB bitmap specified by the resource name and resource resolver.
		/// </summary>
		/// <param name="resourceName">The partially or fully qualified name of the resource to access.</param>
		/// <param name="resourceResolver">A resource resolver for the resource.</param>
		/// <exception cref="ArgumentNullException">Thrown if <paramref name="resourceName"/> is empty or NULL, or <paramref name="resourceResolver"/> is NULL.</exception>
		public FlashOverlayController(string resourceName, IResourceResolver resourceResolver)
			: this()
		{
			Platform.CheckForEmptyString(resourceName, "resourceName");
			Platform.CheckForNullReference(resourceResolver, "resourceResolver");

			using (Bitmap bitmap = new Bitmap(resourceResolver.OpenResource(resourceName)))
			{
				_pixelData = ExtractBitmap(bitmap, out _rows, out _columns);
			}
		}