private async void OnConnectClick( object Sender, RoutedEventArgs E )
        {
            ProgressDialogController controller = await ( ( MetroWindow ) Window.GetWindow( this ) ).ShowProgressAsync( "Signing in.", "Attempting to sign in with the new credentials." );
            controller.SetIndeterminate( );

            Settings.Default.OSUsername = Username.Text;
            Settings.Default.Save( );

            Client tester = new Client( MainWindow.UserAgent );
            BackgroundWorker worker = new BackgroundWorker(  );
            worker.DoWork += ( sender, args ) =>
            {
                Tuple<string, string> info = args.Argument as Tuple<string, string>;
                LogInOutput output = tester.LogIn( info.Item1, info.Item2, info.Item1.Length != info.Item2.Length || info.Item1.Length > 0 );
                args.Result = output;
            };
            worker.RunWorkerCompleted += async ( O, Args ) =>
            {
                await controller.CloseAsync( );

                LogInOutput output = ( LogInOutput ) Args.Result;
                this.IsSignedIn = output.LogInSuccesful;
                StatusImage.Visibility = Visibility.Visible;
                StatusLabel.Visibility = Visibility.Visible;

                StatusLabel.Content = !this.IsSignedIn ? output.StatusString.Substring( 4 ) : string.Empty;
            };
            worker.RunWorkerAsync( new Tuple<string, string>( Username.Text, Password.Password ) );
        }
예제 #2
0
        /// <summary>
        /// Initializes Player.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInitialized( EventArgs e )
        {
            Application.Current.DispatcherUnhandledException += ( Sender, Args ) =>
            {
                using ( FileStream FS = File.Create( "exception.txt" ) )
                    using ( TextWriter Writer = new StreamWriter( FS ) )
                        WriteExceptionDetails( Args.Exception, Writer );

                MessageBox.Show( "An exception has been encountered. The exact details have been saved in exception.txt. Please contact the developer and hand them this file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error );
#if !DEBUG
                Args.Handled = true;
#endif
                Application.Current.Shutdown( );
            };

            Player = new ViderePlayer( new WindowData { Window = this, MediaControlsContainer = MediaControlsContainer, MediaPlayer = new VLCPlayer( MediaArea.MediaPlayer ), MediaArea = MediaArea } );

            MediaComponent mediaComponent = Player.GetComponent<MediaComponent>( );
            mediaComponent.OnMediaLoaded += OnOnMediaLoaded;
            mediaComponent.OnMediaUnloaded += OnOnMediaUnloaded;
            mediaComponent.OnMediaFailedToLoad += MediaComponentOnOnMediaFailedToLoad;

            WindowButtonCommandsOverlayBehavior = WindowCommandsOverlayBehavior.Never;
            RightWindowCommandsOverlayBehavior = WindowCommandsOverlayBehavior.Never;
            LeftWindowCommandsOverlayBehavior = WindowCommandsOverlayBehavior.Never;

            Client = new Client( UserAgent );

            Application.Current.Exit += ( sender, args ) =>
            {
                Settings.Default.SubtitleTimeOffset = 0;
                Settings.Default.Save( );
            };

            KeyDown += OnKeyDown;

            StateComponent stateComponent = Player.GetComponent<StateComponent>( );
            ScreenComponent screenComponent = Player.GetComponent<ScreenComponent>( );

            stateComponent.OnStateChanged += ( Sender, Args ) =>
            {
                switch ( Args.State )
                {
                    case StateComponent.PlayerState.Playing:
                        screenComponent.DisableSleeping( );
                        break;

                    case StateComponent.PlayerState.Paused:
                    case StateComponent.PlayerState.Stopped:
                        screenComponent.EnableSleeping( );
                        break;
                }
            };

            string[ ] cmdArgs = Environment.GetCommandLineArgs( );
            if ( cmdArgs.Length > 1 )
                Player.GetComponent<MediaComponent>( ).LoadMedia( cmdArgs[ 1 ] );

            base.OnInitialized( e );

            ( ( OpenSubtitlesControl ) this.OSFlyout.Content ).InitWindow( this );
        }