updates to phonebook search methods

This commit is contained in:
Neil Dorin
2017-09-26 23:55:10 -06:00
parent a2d42dc77b
commit 33ceff861f
4 changed files with 391 additions and 148 deletions

View File

@@ -5,26 +5,22 @@ using System.Text;
using Crestron.SimplSharp; using Crestron.SimplSharp;
using PepperDash.Core; using PepperDash.Core;
using PepperDash.Essentials.Devices.Common.VideoCodec;
namespace PepperDash.Essentials.Devices.Common.Codec namespace PepperDash.Essentials.Devices.Common.Codec
{ {
public interface iHasDirectory public interface iHasDirectory
{ {
CodecDirectory Directory { get; } CodecDirectory DirectoryRoot { get; }
/// <summary> void SearchDirectory(string searchString);
/// Searches the directory and returns a result
/// </summary> void GetFolderContents(string folderId);
/// <param name="searchString"></param>
/// <param name="key"></param>
void SearchDirectory(string searchString, string key);
} }
public class CodecDirectory public class CodecDirectory
{ {
public List<DirectoryFolder> Folders {get; private set;} public List<DirectoryItem> DirectoryResults { get; private set; }
public List<DirectoryContact> Contacts { get; private set; }
public int Offset { get; private set; } public int Offset { get; private set; }
@@ -32,16 +28,57 @@ namespace PepperDash.Essentials.Devices.Common.Codec
public CodecDirectory() public CodecDirectory()
{ {
Folders = new List<DirectoryFolder>(); DirectoryResults = new List<DirectoryItem>();
Contacts = new List<DirectoryContact>(); }
public void AddFoldersToDirectory(List<DirectoryItem> folders)
{
DirectoryResults.AddRange(folders);
SortDirectory();
}
public void AddContactsToDirectory(List<DirectoryItem> contacts)
{
DirectoryResults.AddRange(contacts);
SortDirectory();
}
/// <summary>
/// Formats the DirectoryResults list to display all folders alphabetically, then all contacts alphabetically
/// </summary>
private void SortDirectory()
{
var sortedFolders = new List<DirectoryItem>();
sortedFolders.AddRange(DirectoryResults.Where(f => f is DirectoryFolder));
sortedFolders.OrderBy(f => f.Name);
var sortedContacts = new List<DirectoryItem>();
sortedContacts.AddRange(DirectoryResults.Where(c => c is DirectoryContact));
sortedFolders.OrderBy(c => c.Name);
DirectoryResults.Clear();
DirectoryResults.AddRange(sortedFolders);
DirectoryResults.AddRange(sortedContacts);
} }
} }
public class DirectoryFolder public class DirectoryItem
{
public string Name { get; set; }
}
public class DirectoryFolder : DirectoryItem
{ {
public List<DirectoryContact> Contacts { get; set; } public List<DirectoryContact> Contacts { get; set; }
public string FolderId { get; set; } public string FolderId { get; set; }
public string Name { get; set; }
public DirectoryFolder ParentFolder { get; set; } public DirectoryFolder ParentFolder { get; set; }
public DirectoryFolder() public DirectoryFolder()
@@ -51,11 +88,10 @@ namespace PepperDash.Essentials.Devices.Common.Codec
} }
} }
public class DirectoryContact public class DirectoryContact : DirectoryItem
{ {
public string ContactId { get; set; } public string ContactId { get; set; }
public DirectoryFolder Folder { get; set; } public string FolderId { get; set; }
public string Name { get; set; }
public string Title { get; set; } public string Title { get; set; }
public List<ContactMethod> ContactMethods { get; set; } public List<ContactMethod> ContactMethods { get; set; }
} }

View File

