// ReSharper restore InconsistentlySynchronizedField

        bool ICredentialsProvider.TryLoad(out ServerCredentials credentials)
        {
            lock (this)
            {
                if (_credentials != null)
                {
                    credentials = _credentials.Clone();
                    return(IsValid);
                }

                var file = Path.Combine(Paths.CompanyPath, _credentialsFile);
                credentials = null;

                try
                {
                    if (File.Exists(file) || File.Exists(file.MakeLegacy()))
                    {
                        credentials = new ServerCredentials();
                        credentials.LoadIfNotNull(file.DeserializeWithMigration <SettingsStorage>());

                        _credentials = credentials.Clone();
                    }
                }
                catch (Exception ex)
                {
                    ex.LogError();
                }

                return(IsValid);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Try load credentials from <see cref="Paths.CompanyPath"/>.
        /// </summary>
        /// <param name="credentials">The class that contains a login and password to access the services https://stocksharp.com .</param>
        /// <returns><see langword="true"/> if the specified credentials was loaded successfully, otherwise, <see langword="false"/>.</returns>
        public static bool TryLoadCredentials(this ServerCredentials credentials)
        {
            if (credentials == null)
            {
                throw new ArgumentNullException(nameof(credentials));
            }

            var file = Path.Combine(Paths.CompanyPath, _credentialsFile);

            if (!File.Exists(file) && !File.Exists(file.MakeLegacy()))
            {
                return(false);
            }

            return(credentials.LoadIfNotNull(file.DeserializeWithMigration <SettingsStorage>()));
        }
Esempio n. 3
0
        bool ICredentialsProvider.TryLoad(out ServerCredentials credentials)
        {
            var file = Path.Combine(Paths.CompanyPath, _credentialsFile);

            if (!File.Exists(file) && !File.Exists(file.MakeLegacy()))
            {
                credentials = null;
                return(false);
            }

            credentials = new ServerCredentials();

            try
            {
                credentials.LoadIfNotNull(file.DeserializeWithMigration <SettingsStorage>());
            }
            catch (Exception ex)
            {
                ex.LogError();
                return(false);
            }

            return(!credentials.Password.IsEmpty() || !credentials.Token.IsEmpty());
        }