Example #1
0
        public static Products ToEnum(this ProductInfoMessage product)
        {
            if (product == null)
            {
                throw new ArgumentNullException(nameof(product));
            }

            return(_productsMapping.First(p => p.Value.Id == product.Id).Key);
        }
Example #2
0
        /// <inheritdoc />
        public void Login(ProductInfoMessage product, Version version, string login, SecureString password)
        {
            //if (login.IsEmpty())
            //	throw new ArgumentNullException(nameof(login));

            if (password.IsEmpty())
            {
                throw new ArgumentNullException(nameof(password));
            }

            HandleResponse(product, Invoke(f => f.Login4(product?.Id ?? 0, version.To <string>(), login, password.UnSecure())));
        }
Example #3
0
        /// <inheritdoc />
        public Tuple <Guid, long> Login(ProductInfoMessage product, Version version, string login, SecureString password)
        {
            //if (login.IsEmpty())
            //	throw new ArgumentNullException(nameof(login));

            if (password.IsEmpty())
            {
                throw new ArgumentNullException(nameof(password));
            }

            return(HandleResponse(product, Invoke(f =>
                                                  IsToken
                                        ? f.Login5(product?.Id ?? 0, version.To <string>(), password.UnSecure())
                                        : f.Login4(product?.Id ?? 0, version.To <string>(), login, password.UnSecure()))));
        }
Example #4
0
        /// <summary>
        /// Get product's public name.
        /// </summary>
        /// <param name="product">Product.</param>
        /// <returns>Public name.</returns>
        public static string GetPublicName(this ProductInfoMessage product)
        {
            if (product == null)
            {
                throw new ArgumentNullException(nameof(product));
            }

            var name = product.Name.Remove("S#.", true);

            if (name.CompareIgnoreCase("Data"))
            {
                name = "Hydra";
            }

            return(name);
        }
Example #5
0
        /// <inheritdoc />
        public void Login(ProductInfoMessage product, Version version, string login, SecureString password)
        {
            if (login.IsEmpty())
            {
                throw new ArgumentNullException(nameof(login));
            }

            if (password.IsEmpty())
            {
                throw new ArgumentNullException(nameof(password));
            }

            var tuple = Invoke(f => f.Login4(product?.Id ?? 0, version.To <string>(), login, password.UnSecure()));

            tuple.Item1.ToErrorCode().ThrowIfError();

            NullableSessionId = tuple.Item1;
            UserId            = tuple.Item2;

            if (product != null)
            {
                _pingTimer = ThreadingHelper.Timer(() =>
                {
                    try
                    {
                        var session = NullableSessionId;

                        if (session == null)
                        {
                            return;
                        }

                        lock (_pingSync)
                        {
                            Invoke(f => f.Ping(session.Value));
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.LogError();
                    }
                }).Interval(TimeSpan.FromMinutes(10));
            }
        }
Example #6
0
        private Tuple <Guid, long> HandleResponse(ProductInfoMessage product, Tuple <Guid, long> tuple)
        {
            if (tuple is null)
            {
                throw new ArgumentNullException(nameof(tuple));
            }

            tuple.Item1.ToErrorCode().ThrowIfError();

            _sessionId = tuple.Item1;
            UserId     = tuple.Item2;

            if (product != null)
            {
                _pingTimer = ThreadingHelper.Timer(() =>
                {
                    try
                    {
                        var session = _sessionId;

                        if (session == null)
                        {
                            return;
                        }

                        lock (_pingSync)
                        {
                            Invoke(f => f.Ping(session.Value));
                        }
                    }
                    catch (Exception ex)
                    {
                        ex.LogError();
                    }
                }).Interval(TimeSpan.FromMinutes(10));
            }

            return(tuple);
        }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommunityAuthorization"/>.
 /// </summary>
 /// <param name="product">Product.</param>
 /// <param name="version">Version.</param>
 /// <param name="client">The client for access to the StockSharp authentication service.</param>
 public CommunityAuthorization(ProductInfoMessage product, Version version, IAuthenticationClient client)
 {
     _product = product ?? throw new ArgumentNullException(nameof(product));
     _version = version ?? throw new ArgumentNullException(nameof(version));
     _client  = client ?? throw new ArgumentNullException(nameof(client));
 }
Example #8
0
 /// <inheritdoc />
 public Tuple <Guid, long> Login(ProductInfoMessage product, Version version, SecureString token)
 {
     return(HandleResponse(product, Invoke(f => f.Login5(product?.Id ?? 0, version.To <string>(), token.UnSecure()))));
 }
Example #9
0
 /// <inheritdoc />
 public void Login(ProductInfoMessage product, Version version, SecureString token)
 {
     HandleResponse(product, Invoke(f => f.Login5(product?.Id ?? 0, version.To <string>(), token.UnSecure())));
 }