Пример #1
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtClientId.Text) || string.IsNullOrEmpty(txtClientSecret.Text))
                {
                    MessageBox.Show("Enter a client id & secret first.");
                    return;
                }

                // Connect to PureCloud
                AddLog("Connecting...");
                Configuration.Default.ApiClient.RestClient.BaseUrl = new Uri($"https://api.{cmbEnvironment.SelectedItem.ToString()}");
                var accessTokenInfo = Configuration.Default.ApiClient.PostToken(txtClientId.Text, txtClientSecret.Text);
                Configuration.Default.AccessToken = accessTokenInfo.AccessToken;
                loggedIn = true;
                AddLog($"Connected.");
                AddLog($"Access Token: {accessTokenInfo.AccessToken}", true);

                // Get APIs
                AddLog("Initializing APIs...", true);
                analyticsApi              = new AnalyticsApi();
                routingApi                = new RoutingApi();
                conversationsApi          = new ConversationsApi();
                tokensApi                 = new TokensApi();
                telephonyProvidersEdgeApi = new TelephonyProvidersEdgeApi();
                AddLog("Finished initializing APIs...", true);

                // Update Controls
                btnConnect.Enabled        = false;
                btnDisconnect.Enabled     = true;
                gbEdges.Enabled           = true;
                gbTroubleshooting.Enabled = true;
                gbAgents.Enabled          = true;
                gbTestGhostCall.Enabled   = true;
                gbCounters.Enabled        = true;

                // Populate Edges
                GetEdges();

                // Get Agents Stats
                AddLog("Starting timer for monitoring agent status", true);
                PullAgentsData();
                timer.Interval = 5000;
                timer.Tick    += (object timerSender, EventArgs eventArgs) => { PullAgentsData(); };
                timer.Start();
                AddLog("Timer started", true);
            }
            catch (Exception ex)
            {
                AddLog($"Error in btnConnect_Click: {ex.Message}");
                AddLog($"Detailled error: {ex}", true);
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnConnect.Enabled        = true;
                btnDisconnect.Enabled     = false;
                gbEdges.Enabled           = false;
                gbTroubleshooting.Enabled = false;
                gbAgents.Enabled          = false;
                gbTestGhostCall.Enabled   = false;
                gbCounters.Enabled        = false;
                loggedIn = false;
            }
        }
Пример #2
0
 public Edges(System.Windows.Forms.ListBox lstLog)
 {
     _lstLog   = lstLog;
     telephony = new TelephonyProvidersEdgeApi();
 }