private void LongTapAction(UIGestureRecognizerState state)
        {
            switch (state)
            {
            case UIGestureRecognizerState.Began:
                break;

            case UIGestureRecognizerState.Ended:
                if (_longCommand == null)
                {
                    TapAction();
                }
                else
                {
                    NotifyTask.Create(
                        async() =>
                    {
                        await Task.Delay(50);
                        _longCommand.Execute(_longParameter);
                    });
                }

                break;

            case UIGestureRecognizerState.Cancelled:
            case UIGestureRecognizerState.Failed:
                break;
            }
        }
Ejemplo n.º 2
0
 public DebtBookPageViewModel(IStore <Debt> store, INavigationService navigationService)
 {
     Title              = "Długi";
     DebtStore          = store;
     _navigationService = navigationService;
     InitializeTask     = NotifyTask.Create(InitializeAsync);
 }
Ejemplo n.º 3
0
        public void PropertyChanged_NoListeners_DoesNotThrow()
        {
            var tcs      = new TaskCompletionSource <object>();
            var notifier = NotifyTask.Create(() => (Task)tcs.Task);

            tcs.SetResult(null);
        }
Ejemplo n.º 4
0
 public MainWindowViewModel(InventoryContext context)
 {
     this._context          = context;
     this.AsyncCommandTest1 = new AsyncCommand(() => Task.Run(() => this.Populate()));
     this.completed         = NotifyTask.Create(this.AsyncCommandTest1.Execution.TaskCompleted);
     this._context.InventoryItems.OfType <Product>().Include(e => e.Instances).Include(e => e.Lots).Include(e => e.ProductType).Include(e => e.Warehouse).LoadAsync();
     this.LabelText = "Text Here";
 }
 private void TapAction()
 {
     NotifyTask.Create(async() =>
     {
         await Task.Delay(50);
         _tapCommand?.Execute(_tapParameter);
     });
 }
        public JobListViewModel(INavigation navigation)
        {
            _navigation = navigation;

            _jobsService = new JobsService();

            GetJobsNotifier = NotifyTask.Create(GetJobsAsync);
        }
Ejemplo n.º 7
0
 private void ViewOnClick(object sender, EventArgs eventArgs)
 {
     NotifyTask.Create(
         async() =>
     {
         await Task.Delay(50);
         TapCommandEffect.GetTap(Element)?.Execute(TapCommandEffect.GetTapParameter(Element));
     });
 }
 public ContactBookPageViewModel(IStore <Contact> store, INavigationService navigationService)
 {
     Title              = "Kontakty";
     ContactStore       = store;
     _navigationService = navigationService;
     InitializeTask     = NotifyTask.Create(InitializeAsync);
     AddContactCommand  = new AsyncCommand(AddContactAsync);
     SelectCommand      = new DelegateCommand <Contact>(SelectItem);
 }
        private async Task ExecuteLoadData(object args)
        {
            var notifyTask = NotifyTask.Create(LoadData);

            if (notifyTask.IsCompleted)
            {
                Info = notifyTask.Result as ObservableCollection <ItemInfo>;
                OnPropertyChanged(nameof(Info));
            }
        }
Ejemplo n.º 10
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var task = Task.Run(async() =>
            {
                await Task.Delay(5000);
                return("test");
            });

            return(NotifyTask.Create(task));
        }
