/// <summary> /// 添加监控任务列表{监控任务列表}对象(即:一条记录 /// </summary> public long Add(TaskMonitor taskMonitor) { using (var dbContext = UnitOfWork.Get(Unity.ContainerName)) { return(new TaskMonitorRepository(dbContext).Add(taskMonitor)); } }
/// <summary> /// 更新监控任务列表{监控任务列表}对象(即:一条记录 /// </summary> public int Update(TaskMonitor taskMonitor) { using (var dbContext = UnitOfWork.Get(Unity.ContainerName)) { return(new TaskMonitorRepository(dbContext).Update(taskMonitor)); } }
public async Task NominalListTest() { bool isCompleted = false; bool isSuccessfullyCompleted = false; bool isFaulted = false; string monitorName = "NominalListTestTask"; var monitor = TaskMonitor <List <string> > .Create( DelayListAsync, t => isCompleted = true, t => isFaulted = true, (t, r) => { isSuccessfullyCompleted = true; Assert.Equal(3, r.Count); }, name : monitorName); await monitor.TaskCompleted; Assert.True(isSuccessfullyCompleted && monitor.IsSuccessfullyCompleted); Assert.False(isFaulted || monitor.IsFaulted); Assert.False(monitor.IsCanceled); Assert.True(isCompleted && monitor.IsCompleted); Assert.Equal(monitorName, monitor.Name); Assert.Equal(3, monitor.Result.Count); }
private void UpdateColor() { if (!_isAttached || Control == null || Element == null) { return; } var imageView = (UIImageView)Control; var effect = (TintableImageEffect)Element.Effects.FirstOrDefault(x => x is TintableImageEffect); var color = effect?.TintColor.ToUIColor(); if (color == null) { return; } Control.TintColor = color; if (imageView?.Image == null) { if (_tintAttempts < 5) { TaskMonitor.Create(() => DelayedPost(500, UpdateColor)); } return; } _tintAttempts = 0; imageView.Image = imageView.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate); }
private void TabButtonOnClicked(object sender, EventArgs e) { TaskMonitor.Create(AnimateTabButton); _currentTheme = _currentTheme == Theme.Light ? Theme.Dark : Theme.Light; ApplyTheme(); }
private void FireForgetTaskWithError(object obj) { Console.WriteLine("------------- FireForgetTaskWithError ---------------"); TaskMonitor.Build() .ExecuteTaskAsync((username), OtherAuthenticateWithError, OtherOnAuthenticationSuccess, OtherOnAuthenticationFail); }
public WorkerTask(Action <object> action, object state, CancellationToken cancellationToken, TaskCreationOptions taskCreationOptions, string name) { var response = TaskMonitor.CreateTask(action, state, cancellationToken, taskCreationOptions, name); _task = response.Task; _taskInfo = response.TaskInfo; }
private void LongTapAction(UIGestureRecognizerState state) { switch (state) { case UIGestureRecognizerState.Began: break; case UIGestureRecognizerState.Ended: if (_longCommand == null) { TapAction(); } else { TaskMonitor.Create( async() => { await Task.Delay(50); _longCommand.Execute(_longParameter); }); } break; case UIGestureRecognizerState.Cancelled: case UIGestureRecognizerState.Failed: break; } }
private void TapAction() { TaskMonitor.Create(async() => { await Task.Delay(50); _tapCommand?.Execute(_tapParameter); }); }
public async Task SimplestTest() { var monitor = TaskMonitor.Create(DelayAsync); await monitor.TaskCompleted; Assert.False(monitor.IsNotCompleted); Assert.True(monitor.IsSuccessfullyCompleted); }
private void ViewOnClick(object sender, EventArgs eventArgs) { TaskMonitor.Create( async() => { await Task.Delay(50); TapCommandEffect.GetTap(Element)?.Execute(TapCommandEffect.GetTapParameter(Element)); }); }
public async Task InNewTaskTest() { int threadId = Thread.CurrentThread.ManagedThreadId; var monitor = TaskMonitor <int> .Create( DelayThreadIdAsync, inNewTask : true); await monitor.TaskCompleted; Assert.NotEqual(threadId, monitor.Result); }
private void FireForgetTaskWithResult(object obj) { Console.WriteLine("------------- FireForgetTaskWithResult ---------------"); Console.WriteLine("------------- Starting ---------------"); TaskMonitor.Build() .WhenStarted(() => IsBusy = true) .WhenFinished(() => IsBusy = false) .ExecuteTaskAsync((username, password), Authenticate, OnAuthenticationSuccess, OnAuthenticationFail); }
private void HandleDragAndDropEnabledAnimation(ViewCell viewCell) { if (_enableDragAndDropCts != null && !_enableDragAndDropCts.IsCancellationRequested && _element.EnableDragAndDrop && _element.DragAndDropEnabledAnimationAsync != null) { InternalLogger.Debug("HandleDragAndDropEnabledAnimation"); TaskMonitor.Create(_element.DragAndDropEnabledAnimationAsync(viewCell, _enableDragAndDropCts.Token)); } }
/// <summary> /// Launch the loading of a data page. /// If a task is currently running, it gets discarded (callbacks won't be called). /// If the first page loading is asked whereas one or several pages have already been loaded, a "refresh" is detected. /// </summary> /// <param name="pageNumber">The page number to load (pageNumber = 1 for the first page).</param> /// <param name="calledFromScroll">True if LoadPage has been called from OnScroll method of the IInfiniteListLoader.</param> public Task <PageResult <TResult> > LoadPage(int pageNumber, bool calledFromScroll = false) { Contract.Requires(() => pageNumber > 0); Contract.Requires( () => calledFromScroll || (pageNumber == 1 || pageNumber == (PageLoadedCount + 1)), "The paginator can only load sequential pages"); InternalLogger.Info($"Requesting page n°{pageNumber} load, {PageLoadedCount} pages loaded so far"); lock (_syncRoot) { if (calledFromScroll) { if (pageNumber <= PageLoadedCount) { InternalLogger.Info($"Aborting IInfiniteListLoader call: only a direct call to LoadPage can lead to a refresh"); return(Task.FromResult(PageResult <TResult> .Empty)); } } if (pageNumber > PageLoadedCount && IsFull) { InternalLogger.Info($"Cannot load page {pageNumber} total item count has already been reached ({TotalCount})"); return(Task.FromResult(PageResult <TResult> .Empty)); } if (pageNumber == 1 && PageLoadedCount > 0) { InternalLogger.Info("Refresh detected"); _refreshRequested = true; } else { _refreshRequested = false; } if (LoadingTask != null && LoadingTask.IsNotCompleted) { // Cancels callbacks of previous task if not completed LoadingTask.CancelCallbacks(); } LoadingTask = new TaskMonitor <PageResult <TResult> > .Builder( () => _pageSourceLoader(pageNumber, PageSize, _refreshRequested)) .WithWhenSuccessfullyCompleted(OnPageRetrieved) .WithWhenCompleted(OnTaskCompleted) .Build(); InternalLogger.Info($"Page n°{pageNumber} loading started"); LoadingTask.Start(); return(LoadingTask.Task); } }
/// <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) { TaskMonitor <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); } }); }
private void ErrorNotificationViewPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == nameof(IsVisible)) { if (ErrorNotificationView.IsVisible) { TaskMonitor.Create(ErrorNotificationView.ScaleTo(1, 500)); } else { ErrorNotificationView.Scale = 0; } } }
private void BusyImagePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == nameof(IsVisible)) { if (BusyImage.IsVisible) { _animationTokenSource = new CancellationTokenSource(); TaskMonitor.Create(StartBeeAnimationAsync(_animationTokenSource.Token)); } else { _animationTokenSource?.Cancel(); } } }
private void LongTapAction(UIGestureRecognizerState state) { switch (state) { case UIGestureRecognizerState.Began: TaskMonitor.Create(TapAnimationAsync(0.5, 0, _alpha, false)); break; case UIGestureRecognizerState.Ended: case UIGestureRecognizerState.Cancelled: case UIGestureRecognizerState.Failed: TaskMonitor.Create(TapAnimationAsync(0.5, _alpha)); break; } }
public override void Load(object parameter) { if (parameter is ObservableCollection <SillyDudeVmo> observableDudes) { SillyPeople = new ObservableCollection <SillyDudeVmo>(observableDudes) { new AddSillyDudeVmo(OnSillyDudeAddedCommand), }; RaisePropertyChanged(nameof(SillyPeople)); return; } TaskMonitor.Create(NavigationService.NavigateBackAsync(typeof(SortSillyPeopleVm))); }
public async Task UseMonitorAsDecoratedFaultTest() { TaskMonitorConfiguration.LogStatistics = true; TaskMonitorConfiguration.StatisticsHandler = TaskMonitorConfiguration.DefaultStatisticsTracer; var monitor = TaskMonitor.Create(DelayFaultAsync, name: "UseMonitorAsDecoratedFaultTest"); try { await Assert.ThrowsAsync <Exception>(() => monitor.Task); } finally { TaskMonitorConfiguration.LogStatistics = false; } }
private void ViewOnLongClick(object sender, View.LongClickEventArgs longClickEventArgs) { var cmd = TapCommandEffect.GetLongTap(Element); if (cmd == null) { longClickEventArgs.Handled = false; return; } TaskMonitor.Create( async() => { await Task.Delay(50); cmd.Execute(TapCommandEffect.GetLongTapParameter(Element)); longClickEventArgs.Handled = true; }); }
static void Main(string[] args) { LicenseHelper.CheckOutLicense(); CheckAndCreateFolder(); TaskMonitor monitor = new TaskMonitor(); //monitor.Start(); monitor.CheckImmediately(); //20200826展示注释 while (true) { ConsoleKeyInfo info = Console.ReadKey(); if (info.Key == ConsoleKey.Escape) { return; } } ; }
private void SettingsButtonOnClicked(object sender, EventArgs e) { if (!_isSettingsShown) { BlurStyleRow.Height = _isAcrylicBlurEnabled ? SettingsRowHeight : 0; SettingsFrame.IsVisible = true; TaskMonitor.Create(SettingsFrame.FadeTo(1)); _isSettingsShown = true; return; } // Hide _isSettingsShown = false; TaskMonitor.Create(async() => { await SettingsFrame.FadeTo(0); SettingsFrame.IsVisible = false; }); }
private void AnimateCell(ViewCell cell) { TaskMonitor.Create( async() => { if (_element.PreRevealAnimationAsync != null) { await _element.PreRevealAnimationAsync(cell); } if (_element.RevealAnimationAsync != null) { await _element.RevealAnimationAsync(cell); } if (_element.PostRevealAnimationAsync != null) { await _element.PostRevealAnimationAsync(cell); } }); }
public async Task NominalTest() { bool isCompleted = false; bool isSuccessfullyCompleted = false; bool isFaulted = false; string monitorName = "NominalTestTask"; var monitor = TaskMonitor.Create( DelayAsync, t => isCompleted = true, t => isFaulted = true, t => isSuccessfullyCompleted = true, name: monitorName); await monitor.TaskCompleted; Assert.True(isSuccessfullyCompleted && monitor.IsSuccessfullyCompleted); Assert.False(isFaulted || monitor.IsFaulted); Assert.False(monitor.IsCanceled); Assert.True(isCompleted && monitor.IsCompleted); Assert.Equal(monitorName, monitor.Name); }
private void UpdateColor() { if (!(Control is Image)) { return; } var effect = (TintableImageEffect)Element.Effects.FirstOrDefault(x => x is TintableImageEffect); var color = effect?.TintColor; if (color == null) { return; } if (Element.Source is FontImageSource fontImageSource) { fontImageSource.Color = color.Value; return; } TaskMonitor.Create(CreateTintEffectBrushAsync(color.Value)); }
public DailyTask(bool enabled, params TimeSpan[] timesOfDay) { _Enabled = enabled; _Timer = new Daily(ExecuteWithLog, timesOfDay); TaskMonitor = new TaskMonitor(); }
private void InitCommands() { OnDragAndDropEndCommand = new Command( () => System.Diagnostics.Debug.WriteLine("SortSillyPeopleVm: OnDragAndDropEndCommand")); OnSillyDudeAddedCommand = new Command(() => TaskMonitor.Create(AddSillyDudeAsync)); }
private void CommandsOnClicked(object sender, EventArgs e) { TaskMonitor.Create(_navigationService.NavigateToViewAsync <CommandsPage>(GamePlatform.Computer)); }
private void SkeletonLoadingOnClicked(object sender, EventArgs e) { TaskMonitor.Create(_navigationService.NavigateToViewAsync <DefaultViewsSkeletonPage>(GamePlatform.Computer)); }