|
|
@ -20,6 +20,7 @@ public class CellularNetworkContext : ICellularNetworkContext, IDisposable |
|
|
|
private CancellationTokenSource _token; |
|
|
|
private bool _isDisposed; |
|
|
|
private bool _isInitialized; |
|
|
|
private string _deviceCode = string.Empty; |
|
|
|
private readonly INetworkIPEndPointManager _networkIPEndPointManager; |
|
|
|
private NetworkConfigType _currentConfigType; |
|
|
|
private readonly ILogger<CellularNetworkContext> _logger; |
|
|
@ -33,6 +34,10 @@ public class CellularNetworkContext : ICellularNetworkContext, IDisposable |
|
|
|
/// 是否已初始化
|
|
|
|
/// </summary>
|
|
|
|
public bool IsInitialized => _isInitialized; |
|
|
|
/// <summary>
|
|
|
|
/// 设备编码
|
|
|
|
/// </summary>
|
|
|
|
public string DeviceCode => _deviceCode; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 网络IP端点管理器
|
|
|
@ -92,6 +97,28 @@ public class CellularNetworkContext : ICellularNetworkContext, IDisposable |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void SetDeviceCode(string deviceCode) |
|
|
|
{ |
|
|
|
if (_isDisposed) |
|
|
|
{ |
|
|
|
throw new ObjectDisposedException(nameof(CellularNetworkContext)); |
|
|
|
} |
|
|
|
if (!_isInitialized) |
|
|
|
{ |
|
|
|
throw new InvalidOperationException("上下文未初始化"); |
|
|
|
} |
|
|
|
if (string.IsNullOrEmpty(deviceCode)) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException(nameof(deviceCode)); |
|
|
|
} |
|
|
|
lock (_lock) |
|
|
|
{ |
|
|
|
_deviceCode = deviceCode; |
|
|
|
_logger.LogInformation($"设备代码已设置为: {deviceCode}"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 更新网络配置类型
|
|
|
|
/// </summary>
|
|
|
@ -246,6 +273,7 @@ public class CellularNetworkContext : ICellularNetworkContext, IDisposable |
|
|
|
_token?.Dispose(); |
|
|
|
_token = new CancellationTokenSource(); |
|
|
|
_neConfigKey = string.Empty; |
|
|
|
_deviceCode =string.Empty; |
|
|
|
_isInitialized = false; |
|
|
|
_networkState = new CellularNetworkState(string.Empty); |
|
|
|
_networkIPEndPointManager.Clear(); |
|
|
|