Пример #1
0
        /// <inheritdoc/>
        public void QueueExecution(uint startAddress)
        {
            SynchronousTask emitTask = new SynchronousTask(
                () => Task.Run(() => ExecutionStream.EmitValue(startAddress)));

            emitTask.RunTask();
        }
Пример #2
0
        private void WebView2_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e)
        {
            SynchronousTask styleTask = new SynchronousTask(
                () => DispatcherService.RunOnUIThreadAsync(
                    () => SetWebViewStyle(sender as WebView2)));

            styleTask.RunTask();
        }
Пример #3
0
        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));
        }
Пример #4
0
        private void WebView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
        {
            SynchronousTask styleTask = new SynchronousTask(
                () => DispatcherService.RunOnUIThreadAsync(
                    () => SetWebViewStyle(sender)));

            styleTask.RunTask();
        }
Пример #5
0
 /// <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);
     }
 }
Пример #6
0
 /// <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));
     }
 }
Пример #7
0
        /// <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();
            }
        }
Пример #8
0
        private void Refresh_Click(object sender, RoutedEventArgs e)
        {
            SynchronousTask refreshTask = new SynchronousTask(ViewModel.RefreshAsync);

            refreshTask.RunTask();
        }
Пример #9
0
        internal static TResult ExecuteSyncTask <TResult>(SynchronousTask <TResult> syncTask)
        {
            CommonUtils.AssertNotNull("syncTask", syncTask);

            return(syncTask.Execute());
        }
Пример #10
0
 public void Delete(T instance)
 {
     SynchronousTask.DoSync(() => {
         this.repository.Delete(instance);
     });
 }
Пример #11
0
 public SaveResult Save(T instance)
 {
     return(SynchronousTask.GetSync(() => {
         return this.repository.Save(instance);
     }));
 }
Пример #12
0
 public IList <T> GetAll()
 {
     return(SynchronousTask.GetSync(() => {
         return this.repository.GetAll();
     }));
 }
Пример #13
0
 public T GetById(Guid id)
 {
     return(SynchronousTask.GetSync(() => {
         return this.repository.GetById(id);
     }));
 }
Пример #14
0
 public T New()
 {
     return(SynchronousTask.GetSync(() => {
         return this.repository.New();
     }));
 }
Пример #15
0
        /// <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"
                  };
        }
Пример #17
0
 public void DeleteId(Guid id)
 {
     SynchronousTask.DoSync(() => {
         this.repository.DeleteId(id);
     });
 }