示例#1
0
        /// Create an outgoing call from source to target identities.
        /// <param name="source"> The source identity </param>
        /// <param name="targets"> The target identities. </param>
        /// <param name="options"> The call options. </param>
        /// <param name="cancellationToken"> The cancellation token. </param>
        /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="targets"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="options"/> is null.</exception>
        public virtual async Task <Response <CallConnection> > CreateCallConnectionAsync(CommunicationIdentifier source, IEnumerable <CommunicationIdentifier> targets, CreateCallOptions options, CancellationToken cancellationToken = default)
        {
            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallingServerClient)}.{nameof(CreateCallConnection)}");
            scope.Start();
            try
            {
                Argument.AssertNotNull(source, nameof(source));
                Argument.AssertNotNullOrEmpty(targets, nameof(targets));
                Argument.AssertNotNull(options, nameof(options));

                var createCallResponse = await CallConnectionRestClient.CreateCallAsync(
                    source : CommunicationIdentifierSerializer.Serialize(source),
                    targets : targets.Select(t => CommunicationIdentifierSerializer.Serialize(t)),
                    callbackUri : options.CallbackUri?.AbsoluteUri,
                    requestedMediaTypes : options.RequestedMediaTypes,
                    requestedCallEvents : options.RequestedCallEvents,
                    alternateCallerId : options.AlternateCallerId == null?null : new PhoneNumberIdentifierModel(options.AlternateCallerId.PhoneNumber),
                    subject : options.Subject,
                    cancellationToken : cancellationToken
                    ).ConfigureAwait(false);

                return(Response.FromValue(
                           new CallConnection(createCallResponse.Value.CallConnectionId, CallConnectionRestClient, _clientDiagnostics),
                           createCallResponse.GetRawResponse()));
            }
            catch (Exception ex)
            {
                scope.Failed(ex);
                throw;
            }
        }
示例#2
0
        /// Create an outgoing call from source to target identities.
        /// <param name="source"> The source identity </param>
        /// <param name="targets"> The target identities. </param>
        /// <param name="options"> The call options. </param>
        /// <param name="cancellationToken"> The cancellation token. </param>
        /// <exception cref="RequestFailedException">The server returned an error. See <see cref="Exception.Message"/> for details returned from the server.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="targets"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="options"/> is null.</exception>
        public virtual Response <CreateCallResponse> CreateCall(CommunicationIdentifier source, IEnumerable <CommunicationIdentifier> targets, CreateCallOptions options, CancellationToken cancellationToken = default)
        {
            using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CallClient)}.{nameof(CreateCall)}");
            scope.Start();
            try
            {
                Argument.AssertNotNull(source, nameof(source));
                Argument.AssertNotNullOrEmpty(targets, nameof(targets));
                Argument.AssertNotNull(options, nameof(options));

                var sourceAlternateIdentity = options.AlternateCallerId == null ? null : new PhoneNumberIdentifierModel(options.AlternateCallerId.PhoneNumber);

                return(RestClient.CreateCall(
                           targets: targets.Select(t => CommunicationIdentifierSerializer.Serialize(t)),
                           source: CommunicationIdentifierSerializer.Serialize(source),
                           callbackUri: options.CallbackUri?.AbsoluteUri,
                           requestedModalities: options.RequestedModalities,
                           requestedCallEvents: options.RequestedCallEvents,
                           sourceAlternateIdentity: sourceAlternateIdentity,
                           subject: options.Subject,
                           cancellationToken: cancellationToken
                           ));
            }
            catch (Exception ex)
            {
                scope.Failed(ex);
                throw;
            }
        }