/// <summary>Deserialize the theme from a file path.</summary> /// <param name="filePath">The file path.</param> /// <returns>The <see cref="Theme" />.</returns> public static Theme Deserialize(string filePath) { if (string.IsNullOrEmpty(filePath)) { throw new NoNullAllowedException(ExceptionMessenger.IsNullOrEmpty(filePath)); } if (!File.Exists(filePath)) { throw new FileNotFoundException(ExceptionMessenger.FileNotFound(filePath)); } Theme _theme = null; try { XDocument themeDocument = XDocument.Load(filePath); _theme = Deserialize(themeDocument); } catch (Exception e) { ConsoleEx.WriteDebug(e); } return(_theme); }
/// <summary>Loads the <see cref="Theme" /> from the file path.</summary> /// <param name="filePath">The file path.</param> public void Load(string filePath) { if (string.IsNullOrEmpty(filePath)) { throw new NoNullAllowedException(ExceptionMessenger.IsNullOrEmpty(filePath)); } if (!File.Exists(filePath)) { throw new FileNotFoundException(ExceptionMessenger.FileNotFound(filePath)); } try { if (File.Exists(filePath)) { XDocument _themeDocument = XDocument.Load(filePath); _rawTheme = File.ReadAllText(filePath); Deserialize(_themeDocument); } else { VisualExceptionDialog.Show(new FileNotFoundException(ExceptionMessenger.FileNotFound(filePath))); } } catch (Exception e) { VisualExceptionDialog.Show(e); } }
/// <summary>Loads the <see cref="Theme" /> from the file path.</summary> /// <param name="filePath">The file path.</param> public void Load(string filePath) { if (string.IsNullOrEmpty(filePath)) { throw new NoNullAllowedException(ExceptionMessenger.IsNullOrEmpty(filePath)); } if (!File.Exists(filePath)) { throw new FileNotFoundException(ExceptionMessenger.FileNotFound(filePath)); } try { if (File.Exists(filePath)) { Theme theme = ThemeSerialization.Deserialize(filePath); UpdateTheme(theme.Information, theme.ColorPalette); } else { ConsoleEx.WriteDebug(new FileNotFoundException(ExceptionMessenger.FileNotFound(filePath))); } } catch (Exception e) { ConsoleEx.WriteDebug(e); } }
/// <summary>Initializes a new instance of the <see cref="Theme" /> class.</summary> /// <param name="filePath">The file.</param> public Theme(string filePath) : this() { if (string.IsNullOrEmpty(filePath)) { throw new NoNullAllowedException(ExceptionMessenger.IsNullOrEmpty(filePath)); } if (!File.Exists(filePath)) { throw new FileNotFoundException(ExceptionMessenger.FileNotFound(filePath)); } Load(filePath); }
/// <summary>Saves the theme to a file.</summary> /// <param name="filePath">The file path.</param> public void Save(string filePath) { if (string.IsNullOrEmpty(filePath)) { throw new NoNullAllowedException(ExceptionMessenger.IsNullOrEmpty(filePath)); } _rawTheme = ThemeSerialization.Serialize(this); if (string.IsNullOrEmpty(_rawTheme)) { throw new ArgumentNullException(nameof(_rawTheme)); } XDocument _theme = XDocument.Parse(_rawTheme); _theme.Save(filePath); }
public async Task TestUnkownExceptionIsThrownShouldReturnErrorCode() { var messenger = new ExceptionMessenger(new Exception("Hi")); var respository = new InMemoryContactRepository(); var interactor = new AddContactInteractor(respository, messenger); var contactAddress = new Address("GUEOJUOWOWYEXYLZXNQUYMLMETF9OOGASSKUZZWUJNMSHLFLYIDIVKXKLTLZPMNNJCYVSRZABFKCAVVIW"); var request = new AddContactRequest { ContactAddress = contactAddress, RequestAddress = new Address(Seed.Random().Value), ImageHash = "kjasdjkahsda89dafhfafa", Name = "Chiota User", PublicKeyAddress = new Address(Seed.Random().Value) }; var response = await interactor.ExecuteAsync(request); Assert.AreEqual(ResponseCode.UnkownException, response.Code); }
public async Task TestMessengerCannotSendMessageShouldReturnErrorCodeAndNotWriteToContactRepository() { var messenger = new ExceptionMessenger(); var respository = new InMemoryContactRepository(); var interactor = new AddContactInteractor(respository, messenger); var contactAddress = new Address("GUEOJUOWOWYEXYLZXNQUYMLMETF9OOGASSKUZZWUJNMSHLFLYIDIVKXKLTLZPMNNJCYVSRZABFKCAVVIW"); var request = new AddContactRequest { ContactAddress = contactAddress, RequestAddress = new Address(Seed.Random().Value), ImagePath = "kjasdjkahsda89dafhfafa", Name = "Chiota User", PublicKeyAddress = new Address(Seed.Random().Value), UserPublicKey = InMemoryContactRepository.NtruKeyPair.PublicKey }; var response = await interactor.ExecuteAsync(request); Assert.AreEqual(ResponseCode.MessengerException, response.Code); Assert.AreEqual(0, respository.PersistedContacts.Count); }