/// <summary> /// Process key press events /// </summary> /// <param name="keyPressed"></param> public override void ProcessKeyPress(int keyPressed) { if (!_shouldSendEventsToService) { return; } _logger.Debug("WebServiceRemoteHandling - ProcessKeyPress {0} {1}", keyPressed, ((Keys)keyPressed).ToString()); // Get the client implementation to translate the key press - this means we can truly detach the browser host from MediaPortal // The client handler for this event should fire the OnNewAction when the key has been translated WebBrowserPlayerCallbackService.SendKeyPress(keyPressed); }
/// <summary> /// /// </summary> /// <param name="msg"></param> /// <returns></returns> public override bool ProcessWndProc(Message msg) { if (!_shouldSendEventsToService) { return(false); } _logger.Debug(string.Format("WebServiceRemoteHandling - WndProc message to be processed {0}, appCommand {1}, LParam {2}, WParam {3}", msg.Msg, ProcessHelper.GetLparamToAppCommand(msg.LParam), msg.LParam, msg.WParam)); if (WebBrowserPlayerCallbackService.SendWndProc(msg)) { return(true); } return(false); }
/// <summary> /// Used to pass messages to remotes. Pre-filter to only messages we're likely to be interested in /// </summary> /// <param name="msg"></param> protected override void WndProc(ref Message msg) { try { if (_remoteProcessing.ProcessWndProc(msg)) { return; } } catch (Exception ex) { _logger.Error(ex); Console.Error.WriteLine(string.Format("{0}\r\n{1}", ex.Message, ex.StackTrace)); Console.Error.Flush(); WebBrowserPlayerCallbackService.LogError(ex); } base.WndProc(ref msg); }
/// <summary> /// Close the application /// </summary> private void ForceQuit() { try { WebBrowserPlayerCallbackService.OnBrowserClosing(); // Let MePo know we're closing if (_connector != null) { _connector.OnClosing(); } ForceClose = true; } catch (Exception ex) { _logger.Error(string.Format("{0}\r\n{1}", ex.Message, ex.StackTrace)); } finally { Thread.Sleep(1000); // Wait 1 second for MePo to show Process.GetCurrentProcess().Kill(); // In case we've got some weird browser issues or something hogging the process } }
/// <summary> /// The form is loaded - let's navigate to the video /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BrowserForm_Load(object sender, EventArgs e) { try { _logger.Debug("Setting current screen"); SetScreenState(); SetCurrentScreen(); ForceClose = false; this.Activate(); this.Focus(); _logger.Debug("AppDomain Root {0}", AppDomain.CurrentDomain.BaseDirectory); _logger.Debug("Current Directory {0}", Directory.GetCurrentDirectory()); _logger.Debug(string.Format("Browser Host started with connector type: {0}, video info: {1}", _connectorType, _videoInfo)); WebBrowserPlayerCallbackService.LogInfo(string.Format("Browser Host started with connector type: {0}, video info: {1}", _connectorType, _videoInfo)); // Set up remote handling _remoteProcessing.ActionReceived += RemoteProcessing_OnNewAction; _remoteProcessing.InitHandlers(); _logger.Debug("Loading Connector"); _connector = BrowserInstanceConnectorFactory.GetConnector(_connectorType, _logger, webBrowser); if (_connector == null) { _logger.Error(string.Format("Unable to load connector type {0}, not found in any site utils", _connectorType)); throw new ApplicationException(string.Format("Unable to load connector type {0}, not found in any site utils", _connectorType)); } _connector.DebugMode = _debugMode; _logger.Debug("Performing Log in"); _connector.PerformLogin(_userName, _password); var result = _connector.WaitForComplete(ForceQuitting, _connectorTimeout); if (result) { _logger.Debug("Playing Video"); _connector.PlayVideo(_videoInfo); result = _connector.WaitForComplete(ForceQuitting, _connectorTimeout); _logger.Debug("Playing WaitforComplete " + result.ToString()); if (!result) { ForceQuit(); } } else { _logger.Error("Log in failed"); ForceQuit(); } } catch (Exception ex) { _logger.Error(ex); Console.Error.WriteLine(string.Format("{0}\r\n{1}", ex.Message, ex.StackTrace)); Console.Error.Flush(); WebBrowserPlayerCallbackService.LogError(ex); ForceQuit(); } }
/// <summary> /// Load the first matching class from the site util dlls with the class name matching the connectorType /// </summary> /// <param name="connectorType"></param> /// <param name="logger"></param> /// <param name="browser"></param> /// <returns></returns> public static BrowserUtilConnector GetConnector(string connectorType, ILog logger, WebBrowser browser = null) { var path = OnlineVideoSettings.Instance.DllsDir; var assemblies = new List <Assembly>(); if (string.IsNullOrEmpty(path)) { path = Directory.GetCurrentDirectory() + "\\plugins\\windows\\onlinevideos"; } if (!Directory.Exists(path)) { path = Directory.GetCurrentDirectory(); } logger.Info(string.Format("Looking in {0} for connector dlls", path)); if (Directory.Exists(path)) { var dllFilesToCheck = Directory.GetFiles(path, "OnlineVideos.Sites.*.dll"); if (dllFilesToCheck.Length == 0) { path = Directory.GetCurrentDirectory(); logger.Info(string.Format("Looking in {0} for connector dlls", path)); } dllFilesToCheck = Directory.GetFiles(path, "OnlineVideos.Sites.*.dll"); foreach (string aDll in dllFilesToCheck) { try { assemblies.Add(AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(aDll))); } catch (Exception ex) { logger.Error(ex); } } } // Find the first type within the assemblies which matches the connectorType foreach (var assembly in assemblies) { WebBrowserPlayerCallbackService.LogInfo(string.Format("Looking for BrowserUtilConnector in {0} (Version: {1})", assembly.GetName().Name, assembly.GetName().Version.ToString())); try { Type[] typeArray = assembly.GetExportedTypes(); foreach (Type type in typeArray) { if (type.BaseType != null && type.IsSubclassOf(typeof(BrowserUtilConnector)) && !type.IsAbstract) { if (type.FullName == connectorType) { // Weve hit gold! var connector = Activator.CreateInstance(type) as BrowserUtilConnector; if (connector != null) { connector.Initialise(browser ?? new WebBrowser { ScriptErrorsSuppressed = true }, logger); return(connector); } } } } } catch (Exception ex) { logger.Error(ex); } } return(null); }