private void ConfigureIoC()
        {
            Container = new WindsorContainer();

            var documentStore = new EmbeddableDocumentStore {
                DataDirectory = "../data"
            };

            documentStore.Initialize();

            var connectionLookup   = new ConnectionLookup();
            var taskNotifier       = new TaskNotifier(connectionLookup);
            var queueFactory       = new DefaultQueueFactory(taskNotifier, documentStore);
            var userAccountService = new DummyUserAccountService();
            var taskDistributor    = new TaskDistributor(queueFactory, userAccountService);

            sessionTimeoutEventSink = taskDistributor;

            Container.Register(Component.For <IDocumentStore>().Instance(documentStore).LifestyleSingleton());
            Container.Register(Component.For <INotifyUsersOfTasks>().Instance(taskNotifier).LifestyleSingleton());
            Container.Register(Component.For <TaskDistributor, IReactToUserLoggedIn, IReactToUserLoggedOff>().Instance(taskDistributor).LifestyleSingleton());

            Container.Register(Component.For <IControllerFactory>()
                               .Instance(new MyControllerFactory(Container))
                               .LifeStyle.Is(Castle.Core.LifestyleType.Singleton));

            Container.Register(AllTypes.FromThisAssembly().BasedOn <IController>().LifestyleTransient());

            GlobalHost.DependencyResolver.Register(typeof(TaskDistributor), () => taskDistributor);
            GlobalHost.DependencyResolver.Register(typeof(ConnectionLookup), () => connectionLookup);
            GlobalHost.DependencyResolver.Register(typeof(IBus), () => Bus);
            GlobalHost.DependencyResolver.Register(typeof(UserTaskEndpoint), () => new UserTaskEndpoint(taskDistributor, connectionLookup, Bus));
        }
        public ProfilePageViewModel()
        {
            _vstsRespository = SimpleIoc.Default.GetInstance <IVSTSRepository>();

            UserProfile = new TaskNotifier <UserProfile>(_vstsRespository.GetUserProfile());
            ReloadPage  = new RelayCommand(() => ReloadPageCommand());
        }
        private async Task CreateRevision(object arg)
        {
            ErrorMessage = string.Empty;

            try
            {
                var duplicateTask = _productServiceModel.DuplicateProduct(Product.Id, Product.Identifier, NewRevision);
                TaskNotifier = new TaskNotifier(duplicateTask);

                var response = await duplicateTask;
                if (response.IdentityConflict || response.InvalidSource)
                {
                    ErrorMessage = Strings.CreateRevisionViewModel_ConflictedIdentity;
                }
                else
                {
                    CreatedProduct = new ProductInfoViewModel(response.Duplicate);
                    TryClose(true);
                }
            }
            catch (Exception e)
            {
                ErrorMessage = e.Message;
            }
        }
