From: <lk...@us...> - 2008-01-29 13:01:26
|
Revision: 1324 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=1324&view=rev Author: lkuech Date: 2008-01-29 05:01:20 -0800 (Tue, 29 Jan 2008) Log Message: ----------- ViewModeSwitcher: Try to switch from the Helper.dll file idea to the usage of .net reflections Modified Paths: -------------- trunk/plugins/ViewModeSwitcher/ViewModeSwitcher.cs trunk/plugins/ViewModeSwitcher/ViewModeSwitcher.csproj Added Paths: ----------- trunk/plugins/ViewModeSwitcher/TVPluginReflection.cs trunk/plugins/ViewModeSwitcher/TVstatusWrapper.cs Added: trunk/plugins/ViewModeSwitcher/TVPluginReflection.cs =================================================================== --- trunk/plugins/ViewModeSwitcher/TVPluginReflection.cs (rev 0) +++ trunk/plugins/ViewModeSwitcher/TVPluginReflection.cs 2008-01-29 13:01:20 UTC (rev 1324) @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; +using System.Windows.Forms; +using MediaPortal.GUI.Library; +using System.Reflection; + + +namespace ProcessPlugins.ViewModeSwitcher +{ + class TVPluginReflection + { + public enum States + { + notstarted, + delayed, + running, + finished + } + + public bool TVPluginFound = false; + public States State = States.notstarted; + + private System.Reflection.PropertyInfo CurrentChannelPropInfo = null; + private object oAssembly = null; + + public string CurrentTVChannel + { + get + { + if (CurrentChannelPropInfo == null && State == States.notstarted) Start(); + if (CurrentChannelPropInfo == null && State == States.finished) return string.Empty; + return GetCurrentChannelViaReflection(); + } + } + + public void Start() + { + Log.Debug("ViewModeSwitcher: TVPluginReflection: Start()"); + State = States.running; + + // Load the TVPlugin Assembly + Log.Debug("ViewModeSwitcher: TVPluginReflection: Try to find the TvPlugin"); + try + { + Assembly assembly = Assembly.LoadFrom("plugins\\Windows\\TvPlugin.dll"); + + Log.Debug("ViewModeSwitcher: TVPluginReflection: Try to load a instance of TvPlugin.ChannelNavigator"); + Type AssemblyType = assembly.GetType("TvPlugin.ChannelNavigator", false); + oAssembly = Activator.CreateInstance(AssemblyType); + + Log.Debug("ViewModeSwitcher: TVPluginReflection: Try to read CurrentTVChannel property"); + CurrentChannelPropInfo = AssemblyType.GetProperty("CurrentChannel"); + string tmpCurrentTVChannel = GetCurrentChannelViaReflection(); + Log.Debug("ViewModeSwitcher: TVPluginReflection: Value was: {0}", tmpCurrentTVChannel); + + //foreach (Type AssemblyType in assembly.GetTypes()) + //{ + // // Wait for the TvPlugin.ChannelNavigator class + // if (AssemblyType.IsClass == true && AssemblyType.FullName == "TvPlugin.ChannelNavigator") + // { + // Log.Debug("ViewModeSwitcher: TVPluginReflection: ...Found Class : {0}", AssemblyType.FullName); + + // // wait for the CurrentChannel property + // foreach (PropertyInfo PropInfo in AssemblyType.GetProperties()) + // { + // if (PropInfo.Name == "CurrentChannel") + // { + // Log.Debug("ViewModeSwitcher: TVPluginReflection: Found Property: {0}", PropInfo.Name); + // CurrentTVChannel = (string)AssemblyType.GetValue(PropInfo); + // Log.Debug("ViewModeSwitcher: TVPluginReflection: Value was: {0}", CurrentTVChannel); + // break; // leave the Properties foreach loop + // } + // } + + // break; // leave the Assembly foreach loop + //} + //} + + } + catch (Exception e) + { + Log.Debug("ViewModeSwitcher: TVPluginReflection: Error! {0}",e.Message); + } + + State = States.finished; + } + + public void DelayedStart(int timeout) + { + State = States.delayed; + Log.Debug("ViewModeSwitcher: TVPluginReflection: Delayed start"); + Timer delayTimer = new Timer(); + delayTimer.Interval = timeout; + delayTimer.Tick += new EventHandler(delayTimer_Tick); + delayTimer.Start(); + } + + string GetCurrentChannelViaReflection() + { + if (CurrentChannelPropInfo == null || oAssembly == null) + { + TVPluginFound = false; + return string.Empty; + } + TVPluginFound = true; + return (string)CurrentChannelPropInfo.GetValue(oAssembly, null); + } + + void delayTimer_Tick(object sender, EventArgs e) + { + Timer tmpTimer = (Timer)sender; + tmpTimer.Stop(); + Start(); + } + + } +} Added: trunk/plugins/ViewModeSwitcher/TVstatusWrapper.cs =================================================================== --- trunk/plugins/ViewModeSwitcher/TVstatusWrapper.cs (rev 0) +++ trunk/plugins/ViewModeSwitcher/TVstatusWrapper.cs 2008-01-29 13:01:20 UTC (rev 1324) @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Text; +using MediaPortal.TV.Recording; + +namespace ProcessPlugins.ViewModeSwitcher +{ + public class TVstatusWrapper + { + private TVPluginReflection TVPluginReference; + + public TVstatusWrapper() + { + TVPluginReference = new TVPluginReflection(); + //Log.Debug("ViewModeSwitcher: {0}", TVPluginReference.CurrentTVChannel); + } + + public string CurrentChannelName + { + get + { + if (TVPluginReference.State == TVPluginReflection.States.notstarted) // make sure tvplug is searched via reflection + { + return TVPluginReference.CurrentTVChannel; + } + + if (TVPluginReference.State == TVPluginReflection.States.finished && TVPluginReference.TVPluginFound) + { + return TVPluginReference.CurrentTVChannel; // return tve3 channel name + } + + return Recorder.GetTVChannelName(); // return tve2 channel name + } + } + + public bool IsViewingTV() + { + if (CurrentChannelName != "") + return true; + else return false; + } + } + + +} Modified: trunk/plugins/ViewModeSwitcher/ViewModeSwitcher.cs =================================================================== --- trunk/plugins/ViewModeSwitcher/ViewModeSwitcher.cs 2008-01-29 12:58:45 UTC (rev 1323) +++ trunk/plugins/ViewModeSwitcher/ViewModeSwitcher.cs 2008-01-29 13:01:20 UTC (rev 1324) @@ -31,7 +31,7 @@ using System.Threading; using System.Diagnostics; using System.Drawing; -using ViewModeSwitcherHelper; +//using ViewModeSwitcherHelper; //TODO remove namespace ProcessPlugins.ViewModeSwitcher { @@ -65,6 +65,7 @@ private bool MenuShown = false; private int CurrentRule = -1; private int RecentGuiWindowID = 0; + private TVstatusWrapper TvStatus = null; enum MoveDirection { @@ -92,7 +93,6 @@ t.Priority = ThreadPriority.BelowNormal; t.Name = "ViewModeSwitcherThread"; t.Start(); - // register to handle playback events so we can wake // the above thread when playback starts Recorder.OnTvViewingStarted += new Recorder.OnTvViewHandler(OnTVStarted); @@ -103,31 +103,32 @@ g_Player.PlayBackEnded += new g_Player.EndedHandler(OnVideoEnded); g_Player.PlayBackStopped += new g_Player.StoppedHandler(OnVideoStopped); - GUIGraphicsContext.OnNewAction += new OnActionHandler(OnAction); + //GUIGraphicsContext.OnNewAction += new OnActionHandler(OnAction); + TvStatus = new TVstatusWrapper(); } - public void OnAction(Action action) - { - switch (action.wID) - { - case Action.ActionType.ACTION_VIEWMODESWITCHER_MENU: - { - ShowMenu(); - } - break; - case Action.ActionType.ACTION_VIEWMODESWITCHER_DOWN: - { - MoveVisibleWindow(MoveDirection.Down); - } - break; - case Action.ActionType.ACTION_VIEWMODESWITCHER_UP: - { - MoveVisibleWindow(MoveDirection.UP); - } - break; - } - } + //public void OnAction(Action action) + //{ + // switch (action.wID) + // { + // case Action.ActionType.ACTION_VIEWMODESWITCHER_MENU: + // { + // ShowMenu(); + // } + // break; + // case Action.ActionType.ACTION_VIEWMODESWITCHER_DOWN: + // { + // MoveVisibleWindow(MoveDirection.Down); + // } + // break; + // case Action.ActionType.ACTION_VIEWMODESWITCHER_UP: + // { + // MoveVisibleWindow(MoveDirection.UP); + // } + // break; + // } + //} public void ShowMenu_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) @@ -502,12 +503,12 @@ { curZoomMode = GUIGraphicsContext.ARType; if (currentSettings.verboseLog) Log.Info("The viewmode has been change to {0}", curZoomMode); - SetZoomModeOffset(curZoomMode); + //SetZoomModeOffset(curZoomMode); } - if (TVstatusWrapper.IsViewingTV()) + if (TvStatus.IsViewingTV()) { - string tmpChannelName = TVstatusWrapper.GetChannelName(); + string tmpChannelName = TvStatus.CurrentChannelName; if (curTVChannelName != tmpChannelName) { curTVChannelName = tmpChannelName; Modified: trunk/plugins/ViewModeSwitcher/ViewModeSwitcher.csproj =================================================================== --- trunk/plugins/ViewModeSwitcher/ViewModeSwitcher.csproj 2008-01-29 12:58:45 UTC (rev 1323) +++ trunk/plugins/ViewModeSwitcher/ViewModeSwitcher.csproj 2008-01-29 13:01:20 UTC (rev 1324) @@ -51,13 +51,14 @@ <SpecificVersion>False</SpecificVersion> <HintPath>..\Core\bin\Debug\Utils.dll</HintPath> </Reference> - <Reference Include="ViewModeSwitcherHelper, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL" /> </ItemGroup> <ItemGroup> <Compile Include="PlugInBase.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Rule.cs" /> <Compile Include="Settings.cs" /> + <Compile Include="TVPluginReflection.cs" /> + <Compile Include="TVstatusWrapper.cs" /> <Compile Include="ViewModeSwitcher.cs" /> <Compile Include="ViewModeSwitcherConfig.cs"> <SubType>Form</SubType> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |