chore: move all files to file-scoped namespace

This commit is contained in:
Andrew Welker 2025-07-04 16:02:32 -05:00 committed by Neil Dorin
parent aaa5b0532b
commit 3ece4f0b7b
522 changed files with 39628 additions and 45678 deletions

View file

@ -4,117 +4,96 @@ using System.Linq;
using PepperDash.Essentials.Core;
using PepperDash.Essentials.Devices.Common.Codec;
namespace PepperDash.Essentials.Devices.Common.AudioCodec
namespace PepperDash.Essentials.Devices.Common.AudioCodec;
public abstract class AudioCodecBase : EssentialsDevice, IHasDialer, IUsageTracking, IAudioCodecInfo
{
public event EventHandler<CodecCallStatusItemChangeEventArgs> CallStatusChange;
public AudioCodecInfo CodecInfo { get; protected set; }
#region IUsageTracking Members
/// <summary>
/// Abstract base class for audio codec devices
/// This object can be added by outside users of this class to provide usage tracking
/// for various services
/// </summary>
public abstract class AudioCodecBase : EssentialsDevice, IHasDialer, IUsageTracking, IAudioCodecInfo
public UsageTracking UsageTracker { get; set; }
#endregion
/// <summary>
/// Returns true when any call is not in state Unknown, Disconnecting, Disconnected
/// </summary>
public bool IsInCall
{
/// <summary>
/// Event fired when call status changes
/// </summary>
public event EventHandler<CodecCallStatusItemChangeEventArgs> CallStatusChange;
/// <summary>
/// Gets or sets the CodecInfo
/// </summary>
public AudioCodecInfo CodecInfo { get; protected set; }
#region IUsageTracking Members
/// <summary>
/// Gets or sets the UsageTracker
/// </summary>
public UsageTracking UsageTracker { get; set; }
#endregion
/// <summary>
/// Returns true when any call is not in state Unknown, Disconnecting, Disconnected
/// </summary>
public bool IsInCall
get
{
get
{
bool value;
bool value;
if (ActiveCalls != null)
value = ActiveCalls.Any(c => c.IsActiveCall);
else
value = false;
return value;
}
if (ActiveCalls != null)
value = ActiveCalls.Any(c => c.IsActiveCall);
else
value = false;
return value;
}
// In most cases only a single call can be active
/// <summary>
/// Gets or sets the ActiveCalls
/// </summary>
public List<CodecActiveCallItem> ActiveCalls { get; set; }
/// <summary>
/// Constructor for AudioCodecBase
/// </summary>
/// <param name="key">Device key</param>
/// <param name="name">Device name</param>
public AudioCodecBase(string key, string name)
: base(key, name)
{
ActiveCalls = new List<CodecActiveCallItem>();
}
/// <summary>
/// Helper method to fire CallStatusChange event with old and new status
/// </summary>
protected void SetNewCallStatusAndFireCallStatusChange(eCodecCallStatus newStatus, CodecActiveCallItem call)
{
call.Status = newStatus;
OnCallStatusChange(call);
}
/// <summary>
/// Handles call status change events
/// </summary>
/// <param name="item">The call item that changed status</param>
protected void OnCallStatusChange(CodecActiveCallItem item)
{
var handler = CallStatusChange;
if (handler != null)
handler(this, new CodecCallStatusItemChangeEventArgs(item));
if (UsageTracker != null)
{
if (IsInCall && !UsageTracker.UsageTrackingStarted)
UsageTracker.StartDeviceUsage();
else if (UsageTracker.UsageTrackingStarted && !IsInCall)
UsageTracker.EndDeviceUsage();
}
}
#region IHasDialer Members
/// <inheritdoc />
public abstract void Dial(string number);
/// <inheritdoc />
public abstract void EndCall(CodecActiveCallItem activeCall);
/// <inheritdoc />
public abstract void EndAllCalls();
/// <inheritdoc />
public abstract void AcceptCall(CodecActiveCallItem item);
/// <inheritdoc />
public abstract void RejectCall(CodecActiveCallItem item);
/// <inheritdoc />
public abstract void SendDtmf(string digit);
#endregion
}
// In most cases only a single call can be active
public List<CodecActiveCallItem> ActiveCalls { get; set; }
public AudioCodecBase(string key, string name)
: base(key, name)
{
ActiveCalls = new List<CodecActiveCallItem>();
}
/// <summary>
/// Helper method to fire CallStatusChange event with old and new status
/// </summary>
protected void SetNewCallStatusAndFireCallStatusChange(eCodecCallStatus newStatus, CodecActiveCallItem call)
{
call.Status = newStatus;
OnCallStatusChange(call);
}
/// <summary>
///
/// </summary>
/// <param name="previousStatus"></param>
/// <param name="newStatus"></param>
/// <param name="item"></param>
protected void OnCallStatusChange(CodecActiveCallItem item)
{
var handler = CallStatusChange;
if (handler != null)
handler(this, new CodecCallStatusItemChangeEventArgs(item));
if (UsageTracker != null)
{
if (IsInCall && !UsageTracker.UsageTrackingStarted)
UsageTracker.StartDeviceUsage();
else if (UsageTracker.UsageTrackingStarted && !IsInCall)
UsageTracker.EndDeviceUsage();
}
}
#region IHasDialer Members
public abstract void Dial(string number);
public abstract void EndCall(CodecActiveCallItem activeCall);
public abstract void EndAllCalls();
public abstract void AcceptCall(CodecActiveCallItem item);
public abstract void RejectCall(CodecActiveCallItem item);
public abstract void SendDtmf(string digit);
#endregion
}