Ejemplo n.º 11
0
        public void NotifierT_TaskFaulted_NotifiesProperties()
        {
            var tcs                                 = new TaskCompletionSource <object>();
            var notifier                            = NotifyTask.Create(() => tcs.Task);
            var exception                           = new NotImplementedException(Guid.NewGuid().ToString("N"));
            var taskNotification                    = TestUtils.PropertyNotified(notifier, n => n.Task);
            var statusNotification                  = TestUtils.PropertyNotified(notifier, n => n.Status);
            var isCompletedNotification             = TestUtils.PropertyNotified(notifier, n => n.IsCompleted);
            var isSuccessfullyCompletedNotification = TestUtils.PropertyNotified(notifier, n => n.IsSuccessfullyCompleted);
            var isCanceledNotification              = TestUtils.PropertyNotified(notifier, n => n.IsCanceled);
            var isFaultedNotification               = TestUtils.PropertyNotified(notifier, n => n.IsFaulted);
            var exceptionNotification               = TestUtils.PropertyNotified(notifier, n => n.Exception);
            var innerExceptionNotification          = TestUtils.PropertyNotified(notifier, n => n.InnerException);
            var errorMessageNotification            = TestUtils.PropertyNotified(notifier, n => n.ErrorMessage);
            var resultNotification                  = TestUtils.PropertyNotified(notifier, n => n.Result);

            Assert.Same(tcs.Task, notifier.Task);
            Assert.False(notifier.TaskCompleted.IsCompleted);
            Assert.Equal(tcs.Task.Status, notifier.Status);
            Assert.False(notifier.IsCompleted);
            Assert.True(notifier.IsNotCompleted);
            Assert.False(notifier.IsSuccessfullyCompleted);
            Assert.Null(notifier.Result);
            Assert.False(notifier.IsCanceled);
            Assert.False(notifier.IsFaulted);
            Assert.Null(notifier.Exception);
            Assert.Null(notifier.InnerException);
            Assert.Null(notifier.ErrorMessage);

            tcs.SetException(exception);

            Assert.Same(tcs.Task, notifier.Task);
            Assert.True(notifier.TaskCompleted.IsCompleted && !notifier.TaskCompleted.IsCanceled && !notifier.TaskCompleted.IsFaulted);
            Assert.Equal(tcs.Task.Status, notifier.Status);
            Assert.True(notifier.IsCompleted);
            Assert.False(notifier.IsNotCompleted);
            Assert.False(notifier.IsSuccessfullyCompleted);
            Assert.Null(notifier.Result);
            Assert.False(notifier.IsCanceled);
            Assert.True(notifier.IsFaulted);
            Assert.NotNull(notifier.Exception);
            Assert.Same(exception, notifier.InnerException);
            Assert.Equal(exception.Message, notifier.ErrorMessage);

            Assert.False(taskNotification());
            Assert.True(statusNotification());
            Assert.True(isCompletedNotification());
            Assert.False(isSuccessfullyCompletedNotification());
            Assert.False(isCanceledNotification());
            Assert.True(isFaultedNotification());
            Assert.True(exceptionNotification());
            Assert.True(innerExceptionNotification());
            Assert.True(errorMessageNotification());
            Assert.False(resultNotification());
        }
Ejemplo n.º 12
0
        public void NotifierT_TaskCompletesSuccessfully_NotifiesProperties()
        {
            var tcs                                 = new TaskCompletionSource <object>();
            var notifier                            = NotifyTask.Create(() => tcs.Task);
            var result                              = new object();
            var taskNotification                    = TestUtils.PropertyNotified(notifier, n => n.Task);
            var statusNotification                  = TestUtils.PropertyNotified(notifier, n => n.Status);
            var isCompletedNotification             = TestUtils.PropertyNotified(notifier, n => n.IsCompleted);
            var isSuccessfullyCompletedNotification = TestUtils.PropertyNotified(notifier, n => n.IsSuccessfullyCompleted);
            var isCanceledNotification              = TestUtils.PropertyNotified(notifier, n => n.IsCanceled);
            var isFaultedNotification               = TestUtils.PropertyNotified(notifier, n => n.IsFaulted);
            var exceptionNotification               = TestUtils.PropertyNotified(notifier, n => n.Exception);
            var innerExceptionNotification          = TestUtils.PropertyNotified(notifier, n => n.InnerException);
            var errorMessageNotification            = TestUtils.PropertyNotified(notifier, n => n.ErrorMessage);
            var resultNotification                  = TestUtils.PropertyNotified(notifier, n => n.Result);

            Assert.AreSame(tcs.Task, notifier.Task);
            Assert.False(notifier.TaskCompleted.IsCompleted);
            Assert.AreEqual(tcs.Task.Status, notifier.Status);
            Assert.False(notifier.IsCompleted);
            Assert.True(notifier.IsNotCompleted);
            Assert.False(notifier.IsSuccessfullyCompleted);
            Assert.Null(notifier.Result);
            Assert.False(notifier.IsCanceled);
            Assert.False(notifier.IsFaulted);
            Assert.Null(notifier.Exception);
            Assert.Null(notifier.InnerException);
            Assert.Null(notifier.ErrorMessage);

            tcs.SetResult(result);

            Assert.AreSame(tcs.Task, notifier.Task);
            Assert.True(notifier.TaskCompleted.IsCompleted && !notifier.TaskCompleted.IsCanceled && !notifier.TaskCompleted.IsFaulted);
            Assert.AreEqual(tcs.Task.Status, notifier.Status);
            Assert.True(notifier.IsCompleted);
            Assert.False(notifier.IsNotCompleted);
            Assert.True(notifier.IsSuccessfullyCompleted);
            Assert.AreSame(result, notifier.Result);
            Assert.False(notifier.IsCanceled);
            Assert.False(notifier.IsFaulted);
            Assert.Null(notifier.Exception);
            Assert.Null(notifier.InnerException);
            Assert.Null(notifier.ErrorMessage);

            Assert.False(taskNotification());
            Assert.True(statusNotification());
            Assert.True(isCompletedNotification());
            Assert.True(isSuccessfullyCompletedNotification());
            Assert.False(isCanceledNotification());
            Assert.False(isFaultedNotification());
            Assert.False(exceptionNotification());
            Assert.False(innerExceptionNotification());
            Assert.False(errorMessageNotification());
            Assert.True(resultNotification());
        }