Beispiel #4
0
        private async Task Duplicate(object parameters)
        {
            ErrorMessage = string.Empty;

            try
            {
                var duplicateTask = _productServiceModel.DuplicateProduct(Product.Id, Identifier, Revision);
                TaskNotifier = new TaskNotifier(duplicateTask);

                var response = await duplicateTask;
                if (response.IdentityConflict || response.InvalidSource)
                {
                    ErrorMessage = Strings.DuplicateProductDialogViewModel_ConflictedIdentity;
                }
                else
                {
                    ClonedProduct = response.Duplicate;
                    TryClose(true);
                }
            }
            catch (Exception e)
            {
                ErrorMessage = e.Message;
            }
        }
        /// <inheritdoc />
        protected override void OnInitialize()
        {
            base.OnInitialize();
            DisplayName = Strings.CreateRevisionViewModel_DisplayName;

            var loadingTask = Task.Run(async delegate
            {
                try
                {
                    _currentRevisions = await _productServiceModel.GetProducts(new ProductQuery
                    {
                        Identifier     = Product.Identifier,
                        RevisionFilter = RevisionFilter.All
                    }).ConfigureAwait(false);

                    await Execute.OnUIThreadAsync(() => NewRevision = (short)(_currentRevisions.Max(pr => pr.Revision) + 1));
                }
                catch (Exception e)
                {
                    await Execute.OnUIThreadAsync(() => ErrorMessage = e.Message);
                }
            });

            TaskNotifier = new TaskNotifier(loadingTask);
        }
        private async Task Create(object arg)
        {
            ErrorMessage = string.Empty;

            try
            {
                var createTask = _productServiceModel.CreateRecipe(SelectedRecipeDefinition.Model.Name);
                TaskNotifier = new TaskNotifier(createTask);

                var newRecipe = await createTask;

                RecipePrototype = new RecipeViewModel(newRecipe)
                {
                    Name = Name
                };

                if (SelectedRecipeDefinition.HasWorkplans)
                {
                    RecipePrototype.Model.WorkplanId = SelectedWorkplan.Id;
                }
            }
            catch (Exception e)
            {
                ErrorMessage = e.Message;
            }

            TryClose(true);
        }
        protected override void OnInitialize()
        {
            base.OnInitialize();

            var loadingTask = Task.Run(async delegate
            {
                try
                {
                    var productsLoadTask = ProductServiceModel.GetProducts(new ProductQuery
                    {
                        Type           = _partConnector.Type,
                        RevisionFilter = RevisionFilter.All
                    });

                    TaskNotifier = new TaskNotifier(productsLoadTask);

                    var products   = await productsLoadTask;
                    var productVms = products.Select(pm => new ProductInfoViewModel(pm)).OrderBy(p => p.FullIdentifier);

                    await Execute.OnUIThreadAsync(delegate
                    {
                        AvailableProducts = productVms.ToArray();
                        NotifyOfPropertyChange(nameof(AvailableProducts));
                    });
                }
                catch (Exception e)
                {
                    await Execute.OnUIThreadAsync(() => ErrorMessage = e.Message);
                }
            });

            TaskNotifier = new TaskNotifier(loadingTask);
        }
Beispiel #8
0
        protected override void OnInitialize()
        {
            base.OnInitialize();
            DisplayName = Strings.RevisionsViewModel_DisplayName;

            var loadingTask = Task.Run(async delegate
            {
                try
                {
                    var revisions = await _productServiceModel.GetProducts(new ProductQuery
                    {
                        Identifier     = Product.Identifier,
                        RevisionFilter = RevisionFilter.All
                    }).ConfigureAwait(false);

                    var vms = revisions.Select(r => new ProductInfoViewModel(r)).ToArray();
                    await Execute.OnUIThreadAsync(() => Revisions.AddRange(vms));
                }
                catch (Exception e)
                {
                    await Execute.OnUIThreadAsync(() => ErrorMessage = e.Message);
                }

                finally
                {
                    await Execute.OnUIThreadAsync(CommandManager.InvalidateRequerySuggested);
                }
            });

            TaskNotifier = new TaskNotifier(loadingTask);
        }
Beispiel #9
0
        protected override void OnInitialize()
        {
            DisplayName = Strings.ImportViewModel_DisplayName;

            OkCmd     = new AsyncCommand(Ok);
            CancelCmd = new RelayCommand(Cancel);


            var loaderTask = Task.Run(async delegate
            {
                var customization = await _productServiceModel.GetCustomization().ConfigureAwait(false);
                await Execute.OnUIThreadAsync(delegate
                {
                    var importers = customization.Importers.Select(i => new ImporterViewModel(i, _productServiceModel));
                    Importers     = new BindableCollection <ImporterViewModel>(importers);

                    if (Importers.Count > 0)
                    {
                        SelectedImporter = Importers[0];
                    }
                });
            });

            TaskNotifier = new TaskNotifier(loaderTask);
        }
Beispiel #10
0
        /// <inheritdoc />
        protected override void OnInitialize()
        {
            base.OnInitialize();

            var loadingTask = Task.Run(async delegate
            {
                try
                {
                    var supportedTypes          = Reference.Type.Model.SupportedTypes;
                    var possibleTargetsLoadTask = _resourceServiceModel.GetResources(new ResourceQuery {
                        Types = supportedTypes
                    });

                    TaskNotifier = new TaskNotifier(possibleTargetsLoadTask);

                    var possibleTargets    = await possibleTargetsLoadTask;
                    var possibleTargetsVms = possibleTargets.Where(resource => Reference.Targets.All(t => t.Id != resource.Id))
                                             .Select(possible => new ResourceInfoViewModel(possible));

                    await Execute.OnUIThreadAsync(delegate
                    {
                        PossibleTargets = possibleTargetsVms.ToArray();
                        SelectedTarget  = PossibleTargets.FirstOrDefault();
                        NotifyOfPropertyChange(nameof(PossibleTargets));
                    });
                }
                catch (Exception e)
                {
                    await Execute.OnUIThreadAsync(() => ErrorMessage = e.Message);
                }
            });

            TaskNotifier = new TaskNotifier(loadingTask);
        }
