/// <summary>
        /// Deserializes the saved users.
        /// </summary>
        private void DeserializeUsers()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(User), typeof(User).GetNestedTypes());

            string[] files = null;

            try
            {
                files = Directory.GetFiles(USERSFOLDER).Where(i => i.EndsWith("xml")).ToArray();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Fatal error while deserializing users: " + ex.Message);
                return;
            }

            foreach (var file in files)
            {
                try
                {
                    using (StreamReader reader = new StreamReader(file))
                    {
                        User usr = (User)serializer.Deserialize(reader);
                        AvailableUsers.Add(usr);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Error deserializing {0}: {1}", file, ex.Message));
                }
            }
        }
 /// <summary>
 /// Deserializes the saved users.
 /// </summary>
 private void DeserializeUsers()
 {
     try
     {
         foreach (var file in _directoryOperator.GetFiles(USERSFOLDER).Where(i => i.EndsWith("xml")))
         {
             try
             {
                 User usr = _userSerializer.Deserialize(file);
                 // connect and disconnect to serialize if recent scrobbles are different
                 usr.RecentScrobblesChanged += User_RecentScrobblesChanged;
                 usr.UpdateRecentScrobbles();
                 usr.RecentScrobblesChanged -= User_RecentScrobblesChanged;
                 AvailableUsers.Add(usr);
             }
             catch (Exception ex)
             {
                 Debug.WriteLine(string.Format("Error deserializing {0}: {1}", file, ex.Message));
             }
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Fatal error while deserializing users: " + ex.Message);
         return;
     }
 }
 /// <summary>
 /// Add a user to the list.
 /// </summary>
 public void AddUser()
 {
     if (_windowManager.ShowDialog(new LoginViewModel(_lastAuth, _windowManager.MessageBoxService)).Value)
     {
         User usr = new User(_lastAuth.UserSession.Username, _lastAuth.UserSession.Token, _lastAuth.UserSession.IsSubscriber);
         AvailableUsers.Add(usr);
         ActiveUser = usr;
         SerializeUsers();
     }
 }
 /// <summary>
 /// Add a user to the list.
 /// </summary>
 public void AddUser()
 {
     if (_windowManager.ShowDialog(new LoginViewModel()).Value)
     {
         User usr = new User(MainViewModel.Client.Auth.UserSession.Username, MainViewModel.Client.Auth.UserSession.Token, MainViewModel.Client.Auth.UserSession.IsSubscriber);
         AvailableUsers.Add(usr);
         ActiveUser = usr;
         SerializeUsers();
     }
 }
        private void NewUserAvailable(UserViewModel user)
        {
            Guard.Against.Null(user, nameof(user));

            user.UserSelectedCommand = UserSelectedCommand;

            Device.BeginInvokeOnMainThread(() =>
            {
                AvailableUsers.Add(user);
                RaisePropertyChanged(nameof(UsersCount));
            });
        }
Beispiel #6
0
        /// <summary>
        /// Allow choosing users that are from the specific selectedUserType
        /// </summary>
        /// <param name="selectedUserType">User type of available users. Expected values per const USER_TYPE_X fields</param>
        private void ChangeAvailableUsers(string selectedUserType)
        {
            // Clean the available users from the previous choice of user types
            AvailableUsers.Clear();

            // Create a query all the editable users in the school from the specified type
            IQueryable <Person> usersQuery;

            switch (selectedUserType)
            {
            case Globals.USER_TYPE_STUDENT:
            {
                usersQuery = _schoolData.Persons.Where(person => person.isStudent);
                break;
            }

            case Globals.USER_TYPE_PARENTS:
            {
                usersQuery = _schoolData.Persons.Where(person => person.isParent);
                break;
            }

            case Globals.USER_TYPE_TEACHERS:
            {
                usersQuery = _schoolData.Persons.Where(person => person.isTeacher);
                break;
            }

            case Globals.USER_TYPE_SECRETARIES:
            {
                usersQuery = _schoolData.Persons.Where(person => person.isSecretary);
                break;
            }

            case Globals.USER_TYPE_PRINCIPAL:
            {
                usersQuery = _schoolData.Persons.Where(person => person.isPrincipal);
                break;
            }

            default:
            {
                usersQuery = Enumerable.Empty <Person>().AsQueryable();
                break;
            }
            }

            // Create a list of all the editable users in the school
            usersQuery.Where(person => !person.User.isDisabled).ToList().
            ForEach(person => AvailableUsers.Add(person.personID, person.firstName + " " + person.lastName));
        }
        private void UpdateConnectedUser(List <UserViewModel> connectedUsers)
        {
            Guard.Against.Null(connectedUsers, nameof(connectedUsers));

            Device.BeginInvokeOnMainThread(() =>
            {
                IsProcessing = true;
                foreach (var user in connectedUsers)
                {
                    user.UserSelectedCommand = UserSelectedCommand;

                    AvailableUsers.Add(user);
                }
                RaisePropertyChanged(nameof(UsersCount));
                IsProcessing = false;
            });
        }
Beispiel #8
0
 /// <summary>
 /// Deserializes the saved users.
 /// </summary>
 private void DeserializeUsers()
 {
     try
     {
         foreach (var file in _directoryOperator.GetFiles(USERSFOLDER).Where(i => i.EndsWith("xml")))
         {
             try
             {
                 User usr = _userSerializer.Deserialize(file);
                 AvailableUsers.Add(usr);
             }
             catch (Exception ex)
             {
                 Debug.WriteLine(string.Format("Error deserializing {0}: {1}", file, ex.Message));
             }
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Fatal error while deserializing users: " + ex.Message);
         return;
     }
 }
Beispiel #9
0
        private void OnApplicationStateChanged(ApplicationState applicationState)
        {
            if (applicationState == ApplicationState.DisconnectedFromServer)
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    AvailableUsers.Clear();
                    AreConnectionSettingsVisible = true;
                    SelectedUser        = null;
                    IsUserListAvailable = false;
                });
            }

            if (applicationState == ApplicationState.ConnectedButNotLoggedIn)
            {
                AreConnectionSettingsVisible = false;

                session.RequestUserList(
                    userList =>
                {
                    Application.Current.Dispatcher.Invoke(async() =>
                    {
                        AvailableUsers.Clear();
                        userList.Do(userData => AvailableUsers.Add(userData));
                        IsUserListAvailable = true;

                        if (AvailableUsers.Count > 0)
                        {
                            SelectedUser = AvailableUsers.Any(user => user.Id == localSettingsRepository.LastLoggedInUserId)
                                                                                                        ? AvailableUsers.First(user => user.Id == localSettingsRepository.LastLoggedInUserId)
                                                                                                        : AvailableUsers.First();
                        }
                        else
                        {
                            var dialog = new UserDialogBox("",
                                                           "Es sind keine verfügbaren User vorhanden\n" +
                                                           "Die Verbindung wird getrennt!",
                                                           MessageBoxButton.OK);
                            await dialog.ShowMahAppsDialog();
                            Disconnect.Execute(null);
                        }
                    });
                },
                    errorMessage =>
                {
                    Application.Current.Dispatcher.Invoke(async() =>
                    {
                        var dialog = new UserDialogBox("",
                                                       "Die Userliste kann nicht vom Server abgefragt werden:\n" +
                                                       $">> {errorMessage} <<\n" +
                                                       "Die Verbindung wird getrennt - versuchen Sie es erneut",
                                                       MessageBoxButton.OK);
                        await dialog.ShowMahAppsDialog();
                        Disconnect.Execute(null);
                    });
                }
                    );
            }


            Application.Current.Dispatcher.Invoke(() =>
            {
                ((ParameterrizedCommand <PasswordBox>)Login).RaiseCanExecuteChanged();
                ((Command)Connect).RaiseCanExecuteChanged();
                ((Command)DebugConnect).RaiseCanExecuteChanged();
                ((Command)Disconnect).RaiseCanExecuteChanged();
            });
        }