Ejemplo n.º 13
0
        public override void Load(object parameter)
        {
            if (parameter is ObservableCollection <SillyDudeVmo> observableDudes)
            {
                SillyPeople = observableDudes;
                RaisePropertyChanged(nameof(SillyPeople));
                return;
            }

            NotifyTask.Create(NavigationService.NavigateBackAsync(typeof(SortSillyPeopleVm)));
        }
Ejemplo n.º 14
0
        public void NotifierT_NonDefaultResult_TaskCanceled_KeepsNonDefaultResult()
        {
            var tcs           = new TaskCompletionSource <object>();
            var defaultResult = new object();
            var notifier      = NotifyTask.Create(() => tcs.Task, defaultResult);

            Assert.Same(defaultResult, notifier.Result);

            tcs.SetCanceled();

            Assert.Same(defaultResult, notifier.Result);
        }
Ejemplo n.º 15
0
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        private async Task SetCuentaAsync(string numCuenta)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            int numeroCuenta = int.Parse(numCuenta);
            var ntcCuenta    = NotifyTask.Create <CuentaMayor>(
                this.CuentaRepo.GetByNumCuentaAsync(numeroCuenta, base.TabCodigoComunidad, base._TabCodigoEjercicio, this),
                x => base.RemoveFromTaskCargando(x));

            //x => base.TaskCargando.Remove(x));
            //base.TaskCargando.Add(ntcCuenta);
            base.AddToTaskCargando(ntcCuenta);
            this.Cuenta = ntcCuenta;
        }
Ejemplo n.º 16
0
        public void NotifierT_NonDefaultResult_TaskFaulted_KeepsNonDefaultResult()
        {
            var tcs           = new TaskCompletionSource <object>();
            var defaultResult = new object();
            var notifier      = NotifyTask.Create(() => tcs.Task, defaultResult);
            var exception     = new NotImplementedException(Guid.NewGuid().ToString("N"));

            Assert.Same(defaultResult, notifier.Result);

            tcs.SetException(exception);

            Assert.Same(defaultResult, notifier.Result);
        }
Ejemplo n.º 17
0
        public aVMTabBase()
        {
            this._TaskCargando = new ObservableCollection <INotifyTask>();
            this._TaskCargando.CollectionChanged += TaskCargando_OnCollectionChanged;

            NotifyTask initializeOwnersTask = NotifyTask.Create(InitializeOwners(), x =>
            {
                this._TaskCargando.Remove(x);
                NotifyPropChanged("TaskCargando");
            });

            this._TaskCargando.Add(initializeOwnersTask);
        }