Beispiel #11
0
        public ProjectListPageViewModel()
        {
            _navigationService = SimpleIoc.Default.GetInstance <IStackNavigationService>();
            _vstsRepository    = SimpleIoc.Default.GetInstance <IVSTSRepository>();

            ToProjectPage = new RelayCommand <TeamProjectReference>(project => _navigationService.ToProjectPage(project));

            ReloadPage = new RelayCommand(() => Projects = new TaskNotifier <List <TeamProjectReference> >(GetProjects()));

            ToProfilePage = new RelayCommand(() => _navigationService.ToProfilePage());
        }
        public OrganizationListPageViewModel()
        {
            _navigationService = SimpleIoc.Default.GetInstance <IStackNavigationService>();
            _vstsRepository    = SimpleIoc.Default.GetInstance <IVSTSRepository>();

            ToProjectListPage = new RelayCommand <AccountData>(account => _navigationService.ToProjectListPage(account));

            ToProfilePage = new RelayCommand(() => _navigationService.ToProfilePage());

            ToAboutPage = new RelayCommand(() => _navigationService.ToAboutPage());

            ReloadPage = new RelayCommand(() => Organizations = new TaskNotifier <List <AccountData> >(GetOrganizations()));
        }
Beispiel #13
0
        /// <summary>
        /// Executes the asynchronous command.
        /// Any exceptions from the asynchronous delegate are captured
        /// and placed on <see cref="Execution"/>; they are not propagated to the UI loop.
        /// </summary>
        /// <param name="parameter">The parameter for the command.</param>
        public async Task ExecuteAsync(object parameter)
        {
            Execution = TaskNotifier.Create(_executeAsync(parameter));

            RaiseCanExecuteChanged();
            RaisePropertyChanged("Execution");
            RaisePropertyChanged("IsExecuting");

            await Execution.TaskCompleted;

            RaiseCanExecuteChanged();
            RaisePropertyChanged("IsExecuting");
        }
Beispiel #14
0
        public LoginPageViewModel()
        {
            _navigationService     = SimpleIoc.Default.GetInstance <IStackNavigationService>();
            _authenticationService = SimpleIoc.Default.GetInstance <IAuthenticationService>();

            ReloadPage       = new RelayCommand(() => ReloadPageCommand());
            IsAuthenticating = new TaskNotifier <bool>(Task.FromResult(false));

            var applicationContext = SimpleIoc.Default.GetInstance <IApplicationContext>();

            _azureADLoginUrl =
                $"{ClientConstants.BaseAuthorizationUrl}?client_id={applicationContext.AuthApplicationId}" +
                $"&response_type={ClientConstants.AuthorizationResponseType}&scope={applicationContext.AuthScopes}&redirect_uri={applicationContext.AuthRedirectUrl}";

            SourceUri = new Uri(_azureADLoginUrl);
        }
