/// <summary>
        /// This is a workaround for when AddInHost.Current.MediaCenterEnvironment.MediaExperience returns null
        /// </summary>
        public static MediaExperience GetMediaExperienceUsingReflection()
        {
            MediaCenterEnvironment env = AddInHost.Current.MediaCenterEnvironment;

            var mce = env.MediaExperience;

            // great window 7 has bugs, lets see if we can work around them
            // http://mediacentersandbox.com/forums/thread/9287.aspx
            if (mce == null)
            {
                mce = env.MediaExperience;

                if (mce == null)
                {
                    try
                    {
                        if (_CheckedMediaExperienceFIeldInfo == null)
                        {
                            _CheckedMediaExperienceFIeldInfo = env.GetType().GetField("_checkedMediaExperience", BindingFlags.NonPublic | BindingFlags.Instance);
                        }

                        if (_CheckedMediaExperienceFIeldInfo != null)
                        {
                            _CheckedMediaExperienceFIeldInfo.SetValue(env, false);
                            mce = env.MediaExperience;
                        }
                    }
                    catch (Exception e)
                    {
                        // give up ... I do not know what to do
                        Logger.ReportException("AddInHost.Current.MediaCenterEnvironment.MediaExperience is null", e);
                    }
                }

                if (mce == null)
                {
                    Logger.ReportVerbose("GetMediaExperienceUsingReflection was unsuccessful");
                }
                else
                {
                    Logger.ReportVerbose("GetMediaExperienceUsingReflection was successful");
                }
            }

            return(mce);
        }
Esempio n. 2
0
        /// <summary>
        /// This is an oddity under TVPack, sometimes the MediaCenterEnvironemt and MediaExperience objects go bad and become
        /// disconnected from their host in the main application. Typically this is after 5 minutes of leaving the application idle (but noot always).
        /// What is odd is that using reflection under these circumstances seems to work - even though it is only doing the same as Reflector shoulds the real
        /// methods do. As I said it's odd but this at least lets us get a warning on the screen before the application crashes out!
        /// </summary>
        /// <param name="message"></param>
        public static void DialogBoxViaReflection(string message)
        {
            MediaCenterEnvironment ev = Microsoft.MediaCenter.Hosting.AddInHost.Current.MediaCenterEnvironment;
            FieldInfo fi = ev.GetType().GetField("_legacyAddInHost", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);

            if (fi != null)
            {
                AddInHost2 ah2 = (AddInHost2)fi.GetValue(ev);
                if (ah2 != null)
                {
                    Type         t  = ah2.GetType();
                    PropertyInfo pi = t.GetProperty("HostControl", BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Public);
                    if (pi != null)
                    {
                        HostControl hc = (HostControl)pi.GetValue(ah2, null);
                        hc.Dialog(message, "Media Browser", 1, 120, true);
                    }
                }
            }
        }
Esempio n. 3
0
        public static void ResetMediaExperienceCache(MediaCenterEnvironment environment)
        {
            if (IsWindows7OrHigher)
            {
                try
                {
                    FieldInfo fieldInfo = environment.GetType().GetField("_checkedMediaExperience",
                        BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

                    if (fieldInfo != null)
                    {
                        fieldInfo.SetValue(environment, false);
                    }
                    else
                    {
                        LogUtility.LogMessage("Warning: cannot find MediaCenterEnvironment._checkedMediaExperience field on Windows 7");
                    }
                }
                catch (Exception e)
                {
                    LogUtility.LogMessage("Error setting MediaCenterEnvironment._checkedMediaExperience flag on Windows 7: " + e.ToString());
                }
            }
        }