Esempio n. 1
0
        public YoutubeSongViewModel(YoutubeSong wrapped, Func <string> downloadPathFunc)
            : base(wrapped)
        {
            this.hasThumbnail = this.WhenAnyValue(x => x.Thumbnail)
                                .Select(x => x != null)
                                .ToProperty(this, x => x.HasThumbnail);

            // Wait for the opening of the context menu to download the YouTube information
            this.WhenAnyValue(x => x.IsContextMenuOpen)
            .FirstAsync(x => x)
            .SelectMany(_ => this.LoadContextMenu().ToObservable())
            .Subscribe();

            // We have to set a dummy here, so that we can connect the commands
            this.isDownloading = Observable.Never <bool>().ToProperty(this, x => x.IsDownloading);

            this.DownloadVideoCommand = ReactiveCommand.CreateAsyncTask(this.WhenAnyValue(x => x.IsDownloading).Select(x => !x),
                                                                        x => this.DownloadVideo((VideoInfo)x, downloadPathFunc()));

            this.DownloadAudioCommand = ReactiveCommand.CreateAsyncTask(this.WhenAnyValue(x => x.IsDownloading).Select(x => !x),
                                                                        x => this.DownloadAudio((VideoInfo)x, downloadPathFunc()));

            this.isDownloading = this.DownloadVideoCommand.IsExecuting
                                 .CombineLatest(this.DownloadAudioCommand.IsExecuting, (x1, x2) => x1 || x2)
                                 .ToProperty(this, x => x.IsDownloading);
        }
Esempio n. 2
0
        private void InitializeCommands()
        {
            var canSignIn = this.WhenAny(vm => vm.UserName, s => !String.IsNullOrWhiteSpace(s.Value));

            canSignIn.Subscribe(x => IsSignInVisible = x ? Visibility.Visible : Visibility.Hidden);

            SignInCommand = ReactiveCommand.CreateAsyncTask(canSignIn, async x =>
            {
                IsOnSignIn  = Visibility.Collapsed;
                IsOnWaiting = Visibility.Visible;
                var pass    = (PasswordBox)x;
                using (var loginSvc = new LoginSvcClient())
                {
                    try
                    {
                        var response =
                            await
                            loginSvc.LoginAsync(new LoginModel
                        {
                            Password = Cypher.Encrypt(pass.Password),
                            Username = Cypher.Encrypt(UserName)
                        });
                        return(response);
                    }
                    catch (Exception ex)
                    {
                        return(new ResponseMessage {
                            IsSuccess = false, Message = ResNetwork.ERROR_NETWORK_DOWN + ex.Message
                        });
                    }
                    finally
                    {
                        pass.Password = String.Empty;
                        IsOnSignIn    = Visibility.Visible;
                        IsOnWaiting   = Visibility.Collapsed;
                        MessageBus.Current.SendMessage(String.Empty, SharedMessageConstants.LOGIN_FOCUS_USERNAME);
                    }
                }
            });


            SignInCommand.Subscribe(x =>
            {
                if (x.IsSuccess)
                {
                    var bForceToInit = CurrentUserSettings.UserInfo.Username == null ||
                                       CurrentUserSettings.UserInfo.Username != UserName;

                    CurrentUserSettings.UserInfo.Username = x.UserDetail.UserName;
                    CurrentUserSettings.UserInfo.FullName = x.UserDetail.FullName;
                    CurrentUserSettings.UserInfo.Role     = x.UserDetail.Role;
                    ShellContainerVm.ChangeCurrentView(StatusScreen.ShMenu, true, bForceToInit);  //Only when comes from login, it should be reinit
                    OnUserChanged(CurrentUserSettings.UserInfo);
                }
                else
                {
                    MessageBus.Current.SendMessage(new MessageBoxSettings
                    {
                        Message = x.Message,
                        Title   = "Error al ingresar",
                    }, SharedMessageConstants.MSG_SHOW_ERRQST);
                    //Message = x.Message;
                }
            });
        }