Example #1
0
        /// <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;
        }
Example #2
0
        ////////////////////////////////////////////////////////////////////
        // 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
                XmlSerializer XmlFile = new XmlSerializer(typeof(SecureSmtpRefreshToken));

                // deserialize the program state
                State = (SecureSmtpRefreshToken)XmlFile.Deserialize(TextFile);
            }
            catch
            {
                State = null;
            }

            // close the file
            if (TextFile != null)
            {
                TextFile.Close();
            }

            // exit
            return(State);
        }