/// <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();
            }
        }
Beispiel #2
0
        /// <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);
        }