/// <summary> /// Writes changes made to the given <paramref name="identity"/> back to the database. /// </summary> /// <param name="identity">The changed identity which should be updated in the database.</param> public void UpdateIdentity(SQRLIdentity identity) { Identity id = GetIdentityInternal(identity.Block0?.UniqueIdentifier.ToHex()); if (id == null) { throw new ArgumentException("This identity does not exist!", nameof(identity)); } id.DataBytes = SerializeIdentity(identity); _db.SaveChanges(); }
/// <summary> /// Saves any changed settings to the database. /// </summary> public void Save() { if (!HasUnsavedChanges) { return; } _userData.LastLoadedIdentity = _lastLoadedIdentity; _userData.StartMinimized = _startMinimized; _db.SaveChanges(); }
/// <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 : "")); }