private bool IsAppResourcePath(string virtualPath)
        {
            String checkPath =
                VirtualPathUtility.ToAppRelative(virtualPath);

            string assemblyName = "ASPNET.Plugin.PluginOne.dll";

            string[] parts        = virtualPath.Split('/');
            string   resourceName = "ASPNET.Plugin.PluginOne";

            foreach (string part in parts)
            {
                if (part == "~" || part == "")
                {
                    continue;
                }
                resourceName += ".";
                resourceName += part;
            }



            assemblyName = Path.Combine(HttpRuntime.BinDirectory, assemblyName);
            System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFile(assemblyName);



            var manifest = assembly.GetManifestResourceInfo(resourceName);

            return(null != manifest);
        }
示例#2
0
        public static Microsoft.MediaCenter.UI.Image GetMediaInfoImage(string name)
        {
            if (name.EndsWith("_"))
            {
                return(null);                    //blank codec or other type
            }
            name = name.ToLower().Replace("-", "_");
            name = name.Replace('/', '-');
            Guid id = ("MiImage" + Config.Instance.ViewTheme + name).GetMD5();

            //try to load from image cache first
            string path = CustomImageCache.Instance.GetImagePath(id);

            if (path != null)
            {
                return(new Image(path));              //was already cached
            }
            //not cached - look in IBN - this is inefficient but only the first time as we will pull from cache next
            string baseLocation = ApplicationPaths.AppIBNPath + "\\MediaInfo";

            //we'll look first in a theme-specific folder if it exists
            string ibnLocation = Path.Combine(baseLocation, Config.Instance.ViewTheme);

            if (!Directory.Exists(ibnLocation))                  //no theme-specific one - use default
            {
                ibnLocation = Path.Combine(baseLocation, "all"); //don't use 'default' cuz that's the name of a theme...
            }
            string fileName = Path.Combine(ibnLocation, RemoveInvalidFileChars(name) + ".png");

            if (File.Exists(fileName))
            {
                Logger.ReportVerbose("===CustomImage " + fileName + " being cached on first access.  Shouldn't have to do this again...");
                //cache it and return resulting cached image
                return(new Image("file://" + CustomImageCache.Instance.CacheImage(id, System.Drawing.Image.FromFile(fileName))));
            }
            else
            {
                //not there, get it from resources in default or the current theme if it exists
                string resourceRef = "resx://MediaBrowser/MediaBrowser.Resources/";
                //Logger.ReportInfo("============== Current Theme: " + Application.CurrentInstance.CurrentTheme.Name);
                System.Reflection.Assembly assembly = Kernel.Instance.FindPluginAssembly(Application.CurrentInstance.CurrentTheme.Name);
                if (assembly != null)
                {
                    //Logger.ReportInfo("============== Found Assembly. ");
                    if (assembly.GetManifestResourceInfo(name) != null)
                    {
                        //Logger.ReportInfo("============== Found Resource: " + name);
                        //cheap way to grab a valid reference to the current themes resources...
                        resourceRef = Application.CurrentInstance.CurrentTheme.PageArea.Substring(0, Application.CurrentInstance.CurrentTheme.PageArea.LastIndexOf("/") + 1);
                    }
                }
                //cache it
                Logger.ReportVerbose("===CustomImage " + resourceRef + name + " being cached on first access.  Should only have to do this once per session...");
                CustomImageCache.Instance.CacheResource(id, resourceRef + name);
                return(new Image(resourceRef + name));
            }
        }
        static Image TryLoadImage(System.Reflection.Assembly asm, string name)
        {
            try {
                if (asm.GetManifestResourceInfo(name) != null)
                {
                    return(Image.FromResource(asm, name));
                }
            }
            catch {
            }

            try {
                if (asm.GetManifestResourceInfo("WpfTestRunner.ReferenceImages." + name) != null)
                {
                    return(Image.FromResource(asm, "WpfTestRunner.ReferenceImages." + name));
                }
            }
            catch {
            }
            return(null);
        }
        public static Microsoft.MediaCenter.UI.Image GetMediaInfoImage(string name)
        {
            if (name.EndsWith("_"))
            {
                return(null);                    //blank codec or other type
            }
            name = name.ToLower().Replace("-", "_");
            name = name.Replace('/', '-');
            Guid id = ("MiImage" + Config.Instance.ViewTheme + name).GetMD5();

            //try to load from image cache first
            string path = CustomImageCache.Instance.GetImagePath(id, true);

            if (path != null)
            {
                return(new Image(path));              //was already cached
            }
            //not cached - get it from the server
            path = Kernel.ApiClient.GetMediaInfoImageUrl(name, Config.Instance.ViewTheme, new ImageOptions());
            var serverImage = new RemoteImage {
                Path = path
            };

            try
            {
                var image = serverImage.DownloadImage();
                Logger.ReportVerbose("===CustomImage " + path + " being cached on first access.  Shouldn't have to do this again...");
                //cache it and return resulting cached image
                return(new Image("file://" + CustomImageCache.Instance.CacheImage(id, image)));
            }
            catch (WebException)
            {
                //not there, get it from resources in default or the current theme if it exists
                string resourceRef = "resx://MediaBrowser/MediaBrowser.Resources/";
                //Logger.ReportInfo("============== Current Theme: " + Application.CurrentInstance.CurrentTheme.Name);
                System.Reflection.Assembly assembly = Kernel.Instance.FindPluginAssembly(Application.CurrentInstance.CurrentTheme.Name);
                if (assembly != null)
                {
                    //Logger.ReportInfo("============== Found Assembly. ");
                    if (assembly.GetManifestResourceInfo(name) != null)
                    {
                        //Logger.ReportInfo("============== Found Resource: " + name);
                        //cheap way to grab a valid reference to the current themes resources...
                        resourceRef = Application.CurrentInstance.CurrentTheme.PageArea.Substring(0, Application.CurrentInstance.CurrentTheme.PageArea.LastIndexOf("/") + 1);
                    }
                }
                //cache it
                Logger.ReportVerbose("===CustomImage " + resourceRef + name + " being cached on first access.  Should only have to do this once per session...");
                CustomImageCache.Instance.CacheResource(id, resourceRef + name);
                return(new Image(resourceRef + name));
            }
        }
        public static SKPicture LoadImage(string imageName, string themeName, bool force = false)
        {
            System.Reflection.Assembly assembly = typeof(SVGIconView).Assembly;
            string value = GetThemedImageSourceName(themeName, imageName);

            if (!imagesCache.ContainsKey(value))
            {
                if (assembly.GetManifestResourceInfo(value) == null)
                {
                    value = imageName;
                }
            }
            return(LoadIconFromResource(value, assembly));
        }