Ejemplo n.º 18
0
    public RepositoriesPageViewModel(INavigationService navigationService, ISecuredDataProvider securedDataProvider)
    {
        _navigationService = navigationService;
        var token = securedDataProvider.Retreive(ConstantsService.ProviderName, UserManager.GetLastUser());

        _session = new Session(UserManager.GetLastUser(), token.Properties.First().Value);
        var navigationParameters = new NavigationParameters {
            { "Session", _session }
        };

        _repositoriesManager = new RepositoriesManager(_session);
        Repositories         = NotifyTask.Create(GetRepositoriesAsync());
    }
            public override void OnScrollStateChanged(RecyclerView recyclerView, int newState)
            {
                InternalLogger.Info($"OnScrollStateChanged( newState: {newState} )");
                switch (newState)
                {
                case RecyclerView.ScrollStateSettling:
                case RecyclerView.ScrollStateDragging:
                {
                    if (!_weakNativeView.TryGetTarget(out AndroidHorizontalListViewRenderer nativeView))
                    {
                        return;
                    }

                    if (nativeView.IsScrolling)
                    {
                        return;
                    }

                    if (_cts != null && !_cts.IsCancellationRequested)
                    {
                        // System.Diagnostics.Debug.WriteLine("DEBUG_SCROLL: Cancelling previous update index task");
                        _cts.Cancel();
                    }

                    nativeView.IsScrolling = true;

                    _element.ScrollBeganCommand?.Execute(null);
                    break;
                }

                case RecyclerView.ScrollStateIdle:
                {
                    if (!_weakNativeView.TryGetTarget(out AndroidHorizontalListViewRenderer nativeView))
                    {
                        return;
                    }

                    if (!nativeView.IsScrolling)
                    {
                        return;
                    }

                    nativeView.IsScrolling = false;

                    _cts = new CancellationTokenSource();
                    NotifyTask.Create(UpdateCurrentIndexAsync(nativeView, _cts.Token));

                    break;
                }
                }
            }
Ejemplo n.º 20
0
 /// <summary>
 /// This method must be called by the UI element in charge of displaying data.
 /// Per example, on android, a scroll listener can reference this paginator as an IInfiniteListLoader and call it from OnScroll.
 /// The call to this method is nearly transparent as it returns immediately and doesn't block the caller.
 /// (benchmarked as 4 ticks for a call (10 000 ticks == 1ms)).
 /// </summary>
 public void OnScroll(int lastVisibleIndex)
 {
     NotifyTask <bool> .Create(
         ShouldLoadNextPage(lastVisibleIndex),
         whenSuccessfullyCompleted : (task, shouldLoad) =>
     {
         if (shouldLoad)
         {
             //InternalLogger.Info($"Scrolled: loading more (max index of visible item {lastVisibleIndex})");
             int pageToLoad = lastVisibleIndex / PageSize + 2;
             LoadPage(pageToLoad, calledFromScroll: true);
         }
     });
 }
        /// <summary>
        /// Execute method is called when any item is requested for load-on-demand items.
        /// </summary>
        /// <param name="obj">TreeViewNode is passed as default parameter </param>
        private async Task ExecuteOnDemandLoading(object obj)
        {
            var notifyTask = NotifyTask.Create(PopulateChildAsync(obj));
            await notifyTask.TaskCompleted;

            if (notifyTask.IsCompleted)
            {
                var items = notifyTask.Result as IEnumerable <MusicInfo>;
                if (items.Count() > 0)
                {
                    //Expand the node after child items are added.
                    (obj as TreeViewNode).IsExpanded = true;
                }
            }
        }
Ejemplo n.º 22
0
        public void NotifierT_NonDefaultResult_TaskCompletesSuccessfully_UpdatesResult()
        {
            var tcs                = new TaskCompletionSource <object>();
            var defaultResult      = new object();
            var notifier           = NotifyTask.Create(() => tcs.Task, defaultResult);
            var result             = new object();
            var resultNotification = TestUtils.PropertyNotified(notifier, n => n.Result);

            Assert.Same(defaultResult, notifier.Result);

            tcs.SetResult(result);

            Assert.Same(result, notifier.Result);
            Assert.True(resultNotification());
        }
        private void LongTapAction(UIGestureRecognizerState state)
        {
            switch (state)
            {
            case UIGestureRecognizerState.Began:
                NotifyTask.Create(TapAnimationAsync(0.5, 0, _alpha, false));
                break;

            case UIGestureRecognizerState.Ended:
            case UIGestureRecognizerState.Cancelled:
            case UIGestureRecognizerState.Failed:
                NotifyTask.Create(TapAnimationAsync(0.5, _alpha));
                break;
            }
        }
Ejemplo n.º 24
0
        public void Notifier_SynchronousTaskCanceled_SetsProperties()
        {
            var task     = Task.FromCanceled(new CancellationToken(true));
            var notifier = NotifyTask.Create(() => task);

            Assert.Same(task, notifier.Task);
            Assert.True(notifier.TaskCompleted.IsCompleted && !notifier.TaskCompleted.IsCanceled && !notifier.TaskCompleted.IsFaulted);
            Assert.Equal(task.Status, notifier.Status);
            Assert.True(notifier.IsCompleted);
            Assert.False(notifier.IsNotCompleted);
            Assert.False(notifier.IsSuccessfullyCompleted);
            Assert.True(notifier.IsCanceled);
            Assert.False(notifier.IsFaulted);
            Assert.Null(notifier.Exception);
            Assert.Null(notifier.InnerException);
            Assert.Null(notifier.ErrorMessage);
        }
