public void UpsertUserProfile(UserProfile user) { Debug.Assert(!this.m_readOnly, "Configuration in use is read-only. Did you forget BeginCachedConfiguration?"); if (user.UniqueId.Length == 0) { user.UniqueId = Guid.NewGuid().ToString(); // Clone the user and add to the configuration's UserProfile dictionary UserProfiles.Add(user.UniqueId, (UserProfile)user.Clone()); _logger.LogInformation($"User {user.Name} added."); } else { Debug.Assert(UserProfiles.ContainsKey(user.UniqueId), "User profile not found in dictionary. Cannot update."); // Clone the user and update the configuration's UserProfile dictionary UserProfiles[user.UniqueId] = (UserProfile)user.Clone(); _logger.LogInformation($"User {user.Name} updated."); } // The Default property is included on the profile just as a helper (it's not saved in the json). // What is saved is the UniqueId of the default user in the DefaultUserProfile field. if (user.Default) { DefaultUserProfile = user.UniqueId; } else if (DefaultUserProfile == user.UniqueId) { DefaultUserProfile = ""; } }
/// <summary> /// 将给定的用户信息实体数据添加至数据库中。 /// </summary> /// <param name="entity">要添加的用户信息实体数据。</param> /// <exception cref="ArgumentNullException"/> /// <exception cref="InvalidOperationException"/> /// <remarks> /// 若给定的实体数据已经存在于数据库中,抛出 InvalidOperationException 异常。 /// 若要更新给定的实体数据,请使用 UpdateUserProfileEntity 方法。 /// </remarks> public void AddUserProfileEntity(UserProfileEntity entity) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } if (QueryUserProfileEntity(entity.Username) != null) { throw new InvalidOperationException("给定的实体对象已经存在于数据库中。"); } UserProfiles.Add(entity); SaveChanges(); }
/// <summary> /// Creates a new user profile for a User in the DiScribe database. /// /// Also creates a corresponding profile with the Azure Speaker Recognition /// endpoint and returns the GUID for that profile on success. /// /// /// </summary> /// <param name="client"></param> /// <param name="locale"></param> /// <returns>Created profile GUID or GUID {00000000-0000-0000-0000-000000000000} on fail</returns> public async Task <Guid> CreateUserProfile(UserParams userParams) { foreach (var profile in UserProfiles) { /*Profile has already been enrolled */ if (profile.Email == userParams.Email) { return(profile.ProfileGUID); } } var taskComplete = new TaskCompletionSource <Guid>(); Task <CreateProfileResponse> profileTask = null; Guid failGuid = new Guid(); try { profileTask = EnrollmentClient.CreateProfileAsync(EnrollmentLocale); await profileTask; } catch (AggregateException ex) { Console.Error.WriteLine("Error creating user profile with Azure Speaker Recognition endpoint\n" + ex.InnerException.Message); taskComplete.SetResult(failGuid); return(failGuid); } userParams.ProfileGUID = profileTask.Result.ProfileId; /*Attempt to Create user profile in DB and add to list of user profiles */ User registeredUser = DatabaseController.CreateUser(userParams); if (registeredUser == null) { taskComplete.SetResult(failGuid); return(failGuid); } UserProfiles.Add(registeredUser); //Add profile to list of profiles managed by this instance taskComplete.SetResult(profileTask.Result.ProfileId); return(profileTask.Result.ProfileId); }
public UserProfileManager() { _userProfileFilePath = Path.Combine(Directory.GetCurrentDirectory(), @"UserProfile.json"); _companyProfileFilePath = Path.Combine(Directory.GetCurrentDirectory(), @"CompanyProfile.json"); CompanyProfiles = LoadCompanyProfiles(_companyProfileFilePath); UserProfiles = LoadUserProfiles(_userProfileFilePath); DataProviders = LoadUserProviders(UserProfiles); NewAccountViewModel.WhenNewProfileAdded.Subscribe((newProfile) => { if (UserProfiles.Contains(newProfile)) { var profile = UserProfiles.FirstOrDefault((p) => p.Equals(newProfile)); profile.Accounts = profile.Accounts.Union(newProfile.Accounts).ToList(); } else { UserProfiles.Add(newProfile); } SaveUserProfile(); }); }
public static async Task <UserProfiles> UserProfileGet(DatabaseSettings databaseSettings, Guid effectiveUserID, Guid userID) { UserProfiles returnValue = null; using (SqlConnection connection = new SqlConnection(databaseSettings.SqlClientConnectionString)) { Task dbOpenTask = connection.OpenAsync(); using (SqlCommand command = new SqlCommand()) { command.CommandText = "csUserProfileGet"; command.CommandType = CommandType.StoredProcedure; SqlParameter parameter = null; parameter = command.Parameters.Add("@uUserID", SqlDbType.UniqueIdentifier); parameter.Value = effectiveUserID; parameter = command.Parameters.Add("@UserID", SqlDbType.UniqueIdentifier); if (Guid.Empty.Equals(userID) == true) { parameter.Value = DBNull.Value; } else { parameter.Value = userID; } await dbOpenTask; command.Connection = connection; using (SqlDataReader reader = await command.ExecuteReaderAsync()) { returnValue = new UserProfiles(); while (await reader.ReadAsync()) { UserProfile up = new UserProfile(); if (Convert.IsDBNull(reader["UserID"]) == false) { up.UserID = (Guid)reader["UserID"]; } if (Convert.IsDBNull(reader["FirstName"]) == false) { up.FirstName = (string)reader["FirstName"]; } if (Convert.IsDBNull(reader["LastName"]) == false) { up.LastName = (string)reader["LastName"]; } if (Convert.IsDBNull(reader["Email"]) == false) { up.Email = (string)reader["Email"]; } if (Convert.IsDBNull(reader["MobilePhone"]) == false) { up.MobilePhone = (string)reader["MobilePhone"]; } if (Convert.IsDBNull(reader["LoginID"]) == false) { up.LoginID = (string)reader["LoginID"]; } if (Convert.IsDBNull(reader["LastSuccessfulLoginDateTime"]) == false) { up.LastSuccessfulLoginDateTime = (DateTime)reader["LastSuccessfulLoginDateTime"]; } if (Convert.IsDBNull(reader["IsLoginAllowed"]) == false) { up.IsLoginAllowed = (bool)reader["IsLoginAllowed"]; } if (Convert.IsDBNull(reader["IsPasswordChangeRequired"]) == false) { up.IsPasswordChangeRequired = (bool)reader["IsPasswordChangeRequired"]; } if (Convert.IsDBNull(reader["HasLoggedIn"]) == false) { up.HasLoggedIn = (bool)reader["HasLoggedIn"]; } returnValue.Add(up); } } } } return(returnValue); }
public LoadSettingsResult Read() { Logger.LogDebug("SettingsService", "Reading settings from disk"); var loadResult = LoadSettingsResult.NoExistingSettings; var configFile = new ConfigFile(); //Try to ready legacy config if present if (LegacyConfigExists()) { try { configFile = ReadLegacy(); loadResult = LoadSettingsResult.LoadedLegacySettings; ApplicationSettings = configFile.ApplicationSettings; DefaultProfileId = configFile.DefaultProfileId; Write(); } catch (Exception e) { configFile = new ConfigFile(); loadResult = LoadSettingsResult.ErrorLoadingLegacySettings; Logger.LogException("SettingsService", "Exception reading legacy settings", e); } } else { //Read existing config if present if (SettingsExist()) { try { JsonConvert.PopulateObject(_fileAccessor.ReadAllText(Path.Combine(ApplicationConfig.ConfigPath, ApplicationConfig.ConfigFileName)), configFile); loadResult = LoadSettingsResult.LoadedExistingSettings; } catch (Exception e) { configFile = new ConfigFile(); loadResult = LoadSettingsResult.ErrorLoadingSettings; Logger.LogException("SettingsService", "Exception reading settings", e); } } } configFile.Servers = new BindableCollection <Server>(configFile.Servers.Union(ApplicationConfig.DefaultServers)); //Add default servers if they are not present DefaultProfileId = configFile.DefaultProfileId; foreach (var profile in configFile.Profiles) { UserProfiles.Add(new UserProfile(profile.Key, profile.Value, profile.Key == DefaultProfileId)); } ApplicationSettings = configFile.ApplicationSettings; Servers = configFile.Servers; //Set culture if no previous settings if (loadResult != LoadSettingsResult.LoadedExistingSettings) { var installedCulture = CultureInfo.InstalledUICulture.TwoLetterISOLanguageName; var cultureMatch = ApplicationConfig.Languages.FirstOrDefault(l => l.StartsWith(installedCulture)); if (cultureMatch != null) { ApplicationSettings.Language = cultureMatch; } } Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(ApplicationConfig.Languages.Contains(ApplicationSettings.Language) ? ApplicationSettings.Language : ApplicationConfig.Languages.First()); Logger.LogDebug("SettingsService", $"Finished reading settings, result was: {loadResult}"); return(loadResult); }
/// <summary> /// Добавление пользователя /// </summary> /// <param name="profile">Профиль пользователя</param> /// <returns></returns> public static int Add(UserProfile profile) { return(UserProfiles.Add(profile)); }
/// <summary> /// Reads the existing legacy launcher configuration and converts into current format /// </summary> /// <returns>ConfigFile object with the configuration</returns> private ConfigFile ReadLegacy() { Logger.LogInfo("SettingsService", "Starting conversion of legacy settings"); ConfigFile configFile = new ConfigFile(); string defaultProfileName = string.Empty; var legacyConfigFile = Path.Combine(ApplicationConfig.ConfigPath, ApplicationConfig.LegacyConfigFileName); var legacyConfigFileContent = _fileAccessor.ReadAllText(legacyConfigFile); using (StringReader stringReader = new StringReader(legacyConfigFileContent)) using (XmlReader reader = XmlReader.Create(stringReader)) { while (reader.Read()) { if (!reader.IsStartElement()) { continue; } try { string value; switch (reader.Name) { case "JavaPath": reader.Read(); value = reader.Value.Trim(); configFile.ApplicationSettings.JavaPath = value; break; case "ArmA3Path": reader.Read(); value = reader.Value.Trim(); configFile.ApplicationSettings.Arma3Path = value; break; case "ArmA3SyncPath": reader.Read(); value = reader.Value.Trim(); configFile.ApplicationSettings.Arma3SyncPath = value; break; case "Profiles": var parameter = reader["default"]; reader.Read(); defaultProfileName = parameter; break; case "Profile": reader.Read(); value = reader.Value.Trim(); UserProfiles.Add(new UserProfile(value)); break; case "minimizeNotification": reader.Read(); value = reader.Value.Trim(); configFile.ApplicationSettings.MinimizeNotification = bool.Parse(value); break; case "startMinimize": reader.Read(); value = reader.Value.Trim(); if (bool.Parse(value)) { configFile.ApplicationSettings.StartAction = StartAction.Minimize; } break; case "startClose": reader.Read(); value = reader.Value.Trim(); if (bool.Parse(value)) { configFile.ApplicationSettings.StartAction = StartAction.Close; } break; case "accent": reader.Read(); value = reader.Value.Trim(); configFile.ApplicationSettings.AccentColor = (AccentColor)int.Parse(value); break; case "checkUpdates": reader.Read(); value = reader.Value.Trim(); configFile.ApplicationSettings.CheckUpdates = bool.Parse(value); break; case "checkServers": reader.Read(); value = reader.Value.Trim(); configFile.ApplicationSettings.CheckServers = bool.Parse(value); break; case "checkRepository": reader.Read(); value = reader.Value.Trim(); configFile.ApplicationSettings.CheckRepository = bool.Parse(value); break; } } catch (Exception e) { Logger.LogException("SettingsService", "Error reading a legacy setting", e); } } } var defaultProfile = UserProfiles.SingleOrDefault(p => p.Name.Equals(defaultProfileName)); if (defaultProfile != null) { configFile.DefaultProfileId = defaultProfile.Id; defaultProfile.IsDefault = true; } //Delete the legacy config file after reading it try { _fileAccessor.DeleteFile(legacyConfigFile); Logger.LogInfo("SettingsService", "Legacy config file deleted"); } catch (Exception e) { Logger.LogException("SettingsService", "Error deleting legacy config file", e); } Logger.LogInfo("SettingsService", "Finished conversion of legacy settings"); return(configFile); }
public void AddProfile(UserProfile userProfile) { UserProfiles.Add(userProfile); }