Beispiel #15
0
        public ProfilePageViewModel()
        {
            _navigationService     = SimpleIoc.Default.GetInstance <IStackNavigationService>();
            _authenticationService = SimpleIoc.Default.GetInstance <IAuthenticationService>();
            _vstsRespository       = SimpleIoc.Default.GetInstance <IVSTSRepository>();

            UserProfile = new TaskNotifier <UserProfile>(_vstsRespository.GetUserProfile());
            Logout      = new RelayCommand(() => _authenticationService.Logout());
            ToAboutPage = new RelayCommand(() => _navigationService.ToAboutPage());
            ReloadPage  = new RelayCommand(() => ReloadPageCommand());

            NavigateToSourceCode         = new RelayCommand(async() => await Launcher.LaunchUriAsync(new Uri(ClientConstants.GitHubUadoUrl)));
            NavigateToPrivacyPolicy      = new RelayCommand(async() => await Launcher.LaunchUriAsync(new Uri(ClientConstants.PrivacyPolicyUrl)));
            NavigateToTermsAndConditions = new RelayCommand(async() => await Launcher.LaunchUriAsync(new Uri(ClientConstants.TermsAndConditionsUrl)));

            AppVersion = VersionHelper.GetAppVersionWithBuildNumber;
        }
        private static void CheckFaultedTaskNotifier(Task task, TaskNotifier taskNotifier, Exception exception)
        {
            Assert.AreSame(task, taskNotifier.Task);

            Assert.NotNull(taskNotifier.TaskCompleted);
            Assert.True(taskNotifier.TaskCompleted.IsCompleted);

            Assert.AreEqual(TaskStatus.Faulted, taskNotifier.Status);
            Assert.True(taskNotifier.IsCompleted);
            Assert.False(taskNotifier.IsNotCompleted);
            Assert.False(taskNotifier.IsCompletedSuccessfully);
            Assert.False(taskNotifier.IsCanceled);
            Assert.True(taskNotifier.IsFaulted);
            Assert.NotNull(taskNotifier.Exception);
            Assert.AreSame(exception, taskNotifier.InnerException);
            Assert.AreEqual(exception.Message, taskNotifier.ErrorMessage);
        }
Beispiel #17
0
        public SideMenuViewModel()
        {
            _navigationService      = SimpleIoc.Default.GetInstance <IStackNavigationService>();
            _userPreferencesService = SimpleIoc.Default.GetInstance <IUserPreferencesService>();
            _vstsRespository        = SimpleIoc.Default.GetInstance <IVSTSRepository>();
            _authenticationService  = SimpleIoc.Default.GetInstance <IAuthenticationService>();

            UserProfile = new TaskNotifier <UserProfile>(_vstsRespository.GetUserProfile());
            Logout      = new AsyncCommand(async() => await LogoutPrompt());
            Account     = _userPreferencesService.GetPreferredAccount();

            ToProfilePage          = new RelayCommand(() => _navigationService.ToProfilePage());
            ToAboutPage            = new RelayCommand(() => _navigationService.ToAboutPage());
            ToOrganizationListPage = new RelayCommand(() => _navigationService.NavigateToAndClearStack(nameof(OrganizationListPage)));
            ToProjectListPage      = new RelayCommand(() => _navigationService.NavigateToAndClearStack(nameof(ProjectListPage), Account));

            AppVersion = VersionHelper.GetAppVersionWithBuildNumber;
        }
        private static void CheckCanceledTaskNotifier <T>(Task <T> task, TaskNotifier <T> taskNotifier, T expectedResult)
        {
            Assert.AreSame(task, taskNotifier.Task);

            Assert.NotNull(taskNotifier.TaskCompleted);
            Assert.True(taskNotifier.TaskCompleted.IsCompleted);

            Assert.AreEqual(expectedResult, taskNotifier.Result);

            Assert.AreEqual(TaskStatus.Canceled, taskNotifier.Status);
            Assert.True(taskNotifier.IsCompleted);
            Assert.False(taskNotifier.IsNotCompleted);
            Assert.False(taskNotifier.IsCompletedSuccessfully);
            Assert.True(taskNotifier.IsCanceled);
            Assert.False(taskNotifier.IsFaulted);
            Assert.Null(taskNotifier.Exception);
            Assert.Null(taskNotifier.InnerException);
            Assert.Null(taskNotifier.ErrorMessage);
        }
        protected override void OnInitialize()
        {
            base.OnInitialize();

            var loaderTask = Task.Run(async delegate
            {
                var parents = await ProductServiceModel.GetProducts(new ProductQuery
                {
                    Identifier     = Product.Identifier,
                    Revision       = Product.Revision,
                    RevisionFilter = RevisionFilter.Specific,
                    Selector       = Selector.Parent
                }).ConfigureAwait(false);

                Parents = parents.Select(p => new ProductInfoViewModel(p)).ToArray();
                await Execute.OnUIThreadAsync(() => NotifyOfPropertyChange(nameof(Parents)));
            });

            TaskNotifier = new TaskNotifier(loaderTask);
        }
        private async Task Remove(object parameter)
        {
            try
            {
                var removalTask = _productServiceModel.DeleteProduct(ProductToRemove.Id);
                TaskNotifier = new TaskNotifier(removalTask);

                var result = await removalTask;
                if (result == false)
                {
                    ErrorMessage = Strings.RemoveProductViewModel_ErrorWhileRemove;
                }
                else
                {
                    TryClose(true);
                }
            }
            catch (Exception e)
            {
                ErrorMessage = e.Message;
            }
        }
