private async Task <bool> GetIsDialSuccesAsync(DialAction action)
        {
            ConnectionStatus connectionStatus = await GetConnectionStatusAsync();

            return(action == DialAction.Connect
                                ? connectionStatus == ConnectionStatus.Connected
                                : connectionStatus != ConnectionStatus.Connected);
        }
        private async Task <bool> DialAsync(DialAction action)
        {
            if (!await TryInitSessionAsync())
            {
                return(false);
            }
            var request = new RestRequest(_dialUrl, Method.POST);

            request.AddHeader(_cookieHeaderName, _cookie);
            request.AddHeader(_requestTokenHeaderName, _csrfTokens.Pop());
            string xmlData = Utils.SerializeXml(new DialRequest {
                Action = (int)action
            });

            request.AddParameter("text/xml", xmlData, ParameterType.RequestBody);
            IRestResponse response = await _client.ExecuteTaskAsync(request);

            _csrfTokens.Push(Utils.GetHttpHeader(response.Headers, _requestTokenHeaderName));
            bool   success = response.Content.Contains("<response>OK</response>");
            string message = success ? "success" : "fail";

            _logger.Debug($"Dial ({action.ToString()}): {message}");
            if (!success)
            {
                return(false);
            }
            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

            while (!await GetIsDialSuccesAsync(action) && stopwatch.ElapsedMilliseconds <= _dialTimeout)
            {
                await Task.Delay(_checkStatusInterval);
            }
            bool failedByTimeout = stopwatch.ElapsedMilliseconds > _dialTimeout;

            message = !failedByTimeout ? "success" : "fail";
            _logger.Debug($"Dial result ({action.ToString()}): {message}");
            return(!failedByTimeout);
        }
Exemple #3
0
 /// <summary>
 /// Overriden method for when scripts starts
 /// </summary>
 protected override void Start()
 {
     base.Start();
     action = GetComponentInChildren <DialAction>();
 }
        public void Dial(string numbers, string callerId, string url, bool record, params CustomParam[] customParams)
        {
            DialAction dialAction = new DialAction(numbers, callerId, url, record, customParams);

            actions.Add(dialAction);
        }
Exemple #5
0
 /// <summary>
 /// Method for when scripts starts
 /// </summary>
 protected void Start()
 {
     action = GetComponentInChildren <DialAction>();
 }