Opc.Ua.Configuration.UserNameCreator.SaveUserName C# (CSharp) Method

SaveUserName() private static method

Save UserNameIdentityToken.
private static SaveUserName ( string applicationName, UserNameIdentityToken userNameToken ) : void
applicationName string
userNameToken UserNameIdentityToken
return void
        private static void SaveUserName(string applicationName, UserNameIdentityToken userNameToken)
        {
            try
            {
                string relativePath = Utils.Format("%CommonApplicationData%\\OPC Foundation\\Accounts\\{0}\\{1}.xml", applicationName, userNameToken.UserName);
                string absolutePath = Utils.GetAbsoluteFilePath(relativePath, false, false, true);

                // oops - nothing found.
                if (absolutePath == null)
                {
                    absolutePath = Utils.GetAbsoluteFilePath(relativePath, true, false, true);
                }

                UserNameIdentityToken outputToken = new UserNameIdentityToken()
                {
                    UserName = userNameToken.UserName,
                    Password = EncryptPassword(userNameToken.Password),
                    EncryptionAlgorithm = "Triple DES",
                };

                // open the file.
                FileStream ostrm = File.Open(absolutePath, FileMode.Create, FileAccess.ReadWrite);

                using (XmlTextWriter writer = new XmlTextWriter(ostrm, System.Text.Encoding.UTF8))
                {
                    DataContractSerializer serializer = new DataContractSerializer(typeof(UserNameIdentityToken));
                    serializer.WriteObject(writer, outputToken);
                }
            }
            catch (Exception e)
            {
                Utils.Trace(e, "Unexpected error saving user configuration for COM Wrapper with UserName={0}.", userNameToken.UserName);
            }
        }