Beispiel #1
0
        /// <summary>
        /// Gets the stream for the given icon resource request.
        /// </summary>
        /// <param name="request">Request object for the icon resource.</param>
        /// <param name="extension">Returns the extension to describe the type of resource.</param>
        /// <returns>A valid Stream if the icon resource found successfully else null.</returns>
        public override Stream GetResource(IRequest request, out string extension)
        {
            //Create IconUrl to parse the request.Url to icon name and path.
            var icon = new IconUrl(new Uri(request.Url));

            var stream = GetIconStream(icon, out extension);

            if (stream == null)
            {
                stream = GetDefaultIconStream(out extension);
            }

            return(stream);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the stream for the given icon resource request.
        /// </summary>
        /// <param name="request">Request object for the icon resource.</param>
        /// <param name="extension">Returns the extension to describe the type of resource.</param>
        /// <returns>A valid Stream if the icon resource found successfully else null.</returns>
        public override Stream GetResource(IRequest request, out string extension)
        {
            //Create IconUrl to parse the request.Url to icon name and path.
            var icon = new IconUrl(new Uri(request.Url));
            //if (request.Url.Contains("Geometry"))
            //{
            //    System.Diagnostics.Trace.WriteLine("请看大宝贝儿");
            //    System.Diagnostics.Trace.WriteLine(request.Url);
            //}
            var stream = GetIconStream(icon, out extension);

            if (stream == null)
            {
                stream = GetDefaultIconStream(out extension);
            }

            return(stream);
        }
Beispiel #3
0
        /// <summary>
        /// Gets the stream for the given icon resource
        /// </summary>
        /// <param name="icon">Icon Url</param>
        /// <param name="extension">Returns the extension to describe the type of resource.</param>
        /// <returns>A valid Stream if the icon resource found successfully else null.</returns>
        private Stream GetIconStream(IconUrl icon, out string extension)
        {
            extension = "png";

            var path = Path.GetFullPath(icon.Path); //Get full path if it's a relative path.
            var libraryCustomization = LibraryCustomizationServices.GetForAssembly(path, pathManager, true);

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

            var assembly = libraryCustomization.ResourceAssembly;

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

            // "Name" can be "Some.Assembly.Name.customization" with multiple dots,
            // we are interested in removal of the "customization" part and the middle dots.
            var temp         = assembly.GetName().Name.Split('.');
            var assemblyName = String.Join("", temp.Take(temp.Length - 1));
            var rm           = new ResourceManager(assemblyName + imagesSuffix, assembly);

            using (var image = (Bitmap)rm.GetObject(icon.Name))
            {
                if (image == null)
                {
                    return(null);
                }

                var stream = new MemoryStream();
                image.Save(stream, ImageFormat.Png);

                return(stream);
            }
        }