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);
}
}