From a2d42dc77b4380ff63779640bdadac50cd50d23f Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Tue, 26 Sep 2017 09:17:47 -0600 Subject: [PATCH] Added booking class and phonebook sync logic --- .../Essentials Devices Common.csproj | 1 + .../CiscoCodec/BookingsDataClasses.cs | 229 ++++++++++++++++++ .../VideoCodec/CiscoCodec/CiscoCodec.cs | 59 ++++- 3 files changed, 287 insertions(+), 2 deletions(-) create mode 100644 Essentials Devices Common/Essentials Devices Common/VideoCodec/CiscoCodec/BookingsDataClasses.cs diff --git a/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj b/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj index a48d5e9e..fd3d52e6 100644 --- a/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj +++ b/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj @@ -135,6 +135,7 @@ + diff --git a/Essentials Devices Common/Essentials Devices Common/VideoCodec/CiscoCodec/BookingsDataClasses.cs b/Essentials Devices Common/Essentials Devices Common/VideoCodec/CiscoCodec/BookingsDataClasses.cs new file mode 100644 index 00000000..429119b6 --- /dev/null +++ b/Essentials Devices Common/Essentials Devices Common/VideoCodec/CiscoCodec/BookingsDataClasses.cs @@ -0,0 +1,229 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; + +namespace PepperDash.Essentials.Devices.Common.VideoCodec +{ + public class CiscoCodecBookings + { + public class TotalRows + { + public string Value { get; set; } + } + + public class ResultInfo + { + public TotalRows TotalRows { get; set; } + } + + public class LastUpdated + { + public DateTime Value { get; set; } + } + + public class Id + { + public string Value { get; set; } + } + + public class Title + { + public string Value { get; set; } + } + + public class Agenda + { + public string Value { get; set; } + } + + public class Privacy + { + public string Value { get; set; } + } + + public class FirstName + { + public string Value { get; set; } + } + + public class LastName + { + public string Value { get; set; } + } + + public class Email + { + public string Value { get; set; } + } + + public class Id2 + { + public string Value { get; set; } + } + + public class Organizer + { + public FirstName FirstName { get; set; } + public LastName LastName { get; set; } + public Email Email { get; set; } + public Id2 Id { get; set; } + } + + public class StartTime + { + public DateTime Value { get; set; } + } + + public class StartTimeBuffer + { + public string Value { get; set; } + } + + public class EndTime + { + public DateTime Value { get; set; } + } + + public class EndTimeBuffer + { + public string Value { get; set; } + } + + public class Time + { + public StartTime StartTime { get; set; } + public StartTimeBuffer StartTimeBuffer { get; set; } + public EndTime EndTime { get; set; } + public EndTimeBuffer EndTimeBuffer { get; set; } + } + + public class MaximumMeetingExtension + { + public string Value { get; set; } + } + + public class MeetingExtensionAvailability + { + public string Value { get; set; } + } + + public class BookingStatus + { + public string Value { get; set; } + } + + public class BookingStatusMessage + { + public string Value { get; set; } + } + + public class Enabled + { + public string Value { get; set; } + } + + public class Url + { + public string Value { get; set; } + } + + public class MeetingNumber + { + public string Value { get; set; } + } + + public class Password + { + public string Value { get; set; } + } + + public class HostKey + { + public string Value { get; set; } + } + + public class DialInNumbers + { + } + + public class Webex + { + public Enabled Enabled { get; set; } + public Url Url { get; set; } + public MeetingNumber MeetingNumber { get; set; } + public Password Password { get; set; } + public HostKey HostKey { get; set; } + public DialInNumbers DialInNumbers { get; set; } + } + + public class Encryption + { + public string Value { get; set; } + } + + public class Role + { + public string Value { get; set; } + } + + public class Recording + { + public string Value { get; set; } + } + + public class Calls + { + } + + public class ConnectMode + { + public string Value { get; set; } + } + + public class DialInfo + { + public Calls Calls { get; set; } + public ConnectMode ConnectMode { get; set; } + } + + public class Booking + { + public string id { get; set; } + public Id Id { get; set; } + public Title Title { get; set; } + public Agenda Agenda { get; set; } + public Privacy Privacy { get; set; } + public Organizer Organizer { get; set; } + public Time Time { get; set; } + public MaximumMeetingExtension MaximumMeetingExtension { get; set; } + public MeetingExtensionAvailability MeetingExtensionAvailability { get; set; } + public BookingStatus BookingStatus { get; set; } + public BookingStatusMessage BookingStatusMessage { get; set; } + public Webex Webex { get; set; } + public Encryption Encryption { get; set; } + public Role Role { get; set; } + public Recording Recording { get; set; } + public DialInfo DialInfo { get; set; } + } + + public class BookingsListResult + { + public string status { get; set; } + public ResultInfo ResultInfo { get; set; } + public LastUpdated LastUpdated { get; set; } + public List Booking { get; set; } + } + + public class CommandResponse + { + public BookingsListResult BookingsListResult { get; set; } + } + + public class RootObject + { + public CommandResponse CommandResponse { get; set; } + } + } +} \ No newline at end of file diff --git a/Essentials Devices Common/Essentials Devices Common/VideoCodec/CiscoCodec/CiscoCodec.cs b/Essentials Devices Common/Essentials Devices Common/VideoCodec/CiscoCodec/CiscoCodec.cs index d3221457..43687cee 100644 --- a/Essentials Devices Common/Essentials Devices Common/VideoCodec/CiscoCodec/CiscoCodec.cs +++ b/Essentials Devices Common/Essentials Devices Common/VideoCodec/CiscoCodec/CiscoCodec.cs @@ -143,6 +143,8 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco private CodecSyncState SyncState; + private CodecPhonebookSyncState PhonebookSyncState; + private StringBuilder JsonMessage; private bool JsonFeedbackMessageIsIncoming; @@ -181,7 +183,9 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco PhonebookMode = props.PhonebookMode; - SyncState = new CodecSyncState(key + "--sync"); + SyncState = new CodecSyncState(key + "--Sync"); + + PhonebookSyncState = new CodecPhonebookSyncState(key + "--PhonebookSync"); SyncState.InitialSyncCompleted += new EventHandler(SyncState_InitialSyncCompleted); @@ -284,7 +288,10 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco void socket_ConnectionChange(object sender, GenericSocketStatusChageEventArgs e) { if (!e.Client.IsConnected) + { SyncState.CodecDisconnected(); + PhonebookSyncState.CodecDisconnected(); + } } /// @@ -507,6 +514,13 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco { JsonConvert.PopulateObject(response, CodecPhonebook); + if (!PhonebookSyncState.InitialPhonebookMessageWasReceived) + { + PhonebookSyncState.InitialPhonebookMessageReceived(); + + PhonebookSyncState.SetPhonebookHasFolders(CodecPhonebook.CommandResponse.PhonebookSearchResult.Folder.Count > 0); + } + Directory = CiscoCodecPhonebook.ConvertCiscoPhonebookToGeneric(CodecPhonebook.CommandResponse.PhonebookSearchResult); if (Debug.Level > 1) @@ -514,6 +528,14 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco //Print phonebook contents } } + else if (response.IndexOf("\"BookingsListResult\":{") > -1) + { + var codecBookings = new CiscoCodecBookings.RootObject(); + + JsonConvert.PopulateObject(response, codecBookings); + + // Do something with this data.... + } } @@ -578,7 +600,7 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco private void GetPhonebook() { - // Get Phonebook (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)); } @@ -834,4 +856,37 @@ namespace PepperDash.Essentials.Devices.Common.VideoCodec.Cisco InitialSyncComplete = false; } } + + public class CodecPhonebookSyncState : IKeyed + { + public string Key { get; private set; } + + public bool InitialPhonebookMessageWasReceived { get; private set; } + + public bool PhonebookHasFolders { get; private set; } + + public CodecPhonebookSyncState(string key) + { + Key = key; + + CodecDisconnected(); + } + + public void InitialPhonebookMessageReceived() + { + InitialPhonebookMessageWasReceived = true; + } + + public void SetPhonebookHasFolders(bool value) + { + PhonebookHasFolders = value; + } + + public void CodecDisconnected() + { + InitialPhonebookMessageWasReceived = false; + PhonebookHasFolders = false; + } + + } } \ No newline at end of file