using System; using System.Collections.Generic; using System.Linq; using System.Text; using Crestron.SimplSharp; using Crestron.SimplSharpPro.Fusion; using PepperDash.Core; using Serilog.Events; namespace PepperDash.Essentials.Core.Fusion { // Helper Classes for GUIDs /// /// Stores GUIDs to be written to a file in NVRAM /// public class FusionRoomGuids { public string RoomName { get; set; } public uint IpId { get; set; } public string RoomGuid { get; set; } public FusionOccupancySensorAsset OccupancyAsset { get; set; } public Dictionary StaticAssets { get; set; } public FusionRoomGuids() { StaticAssets = new Dictionary(); OccupancyAsset = new FusionOccupancySensorAsset(); } public FusionRoomGuids(string roomName, uint ipId, string roomGuid, Dictionary staticAssets) { RoomName = roomName; IpId = ipId; RoomGuid = roomGuid; StaticAssets = staticAssets; OccupancyAsset = new FusionOccupancySensorAsset(); } public FusionRoomGuids(string roomName, uint ipId, string roomGuid, Dictionary staticAssets, FusionOccupancySensorAsset occAsset) { RoomName = roomName; IpId = ipId; RoomGuid = roomGuid; StaticAssets = staticAssets; OccupancyAsset = occAsset; } /// /// Generates a new room GUID prefixed by the program slot number and NIC MAC address /// /// /// /// /// GenerateNewRoomGuid method /// public string GenerateNewRoomGuid(uint progSlot, string mac) { Guid roomGuid = Guid.NewGuid(); return string.Format("{0}-{1}-{2}", progSlot, mac, roomGuid.ToString()); } /// /// Adds an asset to the StaticAssets collection and returns the new asset /// /// /// /// /// /// /// public FusionAsset AddStaticAsset(FusionRoom room, int uid, string assetName, string type, string instanceId) { var slotNum = GetNextAvailableAssetNumber(room); Debug.LogMessage(LogEventLevel.Verbose, "Adding Fusion Asset: {0} of Type: {1} at Slot Number: {2} with GUID: {3}", assetName, type, slotNum, instanceId); var tempAsset = new FusionAsset(slotNum, assetName, type, instanceId); StaticAssets.Add(uid, tempAsset); return tempAsset; } /// /// Returns the next available slot number in the Fusion UserConfigurableAssetDetails collection /// /// /// /// /// GetNextAvailableAssetNumber method /// public static uint GetNextAvailableAssetNumber(FusionRoom room) { uint slotNum = 0; foreach (var item in room.UserConfigurableAssetDetails) { if(item.Number > slotNum) slotNum = item.Number; } if (slotNum < 5) { slotNum = 5; } else slotNum = slotNum + 1; Debug.LogMessage(LogEventLevel.Verbose, "#Next available fusion asset number is: {0}", slotNum); return slotNum; } } /// /// Represents a FusionOccupancySensorAsset /// public class FusionOccupancySensorAsset { // SlotNumber fixed at 4 /// /// Gets or sets the SlotNumber /// public uint SlotNumber { get { return 4; } } /// /// Gets or sets the Name /// public string Name { get { return "Occupancy Sensor"; } } /// /// Gets or sets the Type /// public eAssetType Type { get; set; } /// /// Gets or sets the InstanceId /// public string InstanceId { get; set; } public FusionOccupancySensorAsset() { } public FusionOccupancySensorAsset(eAssetType type) { Type = type; InstanceId = Guid.NewGuid().ToString(); } } /// /// Represents a FusionAsset /// public class FusionAsset { /// /// Gets or sets the SlotNumber /// public uint SlotNumber { get; set; } /// /// Gets or sets the Name /// public string Name { get; set; } /// /// Gets or sets the Type /// public string Type { get; set; } /// /// Gets or sets the InstanceId /// public string InstanceId { get;set; } public FusionAsset() { } public FusionAsset(uint slotNum, string assetName, string type, string instanceId) { SlotNumber = slotNum; Name = assetName; Type = type; if (string.IsNullOrEmpty(instanceId)) { InstanceId = Guid.NewGuid().ToString(); } else { InstanceId = instanceId; } } } //*************************************************************************************************** /// /// Represents a RoomSchedule /// public class RoomSchedule { /// /// Gets or sets the Meetings /// public List Meetings { get; set; } public RoomSchedule() { Meetings = new List(); } } //**************************************************************************************************** // Helper Classes for XML API /// /// Represents a LocalTimeRequest /// public class LocalTimeRequest { public string RequestID { get; set; } } /// /// All the data needed for a full schedule request in a room /// /// //[XmlRoot(ElementName = "RequestSchedule")] public class RequestSchedule { //[XmlElement(ElementName = "RequestID")] /// /// Gets or sets the RequestID /// public string RequestID { get; set; } //[XmlElement(ElementName = "RoomID")] public string RoomID { get; set; } //[XmlElement(ElementName = "Start")] public DateTime Start { get; set; } //[XmlElement(ElementName = "HourSpan")] public double HourSpan { get; set; } public RequestSchedule(string requestID, string roomID) { RequestID = requestID; RoomID = roomID; Start = DateTime.Now; HourSpan = 24; } } //[XmlRoot(ElementName = "RequestAction")] /// /// Represents a RequestAction /// public class RequestAction { //[XmlElement(ElementName = "RequestID")] /// /// Gets or sets the RequestID /// public string RequestID { get; set; } //[XmlElement(ElementName = "RoomID")] /// /// Gets or sets the RoomID /// public string RoomID { get; set; } //[XmlElement(ElementName = "ActionID")] /// /// Gets or sets the ActionID /// public string ActionID { get; set; } //[XmlElement(ElementName = "Parameters")] /// /// Gets or sets the Parameters /// public List Parameters { get; set; } public RequestAction(string roomID, string actionID, List parameters) { RoomID = roomID; ActionID = actionID; Parameters = parameters; } } //[XmlRoot(ElementName = "ActionResponse")] /// /// Represents a ActionResponse /// public class ActionResponse { //[XmlElement(ElementName = "RequestID")] /// /// Gets or sets the RequestID /// public string RequestID { get; set; } //[XmlElement(ElementName = "ActionID")] /// /// Gets or sets the ActionID /// public string ActionID { get; set; } //[XmlElement(ElementName = "Parameters")] /// /// Gets or sets the Parameters /// public List Parameters { get; set; } } //[XmlRoot(ElementName = "Parameter")] /// /// Represents a Parameter /// public class Parameter { //[XmlAttribute(AttributeName = "ID")] /// /// Gets or sets the ID /// public string ID { get; set; } //[XmlAttribute(AttributeName = "Value")] /// /// Gets or sets the Value /// public string Value { get; set; } } ////[XmlRoot(ElementName = "Parameters")] //public class Parameters //{ // //[XmlElement(ElementName = "Parameter")] // public List Parameter { get; set; } //} /// /// Data structure for a ScheduleResponse from Fusion /// /// //[XmlRoot(ElementName = "ScheduleResponse")] public class ScheduleResponse { //[XmlElement(ElementName = "RequestID")] public string RequestID { get; set; } //[XmlElement(ElementName = "RoomID")] public string RoomID { get; set; } //[XmlElement(ElementName = "RoomName")] public string RoomName { get; set; } //[XmlElement("Event")] public List Events { get; set; } public ScheduleResponse() { Events = new List(); } } //[XmlRoot(ElementName = "Event")] /// /// Represents a Event /// public class Event { //[XmlElement(ElementName = "MeetingID")] /// /// Gets or sets the MeetingID /// public string MeetingID { get; set; } //[XmlElement(ElementName = "RVMeetingID")] /// /// Gets or sets the RVMeetingID /// public string RVMeetingID { get; set; } //[XmlElement(ElementName = "Recurring")] /// /// Gets or sets the Recurring /// public string Recurring { get; set; } //[XmlElement(ElementName = "InstanceID")] /// /// Gets or sets the InstanceID /// public string InstanceID { get; set; } //[XmlElement(ElementName = "dtStart")] /// /// Gets or sets the dtStart /// public DateTime dtStart { get; set; } //[XmlElement(ElementName = "dtEnd")] /// /// Gets or sets the dtEnd /// public DateTime dtEnd { get; set; } //[XmlElement(ElementName = "Organizer")] /// /// Gets or sets the Organizer /// public string Organizer { get; set; } //[XmlElement(ElementName = "Attendees")] /// /// Gets or sets the Attendees /// public Attendees Attendees { get; set; } //[XmlElement(ElementName = "Resources")] /// /// Gets or sets the Resources /// public Resources Resources { get; set; } //[XmlElement(ElementName = "IsEvent")] /// /// Gets or sets the IsEvent /// public string IsEvent { get; set; } //[XmlElement(ElementName = "IsRoomViewMeeting")] /// /// Gets or sets the IsRoomViewMeeting /// public string IsRoomViewMeeting { get; set; } //[XmlElement(ElementName = "IsPrivate")] /// /// Gets or sets the IsPrivate /// public string IsPrivate { get; set; } //[XmlElement(ElementName = "IsExchangePrivate")] /// /// Gets or sets the IsExchangePrivate /// public string IsExchangePrivate { get; set; } //[XmlElement(ElementName = "MeetingTypes")] /// /// Gets or sets the MeetingTypes /// public MeetingTypes MeetingTypes { get; set; } //[XmlElement(ElementName = "ParticipantCode")] /// /// Gets or sets the ParticipantCode /// public string ParticipantCode { get; set; } //[XmlElement(ElementName = "PhoneNo")] /// /// Gets or sets the PhoneNo /// public string PhoneNo { get; set; } //[XmlElement(ElementName = "WelcomeMsg")] /// /// Gets or sets the WelcomeMsg /// public string WelcomeMsg { get; set; } //[XmlElement(ElementName = "Subject")] /// /// Gets or sets the Subject /// public string Subject { get; set; } //[XmlElement(ElementName = "LiveMeeting")] /// /// Gets or sets the LiveMeeting /// public LiveMeeting LiveMeeting { get; set; } //[XmlElement(ElementName = "ShareDocPath")] /// /// Gets or sets the ShareDocPath /// public string ShareDocPath { get; set; } //[XmlElement(ElementName = "HaveAttendees")] /// /// Gets or sets the HaveAttendees /// public string HaveAttendees { get; set; } //[XmlElement(ElementName = "HaveResources")] /// /// Gets or sets the HaveResources /// public string HaveResources { get; set; } /// /// Gets the duration of the meeting /// public string DurationInMinutes { get { string duration; var timeSpan = dtEnd.Subtract(dtStart); int hours = timeSpan.Hours; double minutes = timeSpan.Minutes; double roundedMinutes = Math.Round(minutes); if (hours > 0) { duration = string.Format("{0} hours {1} minutes", hours, roundedMinutes); } else { duration = string.Format("{0} minutes", roundedMinutes); } return duration; } } /// /// Gets the remaining time in the meeting. Returns null if the meeting is not currently in progress. /// public string RemainingTime { get { var now = DateTime.Now; string remainingTime; if (GetInProgress()) { var timeSpan = dtEnd.Subtract(now); int hours = timeSpan.Hours; double minutes = timeSpan.Minutes; double roundedMinutes = Math.Round(minutes); if (hours > 0) { remainingTime = string.Format("{0} hours {1} minutes", hours, roundedMinutes); } else { remainingTime = string.Format("{0} minutes", roundedMinutes); } return remainingTime; } else return null; } } /// /// Indicates that the meeting is in progress /// public bool isInProgress { get { return GetInProgress(); } } /// /// Determines if the meeting is in progress /// /// Returns true if in progress bool GetInProgress() { var now = DateTime.Now; if (now > dtStart && now < dtEnd) { return true; } else return false; } } //[XmlRoot(ElementName = "Resources")] /// /// Represents a Resources /// public class Resources { //[XmlElement(ElementName = "Rooms")] /// /// Gets or sets the Rooms /// public Rooms Rooms { get; set; } } //[XmlRoot(ElementName = "Rooms")] /// /// Represents a Rooms /// public class Rooms { //[XmlElement(ElementName = "Room")] /// /// Gets or sets the Room /// public List Room { get; set; } } //[XmlRoot(ElementName = "Room")] /// /// Represents a Room /// public class Room { //[XmlElement(ElementName = "Name")] /// /// Gets or sets the Name /// public string Name { get; set; } //[XmlElement(ElementName = "ID")] /// /// Gets or sets the ID /// public string ID { get; set; } //[XmlElement(ElementName = "MPType")] /// /// Gets or sets the MPType /// public string MPType { get; set; } } //[XmlRoot(ElementName = "Attendees")] /// /// Represents a Attendees /// public class Attendees { //[XmlElement(ElementName = "Required")] /// /// Gets or sets the Required /// public Required Required { get; set; } //[XmlElement(ElementName = "Optional")] /// /// Gets or sets the Optional /// public Optional Optional { get; set; } } //[XmlRoot(ElementName = "Required")] /// /// Represents a Required /// public class Required { //[XmlElement(ElementName = "Attendee")] /// /// Gets or sets the Attendee /// public List Attendee { get; set; } } //[XmlRoot(ElementName = "Optional")] /// /// Represents a Optional /// public class Optional { //[XmlElement(ElementName = "Attendee")] /// /// Gets or sets the Attendee /// public List Attendee { get; set; } } //[XmlRoot(ElementName = "MeetingType")] /// /// Represents a MeetingType /// public class MeetingType { //[XmlAttribute(AttributeName = "ID")] /// /// Gets or sets the ID /// public string ID { get; set; } //[XmlAttribute(AttributeName = "Value")] /// /// Gets or sets the Value /// public string Value { get; set; } } //[XmlRoot(ElementName = "MeetingTypes")] /// /// Represents a MeetingTypes /// public class MeetingTypes { //[XmlElement(ElementName = "MeetingType")] /// /// Gets or sets the MeetingType /// public List MeetingType { get; set; } } //[XmlRoot(ElementName = "LiveMeeting")] /// /// Represents a LiveMeeting /// public class LiveMeeting { //[XmlElement(ElementName = "URL")] /// /// Gets or sets the URL /// public string URL { get; set; } //[XmlElement(ElementName = "ID")] /// /// Gets or sets the ID /// public string ID { get; set; } //[XmlElement(ElementName = "Key")] /// /// Gets or sets the Key /// public string Key { get; set; } //[XmlElement(ElementName = "Subject")] /// /// Gets or sets the Subject /// public string Subject { get; set; } } //[XmlRoot(ElementName = "LiveMeetingURL")] /// /// Represents a LiveMeetingURL /// public class LiveMeetingURL { //[XmlElement(ElementName = "LiveMeeting")] /// /// Gets or sets the LiveMeeting /// public LiveMeeting LiveMeeting { get; set; } } }