private void ClickFullScreen(object obj) { var tries = 0; var found = false; var xPos = 0; var yPos = 0; while (!found && tries < 20) { Thread.Sleep(200); Browser.FindForm().BeginInvoke((MethodInvoker) delegate() { if (Browser == null || Browser.Document == null) { return; } var element = Browser.Document.GetElementById("silverlightWrapperObject"); if (element == null) { return; } found = true; var pos = GetOffset(element); xPos = pos.X + Browser.Document.Window.Position.X + element.OffsetRectangle.Width - 50; // +Browser.FindForm().Left; yPos = pos.Y + Browser.Document.Window.Position.Y + element.OffsetRectangle.Height - 10; // +Browser.FindForm().Top; }); tries++; } Thread.Sleep(7000); TemporaryCursorHelper.MoveMouseTo(xPos, yPos); TemporaryCursorHelper.DoLeftMouseClick(); }
/// <summary> /// Find the play/pause button and click it /// </summary> /// <returns></returns> private EventResult DoPlayOrPause() { if (DateTime.Now < _lastPlayClick.AddMilliseconds(500)) { return(EventResult.Complete()); } TemporaryCursorHelper.MoveMouseTo(Browser.FindForm().Left + (Browser.FindForm().Width / 2) + 50, Browser.FindForm().Top + (Browser.FindForm().Height / 2)); TemporaryCursorHelper.DoLeftMouseClick(); TemporaryCursorHelper.MoveMouseTo(0, 0); _lastPlayClick = DateTime.Now; return(EventResult.Complete()); }
/// <summary> /// Process a message from the web browser /// </summary> /// <returns></returns> public override EventResult BrowserDocumentComplete() { switch (_currentState) { case State.LoggingIn: if (Url.EndsWith("/signin/skygo")) { var jsCode = "document.getElementById('username').value = '" + _username + "';"; jsCode += "document.getElementById('password').value = '" + _password + "';"; jsCode += "document.getElementById('signinform').submit();"; InvokeScript(jsCode); _currentState = State.LoginResult; } break; case State.LoginResult: if (Url == "http://go.sky.com/") { _currentState = State.None; ProcessComplete.Finished = true; ProcessComplete.Success = true; } else { return(EventResult.Error("SkyGoGeneralConnector/ProcessMessage/Expected home page after log in, was actually " + Url)); } break; case State.PlayPage: if (Url.Contains("/content/videos")) { //Browser.Refresh(WebBrowserRefreshOption.Completely);// Need to do this for some reason _currentState = State.None; // The js code to wait for the video to appear var jsCode = "setTimeout('doMaximise()', 1000);"; jsCode += "function doMaximise() {"; jsCode += "if(document.getElementsByClassName('silverlightVodPlayerWrapper') != null) {"; jsCode += " document.getElementsByClassName('silverlightVodPlayerWrapper')[0].setAttribute('style', 'position: fixed; width: 100%; height: 100%; left: 0; top: 0; background: rgba(51,51,51,0.7); z-index: 10;');"; jsCode += "}"; jsCode += "else setTimeout('doMaximise()', 1000);"; jsCode += "}"; InvokeScript(jsCode); var startTime = DateTime.Now; _playPressThread = new Thread(new ParameterizedThreadStart(ClickPlayAfterFullScreen)); _playPressThread.Start(); ProcessComplete.Finished = true; ProcessComplete.Success = true; // Wait 15 seconds for the video to start before disabling app storage - we'll do this in a separate thread if (_disableAppStorageThread == null) { _disableAppStorageThread = new Thread(new ParameterizedThreadStart(DisableAppStorage)); _disableAppStorageThread.Start(); } Browser.FindForm().Activate(); Browser.FindForm().Focus(); } else { if (!Url.EndsWith("/content/videos")) { return(EventResult.Error("SkyGoOnDemandConnector/ProcessMessage/Expected video play page, was actually " + Url)); } } break; case State.PlayPageLiveTv: if (Url.Contains("/detachedLiveTv.do")) { // After 4 seconds we'll assume the page has loaded and will click in the top corner var endDate = DateTime.Now.AddSeconds(4); while (DateTime.Now < endDate) { Application.DoEvents(); System.Threading.Thread.Sleep(200); } TemporaryCursorHelper.MoveMouseTo(50, 50); Application.DoEvents(); TemporaryCursorHelper.DoLeftMouseClick(); Application.DoEvents(); HideLoading(); Browser.FindForm().Activate(); Browser.FindForm().Focus(); ProcessComplete.Finished = true; ProcessComplete.Success = true; } break; } return(EventResult.Complete()); }