extern alias Full;
using System;
using System.Collections.Generic;
using PepperDash.Essentials.Devices.Common.VideoCodec;
using Full.Newtonsoft.Json;
using Full.Newtonsoft.Json.Converters;
namespace PepperDash.Essentials.Devices.Common.Codec
{
public interface IHasCallHistory
{
CodecCallHistory CallHistory { get; }
void RemoveCallHistoryEntry(CodecCallHistory.CallHistoryEntry entry);
}
public enum eCodecOccurrenceType
{
Unknown = 0,
Placed = 1,
Received = 2,
NoAnswer = 3,
}
///
/// Represents the recent call history for a codec device
///
public class CodecCallHistory
{
public event EventHandler RecentCallsListHasChanged;
public List RecentCalls { get; private set; }
///
/// Item that gets added to the list when there are no recent calls in history
///
CallHistoryEntry ListEmptyEntry;
public CodecCallHistory()
{
ListEmptyEntry = new CallHistoryEntry() { Name = "No Recent Calls" };
RecentCalls = new List();
RecentCalls.Add(ListEmptyEntry);
}
void OnRecentCallsListChange()
{
var handler = RecentCallsListHasChanged;
if (handler != null)
{
handler(this, new EventArgs());
}
}
public void RemoveEntry(CallHistoryEntry entry)
{
RecentCalls.Remove(entry);
OnRecentCallsListChange();
}
///
/// Generic call history entry, not device specific
///
public class CallHistoryEntry : CodecActiveCallItem
{
[JsonConverter(typeof(IsoDateTimeConverter))]
[JsonProperty("startTime")]
public DateTime StartTime { get; set; }
[JsonConverter(typeof(StringEnumConverter))]
[JsonProperty("occurrenceType")]
public eCodecOccurrenceType OccurrenceType { get; set; }
[JsonProperty("occurrenceHistoryId")]
public string OccurrenceHistoryId { get; set; }
}
///
/// Converts a list of call history entries returned by a Cisco codec to the generic list type
///
///
///
public void ConvertCiscoCallHistoryToGeneric(List entries)
{
var genericEntries = new List();
foreach (CiscoCallHistory.Entry entry in entries)
{
genericEntries.Add(new CallHistoryEntry()
{
Name = entry.DisplayName.Value,
Number = entry.CallbackNumber.Value,
StartTime = entry.LastOccurrenceStartTime.Value,
OccurrenceHistoryId = entry.LastOccurrenceHistoryId.Value,
OccurrenceType = ConvertToOccurenceTypeEnum(entry.OccurrenceType.Value)
});
}
// Check if list is empty and if so, add an item to display No Recent Calls
if(genericEntries.Count == 0)
genericEntries.Add(ListEmptyEntry);
RecentCalls = genericEntries;
OnRecentCallsListChange();
}
///
/// Takes the Cisco occurence type and converts it to the matching enum
///
///