Exemple #1
0
        public async Task TestLoginExpectNoErrors()
        {
            var response = await IgRestService.Authenticate(_conversationContext, _identifier, _password);

            _conversationContext = IgRestService.GetConversationContext();
            Assert.IsTrue(response.StatusCode == HttpStatusCode.OK && _conversationContext.xSecurityToken.Length > 0);
        }
Exemple #2
0
        public async void Connect(string username, string password, string apikey, IgRestApiClient igRestApiClient)
        {
            if (String.IsNullOrEmpty(apikey) || String.IsNullOrEmpty(password) ||
                String.IsNullOrEmpty(username))
            {
                Log.Instance.WriteEntry("Please enter API key, Password and Username", EventLogEntryType.Error);
                return;
            }
            _igRestApiClient = igRestApiClient;

            // use v1 login...
            var ar = new AuthenticationRequest();

            ar.identifier = username;
            ar.password   = password;

            //log in...
            var authenticationResponse = await _igRestApiClient.SecureAuthenticate(ar, apikey);

            if (authenticationResponse && (authenticationResponse.Response != null) && (authenticationResponse.Response.accounts != null))
            {
                if (authenticationResponse.Response.accounts.Count > 0)
                {
                    Log.Instance.WriteEntry(JsonConvert.SerializeObject(authenticationResponse, Formatting.Indented), EventLogEntryType.Information);
                    Log.Instance.WriteEntry("Logged in, current account: " + authenticationResponse.Response.currentAccountId, EventLogEntryType.Information);

                    _currentAccount = authenticationResponse.Response.currentAccountId;

                    ConversationContext context = _igRestApiClient.GetConversationContext();

                    Log.Instance.WriteEntry("establishing streaming data connection", EventLogEntryType.Information);

                    if ((context != null) && (authenticationResponse.Response.currentAccountId != null) &&
                        (authenticationResponse.Response.lightstreamerEndpoint != null))
                    {
                        if (_igStreamApiClient != null)
                        {
                            _igStreamApiClient.ConnectionClosed = ConnectionClosed;
                            var connectionEstablished =
                                _igStreamApiClient.Connect(authenticationResponse.Response.currentAccountId, context.cst,
                                                           context.xSecurityToken, context.apiKey,
                                                           authenticationResponse.Response.lightstreamerEndpoint);
                            if (connectionEstablished)
                            {
                                Log.Instance.WriteEntry("streaming data connection established", EventLogEntryType.Information);
                            }
                            else
                            {
                                Log.Instance.WriteEntry("streaming data connection could NOT be established", EventLogEntryType.Error);
                            }
                        }
                    }
                    else
                    {
                        Log.Instance.WriteEntry("Could not establish streaming data connection.", EventLogEntryType.Error);
                    }
                }
                else
                {
                    Log.Instance.WriteEntry("no accounts", EventLogEntryType.Error);
                }
            }
            else
            {
                Log.Instance.WriteEntry("Authentication Rest Response error : " + authenticationResponse.StatusCode, EventLogEntryType.Error);
            }
        }
Exemple #3
0
        ///<Summary>
        ///loginButton_Click
        ///This method deals with logging into the app.
        ///</Summary>
        private async void loginButton_Click(object sender, EventArgs e)
        {
            try
            {
                AppendActivityMessage("Attempting login");

                if (String.IsNullOrEmpty(_APIKey) || String.IsNullOrEmpty(passwordTextbox.Text) ||
                    String.IsNullOrEmpty(identifierTextbox.Text) || (_igRestApiClient == null))
                {
                    AppendActivityMessage("Please enter API key, Password and Username");
                    return;
                }

                // use v1 login...
                var ar = new AuthenticationRequest();
                ar.identifier = identifierTextbox.Text;
                ar.password   = passwordTextbox.Text;

                //log in...
                var authenticationResponse = await _igRestApiClient.SecureAuthenticate(ar, _APIKey);

                if (authenticationResponse && (authenticationResponse.Response != null) && (authenticationResponse.Response.accounts != null))
                {
                    if (authenticationResponse.Response.accounts.Count > 0)
                    {
                        AppendRestDataMessage(JsonConvert.SerializeObject(authenticationResponse, Formatting.Indented));
                        AppendActivityMessage("Logged in, current account: " + authenticationResponse.Response.currentAccountId);

                        _currentAccount = authenticationResponse.Response.currentAccountId;

                        ConversationContext context = _igRestApiClient.GetConversationContext();

                        AppendActivityMessage("establishing streaming data connection");

                        if ((context != null) && (authenticationResponse.Response.currentAccountId != null) &&
                            (authenticationResponse.Response.lightstreamerEndpoint != null))
                        {
                            if (_igStreamApiClient != null)
                            {
                                var connectionEstablished =
                                    _igStreamApiClient.Connect(authenticationResponse.Response.currentAccountId, context.cst,
                                                               context.xSecurityToken, context.apiKey,
                                                               authenticationResponse.Response.lightstreamerEndpoint);
                                if (connectionEstablished)
                                {
                                    AppendActivityMessage("streaming data connection established");
                                    EnableCommandButtons(true);
                                }
                                else
                                {
                                    AppendActivityMessage("streaming data connection could NOT be established");
                                    EnableCommandButtons(false);
                                }
                            }
                        }
                        else
                        {
                            AppendActivityMessage("Could not establish streaming data connection.");
                        }
                    }
                    else
                    {
                        AppendActivityMessage("no accounts");
                    }
                }
                else
                {
                    AppendActivityMessage("Authentication Rest Response error : " + authenticationResponse.StatusCode);
                }
            }
            catch (Exception ex)
            {
                AppendActivityMessage(ex.Message);
            }
        }