/// <inheritdoc/> public void QueueExecution(uint startAddress) { SynchronousTask emitTask = new SynchronousTask( () => Task.Run(() => ExecutionStream.EmitValue(startAddress))); emitTask.RunTask(); }
private void WebView2_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e) { SynchronousTask styleTask = new SynchronousTask( () => DispatcherService.RunOnUIThreadAsync( () => SetWebViewStyle(sender as WebView2))); styleTask.RunTask(); }
internal static TResult ExecuteSyncTaskWithRetry <TResult>(SynchronousTask <TResult> syncTask, RetryPolicy policy) { CommonUtils.AssertNotNull("syncTask", syncTask); CommonUtils.AssertNotNull("policy", policy); var oracle = policy(); return(RequestWithRetry.RequestWithRetrySyncImpl <TResult>(oracle, syncTask)); }
private void WebView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args) { SynchronousTask styleTask = new SynchronousTask( () => DispatcherService.RunOnUIThreadAsync( () => SetWebViewStyle(sender))); styleTask.RunTask(); }
/// <summary> /// Starts the <see cref="App"/>, activating the needed services and the UI/view-models. /// </summary> /// <param name="args">The <see cref="IActivatedEventArgs"/> describing how the <see cref="App"/> was started.</param> public void Activate(IActivatedEventArgs args) { if (args is BackgroundActivatedEventArgs backgroundArgs) { ActivateBackground(backgroundArgs); } else { SynchronousTask registerTask = new SynchronousTask(RegisterBackgroundTasks); registerTask.RunTask(); ActivateForeground(args); } }
/// <inheritdoc/> protected override void SetViewInternal(NavigationRequest request, IConsoleView view) { if (request.Properties.LayerMode == LayerBehavior.Default) { SynchronousTask syncTask = new SynchronousTask( () => view.ShowView()); syncTask.RunTask(); } else { throw new ArgumentException($"Console apps currently do not have support for navigation layers.", nameof(request)); } }
/// <inheritdoc/> public void Navigate(NavigationRequest request, bool includeHistory = true) { if (request.IsCloseRequest) { //// Send close request to IViewProvider. ViewProvider.SetView(request, null); if (includeHistory) { //// Reports request to history. History.HandleNavigation(request, null); } } else { //// Resolves values from the request. IViewModel viewModel = (IViewModel)LifetimeScope.Resolve(request.ViewModelType); Type viewModelRealizedType = viewModel.GetType(); Type viewType = typeof(IView <>).MakeGenericType(viewModelRealizedType); IView view = (IView)LifetimeScope.Resolve(viewType, new TypedParameter(viewModelRealizedType, viewModel)); //// Sets the view. ViewProvider.SetView(request, view); if (includeHistory) { //// Reports navigated content to history. History.HandleNavigation(request, viewModel); } //// Initializes the view-model and view. view.Initialize(); SynchronousTask initViewModelTask = new SynchronousTask(() => viewModel.InitializeAsync(request.Parameter)); initViewModelTask.RunTask(); } }
private void Refresh_Click(object sender, RoutedEventArgs e) { SynchronousTask refreshTask = new SynchronousTask(ViewModel.RefreshAsync); refreshTask.RunTask(); }
internal static TResult ExecuteSyncTask <TResult>(SynchronousTask <TResult> syncTask) { CommonUtils.AssertNotNull("syncTask", syncTask); return(syncTask.Execute()); }
public void Delete(T instance) { SynchronousTask.DoSync(() => { this.repository.Delete(instance); }); }
public SaveResult Save(T instance) { return(SynchronousTask.GetSync(() => { return this.repository.Save(instance); })); }
public IList <T> GetAll() { return(SynchronousTask.GetSync(() => { return this.repository.GetAll(); })); }
public T GetById(Guid id) { return(SynchronousTask.GetSync(() => { return this.repository.GetById(id); })); }
public T New() { return(SynchronousTask.GetSync(() => { return this.repository.New(); })); }
/// <inheritdoc/> protected override void SetViewInternal(NavigationRequest request, UIElement view) { if (request.IsCloseRequest) { if (UILayers.Count > 1) { if (CurrentElement is ContentDialog dialog) { SynchronousTask hideTask = new SynchronousTask( () => Dispatchers.RunOnUIThreadAsync( () => dialog.Hide())); hideTask.RunTask(); } UILayers.RemoveAt(UILayers.Count - 1); } else { throw new InvalidOperationException("Cannot remove root content layer in close operation."); } } else { if (request.Properties.LayerMode == LayerBehavior.Modal) { ContentDialog dialog = new ContentDialog() { Title = null, Content = view, Padding = new Thickness(0), Margin = new Thickness(0) }; UILayers.Add(dialog); dialog.CloseButtonClick += DialogClosed; SynchronousTask showTask = new SynchronousTask( () => Dispatchers.RunOnUIThreadAsync( () => ShowDialogTask(dialog))); showTask.RunTask(); } else if (request.Properties.LayerMode == LayerBehavior.Default) { CurrentElement.Content = view; } else if (request.Properties.LayerMode == LayerBehavior.Shell) { if (view is ILayerContainer container) { CurrentElement.Content = container; UILayers.Add(container.Container); } else { throw new ArgumentException("UWP apps require all new navigation layers be created in ILayerContainers.", nameof(view)); } } else { throw new ArgumentException($"UWP apps currently do not have support for the given LayerMode {request.Properties.LayerMode}.", nameof(request)); } } }
/// <summary> /// Implementation of the *RequestWithRetry methods. /// </summary> /// <typeparam name="TResult">The result type of the task.</typeparam> /// <param name="retryOracle">The retry oracle.</param> /// <param name="syncTask">The task implementation.</param> /// <returns>A <see cref="TaskSequence"/> that performs the request with retries.</returns> internal static TResult RequestWithRetrySyncImpl <TResult>(ShouldRetry retryOracle, SynchronousTask <TResult> syncTask) { int retryCount = 0; bool shouldRetry = false; do { TimeSpan delay = TimeSpan.FromMilliseconds(-1); try { return(syncTask.Execute()); } catch (TimeoutException e) { shouldRetry = retryOracle != null?retryOracle(retryCount ++, e, out delay) : false; // We should just throw out the exception if we are not retrying if (!shouldRetry) { throw; } } catch (StorageServerException e) { if (e.StatusCode == HttpStatusCode.NotImplemented || e.StatusCode == HttpStatusCode.HttpVersionNotSupported) { throw; } shouldRetry = retryOracle != null?retryOracle(retryCount ++, e, out delay) : false; // We should just throw out the exception if we are not retrying if (!shouldRetry) { throw; } } catch (InvalidOperationException e) {/* * DataServiceClientException dsce = CommonUtils.FindInnerDataServiceClientException(e); * * // rethrow 400 class errors immediately as they can't be retried * // 501 (Not Implemented) and 505 (HTTP Version Not Supported) shouldn't be retried either. * if (dsce != null && * ((dsce.StatusCode >= 400 && dsce.StatusCode < 500) || dsce.StatusCode == (int)HttpStatusCode.NotImplemented || dsce.StatusCode == (int)HttpStatusCode.HttpVersionNotSupported)) ||{ || throw; ||} */ // If it is BlobTypeMismatchExceptionMessage, we should throw without retry if (e.Message == SR.BlobTypeMismatchExceptionMessage) { throw; } shouldRetry = retryOracle != null?retryOracle(retryCount ++, e, out delay) : false; // We should just throw out the exception if we are not retrying if (!shouldRetry) { throw; } } if (shouldRetry && delay > TimeSpan.Zero) { Thread.Sleep(delay); } }while (shouldRetry); throw new StorageClientException( StorageErrorCode.None, "Unexpected internal storage client error.", System.Net.HttpStatusCode.Unused, null, null) { HelpLink = "http://go.microsoft.com/fwlink/?LinkID=182765" }; }
public void DeleteId(Guid id) { SynchronousTask.DoSync(() => { this.repository.DeleteId(id); }); }