Exemplo n.º 1
0
        internal RecordAction(Call call, string controlID, CallRecord record)
        {
            Call      = call;
            ControlID = controlID;
            Record    = record;

            Call.OnRecordStateChange += Call_OnRecordStateChange;
        }
Exemplo n.º 2
0
        private async Task <RecordResult> InternalRecordAsync(string controlID, CallRecord record)
        {
            await API.API.SetupAsync();

            RecordResult resultRecord = new RecordResult();
            TaskCompletionSource <bool> tcsCompletion = new TaskCompletionSource <bool>();

            // Hook callbacks temporarily to catch required events
            RecordFinishedCallback finishedCallback = (a, c, e, p) =>
            {
                resultRecord.Event    = new Event(e.EventType, JObject.FromObject(p));
                resultRecord.Url      = p.URL;
                resultRecord.Duration = p.Duration;
                resultRecord.Size     = p.Size;
                tcsCompletion.SetResult(true);
            };
            RecordNoInputCallback noinputCallback = (a, c, e, p) =>
            {
                resultRecord.Event = new Event(e.EventType, JObject.FromObject(p));
                tcsCompletion.SetResult(false);
            };

            OnRecordFinished += finishedCallback;
            OnRecordNoInput  += noinputCallback;

            try
            {
                Task <LL_RecordResult> taskLLRecord = mAPI.LL_RecordAsync(new LL_RecordParams()
                {
                    NodeID    = mNodeID,
                    CallID    = mID,
                    ControlID = controlID,
                    Record    = record,
                });

                // The use of await rethrows exceptions from the task
                LL_RecordResult resultLLRecord = await taskLLRecord;
                if (resultLLRecord.Code == "200")
                {
                    mLogger.LogDebug("Record {0} for call {1} waiting for completion events", controlID, ID);

                    resultRecord.Successful = await tcsCompletion.Task;

                    mLogger.LogDebug("Record {0} for call {1} {2}", controlID, ID, resultRecord.Successful ? "successful" : "unsuccessful");
                }
            }
            catch (Exception exc)
            {
                mLogger.LogError(exc, "Record {0} for call {1} exception", controlID, ID);
            }

            // Unhook temporary callbacks
            OnRecordFinished -= finishedCallback;
            OnRecordNoInput  -= noinputCallback;

            return(resultRecord);
        }
Exemplo n.º 3
0
        public RecordAction RecordAsync(CallRecord record)
        {
            RecordAction action = new RecordAction
            {
                Call      = this,
                ControlID = Guid.NewGuid().ToString(),
                Payload   = record,
            };

            Task.Run(async() =>
            {
                RecordStateChangeCallback recordStateChangeCallback = (a, c, e, p) => action.State = p.State;
                OnRecordStateChange += recordStateChangeCallback;

                action.Result    = await InternalRecordAsync(action.ControlID, record);
                action.Completed = true;

                OnRecordStateChange -= recordStateChangeCallback;
            });
            return(action);
        }
Exemplo n.º 4
0
        public async Task <RecordAction> RecordAsync(CallRecord record)
        {
            // Create the action first so it can hook events and not potentially miss anything
            RecordAction action = new RecordAction(this, Guid.NewGuid().ToString(), record);

            Task <CallRecordResult> taskCallRecordResult = mAPI.LL_CallRecordAsync(new CallRecordParams()
            {
                NodeID    = mNodeID,
                CallID    = mCallID,
                ControlID = action.ControlID,
                Record    = record
            });

            // The use of await ensures that exceptions are rethrown, or OperationCancelledException is thrown
            CallRecordResult callRecordResult = await taskCallRecordResult;

            // If there was an internal error of any kind then throw an exception
            mAPI.ThrowIfError(callRecordResult.Code, callRecordResult.Message);

            return(action);
        }
Exemplo n.º 5
0
 public RecordResult Record(CallRecord record)
 {
     return(InternalRecordAsync(Guid.NewGuid().ToString(), record).Result);
 }
Exemplo n.º 6
0
 public RecordAction Record(CallRecord record)
 {
     return(RecordAsync(record).Result);
 }