using System; using System.Collections.Generic; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using PepperDash.Essentials.Devices.Common.VideoCodec; namespace PepperDash.Essentials.Devices.Common.Codec { /// /// Defines the contract for IHasCallHistory /// public interface IHasCallHistory { /// /// Gets the call history for this device /// CodecCallHistory CallHistory { get; } /// /// Removes the specified call history entry /// /// The call history entry to remove void RemoveCallHistoryEntry(CodecCallHistory.CallHistoryEntry entry); } /// /// Enumeration of eCodecOccurrenceType values /// public enum eCodecOccurrenceType { /// /// Unknown occurrence type /// Unknown = 0, /// /// Call was placed (outgoing) /// Placed = 1, /// /// Call was received (incoming) /// Received = 2, /// /// Call received no answer /// NoAnswer = 3, } /// /// Represents a CodecCallHistory /// public class CodecCallHistory { /// /// Event that is raised when the recent calls list has changed /// public event EventHandler RecentCallsListHasChanged; /// /// Gets or sets the RecentCalls /// public List RecentCalls { get; private set; } /// /// Item that gets added to the list when there are no recent calls in history /// CallHistoryEntry ListEmptyEntry; /// /// Initializes a new instance of the CodecCallHistory class /// 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()); } } /// /// RemoveEntry method /// public void RemoveEntry(CallHistoryEntry entry) { RecentCalls.Remove(entry); OnRecentCallsListChange(); } /// /// Represents a CallHistoryEntry /// public class CallHistoryEntry : CodecActiveCallItem { /// /// Gets or sets the StartTime /// [JsonConverter(typeof(IsoDateTimeConverter))] [JsonProperty("startTime")] public DateTime StartTime { get; set; } /// /// Gets or sets the occurrence type for this call history entry /// [JsonConverter(typeof(StringEnumConverter))] [JsonProperty("occurrenceType")] public eCodecOccurrenceType OccurrenceType { get; set; } /// /// Gets or sets the occurrence history identifier /// [JsonProperty("occurrenceHistoryId")] public string OccurrenceHistoryId { get; set; } } /// /// Converts a list of call history entries returned by a Cisco codec to the generic list type /// /// /// /// /// ConvertCiscoCallHistoryToGeneric method /// 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 /// /// /// /// ConvertToOccurenceTypeEnum method /// public eCodecOccurrenceType ConvertToOccurenceTypeEnum(string s) { switch (s) { case "Placed": { return eCodecOccurrenceType.Placed; } case "Received": { return eCodecOccurrenceType.Received; } case "NoAnswer": { return eCodecOccurrenceType.NoAnswer; } default: return eCodecOccurrenceType.Unknown; } } } }