//////////////////////////////////////////////////////////////////// // Load Program State //////////////////////////////////////////////////////////////////// /// <summary> /// Load Program State /// </summary> /// <param name="fileName">Refresh token file name</param> /// <returns>Refresh token class</returns> public static SecureSmtpRefreshToken LoadState(string fileName) { // program state file does not exist if (!File.Exists(fileName)) { return(null); } XmlTextReader textFile = null; SecureSmtpRefreshToken state = null; try { // read program state file textFile = new XmlTextReader(fileName); // create xml serializing object var xmlFile = new XmlSerializer(typeof(SecureSmtpRefreshToken)); // deserialize the program state state = (SecureSmtpRefreshToken)xmlFile.Deserialize(textFile); } catch { state = null; } // close the file textFile?.Close(); // exit return(state); }
/// <summary> /// Secure SMTP OAuth2 constructor /// </summary> /// <param name="refreshTokenFileName">Refresh token file name</param> public SecureSmtpOAuth2(string refreshTokenFileName) { // no file name if (string.IsNullOrWhiteSpace(refreshTokenFileName)) { throw new ApplicationException("Refresh token file name is missing or empty"); } // look for refresh token _refreshToken = SecureSmtpRefreshToken.LoadState(refreshTokenFileName); if (_refreshToken == null) { throw new ApplicationException("SecureSmtpRefreshToken.xml file is missing or invalid"); } return; }