Ejemplo n.º 25
0
        public MainViewModel(IZoomService zoomService, ICredentialsService credentialsService)
        {
            Title = "zoom-custom-ui-wpf";

            _credentialsService = credentialsService;
            UserName            = _credentialsService.GetUserName();
            MeetingNumber       = _credentialsService.GetMeetingNumber();
            Password            = _credentialsService.GetPassword();

            _zoomService = zoomService;
            _zoomService.InitializedChanged   += ZoomServiceOnInitializedChanged;
            _zoomService.MeetingStatusChanged += ZoomServiceOnMeetingStatusChanged;

            // Running async code from constructor
            // Thanks Stephen Cleary and his Nito.Mvvm.Async library
            // https://blog.stephencleary.com/2013/01/async-oop-2-constructors.html
            InitializationNotifier = NotifyTask.Create(InitializationAsync());
        }
Ejemplo n.º 26
0
        public void NotifierT_SynchronousTaskCompletedSuccessfully_SetsProperties()
        {
            var task     = Task.FromResult(13);
            var notifier = NotifyTask.Create(() => task, 17);

            Assert.Same(task, notifier.Task);
            Assert.True(notifier.TaskCompleted.IsCompleted && !notifier.TaskCompleted.IsCanceled && !notifier.TaskCompleted.IsFaulted);
            Assert.Equal(13, notifier.Result);
            Assert.Equal(task.Status, notifier.Status);
            Assert.True(notifier.IsCompleted);
            Assert.False(notifier.IsNotCompleted);
            Assert.True(notifier.IsSuccessfullyCompleted);
            Assert.False(notifier.IsCanceled);
            Assert.False(notifier.IsFaulted);
            Assert.Null(notifier.Exception);
            Assert.Null(notifier.InnerException);
            Assert.Null(notifier.ErrorMessage);
        }
Ejemplo n.º 27
0
        public void Notifier_SynchronousTaskFaulted_SetsProperties()
        {
            var exception = new Exception(Guid.NewGuid().ToString("N"));
            var task      = Task.FromException(exception);
            var notifier  = NotifyTask.Create(() => task);

            Assert.Same(task, notifier.Task);
            Assert.True(notifier.TaskCompleted.IsCompleted && !notifier.TaskCompleted.IsCanceled && !notifier.TaskCompleted.IsFaulted);
            Assert.Equal(task.Status, notifier.Status);
            Assert.True(notifier.IsCompleted);
            Assert.False(notifier.IsNotCompleted);
            Assert.False(notifier.IsSuccessfullyCompleted);
            Assert.False(notifier.IsCanceled);
            Assert.True(notifier.IsFaulted);
            Assert.NotNull(notifier.Exception);
            Assert.Same(exception, notifier.InnerException);
            Assert.Equal(exception.Message, notifier.ErrorMessage);
        }
Ejemplo n.º 28
0
        private void ViewOnLongClick(object sender, View.LongClickEventArgs longClickEventArgs)
        {
            var cmd = TapCommandEffect.GetLongTap(Element);

            if (cmd == null)
            {
                longClickEventArgs.Handled = false;
                return;
            }

            NotifyTask.Create(
                async() =>
            {
                await Task.Delay(50);
                cmd.Execute(TapCommandEffect.GetLongTapParameter(Element));
                longClickEventArgs.Handled = true;
            });
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Frame> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                NotifyTask.Create(async() =>
                {
                    await Task.Delay(100);
                    if (Element == null || _isDisposed)
                    {
                        return;
                    }

                    SetNeedsDisplay();
                    LayoutIfNeeded();
                });
            }
        }
Ejemplo n.º 30
0
        public bool AddToTaskCargando(Task task, bool removeFromCollectionWhenCompleted = true)
        {
            Action <INotifyTask> removeWhenCompleted = null;

            if (removeFromCollectionWhenCompleted)
            {
                removeWhenCompleted = nTask => this._TaskCargando.Remove(nTask);
            }

            var notifyTask = NotifyTask.Create(task, removeWhenCompleted);

            if (this._TaskCargando.Contains(notifyTask))
            {
                return(false);
            }

            this._TaskCargando.Add(notifyTask);
            NotifyAllTaskCargandoProperties();
            return(true);
        }