/// <summary>
        /// Tries setting the identity with the given <paramref name="uniqueId"/> as
        /// the currently active identity. If the currently selected identity should
        /// be unspecified, just pass <c>null</c> for the <paramref name="uniqueId"/>.
        /// </summary>
        /// <param name="uniqueId">The unique id of the identity to be set active.</param>
        public void SetCurrentIdentity(string uniqueId)
        {
            if (_currentIdentityDB?.UniqueId == uniqueId)
            {
                return;
            }

            Identity id = null;

            if (uniqueId != null)
            {
                // Fetch the identity from the database
                id = GetIdentityInternal(uniqueId);
                if (id == null)
                {
                    throw new ArgumentException("No matching identity found!", nameof(uniqueId));
                }

                // Set it as currently active identity
                _currentIdentityDB = id;
                _currentIdentity   = DeserializeIdentity(_currentIdentityDB.DataBytes);

                // Save the last active identity unique id in the database
                GetUserData().LastLoadedIdentity = id.UniqueId;
                _db.SaveChanges();
            }
            else
            {
                _currentIdentityDB = null;
                _currentIdentity   = null;
            }

            // And finally fire the IdentityChanged event
            IdentityChanged?.Invoke(this, new IdentityChangedEventArgs(
                                        _currentIdentity,
                                        (id != null) ? id.Name : "",
                                        (id != null) ? id.UniqueId : ""));
        }
Esempio n. 2
0
 public void OnIdentityChanged(IdentityPropertyChangedEventArgs e)
 {
     IdentityChanged?.Invoke(this, e);
 }