View file

@ -1,24 +1,18 @@
namespace PepperDash.Essentials.Devices.Common.AudioCodec
{
/// <summary>
/// Implements a common set of data about a codec
/// </summary>
public interface IAudioCodecInfo
{
/// <summary>
/// Gets the codec information
/// </summary>
AudioCodecInfo CodecInfo { get; }
}
/// <summary>
/// Stores general information about a codec
/// </summary>
public abstract class AudioCodecInfo
{
/// <summary>
/// Gets or sets the phone number
/// </summary>
public abstract string PhoneNumber { get; set; }
}
namespace PepperDash.Essentials.Devices.Common.AudioCodec;
/// <summary>
/// Implements a common set of data about a codec
/// </summary>
public interface IAudioCodecInfo
{
AudioCodecInfo CodecInfo { get; }
}
/// <summary>
/// Stores general information about a codec
/// </summary>
public abstract class AudioCodecInfo
{
public abstract string PhoneNumber { get; set; }
}

View file

@ -1,17 +1,14 @@
using PepperDash.Essentials.Core;
namespace PepperDash.Essentials.Devices.Common.AudioCodec
namespace PepperDash.Essentials.Devices.Common.AudioCodec;
/// <summary>
/// Interface for devices that have an audio codec.
/// </summary>
public interface IHasAudioCodec:IHasInCallFeedback
{
/// <summary>
/// For rooms that have audio codec
/// Gets the audio codec device
/// </summary>
public interface IHasAudioCodec : IHasInCallFeedback
{
/// <summary>
/// Gets the audio codec device
/// </summary>
AudioCodecBase AudioCodec { get; }
//List<PepperDash.Essentials.Devices.Common.Codec.CodecActiveCallItem> ActiveCalls { get; }
}
AudioCodecBase AudioCodec { get; }
}

View file

@ -6,169 +6,121 @@ using PepperDash.Essentials.Core.Config;
using PepperDash.Essentials.Devices.Common.Codec;
using Serilog.Events;
namespace PepperDash.Essentials.Devices.Common.AudioCodec
namespace PepperDash.Essentials.Devices.Common.AudioCodec;
public class MockAC : AudioCodecBase
{
/// <summary>
/// Represents a MockAC
/// </summary>
public class MockAC : AudioCodecBase
public MockAC(string key, string name, MockAcPropertiesConfig props)
: base(key, name)
{
/// <summary>
/// Constructor for MockAC
/// </summary>
/// <param name="key">Device key</param>
/// <param name="name">Device name</param>
/// <param name="props">MockAC properties configuration</param>
public MockAC(string key, string name, MockAcPropertiesConfig props)
: base(key, name)
{
CodecInfo = new MockAudioCodecInfo();
CodecInfo = new MockAudioCodecInfo();
CodecInfo.PhoneNumber = props.PhoneNumber;
}
CodecInfo.PhoneNumber = props.PhoneNumber;
}
/// <summary>
/// Dial method
/// </summary>
/// <inheritdoc />
public override void Dial(string number)
public override void Dial(string number)
{
if (!IsInCall)
{
if (!IsInCall)
Debug.LogMessage(LogEventLevel.Debug, this, "Dial: {0}", number);
var call = new CodecActiveCallItem()
{
Debug.LogMessage(LogEventLevel.Debug, this, "Dial: {0}", number);
var call = new CodecActiveCallItem()
{
Name = "Mock Outgoing Call",
Number = number,
Type = eCodecCallType.Audio,
Status = eCodecCallStatus.Connected,
Direction = eCodecCallDirection.Outgoing,
Id = "mockAudioCall-1"
};
Name = "Mock Outgoing Call",
Number = number,
Type = eCodecCallType.Audio,
Status = eCodecCallStatus.Connected,
Direction = eCodecCallDirection.Outgoing,
Id = "mockAudioCall-1"
};
ActiveCalls.Add(call);
OnCallStatusChange(call);
}
else
{
Debug.LogMessage(LogEventLevel.Debug, this, "Already in call. Cannot dial new call.");
}
}
/// <summary>
/// EndCall method
/// </summary>
/// <inheritdoc />
public override void EndCall(CodecActiveCallItem call)
{
Debug.LogMessage(LogEventLevel.Debug, this, "EndCall");
ActiveCalls.Remove(call);
SetNewCallStatusAndFireCallStatusChange(eCodecCallStatus.Disconnected, call);
}
/// <summary>
/// EndAllCalls method
/// </summary>
/// <inheritdoc />
public override void EndAllCalls()
{
Debug.LogMessage(LogEventLevel.Debug, this, "EndAllCalls");
for (int i = ActiveCalls.Count - 1; i >= 0; i--)
{
var call = ActiveCalls[i];
ActiveCalls.Remove(call);
SetNewCallStatusAndFireCallStatusChange(eCodecCallStatus.Disconnected, call);
}
}
/// <summary>
/// AcceptCall method
/// </summary>
/// <inheritdoc />
public override void AcceptCall(CodecActiveCallItem call)
{
Debug.LogMessage(LogEventLevel.Debug, this, "AcceptCall");
SetNewCallStatusAndFireCallStatusChange(eCodecCallStatus.Connecting, call);
}
/// <summary>
/// RejectCall method
/// </summary>
public override void RejectCall(CodecActiveCallItem call)
{
Debug.LogMessage(LogEventLevel.Debug, this, "RejectCall");
ActiveCalls.Remove(call);
SetNewCallStatusAndFireCallStatusChange(eCodecCallStatus.Disconnected, call);
}
/// <summary>
/// SendDtmf method
/// </summary>
/// <inheritdoc />
public override void SendDtmf(string s)
{
Debug.LogMessage(LogEventLevel.Debug, this, "BEEP BOOP SendDTMF: {0}", s);
}
/// <summary>
/// TestIncomingAudioCall method
/// </summary>
/// <param name="number">Phone number to call from</param>
public void TestIncomingAudioCall(string number)
{
Debug.LogMessage(LogEventLevel.Debug, this, "TestIncomingAudioCall from {0}", number);
var call = new CodecActiveCallItem() { Name = number, Id = number, Number = number, Type = eCodecCallType.Audio, Direction = eCodecCallDirection.Incoming };
ActiveCalls.Add(call);
SetNewCallStatusAndFireCallStatusChange(eCodecCallStatus.Ringing, call);
}
OnCallStatusChange(call);
}
else
{
Debug.LogMessage(LogEventLevel.Debug, this, "Already in call. Cannot dial new call.");
}
}
public override void EndCall(CodecActiveCallItem call)
{
Debug.LogMessage(LogEventLevel.Debug, this, "EndCall");
ActiveCalls.Remove(call);
SetNewCallStatusAndFireCallStatusChange(eCodecCallStatus.Disconnected, call);
}
public override void EndAllCalls()
{
Debug.LogMessage(LogEventLevel.Debug, this, "EndAllCalls");
for (int i = ActiveCalls.Count - 1; i >= 0; i--)
{
var call = ActiveCalls[i];
ActiveCalls.Remove(call);
SetNewCallStatusAndFireCallStatusChange(eCodecCallStatus.Disconnected, call);
}
}
public override void AcceptCall(CodecActiveCallItem call)
{
Debug.LogMessage(LogEventLevel.Debug, this, "AcceptCall");
SetNewCallStatusAndFireCallStatusChange(eCodecCallStatus.Connecting, call);
}
public override void RejectCall(CodecActiveCallItem call)
{
Debug.LogMessage(LogEventLevel.Debug, this, "RejectCall");
ActiveCalls.Remove(call);
SetNewCallStatusAndFireCallStatusChange(eCodecCallStatus.Disconnected, call);
}
public override void SendDtmf(string s)
{
Debug.LogMessage(LogEventLevel.Debug, this, "BEEP BOOP SendDTMF: {0}", s);
}
/// <summary>
/// Represents a MockAudioCodecInfo
///
/// </summary>
public class MockAudioCodecInfo : AudioCodecInfo
/// <param name="url"></param>
public void TestIncomingAudioCall(string number)
{
string _phoneNumber;
/// <inheritdoc />
public override string PhoneNumber
{
get
{
return _phoneNumber;
}
set
{
_phoneNumber = value;
}
}
Debug.LogMessage(LogEventLevel.Debug, this, "TestIncomingAudioCall from {0}", number);
var call = new CodecActiveCallItem() { Name = number, Id = number, Number = number, Type = eCodecCallType.Audio, Direction = eCodecCallDirection.Incoming };
ActiveCalls.Add(call);
SetNewCallStatusAndFireCallStatusChange(eCodecCallStatus.Ringing, call);
}
/// <summary>
/// Represents a MockACFactory
/// </summary>
public class MockACFactory : EssentialsDeviceFactory<MockAC>
{
/// <summary>
/// Constructor for MockACFactory
/// </summary>
public MockACFactory()
{
TypeNames = new List<string>() { "mockac" };
}
}
/// <summary>
/// BuildDevice method
/// </summary>
/// <inheritdoc />
public override EssentialsDevice BuildDevice(DeviceConfig dc)
public class MockAudioCodecInfo : AudioCodecInfo
{
string _phoneNumber;
public override string PhoneNumber
{
get
{
Debug.LogMessage(LogEventLevel.Debug, "Factory Attempting to create new MockAc Device");
var props = Newtonsoft.Json.JsonConvert.DeserializeObject<AudioCodec.MockAcPropertiesConfig>(dc.Properties.ToString());
return new AudioCodec.MockAC(dc.Key, dc.Name, props);
return _phoneNumber;
}
set
{
_phoneNumber = value;
}
}
}
public class MockACFactory : EssentialsDeviceFactory<MockAC>
{
public MockACFactory()
{
TypeNames = new List<string>() { "mockac" };
}
public override EssentialsDevice BuildDevice(DeviceConfig dc)
{
Debug.LogMessage(LogEventLevel.Debug, "Factory Attempting to create new MockAc Device");
var props = Newtonsoft.Json.JsonConvert.DeserializeObject<AudioCodec.MockAcPropertiesConfig>(dc.Properties.ToString());
return new AudioCodec.MockAC(dc.Key, dc.Name, props);
}
}

View file

@ -1,16 +1,9 @@
using Newtonsoft.Json;
namespace PepperDash.Essentials.Devices.Common.AudioCodec
namespace PepperDash.Essentials.Devices.Common.AudioCodec;
public class MockAcPropertiesConfig
{
/// <summary>
/// Represents a MockAcPropertiesConfig
/// </summary>
public class MockAcPropertiesConfig
{
/// <summary>
/// Gets or sets the PhoneNumber
/// </summary>
[JsonProperty("phoneNumber")]
public string PhoneNumber { get; set; }
}
[JsonProperty("phoneNumber")]
public string PhoneNumber { get; set; }
}