namespace StockSharp.Community { using System; using System.IO; using Ecng.Serialization; /// /// Extension class. /// public static class ServerCredentialsExtensions { /// /// The StockSharp folder in location. /// public static string StockSharpFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "StockSharp"); private const string _credentialsFile = "credentials.xml"; /// /// Try load credentials from . /// /// The class that contains a login and password to access the services http://stocksharp.com . /// if the specified credentials was loaded successfully, otherwise, . public static bool TryLoadCredentials(this ServerCredentials credentials) { if (credentials == null) throw new ArgumentNullException(nameof(credentials)); var file = Path.Combine(StockSharpFolder, _credentialsFile); if (!File.Exists(file)) return false; credentials.Load(new XmlSerializer().Deserialize(file)); return true; } /// /// Save the credentials to . /// /// The class that contains a login and password to access the services http://stocksharp.com . public static void SaveCredentials(this ServerCredentials credentials) { if (credentials == null) throw new ArgumentNullException(nameof(credentials)); var file = Path.Combine(StockSharpFolder, _credentialsFile); new XmlSerializer().Serialize(credentials.Save(), file); } } }