@@ -14,13 +14,16 @@ using PepperDash.Core;
using PepperDash.Essentials.Core; using PepperDash.Essentials.Core;
using PepperDash.Essentials.Core.Routing; using PepperDash.Essentials.Core.Routing;
using PepperDash.Essentials.Devices.Common.Codec; using PepperDash.Essentials.Devices.Common.Codec;
using PepperDash.Essentials.Devices.Common.VideoCodec;
namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco
{ {
enum eCommandType { SessionStart, SessionEnd, Command, GetStatus, GetConfiguration }; enum eCommandType { SessionStart, SessionEnd, Command, GetStatus, GetConfiguration };
public class CiscoCodec : VideoCodecBase, IHasCallHistory, iHasCallFavorites public class CiscoCodec : VideoCodecBase, IHasCallHistory, iHasCallFavorites, iHasDirectory
{ {
public event EventHandler<EventArgs> UpcomingMeetingWarning;
public IBasicCommunication Communication { get; private set; } public IBasicCommunication Communication { get; private set; }
public CommunicationGather PortGather { get; private set; } public CommunicationGather PortGather { get; private set; }
public CommunicationGather JsonGather { get; private set; } public CommunicationGather JsonGather { get; private set; }
@@ -43,13 +46,13 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco
private CiscoCodecStatus.RootObject CodecStatus; private CiscoCodecStatus.RootObject CodecStatus;
private CiscoCodecPhonebook.RootObject CodecPhonebook; //private CiscoCodecPhonebook.RootObject CodecPhonebook;
public CodecCallHistory CallHistory { get; private set; } public CodecCallHistory CallHistory { get; private set; }
public CodecCallFavorites CallFavorites { get; private set; } public CodecCallFavorites CallFavorites { get; private set; }
public CodecDirectory Directory { get; private set; } public CodecDirectory DirectoryRoot { get; private set; }
/// <summary> /// <summary>
/// Gets and returns the scaled volume of the codec /// Gets and returns the scaled volume of the codec
@@ -199,14 +202,13 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco
CodecConfiguration = new CiscoCodecConfiguration.RootObject(); CodecConfiguration = new CiscoCodecConfiguration.RootObject();
CodecStatus = new CiscoCodecStatus.RootObject(); CodecStatus = new CiscoCodecStatus.RootObject();
CodecPhonebook = new CiscoCodecPhonebook.RootObject();
CallHistory = new CodecCallHistory(); CallHistory = new CodecCallHistory();
CallFavorites = new CodecCallFavorites(); CallFavorites = new CodecCallFavorites();
CallFavorites.Favorites = props.Favorites; CallFavorites.Favorites = props.Favorites;
Directory = new CodecDirectory(); DirectoryRoot = new CodecDirectory();
//Set Feedback Actions //Set Feedback Actions
CodecStatus.Status.Audio.Volume.ValueChangedAction = VolumeLevelFeedback.FireUpdate; CodecStatus.Status.Audio.Volume.ValueChangedAction = VolumeLevelFeedback.FireUpdate;
@@ -268,7 +270,7 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco
// Get bookings for the day // Get bookings for the day
//SendText("xCommand Bookings List Days: 1 DayOffset: 0"); //SendText("xCommand Bookings List Days: 1 DayOffset: 0");
GetPhonebook(); GetPhonebookFolders();
} }
public void SetCommDebug(string s) public void SetCommDebug(string s)
@@ -512,20 +514,40 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco
} }
else if (response.IndexOf("\"PhonebookSearchResult\":{") > -1) else if (response.IndexOf("\"PhonebookSearchResult\":{") > -1)
{ {
JsonConvert.PopulateObject(response, CodecPhonebook); var codecPhonebook = new CiscoCodecPhonebook.RootObject();
if (!PhonebookSyncState.InitialPhonebookMessageWasReceived) if (!PhonebookSyncState.InitialPhonebookMessageWasReceived)
{ {
// Check if the phonebook has any folders
PhonebookSyncState.InitialPhonebookMessageReceived(); PhonebookSyncState.InitialPhonebookMessageReceived();
PhonebookSyncState.SetPhonebookHasFolders(CodecPhonebook.CommandResponse.PhonebookSearchResult.Folder.Count > 0); PhonebookSyncState.SetPhonebookHasFolders(codecPhonebook.CommandResponse.PhonebookSearchResult.Folder.Count > 0);
if (PhonebookSyncState.PhonebookHasFolders)
{
DirectoryRoot.AddFoldersToDirectory(CiscoCodecPhonebook.GetRootFoldersFromSearchResult(codecPhonebook.CommandResponse.PhonebookSearchResult));
}
// Get the number of contacts in the phonebook
GetPhonebookContacts();
} }
else if (!PhonebookSyncState.NumberOfContactsWasReceived)
Directory = CiscoCodecPhonebook.ConvertCiscoPhonebookToGeneric(CodecPhonebook.CommandResponse.PhonebookSearchResult);
if (Debug.Level > 1)
{ {
//Print phonebook contents // Store the total number of contacts in the phonebook
PhonebookSyncState.SetNumberOfContacts(Int32.Parse(codecPhonebook.CommandResponse.PhonebookSearchResult.ResultInfo.TotalRows.Value));
DirectoryRoot.AddContactsToDirectory(CiscoCodecPhonebook.GetRootContactsFromSearchResult(codecPhonebook.CommandResponse.PhonebookSearchResult));
}
else if (PhonebookSyncState.InitialSyncComplete)
{
JsonConvert.PopulateObject(response, codecPhonebook);
if (Debug.Level > 1)
{
//Print phonebook contents
}
// Fire some sort of callback delegate to the UI that requested the directory search results
} }
} }
else if (response.IndexOf("\"BookingsListResult\":{") > -1) else if (response.IndexOf("\"BookingsListResult\":{") > -1)
@@ -598,10 +620,34 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco
SendText("xCommand CallHistory Recents Limit: 20 Order: OccurrenceTime"); SendText("xCommand CallHistory Recents Limit: 20 Order: OccurrenceTime");
} }
private void GetPhonebook() private void GetPhonebookFolders()
{ {
// Get Phonebook Folders (determine local/corporate from config, and set results limit) // Get Phonebook Folders (determine local/corporate from config, and set results limit)
SendText(string.Format("xCommand Phonebook Search PhonebookType: {0} ContactType: Folder Limit: {1}", PhonebookMode, PhonebookResultsLimit)); SendText(string.Format("xCommand Phonebook Search PhonebookType: {0} ContactType: Folder", PhonebookMode));
}
private void GetPhonebookContacts()
{
// Get Phonebook Folders (determine local/corporate from config, and set results limit)
SendText(string.Format("xCommand Phonebook Search PhonebookType: {0} ContactType: Contact", PhonebookMode));
}
/// <summary>
/// Searches the codec phonebook for all contacts matching the search string
/// </summary>
/// <param name="searchString"></param>
public void SearchDirectory(string searchString)
{
SendText(string.Format("xCommand Phonebook Search SearchString: \"{0}\" PhonebookType: {1} ContactType: Contact, Limit: {2}", searchString, PhonebookMode, PhonebookResultsLimit));
}
/// <summary>
/// // Get contents of a specific folder in the phonebook
/// </summary>
/// <param name="folderId"></param>
public void GetFolderContents(string folderId)
{
SendText(string.Format("xCommand Phonebook Search FolderId: {0} PhonebookType: {1} ContactType: Contact, Limit: {2}", folderId, PhonebookMode, PhonebookResultsLimit));
} }
public override void Dial(string s) public override void Dial(string s)
@@ -857,14 +903,41 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco
} }
} }
/// <summary>
/// Used to track the status of syncronizing the phonebook values when connecting to a codec or refreshing the phonebook info
/// </summary>
public class CodecPhonebookSyncState : IKeyed public class CodecPhonebookSyncState : IKeyed
{ {
bool _InitialSyncComplete;
public event EventHandler<EventArgs> InitialSyncCompleted;
public string Key { get; private set; } public string Key { get; private set; }
public bool InitialSyncComplete
{
get { return _InitialSyncComplete; }
private set
{
if (value == true)
{
var handler = InitialSyncCompleted;
if (handler != null)
handler(this, new EventArgs());
}
_InitialSyncComplete = value;
}
}
public bool InitialPhonebookMessageWasReceived { get; private set; } public bool InitialPhonebookMessageWasReceived { get; private set; }
public bool NumberOfContactsWasReceived { get; private set; }
public bool PhonebookHasFolders { get; private set; } public bool PhonebookHasFolders { get; private set; }
public int NumberOfContacts { get; private set; }
public CodecPhonebookSyncState(string key) public CodecPhonebookSyncState(string key)
{ {
Key = key; Key = key;
@@ -880,12 +953,24 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco
public void SetPhonebookHasFolders(bool value) public void SetPhonebookHasFolders(bool value)
{ {
PhonebookHasFolders = value; PhonebookHasFolders = value;
Debug.Console(1, this, "Phonebook has folders: {0}", PhonebookHasFolders);
}
public void SetNumberOfContacts(int contacts)
{
NumberOfContacts = contacts;
NumberOfContactsWasReceived = true;
Debug.Console(1, this, "Phonebook contains {0} contacts.", NumberOfContacts);
} }
public void CodecDisconnected() public void CodecDisconnected()
{ {
InitialPhonebookMessageWasReceived = false; InitialPhonebookMessageWasReceived = false;
PhonebookHasFolders = false; PhonebookHasFolders = false;
NumberOfContacts = 0;
NumberOfContactsWasReceived = false;
} }
} }

View File

@@ -147,6 +147,122 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec
} }
/// <summary>
/// Extracts the folders with no ParentFolder and returns them sorted alphabetically
/// </summary>
/// <param name="result"></param>
/// <returns></returns>
public static List<DirectoryItem> GetRootFoldersFromSearchResult(PhonebookSearchResult result)
{
var rootFolders = new List<DirectoryItem>();
if (result.Folder.Count > 0)
{
return null;
}
else if (result.Folder.Count > 0)
{
if (Debug.Level > 1)
Debug.Console(1, "Phonebook Folders:\n");
foreach (Folder f in result.Folder)
{
var folder = new DirectoryFolder();
folder.Name = f.Name.Value;
folder.FolderId = f.FolderId.Value;
if (f.ParentFolderId == null)
rootFolders.Add(folder);
if (Debug.Level > 1)
Debug.Console(1, "+ {0}", folder.Name);
}
}
rootFolders.OrderBy(f => f.Name);
return rootFolders;
}
public static List<DirectoryItem> GetRootContactsFromSearchResult(PhonebookSearchResult result)
{
var rootContacts = new List<DirectoryItem>();
if (result.Contact.Count == 0)
{
return null;
}
else if (result.Contact.Count > 0)
{
if (Debug.Level > 1)
Debug.Console(1, "Root Contacts:\n");
foreach (Contact c in result.Contact)
{
var contact = new DirectoryContact();
if (c.FolderId == null)
{
contact.Name = c.Name.Value;
contact.ContactId = c.ContactId.Value;
contact.Title = c.Title.Value;
contact.FolderId = c.FolderId.Value;
if (Debug.Level == 1)
Debug.Console(1, "{0}\nContact Methods:", contact.Name);
foreach (ContactMethod m in c.ContactMethod)
{
eContactMethodCallType callType = eContactMethodCallType.Unknown;
if (m.CallType != null)
{
if (m.CallType.Value.ToLower() == "audio")
callType = eContactMethodCallType.Audio;
else if (m.CallType.Value.ToLower() == "video")
callType = eContactMethodCallType.Video;
}
eContactMethodDevice device = eContactMethodDevice.Unknown;
if (m.Device.Value.ToLower() == "mobile")
device = eContactMethodDevice.Mobile;
else if (m.Device.Value.ToLower() == "telephone")
device = eContactMethodDevice.Telephone;
else if (m.Device.Value.ToLower() == "video")
device = eContactMethodDevice.Video;
else if (m.Device.Value.ToLower() == "other")
device = eContactMethodDevice.Other;
if (Debug.Level > 1)
Debug.Console(1, "Number: {0} CallType: {1} Device: {2}", m.Number.Value, callType, device);
contact.ContactMethods.Add(new PepperDash.Essentials.Devices.Common.Codec.ContactMethod()
{
Number = m.Number.Value,
ContactMethodId = m.ContactMethodId.Value,
CallType = callType,
Device = device
});
}
rootContacts.Add(contact);
}
if (Debug.Level == 1)
Debug.Console(1, "{0}", contact.Name);
}
}
rootContacts.OrderBy(f => f.Name);
return rootContacts;
}
/// <summary> /// <summary>
/// Converts data returned from a cisco codec to the generic Directory format. /// Converts data returned from a cisco codec to the generic Directory format.
/// </summary> /// </summary>
@@ -154,8 +270,14 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec
/// <returns></returns> /// <returns></returns>
public static CodecDirectory ConvertCiscoPhonebookToGeneric(PhonebookSearchResult result) public static CodecDirectory ConvertCiscoPhonebookToGeneric(PhonebookSearchResult result)
{ {
#warning Modify this to return a flat list of mixed folders/contacts
var directory = new Codec.CodecDirectory(); var directory = new Codec.CodecDirectory();
var folders = new List<Codec.DirectoryFolder>();
var contacts = new List<Codec.DirectoryContact>();
if (result.Folder.Count > 0) if (result.Folder.Count > 0)
{ {
foreach (Folder f in result.Folder) foreach (Folder f in result.Folder)
@@ -167,11 +289,11 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec
if (f.ParentFolderId != null) if (f.ParentFolderId != null)
{ {
//
folder.ParentFolder = directory.Folders.FirstOrDefault(fld => fld.FolderId.Equals(f.ParentFolderId.Value)); folder.ParentFolder = folders.FirstOrDefault(fld => fld.FolderId.Equals(f.ParentFolderId.Value));
} }
directory.Folders.Add(folder); folders.Add(folder);
} }
} }
@@ -188,7 +310,7 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec
// Go find the folder to which this contact belongs and store it // Go find the folder to which this contact belongs and store it
if(!string.IsNullOrEmpty(c.FolderId.Value)) if(!string.IsNullOrEmpty(c.FolderId.Value))
{ {
contact.Folder = directory.Folders.FirstOrDefault(f => f.FolderId.Equals(c.FolderId.Value)); //contact.Folder = directory.Folders.FirstOrDefault(f => f.FolderId.Equals(c.FolderId.Value));
} }
foreach (ContactMethod m in c.ContactMethod) foreach (ContactMethod m in c.ContactMethod)
@@ -221,7 +343,7 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec
Device = device Device = device
}); });
} }
directory.Contacts.Add(contact); //directory.Contacts.Add(contact);
} }
} }