Beispiel #1
0
        public void SetConfig(Config c)
        {
            _myConfig = c;

            TeamsCollection.Clear();
            TeamsCollection.Add("<unmapped>"); // Need to add <unmapped> to make this value legal.

            // Set TeamsRootNode base on RootNode
            // Ex. If team nodes are APT\A, APT\B - RootNode can be: APT or A or B (user choice)
            // but Teams root node will always be APT
            c.TeamsRootNode = c.RootNode;
            foreach (TeamConfig t in myConfig().Teams)
            {
                TeamsCollection.Add(t.GroupName);
                if (c.RootNode.Contains(t.GroupName))
                {
                    c.TeamsRootNode = c.RootNode.Substring(0, c.RootNode.IndexOf(t.GroupName));
                }
            }
        }
        private async Task RefreshExecuted()
        {
            LoggingService.Trace("Executing TeamsListViewModel.RefreshCommand");

            if (IsRefreshing)
            {
                return;
            }

            if (Connectivity.NetworkAccess != NetworkAccess.Internet)
            {
                _userDialogs.Toast("No Internet, please verify your network access");
                return;
            }

            try
            {
                IsRefreshing = true;

                var userModel = await _wasabeeApiV1Service.User_GetUserInformations();

                if (userModel != null)
                {
                    await _usersDatabase.SaveUserModel(userModel);

                    if (userModel.Teams != null && userModel.Teams.Any())
                    {
                        TeamsCollection = new MvxObservableCollection <Team>(userModel.Teams.Select(x =>
                                                                                                    new Team(x.Name, x.Id)
                        {
                            IsEnabled = x.State.Equals("On"),
                            IsOwner   = x.Owner.Equals(_userSettingsService.GetLoggedUserGoogleId())
                        }
                                                                                                    ));
                    }
                    else
                    {
                        TeamsCollection.Clear();
                        await RaisePropertyChanged(() => TeamsCollection);

                        await _operationsDatabase.DeleteAllExceptOwnedBy(_userSettingsService.GetLoggedUserGoogleId());

                        var operationsCount = await _operationsDatabase.CountLocalOperations();

                        if (operationsCount == 0)
                        {
                            // Leaves app
                            await _navigationService.Navigate(Mvx.IoCProvider.Resolve <SplashScreenViewModel>(), new SplashScreenNavigationParameter(doDataRefreshOnly : true));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                LoggingService.Error(e, "Error Executing TeamsListViewModel.RefreshCommand");

                _userDialogs.Toast("Error occured while loading your teams");
            }
            finally
            {
                IsRefreshing = false;
            }
        }