示例#6
0
        //Here put any helper methods or really anything else you may want.
        //You may find it handy to have methods here that other systems can access.
        public void playSound(string soundLocation, bool loop)
        {
            if (GlobalVars.soundOn)
            {
                if (!mediaPlayer)
                {
                    System.IO.Stream stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(soundLocation);
                    SoundPlayer      player = new SoundPlayer(stream);
                    if (playingSoundsMP.ContainsKey(soundLocation))
                    {
                        stopSound(soundLocation);
                    }
                    if (loop)
                    {
                        player.PlayLooping();
                    }
                    else
                    {
                        player.Play();
                    }
                    playingSounds.Add(soundLocation, player);
                }
                else
                {
                    WindowsMediaPlayer                     player = new WindowsMediaPlayer();
                    System.Reflection.Assembly             a      = System.Reflection.Assembly.GetExecutingAssembly();
                    System.Reflection.ManifestResourceInfo info   = a.GetManifestResourceInfo(soundLocation);
                    player.URL = info.FileName;

                    Console.WriteLine("URL: " + player.URL);
                    if (playingSoundsMP.ContainsKey(soundLocation))
                    {
                        stopSound(soundLocation);
                    }
                    if (loop)
                    {
                        player.settings.setMode("loop", true);
                        player.controls.play();
                    }
                    else
                    {
                        player.controls.play();
                    }
                    playingSoundsMP.Add(soundLocation, player);
                }
            }
        }
示例#7
0
 /// <summary>
 /// Checks to see if a resource exists in an assembly.
 /// </summary>
 /// <param name="assembly">The assembly containing the resource.</param>
 /// <param name="resourceName">The name of the resource.</param>
 /// <returns>A boolean indicating if the resource exists in the assembly.</returns>
 public static bool ResourceExists(System.Reflection.Assembly assembly, string resourceName)
 {
     return(assembly.GetManifestResourceInfo(resourceName) != null);
 }