Beispiel #21
0
        private async Task Remove(object arg)
        {
            try
            {
                var removeTask = _resourceServiceModel.RemoveResource(ResourceToRemove.Id);
                TaskNotifier = new TaskNotifier(removeTask);

                var result = await removeTask;
                if (result == false)
                {
                    ErrorMessage = Strings.RemoveResourceViewModel_ErrorWhileRemove;
                }
                else
                {
                    TryClose(true);
                }
            }
            catch (Exception e)
            {
                ErrorMessage = e.Message;
            }
        }
        protected override void OnInitialize()
        {
            base.OnInitialize();

            var loadingTask = Task.Run(async delegate
            {
                try
                {
                    var customization = await _productServiceModel.GetCustomization().ConfigureAwait(false);
                    await Execute.OnUIThreadAsync(delegate
                    {
                        PossibleRecipeTypes      = customization.RecipeTypes.Select(r => new RecipeDefinitionViewModel(r)).ToArray();
                        SelectedRecipeDefinition = PossibleRecipeTypes.FirstOrDefault();
                    });
                }
                catch (Exception e)
                {
                    await Execute.OnUIThreadAsync(() => ErrorMessage = e.Message);
                }
            });

            TaskNotifier = new TaskNotifier(loadingTask);
        }
        /// <inheritdoc />
        protected override void OnInitialize()
        {
            DisplayName = Strings.RemoveProductViewModel_DisplayName;

            var loadingTask = Task.Run(async delegate
            {
                var affectedProducts = await _productServiceModel.GetProducts(new ProductQuery
                {
                    Identifier     = ProductToRemove.Identifier,
                    Revision       = ProductToRemove.Revision,
                    RevisionFilter = RevisionFilter.Specific,
                    Selector       = Selector.Parent
                }).ConfigureAwait(false);

                var vms = affectedProducts.Select(r => new ProductInfoViewModel(r)).ToArray();
                await Execute.OnUIThreadAsync(delegate
                {
                    AffectedProducts.AddRange(vms);
                    ErrorMessage = Strings.RemoveProductViewModel_NonDeletableHint;
                });
            });

            TaskNotifier = new TaskNotifier(loadingTask);
        }
Beispiel #24
0
 public SpeakAction()
 {
     _speaking    = false;
     _notifier    = new TaskNotifier(this);
     _synthesiser = new SpeechSynthesizer();
 }
 /// <summary>
 /// Compares the current and new values for a given field (which should be the backing
 /// field for a property). If the value has changed, raises the <see cref="PropertyChanging"/>
 /// event, updates the field and then raises the <see cref="PropertyChanged"/> event.
 /// This method is just like <see cref="SetPropertyAndNotifyOnCompletion{T}(ref TaskNotifier{T},Task{T},string)"/>,
 /// with the difference being an extra <see cref="Action{T}"/> parameter with a callback being invoked
 /// either immediately, if the new task has already completed or is <see langword="null"/>, or upon completion.
 /// </summary>
 /// <typeparam name="T">The type of result for the <see cref="Task{TResult}"/> to set and monitor.</typeparam>
 /// <param name="taskNotifier">The field notifier to modify.</param>
 /// <param name="newValue">The property's value after the change occurred.</param>
 /// <param name="callback">A callback to invoke to update the property value.</param>
 /// <param name="propertyName">(optional) The name of the property that changed.</param>
 /// <returns><see langword="true"/> if the property was changed, <see langword="false"/> otherwise.</returns>
 /// <remarks>
 /// The <see cref="PropertyChanging"/> and <see cref="PropertyChanged"/> events are not raised
 /// if the current and new value for the target property are the same.
 /// </remarks>
 protected bool SetPropertyAndNotifyOnCompletion <T>(ref TaskNotifier <T>?taskNotifier, Task <T>?newValue, Action <Task <T>?> callback, [CallerMemberName] string?propertyName = null)
 {
     return(SetPropertyAndNotifyOnCompletion(taskNotifier ??= new TaskNotifier <T>(), newValue, callback, propertyName));
 }