public static void UpdateConfiguration(int id, ServiceConfig ic) { var list = GetListOfConfigurationsInternal(); var configuration = list.FirstOrDefault(c => c.Id == id); if (configuration == null) throw new ArgumentException("Configuration with Id \"" + ic.Id + "\" can't be found."); if (string.IsNullOrEmpty(ic.Password) || ic.Password.Equals(ReturnPassword)) { var password = configuration.Password; ic.Password = password; } var errorMessage = CheckValidityOfConfig(ic); if (!string.IsNullOrEmpty(errorMessage)) { throw new ArgumentException(errorMessage); } list[list.IndexOf(configuration)] = ic; WriteToFile(list); ConfigurationListChanged(); }
public static void AddConfiguration(ServiceConfig ic) { try { ic.Password = AesDecryptor.DecryptStringAES(ic.Password); var list = GetListOfConfigurationsInternal(); if (list.FirstOrDefault(c => String.Equals(c.Uri, ic.Uri, StringComparison.CurrentCultureIgnoreCase)) != null) throw new ArgumentException("Configuration with Uri \"" + ic.Uri + "\" Already exists."); ic.Id = list.Any() ? (list.Max(c => c.Id) + 1) : (0); var errorMessage = CheckValidityOfConfig(ic); if (!string.IsNullOrEmpty(errorMessage)) { throw new ArgumentException(errorMessage); } list.Add(ic); WriteToFile(list); ConfigurationListChanged(); } catch (Exception e) { LogService.WriteError(e); throw; } }