├── images ├── log.jpg ├── 二维码.jpg ├── device.jpg ├── shebei.jpg ├── shouye.jpg ├── weixi.jpg ├── 1648884682.jpg ├── 1648891279.jpg ├── 1648891309.jpg ├── 1648891338.jpg ├── 1648891377.jpg ├── 1648891419.jpg ├── 1648894225.jpg ├── deviceParm.jpg ├── diagnostics.png └── datalocation.jpg └── src ├── IOTCS.EdgeGateway.Infrastructure ├── WebApi │ ├── Views │ │ ├── Home │ │ │ └── Index.cshtml │ │ ├── _ViewStart.cshtml │ │ └── _Layout.cshtml │ ├── Settings │ │ ├── AccessToken.cs │ │ ├── Token.cs │ │ ├── Settings.cs │ │ ├── CustomException.cs │ │ └── OpenApiData.cs │ ├── Filter │ │ ├── HttpGlobalExceptionFilter.cs │ │ └── ManageVerifyAttribute.cs │ ├── Controller │ │ ├── SystemController.cs │ │ ├── LoginController.cs │ │ └── DeviceConfigController.cs │ └── ApplicationMvcModule.cs ├── Socket │ ├── Model │ │ ├── NullClientToServerProtocol.cs │ │ ├── WebSocketClientToServerProtocol.cs │ │ └── WebSocketProtocol.cs │ ├── WebSocketServerOptions.cs │ └── AppWebSocketModule.cs ├── Server │ ├── ServerPortDetecter.cs │ ├── ApplicationStartModule.cs │ ├── ApplicationStartBase.cs │ └── ApplicationWithServiceProvider.cs ├── Serialize │ └── AppJsonModule.cs ├── Extensions │ └── SwaggerExtension.cs └── IOTCS.EdgeGateway.Infrastructure.csproj ├── IOTCS.EdgeGateway.Server ├── iotcs.db ├── Database │ └── iotcs.db ├── IOTCS.EdgeGateway.Server.csproj ├── Program.cs └── appSettings.json ├── IOTCS.EdgeGateway.ComResDriver ├── IHttpDriver.cs ├── IMqttDriver.cs ├── IOTCS.EdgeGateway.ComResDriver.csproj └── IResourceDriver.cs ├── IOTCS.EdgeGateway.Freesql.Helper ├── Application │ ├── IService.cs │ ├── ServiceBase.cs │ └── ServiceBaseAbstract.cs ├── Domain │ ├── UnitOfWorkManager.cs │ ├── IRepositoryBase.cs │ └── RepositoryBase.cs └── IOTCS.EdgeGateway.Freesql.Helper.csproj ├── IOTCS.EdgeGateway.Plugins ├── Monitor │ ├── IMonitorTask.cs │ └── Model │ │ ├── OpcConnectionStatusDto.cs │ │ ├── WebSocketProtocol.cs │ │ └── SystemInfoDto.cs ├── ModbusDriver │ ├── IModbusRTUDriver.cs │ ├── IModbusRTUOverTcpDriver.cs │ └── IModbusTcpDriver.cs ├── OpcUADriver │ └── IOpcUADriver.cs ├── BACNetDriver │ └── IBACNetDriver.cs ├── SiemensDriver │ ├── ISiemensS71200NetDriver.cs │ └── ISiemensS71500NetDriver.cs ├── Executor │ ├── ICollector.cs │ └── ResourceComparer .cs ├── DataInitialize │ └── IInitializeConfiguration.cs ├── IOTCS.EdgeGateway.Plugins.csproj └── AppPluginModule.cs ├── IOTCS.EdgeGateway.Freesql ├── IOuterDBSessionContext.cs ├── ICommonDbSessionContext.cs ├── IdleBus │ └── DbBus.cs ├── IDBSessionContext.cs ├── Extensions │ ├── OuterDbContextOptions.cs │ ├── DbContextOptions.cs │ ├── CommonDbContextServiceCollectionExtensions.cs │ ├── OuterDbContextServiceCollectionExtensions.cs │ └── DbContextServiceCollectionExtensions.cs ├── DbContext │ └── AppFreeSqlDbContextModule.cs └── IOTCS.EdgeGateway.Freesql.csproj ├── IOTCS.EdgeGateway.BaseDriver ├── IOTCS.EdgeGateway.BaseDriver.csproj └── IDriver.cs ├── IOTCS.EdgeGateway.BaseProcPipeline ├── IPipelineContext.cs ├── IOTCS.EdgeGateway.BaseProcPipeline.csproj └── RouterMessage.cs ├── IOTCS.EdgeGateway.Reflection ├── IOTCS.EdgeGateway.Reflection.csproj └── StructTuple.cs ├── IOTCS.EdgeGateway.Core ├── IocManager.cs ├── Collections │ ├── IConcurrentList.cs │ ├── ITypeList.cs │ ├── IKeyValueCache.cs │ ├── ConcurrentHashSet.cs │ ├── SystemKeyValue.cs │ └── Pair.cs ├── Extensions │ ├── DecimalExtensions.cs │ ├── ByteArrayExtensions.cs │ ├── DateTimeExtensions.cs │ └── CollectionExtensions.cs ├── IOTCS.EdgeGateway.Core.csproj └── Security │ ├── MD5Helper.cs │ └── RC4.cs ├── IOTCS.EdgeGateway.Application ├── IOpcStorageService.cs ├── IDBDataStorageService.cs ├── IFreeSqlMgrService.cs ├── IAuthorizationService.cs ├── IUserService.cs ├── IDriveService.cs ├── IResourceService.cs ├── IDataLocationService.cs ├── IDeviceConfigService.cs ├── IRelationshipService.cs ├── IDeviceService.cs ├── Imps │ ├── OpcStorageService.cs │ ├── FreeSqlMgrService.cs │ ├── DriveService.cs │ └── RelationshipService.cs ├── IOTCS.EdgeGateway.Application.csproj ├── Utils │ └── TimestampHelper.cs └── AppServicesModule.cs ├── IOTCS.EdgeGateway.Commands ├── OpcUaCommand.cs ├── OpcUaNotification.cs ├── IOTCS.EdgeGateway.Commands.csproj └── UINotification.cs ├── IOTCS.EdgeGateway.Diagnostics ├── ISystemDiagnostics.cs ├── IUINotification.cs ├── Notification │ └── SystemNotification.cs ├── DiagnosticsContext │ └── AppDiagnosticsContextModule.cs ├── IOTCS.EdgeGateway.Diagnostics.csproj ├── UINotification.cs └── SystemDiagnostics.cs ├── IOTCS.EdgeGateway.Domain ├── ValueObject │ ├── PublishStatusDto.cs │ ├── TokenObject.cs │ ├── SystemManagerDto.cs │ ├── InitailizeDatabaseDto.cs │ ├── Notification │ │ ├── MonitorVariableValueDto.cs │ │ ├── NotifyChangeDto.cs │ │ ├── NotifyBase.cs │ │ └── NotifyChangeVariableDto.cs │ ├── SendMessageDto.cs │ ├── DataRequestDto.cs │ ├── JwtSettingsDto.cs │ ├── DataNodeDto.cs │ ├── LoginDto.cs │ ├── RelationshipDto.cs │ ├── Device │ │ ├── DriveDto.cs │ │ ├── DeviceConfigDto.cs │ │ └── DeviceDto.cs │ ├── OpcConfigDto.cs │ ├── UserDto.cs │ ├── DataResponseDto.cs │ ├── ResourceDto.cs │ └── DataLocationDto.cs ├── DomainService │ ├── IDeviceDomainService.cs │ ├── IRelationshipDomainService.cs │ └── Impl │ │ ├── RelationshipDomainService.cs │ │ └── DeviceDomainService.cs ├── Repositories │ ├── IFreeSqlMgrRepository.cs │ ├── IOpcStorageRepository.cs │ ├── IUserRepository.cs │ ├── IDataLocationRepository.cs │ ├── IDeviceConfigRepository.cs │ ├── IResourceRepository.cs │ ├── IDriveRepository.cs │ ├── IRelationshipRepository.cs │ └── IDeviceRepository.cs ├── Models │ ├── InitailizeDatabaseModel.cs │ ├── NodeTypeConfigModel.cs │ ├── RelationshipModel.cs │ ├── DriveModel.cs │ ├── DeviceConfigModel.cs │ ├── UserModel.cs │ ├── ResourceModel.cs │ ├── DataLocationModel.cs │ ├── DeviceModel.cs │ └── RuleModel.cs └── IOTCS.EdgeGateway.Domain.csproj ├── IOTCS.EdgeGateway.Dispatch ├── IDispatchManager.cs ├── AppDispatchModule.cs ├── IOTCS.EdgeGateway.Dispatch.csproj └── DispatchManager.cs ├── IOTCS.EdgeGateway.Library ├── IOTCS.EdgeGateway.Library.csproj └── OpcUaStatusEventArgs.cs ├── IOTCS.EdgeGateway.MqttHandler ├── IMqttSessionContext.cs ├── IOTCS.EdgeGateway.MqttHandler.csproj ├── AppMqttHandlerModule.cs ├── Extensions │ └── MqttContextOptions.cs └── MqttSessionContext.cs ├── IOTCS.EdgeGateway.WsHandler ├── IOTCS.EdgeGateway.WsHandler.csproj └── WsMessageHandler.cs ├── IOTCS.EdgeGateway.HttpHandler ├── IOTCS.EdgeGateway.HttpHandler.csproj └── AppHttpHandlerModule.cs ├── IOTCS.EdgeGateway.WebSocketManager ├── IOTCS.EdgeGateway.WebSocketManager.csproj ├── Networking │ ├── Message.cs │ ├── RemoteException.cs │ ├── InvocationResult.cs │ └── InvocationDescriptor.cs ├── Json │ ├── JsonBinderWithoutAssembly.cs │ └── PrimitiveJsonConverter.cs ├── Strategies │ └── MethodInvocationStrategy.cs └── WebSocketManagerExtensions.cs ├── IOTCS.EdgeGateway.Logging ├── Logging │ ├── ILoggerProvider.cs │ ├── LoggerFactoryExtensions.cs │ ├── ILoggerFactory.cs │ ├── ILogger.cs │ ├── Internal │ │ ├── NullLoggerProvider.cs │ │ └── NullLogger.cs │ └── LogLevel.cs ├── NullLogger.cs ├── IOTCS.EdgeGateway.Logging.csproj ├── Log4Net │ ├── Internal │ │ └── InternalConst.cs │ └── Log4NetLoggerProvider.cs ├── Console │ ├── Console │ │ ├── Internal │ │ │ ├── LogMessage.cs │ │ │ └── WindowsLogConsole.cs │ │ ├── IConsole.cs │ │ └── ConsoleLoggerProvider.cs │ └── ConsoleLoggerFactoryExtensions.cs ├── Log4NetLoggerFactoryExtensions.cs └── LoggingServiceCollectionExtensions.cs ├── IOTCS.EdgeGateway.CmdHandler ├── OpcHandlerModule.cs ├── Models │ └── WebSocketProtocol.cs ├── IOTCS.EdgeGateway.CmdHandler.csproj ├── SystemNotificationHandler.cs └── OpcUaNotificationHandler.cs ├── IOTCS.EdgeGateway.Repository ├── IOTCS.EdgeGateway.Repository.csproj ├── QuickCollect.SCADA.Server.Repository.csproj ├── RepositoryModule.cs ├── FreeSqlMgrRepository.cs ├── OpcStorageRepository.cs └── DeviceConfigRepository.cs ├── IOTCS.EdgeGateway.ProcPipeline ├── AppPipelineModule.cs └── IOTCS.EdgeGateway.ProcPipeline.csproj └── IOTCS.EdgeGateway.ResDriver └── IOTCS.EdgeGateway.ResDriver.csproj /images/log.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOT-CS/IOTCS/HEAD/images/log.jpg -------------------------------------------------------------------------------- /images/二维码.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOT-CS/IOTCS/HEAD/images/二维码.jpg -------------------------------------------------------------------------------- /images/device.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOT-CS/IOTCS/HEAD/images/device.jpg -------------------------------------------------------------------------------- /images/shebei.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOT-CS/IOTCS/HEAD/images/shebei.jpg -------------------------------------------------------------------------------- /images/shouye.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOT-CS/IOTCS/HEAD/images/shouye.jpg -------------------------------------------------------------------------------- /images/weixi.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOT-CS/IOTCS/HEAD/images/weixi.jpg -------------------------------------------------------------------------------- /images/1648884682.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOT-CS/IOTCS/HEAD/images/1648884682.jpg -------------------------------------------------------------------------------- /images/1648891279.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOT-CS/IOTCS/HEAD/images/1648891279.jpg -------------------------------------------------------------------------------- /images/1648891309.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOT-CS/IOTCS/HEAD/images/1648891309.jpg -------------------------------------------------------------------------------- /images/1648891338.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOT-CS/IOTCS/HEAD/images/1648891338.jpg -------------------------------------------------------------------------------- /images/1648891377.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOT-CS/IOTCS/HEAD/images/1648891377.jpg -------------------------------------------------------------------------------- /images/1648891419.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOT-CS/IOTCS/HEAD/images/1648891419.jpg -------------------------------------------------------------------------------- /images/1648894225.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOT-CS/IOTCS/HEAD/images/1648894225.jpg -------------------------------------------------------------------------------- /images/deviceParm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOT-CS/IOTCS/HEAD/images/deviceParm.jpg -------------------------------------------------------------------------------- /images/diagnostics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOT-CS/IOTCS/HEAD/images/diagnostics.png -------------------------------------------------------------------------------- /images/datalocation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOT-CS/IOTCS/HEAD/images/datalocation.jpg -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/WebApi/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | 3 | } 4 | 5 |
6 | 7 |
-------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/WebApi/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "~/Views/_Layout.cshtml"; 3 | } -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Server/iotcs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOT-CS/IOTCS/HEAD/src/IOTCS.EdgeGateway.Server/iotcs.db -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Server/Database/iotcs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IOT-CS/IOTCS/HEAD/src/IOTCS.EdgeGateway.Server/Database/iotcs.db -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.ComResDriver/IHttpDriver.cs: -------------------------------------------------------------------------------- 1 | namespace IOTCS.EdgeGateway.ComResDriver 2 | { 3 | public interface IHttpDriver : IResourceDriver 4 | { 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.ComResDriver/IMqttDriver.cs: -------------------------------------------------------------------------------- 1 | namespace IOTCS.EdgeGateway.ComResDriver 2 | { 3 | public interface IMqttDriver : IResourceDriver 4 | { 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Freesql.Helper/Application/IService.cs: -------------------------------------------------------------------------------- 1 | namespace IOTCS.EdgeGateway.Freesql.Helper.Application 2 | { 3 | public interface IService 4 | { 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Freesql.Helper/Domain/UnitOfWorkManager.cs: -------------------------------------------------------------------------------- 1 | namespace IOTCS.EdgeGateway.Freesql.Helper 2 | { 3 | public class UnitOfWorkManager 4 | { 5 | 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Plugins/Monitor/IMonitorTask.cs: -------------------------------------------------------------------------------- 1 | namespace IOTCS.EdgeGateway.Plugins.Monitor 2 | { 3 | public interface IMonitorTask 4 | { 5 | bool Executing(); 6 | } 7 | } -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Freesql/IOuterDBSessionContext.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace IOTCS.EdgeGateway.Freesql 3 | { 4 | public interface IOuterDBSessionContext 5 | { 6 | IFreeSql CreateDbContext(); 7 | } 8 | } -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/Socket/Model/NullClientToServerProtocol.cs: -------------------------------------------------------------------------------- 1 | namespace IOTCS.EdgeGateway.Infrastructure.Socket 2 | { 3 | public class NullClientToServerProtocol 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/WebApi/Views/_Layout.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | @RenderBody() 8 |
9 | 10 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.BaseDriver/IOTCS.EdgeGateway.BaseDriver.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.BaseProcPipeline/IPipelineContext.cs: -------------------------------------------------------------------------------- 1 | namespace IOTCS.EdgeGateway.BaseProcPipeline 2 | { 3 | public interface IPipelineContext 4 | { 5 | void SendPayload(RouterMessage router); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/WebApi/Settings/AccessToken.cs: -------------------------------------------------------------------------------- 1 | namespace IOTCS.EdgeGateway.Infrastructure.WebApi 2 | { 3 | public class AccessToken 4 | { 5 | public string Token { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Reflection/IOTCS.EdgeGateway.Reflection.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.ComResDriver/IOTCS.EdgeGateway.ComResDriver.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Plugins/ModbusDriver/IModbusRTUDriver.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.BaseDriver; 2 | 3 | namespace IOTCS.EdgeGateway.Plugins.ModbusDriver 4 | { 5 | public interface IModbusRTUDriver : IDriver 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Plugins/OpcUADriver/IOpcUADriver.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.BaseDriver; 2 | 3 | namespace IOTCS.EdgeGateway.Plugins.OpcUADriver 4 | { 5 | public interface IOpcUADriver : IDriver 6 | { 7 | 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Plugins/BACNetDriver/IBACNetDriver.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.BaseDriver; 2 | 3 | namespace IOTCS.EdgeGateway.Plugins.BACNetDriver 4 | { 5 | public interface IBACNetDriver : IDriver 6 | { 7 | 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Plugins/ModbusDriver/IModbusRTUOverTcpDriver.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.BaseDriver; 2 | 3 | namespace IOTCS.EdgeGateway.Plugins.ModbusDriver 4 | { 5 | public interface IModbusRTUOverTcpDriver : IDriver 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Plugins/ModbusDriver/IModbusTcpDriver.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.BaseDriver; 2 | 3 | namespace IOTCS.EdgeGateway.Plugins.ModbusDriver 4 | { 5 | public interface IModbusTcpDriver : IDriver 6 | { 7 | 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Freesql/ICommonDbSessionContext.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | namespace IOTCS.EdgeGateway.Freesql 4 | { 5 | public interface ICommonDbSessionContext 6 | { 7 | IFreeSql CreateDbContext(dynamic options, string type); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Plugins/SiemensDriver/ISiemensS71200NetDriver.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.BaseDriver; 2 | 3 | namespace IOTCS.EdgeGateway.Plugins.SiemensDriver 4 | { 5 | public interface ISiemensS71200NetDriver : IDriver 6 | { 7 | 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Plugins/SiemensDriver/ISiemensS71500NetDriver.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.BaseDriver; 2 | 3 | namespace IOTCS.EdgeGateway.Plugins.SiemensDriver 4 | { 5 | public interface ISiemensS71500NetDriver : IDriver 6 | { 7 | 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Core/IocManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.WebSockets; 3 | 4 | namespace IOTCS.EdgeGateway.Core 5 | { 6 | public class IocManager 7 | { 8 | public static IServiceProvider Instance { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Freesql/IdleBus/DbBus.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IOTCS.EdgeGateway.Freesql.IdleBus 4 | { 5 | public class DbBus : IdleBus 6 | { 7 | public DbBus() : base(TimeSpan.FromMinutes(30)) { } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Application/IOpcStorageService.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace IOTCS.EdgeGateway.Application 4 | { 5 | public interface IOpcStorageService 6 | { 7 | Task Insert(string resourceId, string sql); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/WebApi/Settings/Token.cs: -------------------------------------------------------------------------------- 1 | namespace IOTCS.EdgeGateway.Infrastructure.WebApi 2 | { 3 | public class Token 4 | { 5 | public string Name { get; set; } 6 | public string Id { get; set; } 7 | 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/Server/ServerPortDetecter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Infrastructure.Server 6 | { 7 | public class ServerPortDetecter 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Plugins/Executor/ICollector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Plugins.Executor 6 | { 7 | public interface ICollector 8 | { 9 | void Run(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Freesql/IDBSessionContext.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace IOTCS.EdgeGateway.Freesql 3 | { 4 | /// 5 | /// 数据连接的Session接口 6 | /// 7 | public interface IDBSessionContext 8 | { 9 | IFreeSql CreateDbContext(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.BaseDriver/IDriver.cs: -------------------------------------------------------------------------------- 1 | namespace IOTCS.EdgeGateway.BaseDriver 2 | { 3 | public interface IDriver 4 | { 5 | bool Connect(string deviceID); 6 | 7 | string Run(string deviceID, string groupID); 8 | 9 | bool IsAviable(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/Socket/WebSocketServerOptions.cs: -------------------------------------------------------------------------------- 1 | namespace IOTCS.EdgeGateway.Infrastructure.Socket 2 | { 3 | public class WebSocketServerOptions 4 | { 5 | public string IpAddress { get; set; } = "*"; 6 | 7 | public int Port { get; set; } = 6003; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Commands/OpcUaCommand.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | 3 | namespace IOTCS.EdgeGateway.Commands 4 | { 5 | public class OpcUaCommand : INotification 6 | { 7 | /// 8 | /// 主体数据 9 | /// 10 | public string Message { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Diagnostics/ISystemDiagnostics.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace IOTCS.EdgeGateway.Diagnostics 4 | { 5 | public interface ISystemDiagnostics 6 | { 7 | void Publish(string message); 8 | 9 | void PublishDiagnosticsInfo(string message); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/PublishStatusDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.ValueObject 6 | { 7 | public class PublishStatusDto 8 | { 9 | public bool IsPublish { get; set; } = false; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Plugins/DataInitialize/IInitializeConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Plugins.DataInitialize 6 | { 7 | public interface IInitializeConfiguration 8 | { 9 | void Executing(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Commands/OpcUaNotification.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | 3 | namespace IOTCS.EdgeGateway.Commands 4 | { 5 | public class OpcUaNotification : INotification 6 | { 7 | /// 8 | /// 主体数据 9 | /// 10 | public string Message { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Diagnostics/IUINotification.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Diagnostics 6 | { 7 | public interface IUINotification 8 | { 9 | void Publish(string message, string deviceID, string groupID); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Dispatch/IDispatchManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | 6 | namespace IOTCS.EdgeGateway.Dispatch 7 | { 8 | public interface IDispatchManager 9 | { 10 | Task RunTaskAsync(dynamic data); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Commands/IOTCS.EdgeGateway.Commands.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/TokenObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.ValueObject 6 | { 7 | public class TokenObject 8 | { 9 | public string Name { get; set; } 10 | public string Id { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.BaseProcPipeline/IOTCS.EdgeGateway.BaseProcPipeline.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/Server/ApplicationStartModule.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Infrastructure.WebApi; 2 | using Volo.Abp.Modularity; 3 | 4 | namespace IOTCS.EdgeGateway.Infrastructure.Server 5 | { 6 | [DependsOn(typeof(ApplicationMvcModule))] 7 | public class ApplicationStartModule : AbpModule 8 | { 9 | 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Library/IOTCS.EdgeGateway.Library.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.BaseProcPipeline/RouterMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.BaseProcPipeline 6 | { 7 | public class RouterMessage 8 | { 9 | public string Message { get; set; } 10 | 11 | public string OriginMessage { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.MqttHandler/IMqttSessionContext.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.MqttHandler.Extensions; 2 | using MQTTnet.Client; 3 | using System.Threading.Tasks; 4 | 5 | namespace IOTCS.EdgeGateway.MqttHandler 6 | { 7 | public interface IMqttSessionContext 8 | { 9 | Task CreateMqttContextAsync(MqttContextOptions options); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Freesql.Helper/Application/ServiceBase.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | 4 | namespace IOTCS.EdgeGateway.Freesql.Helper.Application 5 | { 6 | public abstract class ServiceBase 7 | { 8 | protected ServiceBase(IServiceProvider services) 9 | { 10 | 11 | } 12 | 13 | public IServiceProvider Services { get; protected set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Application/IDBDataStorageService.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.ValueObject; 2 | using System.Threading.Tasks; 3 | 4 | namespace IOTCS.EdgeGateway.Application 5 | { 6 | public interface IDBDataStorageService 7 | { 8 | Task Insert(DataRequestDto request); 9 | 10 | Task BatchInsert(DataRequestDto request); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/SystemManagerDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.ValueObject 6 | { 7 | public class SystemManagerDto 8 | { 9 | public bool IsPublishing { get; set; } = false; 10 | 11 | public bool Reboot { get; set; } = false; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.WsHandler/IOTCS.EdgeGateway.WsHandler.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/Server/ApplicationStartBase.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | 3 | namespace IOTCS.EdgeGateway.Infrastructure.Server 4 | { 5 | public class ApplicationStartBase : ApplicationIntegrated 6 | { 7 | public ApplicationStartBase(IServiceCollection services) : base(services) 8 | { } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Application/IFreeSqlMgrService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using System.Collections.Generic; 4 | using IOTCS.EdgeGateway.Domain.ValueObject; 5 | 6 | namespace IOTCS.EdgeGateway.Application 7 | { 8 | public interface IFreeSqlMgrService 9 | { 10 | InitailizeDatabaseDto CreateDbConnections(IEnumerable resources); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Freesql.Helper/IOTCS.EdgeGateway.Freesql.Helper.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.MqttHandler/IOTCS.EdgeGateway.MqttHandler.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Diagnostics/Notification/SystemNotification.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | 3 | namespace IOTCS.EdgeGateway.Diagnostics.Notification 4 | { 5 | /// 6 | /// 系统通知相关的信息 7 | /// 8 | public class SystemNotification : INotification 9 | { 10 | public dynamic Message { get; set; } 11 | 12 | public string MsgType { get; set; } = ""; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.HttpHandler/IOTCS.EdgeGateway.HttpHandler.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/DomainService/IDeviceDomainService.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.ValueObject; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace IOTCS.EdgeGateway.Domain.DomainService 8 | { 9 | public interface IDeviceDomainService 10 | { 11 | Task> GetAllDevice (); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/Repositories/IFreeSqlMgrRepository.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace IOTCS.EdgeGateway.Domain.Repositories 7 | { 8 | public interface IFreeSqlMgrRepository 9 | { 10 | InitailizeDatabaseModel CreateDbConnections(IEnumerable resources); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/Repositories/IOpcStorageRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Threading.Tasks; 3 | 4 | namespace IOTCS.EdgeGateway.Domain.Repositories 5 | { 6 | public interface IOpcStorageRepository 7 | { 8 | Task Insert(string resourceId, string sql); 9 | 10 | Task BatchInsert(string resourceId, IEnumerable sqlList); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/WebApi/Settings/Settings.cs: -------------------------------------------------------------------------------- 1 | namespace IOTCS.EdgeGateway.Infrastructure.WebApi 2 | { 3 | public class Settings 4 | { 5 | public string SecurityKey { get; set; } 6 | public string Issuer { get; set; } 7 | public string Audience { get; set; } 8 | public int LifeTime { get; set; } 9 | public bool ValidateLifetime { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.WebSocketManager/IOTCS.EdgeGateway.WebSocketManager.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | netcoreapp3.1 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/InitailizeDatabaseDto.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Freesql.IdleBus; 2 | using System; 3 | using System.Collections.Concurrent; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.ValueObject 6 | { 7 | public class InitailizeDatabaseDto 8 | { 9 | public DbBus DBBus { get; set; } 10 | 11 | public ConcurrentDictionary TDengine { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Commands/UINotification.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | 3 | namespace IOTCS.EdgeGateway.Commands 4 | { 5 | public class UINotification : INotification 6 | { 7 | public string DeviceID { get; set; } 8 | 9 | public string GroupID { get; set; } 10 | 11 | /// 12 | /// 主体数据 13 | /// 14 | public string UIMessage { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/DomainService/IRelationshipDomainService.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.ValueObject; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace IOTCS.EdgeGateway.Domain.DomainService 8 | { 9 | public interface IRelationshipDomainService 10 | { 11 | Task> GetRelationship(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.HttpHandler/AppHttpHandlerModule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Volo.Abp.Modularity; 5 | 6 | namespace IOTCS.EdgeGateway.HttpHandler 7 | { 8 | public class AppHttpHandlerModule : AbpModule 9 | { 10 | public override void ConfigureServices(ServiceConfigurationContext context) 11 | { 12 | 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Application/IAuthorizationService.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.ValueObject; 2 | using Newtonsoft.Json.Linq; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace IOTCS.EdgeGateway.Application 8 | { 9 | public interface IAuthorizationService 10 | { 11 | UserDto GenerateToken(string name, string password); 12 | 13 | bool ValidateToken(JToken token); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/Models/InitailizeDatabaseModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.Concurrent; 4 | using IOTCS.EdgeGateway.Freesql.IdleBus; 5 | 6 | namespace IOTCS.EdgeGateway.Domain.Models 7 | { 8 | public class InitailizeDatabaseModel 9 | { 10 | public DbBus DBBus { get; set; } 11 | 12 | public ConcurrentDictionary TDengine { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Logging/Logging/ILoggerProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IOTCS.EdgeGateway.Logging 4 | { 5 | /// 6 | /// 日志提供程序 7 | /// 8 | public interface ILoggerProvider : IDisposable 9 | { 10 | /// 11 | /// 创建一个新的实例 12 | /// 13 | /// 日志名称 14 | ILogger CreateLogger(string name); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.CmdHandler/OpcHandlerModule.cs: -------------------------------------------------------------------------------- 1 | using MediatR; 2 | using Volo.Abp.Modularity; 3 | 4 | namespace IOTCS.EdgeGateway.CmdHandler 5 | { 6 | public class OpcHandlerModule : AbpModule 7 | { 8 | public override void PreConfigureServices(ServiceConfigurationContext context) 9 | { 10 | context.Services.AddMediatR(new[] { typeof(UINotificationHandler), typeof(SystemNotificationHandler) }); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Core/Collections/IConcurrentList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace IOTCS.EdgeGateway.Core.Collections 7 | { 8 | public interface IConcurrentList : IList, ICollection, IEnumerable 9 | { 10 | int BinSearch(T value); 11 | 12 | T Find(Predicate match); 13 | 14 | bool Exists(Predicate match); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.MqttHandler/AppMqttHandlerModule.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using Volo.Abp.Modularity; 3 | 4 | namespace IOTCS.EdgeGateway.MqttHandler 5 | { 6 | public class AppMqttHandlerModule : AbpModule 7 | { 8 | public override void ConfigureServices(ServiceConfigurationContext context) 9 | { 10 | context.Services.Add(ServiceDescriptor.Singleton()); 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.WebSocketManager/Networking/Message.cs: -------------------------------------------------------------------------------- 1 | namespace IOTCS.EdgeGateway.WebSocketManager.Common 2 | { 3 | public enum MessageType 4 | { 5 | Text, 6 | MethodInvocation, 7 | ConnectionEvent, 8 | MethodReturnValue 9 | } 10 | 11 | public class Message 12 | { 13 | public MessageType MessageType { get; set; } 14 | 15 | public string RequestType { get; set; } = "No"; 16 | 17 | public dynamic Data { get; set; } 18 | } 19 | } -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/Models/NodeTypeConfigModel.cs: -------------------------------------------------------------------------------- 1 | using FreeSql.DataAnnotations; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace IOTCS.EdgeGateway.Domain.Models 7 | { 8 | [Table(Name = "tb_nodetypeconfig")] 9 | public class NodeTypeConfigModel 10 | { 11 | public string Id { get; set; } 12 | 13 | public string DriveType { get; set; } 14 | 15 | public string NodeTypeJson { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.WsHandler/WsMessageHandler.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.WebSocketManager; 2 | using IOTCS.EdgeGateway.WebSocketManager.Common; 3 | 4 | namespace IOTCS.EdgeGateway.WsHandler 5 | { 6 | public class WsMessageHandler : WebSocketHandler 7 | { 8 | public WsMessageHandler(WebSocketConnectionManager webSocketConnectionManager) 9 | : base(webSocketConnectionManager, new StringMethodInvocationStrategy()) 10 | { 11 | 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/Notification/MonitorVariableValueDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.ValueObject.Notification 6 | { 7 | public class MonitorVariableValueDto 8 | { 9 | public string Id { get; set; } 10 | 11 | public string Source { get; set; } 12 | 13 | public string Sink { get; set; } 14 | 15 | public string Status { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/SendMessageDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.ValueObject 6 | { 7 | public class SendMessageDto 8 | { 9 | public PayloadMessage Payload { get; set; } 10 | } 11 | 12 | public class PayloadMessage 13 | { 14 | public string ClientID { get; set; } = "OPC UA"; 15 | 16 | public List Values { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/DataRequestDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.ValueObject 6 | { 7 | public class DataRequestDto 8 | { 9 | /// 10 | /// 数据资源ID号 11 | /// 12 | public string ResourceId { get; set; } 13 | 14 | public string InputMessage { get; set; } 15 | 16 | public string SqlTemplate { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/JwtSettingsDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.ValueObject 6 | { 7 | public class JwtSettingsDto 8 | { 9 | public string SecurityKey { get; set; } 10 | public string Issuer { get; set; } 11 | public string Audience { get; set; } 12 | public int LifeTime { get; set; } 13 | public bool ValidateLifetime { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Plugins/Monitor/Model/OpcConnectionStatusDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Plugins.Monitor 6 | { 7 | public class OpcConnectionStatusDto 8 | { 9 | public string OpcName { get; set; } 10 | 11 | public string OpcUrl { get; set; } 12 | 13 | 14 | public DateTime ConnectTime { get; set; } 15 | 16 | public bool IsConnected { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/DataNodeDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.ValueObject 6 | { 7 | public class DataNodeDto 8 | { 9 | public string Tag { get; set; } 10 | 11 | public string FieldName { get; set; } 12 | 13 | public string NodeId { get; set; } 14 | 15 | public string NodeValue { get; set; } 16 | 17 | public string StatusCode { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/LoginDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.ValueObject 6 | { 7 | public class LoginDto 8 | { 9 | public string UserName { get; set; } 10 | 11 | public string Password { get; set; } 12 | 13 | public string ValidCode { get; set; } 14 | 15 | public string Token { get; set; } 16 | 17 | public string DisplayName { get; set; } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.ComResDriver/IResourceDriver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | 6 | namespace IOTCS.EdgeGateway.ComResDriver 7 | { 8 | public interface IResourceDriver 9 | { 10 | dynamic Parameter { get; set; } 11 | 12 | string Initialize(string config); 13 | 14 | string CheckConnected(string config); 15 | 16 | bool IsConnected(); 17 | 18 | Task Run(dynamic data); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Application/IUserService.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.ValueObject; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | 5 | namespace IOTCS.EdgeGateway.Application 6 | { 7 | public interface IUserService 8 | { 9 | Task GetUserInfoByName(string userName); 10 | Task> GetAsync(); 11 | Task Insert(UserDto data); 12 | Task UpdatePwd(UserDto data); 13 | Task Delete(UserDto data); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Logging/NullLogger.cs: -------------------------------------------------------------------------------- 1 | namespace IOTCS.EdgeGateway.Logging 2 | { 3 | public class NullLogger 4 | { 5 | public static ILogger Logger 6 | { 7 | get 8 | { 9 | var loggerFactory = new LoggerFactory() 10 | .AddConsole(LogLevel.Trace, true) 11 | .AddLog4Net(); 12 | var logger = loggerFactory.CreateLogger("errorAppender"); 13 | return logger; 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Core/Extensions/DecimalExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace System 2 | { 3 | /// 4 | /// Decimal extension methods
5 | /// Decimal的扩展函数
6 | ///
7 | public static class DecimalExtensions { 8 | /// 9 | /// Remove excess 0s after decimal
10 | /// 删除小数点后多余的0
11 | /// Eg: giving 12.3000 will return 12.3 12 | ///
13 | public static decimal Normalize(this decimal value) { 14 | return value / 1.000000000000000000000000000000000m; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Dispatch/AppDispatchModule.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using Volo.Abp.Modularity; 6 | 7 | namespace IOTCS.EdgeGateway.Dispatch 8 | { 9 | public class AppDispatchModule : AbpModule 10 | { 11 | public override void ConfigureServices(ServiceConfigurationContext context) 12 | { 13 | context.Services.Add(ServiceDescriptor.Singleton()); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/RelationshipDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.ValueObject 6 | { 7 | public class RelationshipDto 8 | { 9 | public string Id { get; set; } 10 | public string ResourceId { get; set; } 11 | 12 | public string ResourceName { get; set; } 13 | public string Topic { get; set; } 14 | public string CreateTime { get; set; } 15 | public string CreaterBy { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Application/IDriveService.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.ValueObject.Device; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace IOTCS.EdgeGateway.Application 8 | { 9 | public interface IDriveService 10 | { 11 | Task Create(DriveDto deviceDto); 12 | 13 | Task> GetAllrive(); 14 | 15 | Task Update(DriveDto deviceDto); 16 | 17 | Task Delete(DriveDto deviceDto); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Application/IResourceService.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.ValueObject; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | 5 | namespace IOTCS.EdgeGateway.Application 6 | { 7 | public interface IResourceService 8 | { 9 | Task> GetAsync(); 10 | 11 | Task Insert(ResourceDto data); 12 | 13 | Task Update(ResourceDto data); 14 | Task Delete(ResourceDto data); 15 | 16 | Task TestAsync(ResourceDto data); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Logging/IOTCS.EdgeGateway.Logging.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/IOTCS.EdgeGateway.Domain.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/Models/RelationshipModel.cs: -------------------------------------------------------------------------------- 1 | using FreeSql.DataAnnotations; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace IOTCS.EdgeGateway.Domain.Models 7 | { 8 | [Table(Name = "tb_relationship")] 9 | public class RelationshipModel 10 | { 11 | public string Id { get; set; } 12 | public string ResourceId { get; set; } 13 | public string Topic { get; set; } 14 | public string CreateTime { get; set; } 15 | public string CreaterBy { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/WebApi/Settings/CustomException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IOTCS.EdgeGateway.Infrastructure.WebApi 4 | { 5 | public class CustomerException:SystemException 6 | { 7 | public CustomerException():base() 8 | { 9 | 10 | } 11 | public CustomerException(string message):base(message) 12 | { 13 | 14 | } 15 | 16 | public CustomerException(string message, Exception innerException):base(message,innerException) 17 | { 18 | 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Core/Collections/ITypeList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace IOTCS.EdgeGateway.Core.Collections 5 | { 6 | public interface ITypeList : ITypeList 7 | { 8 | 9 | } 10 | 11 | public interface ITypeList : IList 12 | { 13 | void Add() where T : TBaseType; 14 | 15 | 16 | void TryAdd() where T : TBaseType; 17 | 18 | bool Contains() where T : TBaseType; 19 | 20 | void Remove() where T : TBaseType; 21 | } 22 | } -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/WebApi/Settings/OpenApiData.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace IOTCS.EdgeGateway.Infrastructure.WebApi 4 | { 5 | public class OpenApiData 6 | { 7 | public int State_Code { get; set; } = 200; 8 | 9 | public string Message { get; set; } 10 | 11 | } 12 | public class RestfulData : OpenApiData 13 | { 14 | public virtual T Data { get; set; } 15 | 16 | } 17 | 18 | public class RestfulArray : RestfulData> 19 | { 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Logging/Logging/LoggerFactoryExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace IOTCS.EdgeGateway.Logging 2 | { 3 | /// 4 | /// 日志工厂() 扩展 5 | /// 6 | public static class LoggerFactoryExtensions 7 | { 8 | /// 9 | /// 创建日志操作实例 10 | /// 11 | /// 类型 12 | /// 日志工厂 13 | public static ILogger CreateLogger(this ILoggerFactory factory) => factory.CreateLogger(typeof(T).FullName); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Logging/Log4Net/Internal/InternalConst.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | namespace IOTCS.EdgeGateway.Logging.Log4Net.Internal 4 | { 5 | /// 6 | /// 内部常量 7 | /// 8 | internal class InternalConst 9 | { 10 | /// 11 | /// 默认日志名称 12 | /// 13 | public const string DefaultLogName = "NETCoreRepository"; 14 | 15 | /// 16 | /// 默认配置文件 17 | /// 18 | public const string DefaultConfigFile = "log4net.config"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/Repositories/IUserRepository.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Threading.Tasks; 5 | 6 | namespace IOTCS.EdgeGateway.Domain.Repositories 7 | { 8 | public interface IUserRepository 9 | { 10 | Task Insert(UserModel model); 11 | 12 | Task UpdatePwd(UserModel model); 13 | Task Delete(UserModel model); 14 | 15 | Task> GetAsync(); 16 | 17 | Task GetInfoByUserName(UserModel model); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Application/IDataLocationService.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.ValueObject; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | 5 | namespace IOTCS.EdgeGateway.Application 6 | { 7 | public interface IDataLocationService 8 | { 9 | Task> GetAsync(); 10 | 11 | Task> GetNodeByIdAsync(string id); 12 | 13 | Task Insert(DataLocationDto data); 14 | 15 | Task Update(DataLocationDto data); 16 | Task Delete(DataLocationDto data); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/Notification/NotifyChangeDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace IOTCS.EdgeGateway.Domain.ValueObject.Notification 7 | { 8 | public class NotifyChangeDto 9 | { 10 | public string DeviceID { get; set; } = string.Empty; 11 | 12 | public string GroupID { get; set; } = string.Empty; 13 | 14 | /// 15 | /// 键值对 16 | /// 17 | public List Nodes { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/Socket/Model/WebSocketClientToServerProtocol.cs: -------------------------------------------------------------------------------- 1 | namespace IOTCS.EdgeGateway.Infrastructure.Socket 2 | { 3 | public class WebSocketClientToServerProtocol 4 | { 5 | public string RequestID { get; set; } 6 | 7 | /// 8 | /// 自定义操作类型,以下操作已经封装 9 | ///1.connected 表示服务端主动推送 10 | ///2.ping 客户端发送心跳包到服务端,服务端返回RequestType=pong 11 | ///3.close 服务器端异常发送RequestType = close 到客户端 12 | /// 13 | public string RequestType { get; set; } 14 | 15 | public T Data { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Logging/Logging/ILoggerFactory.cs: -------------------------------------------------------------------------------- 1 | namespace IOTCS.EdgeGateway.Logging 2 | { 3 | /// 4 | /// 日志工厂 5 | /// 6 | public interface ILoggerFactory 7 | { 8 | /// 9 | /// 创建日志操作实例 10 | /// 11 | /// 日志名称 12 | ILogger CreateLogger(string name); 13 | 14 | /// 15 | /// 添加日志提供程序 16 | /// 17 | /// 日志提供程序列表 18 | void AddProvider(params ILoggerProvider[] providers); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Application/IDeviceConfigService.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.ValueObject.Device; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace IOTCS.EdgeGateway.Application 8 | { 9 | public interface IDeviceConfigService 10 | { 11 | Task GetAllDeviceConfigByDeviceId(string deviceId); 12 | 13 | Task Create(DeviceConfigDto configDto); 14 | 15 | Task Update(DeviceConfigDto configDto); 16 | 17 | Task> GetAsync(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/Repositories/IDataLocationRepository.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.Models; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.Repositories 6 | { 7 | public interface IDataLocationRepository 8 | { 9 | Task> GetAsync(); 10 | Task Insert(DataLocationModel model); 11 | Task Update(DataLocationModel model); 12 | Task Delete(DataLocationModel model); 13 | Task> GetNodeByIdAsync(string id); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/Device/DriveDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.ValueObject.Device 6 | { 7 | public class DriveDto 8 | { 9 | public string Id { get; set; } 10 | 11 | public string DriveName { get; set; } 12 | public string DriveType { get; set; } 13 | public string DriveParams { get; set; } 14 | public string Description { get; set; } 15 | 16 | public string CreateTime { get; set; } 17 | 18 | public string CreaterBy { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Core/IOTCS.EdgeGateway.Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Diagnostics/DiagnosticsContext/AppDiagnosticsContextModule.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using Volo.Abp.Modularity; 3 | 4 | namespace IOTCS.EdgeGateway.Diagnostics.DiagnosticsContext 5 | { 6 | public class AbpDiagnosticsContextModule : AbpModule 7 | { 8 | public override void ConfigureServices(ServiceConfigurationContext context) 9 | { 10 | context.Services.Add(ServiceDescriptor.Singleton()); 11 | context.Services.Add(ServiceDescriptor.Singleton()); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/Repositories/IDeviceConfigRepository.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace IOTCS.EdgeGateway.Domain.Repositories 8 | { 9 | public interface IDeviceConfigRepository 10 | { 11 | 12 | Task GetAllDeviceConfigByDeviceId(string deviceId); 13 | 14 | Task Create(DeviceConfigModel configDto); 15 | 16 | Task Update(DeviceConfigModel configDto); 17 | 18 | Task> GetAsync(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Freesql/Extensions/OuterDbContextOptions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Options; 2 | 3 | namespace IOTCS.EdgeGateway.Freesql.Extensions 4 | { 5 | public class OuterDbContextOptions : IOptions 6 | { 7 | public string DbType { get; set; } = "1"; 8 | 9 | public string DbIp { get; set; } 10 | 11 | public string DbPort { get; set; } 12 | 13 | public string Database { get; set; } 14 | 15 | public string DbUid { get; set; } 16 | 17 | public string DbPwd { get; set; } 18 | 19 | public OuterDbContextOptions Value => this; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Diagnostics/IOTCS.EdgeGateway.Diagnostics.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/Server/ApplicationWithServiceProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Extensions.DependencyInjection; 3 | 4 | namespace IOTCS.EdgeGateway.Infrastructure.Server 5 | { 6 | public abstract class ApplicationWithServiceProvider 7 | { 8 | protected abstract IServiceProvider ServiceProvider { get; } 9 | 10 | protected virtual T GetService() 11 | { 12 | return ServiceProvider.GetService(); 13 | } 14 | 15 | protected virtual T GetRequiredService() 16 | { 17 | return ServiceProvider.GetRequiredService(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/Repositories/IResourceRepository.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.Models; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.Repositories 6 | { 7 | public interface IResourceRepository 8 | { 9 | Task Insert(ResourceModel model); 10 | 11 | Task Update(ResourceModel model); 12 | 13 | Task Delete(ResourceModel model); 14 | 15 | Task> GetAsync(); 16 | 17 | Task GetById(string Id); 18 | 19 | Task TestAsync(ResourceModel model); 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Application/IRelationshipService.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.ValueObject; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace IOTCS.EdgeGateway.Application 8 | { 9 | public interface IRelationshipService 10 | { 11 | public Task Create(RelationshipDto deviceDto); 12 | 13 | Task Update(RelationshipDto deviceModel); 14 | 15 | Task Delete(RelationshipDto deviceModel); 16 | 17 | Task> GetAllRelationship(); 18 | 19 | Task> GetTopics(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/Models/DriveModel.cs: -------------------------------------------------------------------------------- 1 | using FreeSql.DataAnnotations; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace IOTCS.EdgeGateway.Domain.Models 7 | { 8 | [Table(Name = "tb_drive")] 9 | public class DriveModel 10 | { 11 | public string Id { get; set; } 12 | 13 | public string DriveName { get; set; } 14 | public string DriveType { get; set; } 15 | public string DriveParams { get; set; } 16 | public string Description { get; set; } 17 | public string CreateTime { get; set; } 18 | 19 | public string CreaterBy { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/Models/DeviceConfigModel.cs: -------------------------------------------------------------------------------- 1 | using FreeSql.DataAnnotations; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace IOTCS.EdgeGateway.Domain.Models 7 | { 8 | [Table(Name = "tb_deviceconfig")] 9 | public class DeviceConfigModel 10 | { 11 | public string Id { get; set; } 12 | public string ConfigJson { get; set; } 13 | public string DeviceId { get; set; } 14 | public string CreateTime { get; set; } 15 | public string CreateBy { get; set; } 16 | public string UpdateTime { get; set; } 17 | public string UpdateBy { get; set; } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Freesql/Extensions/DbContextOptions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Options; 2 | 3 | namespace IOTCS.EdgeGateway.Freesql.Extensions 4 | { 5 | public class DbContextOptions : IOptions 6 | { 7 | public string DbType { get; set; } = "1"; 8 | 9 | public string DbIp { get; set; } 10 | 11 | public string DbPort { get; set; } 12 | 13 | public string Database { get; set; } 14 | 15 | public string DbUid { get; set; } 16 | 17 | public string DbPwd { get; set; } 18 | 19 | public bool Debug { get; set; } 20 | 21 | public DbContextOptions Value => this; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Logging/Console/Console/Internal/LogMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IOTCS.EdgeGateway.Logging.Console.Internal 4 | { 5 | /// 6 | /// 日志消息 7 | /// 8 | internal class LogMessage 9 | { 10 | /// 11 | /// 背景色 12 | /// 13 | public ConsoleColor? Background { get; set; } 14 | 15 | /// 16 | /// 前景色 17 | /// 18 | public ConsoleColor? Foreground { get; set; } 19 | 20 | /// 21 | /// 消息 22 | /// 23 | public string Message { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Repository/IOTCS.EdgeGateway.Repository.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/Device/DeviceConfigDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.ValueObject.Device 6 | { 7 | public class DeviceConfigDto 8 | { 9 | public string Id { get; set; } 10 | public string ConfigJson { get; set; } 11 | public string DeviceId { get; set; } 12 | public string CreateTime { get; set; } 13 | public string CreateBy { get; set; } 14 | public string UpdateTime { get; set; } 15 | public string UpdateBy { get; set; } 16 | public string DriveType { get; set; } = "OPCUA"; 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/OpcConfigDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.ValueObject 6 | { 7 | public class OpcConfigDto 8 | { 9 | public string Id { get; set; } 10 | /// 11 | /// OPC名称 12 | /// 13 | public string OpcName { get; set; } 14 | /// 15 | /// OPC地址 16 | /// 17 | public string OpcUrl { get; set; } 18 | /// 19 | /// 采集周期 ms 20 | /// 21 | public int Duration { get; set; } = 600; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/Repositories/IDriveRepository.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace IOTCS.EdgeGateway.Domain.Repositories 8 | { 9 | public interface IDriveRepository 10 | { 11 | Task Create(DriveModel deviceModel); 12 | 13 | 14 | Task> GetAllDrive(); 15 | 16 | Task Update(DriveModel deviceModel); 17 | 18 | Task Delete(DriveModel deviceModel); 19 | Task GetDriveByDeviceId(string deviceId); 20 | 21 | Task GetDriveByGroupId(string groupId); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Logging/Logging/ILogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IOTCS.EdgeGateway.Logging 4 | { 5 | /// 6 | /// 日志操作 7 | /// 8 | public interface ILogger 9 | { 10 | /// 11 | /// 检查给定日志级别是否启用 12 | /// 13 | /// 日志级别 14 | bool IsEnabled(LogLevel level); 15 | 16 | /// 17 | /// 写入日志 18 | /// 19 | /// 日志级别 20 | /// 日志消息 21 | /// 异常信息 22 | void Log(LogLevel level, string message, Exception exception); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Plugins/Executor/ResourceComparer .cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.ValueObject; 2 | using System.Collections.Generic; 3 | 4 | namespace IOTCS.EdgeGateway.Plugins.Executor 5 | { 6 | public class ResourceComparer : IEqualityComparer 7 | { 8 | public bool Equals(ResourceDto x, ResourceDto y) 9 | { 10 | if (x == null) 11 | return y == null; 12 | return x.ResourceName == y.ResourceName; 13 | } 14 | 15 | 16 | public int GetHashCode(ResourceDto obj) 17 | { 18 | if (obj == null) 19 | return 0; 20 | return obj.ResourceName.GetHashCode(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Freesql/Extensions/CommonDbContextServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | 2 | using IOTCS.EdgeGateway.Freesql; 3 | using System; 4 | 5 | namespace Microsoft.Extensions.DependencyInjection 6 | { 7 | public static class CommonDbContextServiceCollectionExtensions 8 | { 9 | public static IServiceCollection AddCommonDbContext(this IServiceCollection services) 10 | { 11 | if (services == null) 12 | { 13 | throw new ArgumentNullException(nameof(services)); 14 | } 15 | 16 | services.Add(ServiceDescriptor.Singleton()); 17 | 18 | return services; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/Serialize/AppJsonModule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Newtonsoft.Json; 3 | using Volo.Abp; 4 | using Volo.Abp.Modularity; 5 | 6 | namespace IOTCS.EdgeGateway.Infrastructure.Serialize 7 | { 8 | public class AppJsonModule : AbpModule 9 | { 10 | public override void OnPreApplicationInitialization(ApplicationInitializationContext context) 11 | { 12 | JsonConvert.DefaultSettings = () => 13 | { 14 | var settings = new JsonSerializerSettings(); 15 | // Avoid add items to exist collection. 16 | settings.ObjectCreationHandling = ObjectCreationHandling.Replace; 17 | settings.Formatting = Formatting.Indented; 18 | return settings; 19 | }; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/Repositories/IRelationshipRepository.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.Models; 2 | using IOTCS.EdgeGateway.Domain.ValueObject; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace IOTCS.EdgeGateway.Domain.Repositories 9 | { 10 | public interface IRelationshipRepository 11 | { 12 | Task Create(RelationshipModel deviceModel); 13 | 14 | Task> GetRelationship(); 15 | 16 | Task Delete(RelationshipModel deviceModel); 17 | 18 | Task Update(RelationshipModel relationshipModel); 19 | 20 | Task> GetTopics(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Freesql.Helper/Application/ServiceBaseAbstract.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | 4 | namespace IOTCS.EdgeGateway.Freesql.Helper.Application 5 | { 6 | public abstract class ServiceBase : ServiceBase 7 | { 8 | TRepository _repository; 9 | 10 | protected ServiceBase(IServiceProvider services) : base(services) 11 | { 12 | 13 | } 14 | 15 | public TRepository Repository 16 | { 17 | get 18 | { 19 | if (this._repository == null) 20 | this._repository = (TRepository)this.Services.GetService(typeof(TRepository)); 21 | 22 | return this._repository; 23 | } 24 | } 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/Models/UserModel.cs: -------------------------------------------------------------------------------- 1 | using FreeSql.DataAnnotations; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace IOTCS.EdgeGateway.Domain.Models 7 | { 8 | [Table(Name = "tb_users")] 9 | public class UserModel 10 | { 11 | public string Id { get; set; } 12 | public string UserName { get; set; } 13 | public string Password { get; set; } 14 | public string PhoneNumber { get; set; } 15 | public string Creator { get; set; } 16 | public string CreateTime { get; set; } 17 | public string Updator { get; set; } 18 | public string UpdatedTime { get; set; } 19 | public string DisplayName { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Application/IDeviceService.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.ValueObject; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace IOTCS.EdgeGateway.Application 8 | { 9 | public interface IDeviceService 10 | { 11 | public Task Create(DeviceDto deviceDto); 12 | 13 | 14 | Task Update(DeviceDto deviceModel); 15 | 16 | Task Delete(DeviceDto deviceModel); 17 | 18 | Task> GetDeviceGroup(); 19 | 20 | Task> GetAllDevice(); 21 | 22 | Task> GetAsync(); 23 | 24 | Task GetNodeTypeConfigByDevId(string deviceId); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Dispatch/IOTCS.EdgeGateway.Dispatch.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/UserDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.ValueObject 6 | { 7 | public class UserDto 8 | { 9 | public string Id { get; set; } 10 | public string UserName { get; set; } 11 | public string OldPassword { get; set; } 12 | public string Password { get; set; } 13 | public string PhoneNumber { get; set; } 14 | public string Token { get; set; } 15 | public string Creator { get; set; } 16 | public string CreateTime { get; set; } 17 | public string Updator { get; set; } 18 | public string UpdatedTime { get; set; } 19 | public string DisplayName { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Application/Imps/OpcStorageService.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.Repositories; 2 | using System.Threading.Tasks; 3 | 4 | namespace IOTCS.EdgeGateway.Application.Imps 5 | { 6 | public class OpcStorageService : IOpcStorageService 7 | { 8 | private readonly IOpcStorageRepository _storageRepository; 9 | 10 | public OpcStorageService(IOpcStorageRepository storageRepository) 11 | { 12 | _storageRepository = storageRepository; 13 | } 14 | 15 | public async Task Insert(string resourceId, string sql) 16 | { 17 | var result = false; 18 | 19 | result = await _storageRepository.Insert(resourceId, sql); 20 | 21 | return result; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Logging/Log4Net/Log4NetLoggerProvider.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Logging.Log4Net.Internal; 2 | using System.Reflection; 3 | 4 | namespace IOTCS.EdgeGateway.Logging.Log4Net 5 | { 6 | /// 7 | /// Log4Net 日志提供程序 8 | /// 9 | public class Log4NetLoggerProvider : ILoggerProvider 10 | { 11 | /// 12 | /// 释放资源 13 | /// 14 | public void Dispose() => log4net.LogManager.Shutdown(); 15 | 16 | /// 17 | /// 创建一个新的实例 18 | /// 19 | /// 日志名称 20 | public ILogger CreateLogger(string name) => new Log4NetLogger(log4net.LogManager.GetLogger(Log4NetLogger.RepositoryName, name)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Logging/Logging/Internal/NullLoggerProvider.cs: -------------------------------------------------------------------------------- 1 | namespace IOTCS.EdgeGateway.Logging.Internal 2 | { 3 | /// 4 | /// 空日志提供程序 5 | /// 6 | internal class NullLoggerProvider : ILoggerProvider 7 | { 8 | /// 9 | /// 空日志提供程序实例 10 | /// 11 | internal static NullLoggerProvider Instance = new NullLoggerProvider(); 12 | 13 | /// 14 | /// 释放资源 15 | /// 16 | public void Dispose() 17 | { 18 | } 19 | 20 | /// 21 | /// 创建一个新的实例 22 | /// 23 | /// 日志名称 24 | public ILogger CreateLogger(string name) => NullLogger.Instance; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.WebSocketManager/Json/JsonBinderWithoutAssembly.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json.Serialization; 2 | using System; 3 | 4 | namespace IOTCS.EdgeGateway.WebSocketManager.Common 5 | { 6 | /// 7 | /// Finds types without looking at the assembly. 8 | /// 9 | /// 10 | public class JsonBinderWithoutAssembly : ISerializationBinder 11 | { 12 | public void BindToName(Type serializedType, out string assemblyName, out string typeName) 13 | { 14 | typeName = serializedType.FullName; 15 | assemblyName = null; 16 | } 17 | 18 | public Type BindToType(string assemblyName, string typeName) 19 | { 20 | return Type.GetType(typeName); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/Socket/Model/WebSocketProtocol.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IOTCS.EdgeGateway.Infrastructure.Socket 4 | { 5 | public class WebSocketProtocol 6 | { 7 | /// 8 | /// 消息流水号 9 | /// 10 | public string RequestId { get; set; } = Guid.NewGuid().ToString("N"); 11 | 12 | /// 13 | /// 请求类型 14 | /// 15 | /// pong 16 | /// sysInfo 17 | /// connection 18 | /// nodeVaule 19 | /// diagnosticLog 20 | /// subLog 21 | /// 22 | /// 23 | public string RequestType { get; set; } 24 | 25 | /// 26 | /// 数据内容 27 | /// 28 | public T Data { get; set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.CmdHandler/Models/WebSocketProtocol.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IOTCS.EdgeGateway.CmdHandler 4 | { 5 | public class WebSocketProtocol 6 | { 7 | /// 8 | /// 消息流水号 9 | /// 10 | public string RequestId { get; set; } = Guid.NewGuid().ToString("N"); 11 | 12 | /// 13 | /// 请求类型 14 | /// 15 | /// pong 心跳 16 | /// dashboard 仪表盘信息 17 | /// nodeVaule 点位信息 18 | /// diagnosticLog 诊断日志 19 | /// subLog 系统日志 20 | /// 21 | /// 22 | public string RequestType { get; set; } 23 | 24 | /// 25 | /// 数据内容 26 | /// 27 | public T Data { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Plugins/Monitor/Model/WebSocketProtocol.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IOTCS.EdgeGateway.Plugins 4 | { 5 | public class WebSocketProtocol 6 | { 7 | /// 8 | /// 消息流水号 9 | /// 10 | public string RequestId { get; set; } = Guid.NewGuid().ToString("N"); 11 | 12 | /// 13 | /// 请求类型 14 | /// 15 | /// pong 心跳 16 | /// dashboard 仪表盘信息 17 | /// nodeVaule 点位信息 18 | /// diagnosticLog 诊断日志 19 | /// subLog 系统日志 20 | /// 21 | /// 22 | public string RequestType { get; set; } 23 | 24 | /// 25 | /// 数据内容 26 | /// 27 | public T Data { get; set; } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.ProcPipeline/AppPipelineModule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using Volo.Abp.Modularity; 4 | using IOTCS.EdgeGateway.BaseProcPipeline; 5 | 6 | namespace IOTCS.EdgeGateway.ProcPipeline 7 | { 8 | public class AppPipelineModule : AbpModule 9 | { 10 | //public override void ConfigureServices(ServiceConfigurationContext context) 11 | //{ 12 | // var pipeline = new PipelineContext(); 13 | // context.Services.Add(ServiceDescriptor.Singleton(pipeline)); 14 | //} 15 | 16 | public override void PostConfigureServices(ServiceConfigurationContext context) 17 | { 18 | context.Services.Add(ServiceDescriptor.Singleton()); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/DataResponseDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.ValueObject 6 | { 7 | public class DataResponseDto 8 | { 9 | /// 10 | /// true:成功 11 | /// false: 失败 12 | /// 13 | public bool Successful { get; set; } 14 | 15 | /// 16 | /// 系统出错信息 17 | /// 18 | public string ErrorMessage { get; set; } = string.Empty; 19 | 20 | /// 21 | /// 系统错误编号 22 | /// 0: 正确值 23 | /// 24 | public int ErrorCode { get; set; } = 0; 25 | 26 | /// 27 | /// 详细数据信息 28 | /// 29 | public T Data { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Core/Extensions/ByteArrayExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace System 2 | { 3 | /// 4 | /// Byte array extension methods
5 | /// 字节数组的扩展函数
6 | ///
7 | public static class ByteArrayExtensions { 8 | /// 9 | /// Convert byte array to hex former, in lower case
10 | /// 转换字节数组到Hex格式, 且英文字母是小写
11 | ///
12 | /// Byte array 13 | /// 14 | /// 15 | /// 16 | /// var bytes = new byte[] { 1, 0x12, 0x13 }; 17 | /// var hex = bytes.ToHex(); // "011213" 18 | /// 19 | /// 20 | public static string ToHex(this byte[] data) { 21 | if (data == null) { 22 | return ""; 23 | } 24 | return BitConverter.ToString(data).Replace("-", "").ToLowerInvariant(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Logging/Console/ConsoleLoggerFactoryExtensions.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Logging.Console; 2 | 3 | namespace IOTCS.EdgeGateway.Logging 4 | { 5 | /// 6 | /// 控制台日志工厂() 扩展 7 | /// 8 | public static class ConsoleLoggerFactoryExtensions 9 | { 10 | /// 11 | /// 添加控制台输出记录器 12 | /// 13 | /// 日志工厂 14 | /// 最小日志级别 15 | /// 是否启用颜色 16 | public static ILoggerFactory AddConsole(this ILoggerFactory factory, LogLevel minLevel, bool colorEnabled = true) 17 | { 18 | factory.AddProvider(new ConsoleLoggerProvider(minLevel, colorEnabled)); 19 | return factory; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/Repositories/IDeviceRepository.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.Models; 2 | using IOTCS.EdgeGateway.Domain.ValueObject; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace IOTCS.EdgeGateway.Domain.Repositories 9 | { 10 | public interface IDeviceRepository 11 | { 12 | Task Create(DeviceModel deviceModel); 13 | 14 | Task Update(DeviceModel deviceModel); 15 | 16 | Task Delete(DeviceModel deviceModel); 17 | 18 | Task> GetDeviceGroup(); 19 | 20 | Task> GetGroupByDeviceId(string deviceId); 21 | 22 | Task> GetAsync(); 23 | 24 | Task GetNodeTypeConfigByDriveType(string driveType); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/Models/ResourceModel.cs: -------------------------------------------------------------------------------- 1 | using FreeSql.DataAnnotations; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace IOTCS.EdgeGateway.Domain.Models 7 | { 8 | [Table(Name = "tb_resource")] 9 | public class ResourceModel 10 | { 11 | public string Id { get; set; } 12 | 13 | /// 14 | /// 资源类型 15 | /// 16 | public string ResourceType { get; set; } 17 | 18 | /// 19 | /// 资源名称 20 | /// 21 | public string ResourceName { get; set; } 22 | 23 | /// 24 | /// 资源参数 => JSON 25 | /// 26 | public string ResourceParams { get; set; } 27 | 28 | public string CreaterBy { get; set; } 29 | public string CreateTime { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Plugins/Monitor/Model/SystemInfoDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Plugins.Monitor 6 | { 7 | public class SystemInfoDto 8 | { 9 | public PerformanceDto Performance { get; set; } 10 | 11 | public List Connections { get; set; } 12 | } 13 | 14 | public class PerformanceDto 15 | { 16 | public float CpuRate { get; set; } 17 | 18 | public ulong AvailableMemory { get; set; } 19 | 20 | public ulong Memory { get; set; } 21 | 22 | /// 23 | /// 网络上行速度 24 | /// 25 | public ulong UplinkSpeed { get; set; } 26 | 27 | /// 28 | /// 网络下行速度 29 | /// 30 | public ulong DownlinkSpeed { get; set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Application/IOTCS.EdgeGateway.Application.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.ProcPipeline/IOTCS.EdgeGateway.ProcPipeline.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/ResourceDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.ValueObject 6 | { 7 | public class ResourceDto 8 | { 9 | 10 | /// 11 | /// Id 12 | /// 13 | public string Id { get; set; } 14 | /// 15 | /// 资源类型,1.db, 2.http, 3.mqtt 16 | /// 17 | public string ResourceType { get; set; } 18 | 19 | /// 20 | /// 资源名称 21 | /// 22 | public string ResourceName { get; set; } 23 | 24 | /// 25 | /// 资源参数 => JSON 26 | /// 27 | public string ResourceParams { get; set; } 28 | public string CreaterBy { get; set; } 29 | 30 | public string CreateTime { get; set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Repository/QuickCollect.SCADA.Server.Repository.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Server/IOTCS.EdgeGateway.Server.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | Always 19 | 20 | 21 | Always 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.ResDriver/IOTCS.EdgeGateway.ResDriver.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Logging/Logging/Internal/NullLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IOTCS.EdgeGateway.Logging.Internal 4 | { 5 | /// 6 | /// 空日志操作 7 | /// 8 | internal class NullLogger : ILogger 9 | { 10 | /// 11 | /// 空日志操作实例 12 | /// 13 | internal static NullLogger Instance = new NullLogger(); 14 | 15 | /// 16 | /// 检查给定日志级别是否启用 17 | /// 18 | /// 日志级别 19 | public bool IsEnabled(LogLevel level) => false; 20 | 21 | /// 22 | /// 写入日志 23 | /// 24 | /// 日志级别 25 | /// 日志消息 26 | /// 异常信息 27 | public void Log(LogLevel level, string message, Exception exception) 28 | { 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/Notification/NotifyBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Runtime.CompilerServices; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.ValueObject.Notification 6 | { 7 | public class NotifyBase : INotifyPropertyChanged 8 | { 9 | public event PropertyChangedEventHandler PropertyChanged; 10 | protected bool SetProperty(ref T storage, T value, [CallerMemberName] String propertyName = null) 11 | { 12 | if (object.Equals(storage, value)) return false; 13 | storage = value; 14 | this.OnPropertyChanged(propertyName); 15 | return true; 16 | } 17 | 18 | protected void OnPropertyChanged([CallerMemberName] string propertyName = null) 19 | { 20 | var eventHandler = this.PropertyChanged; 21 | if (eventHandler != null) 22 | eventHandler(this, new PropertyChangedEventArgs(propertyName)); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Logging/Console/Console/IConsole.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IOTCS.EdgeGateway.Logging.Console 4 | { 5 | /// 6 | /// 控制台 7 | /// 8 | internal interface IConsole 9 | { 10 | /// 11 | /// 写入 12 | /// 13 | /// 日志消息 14 | /// 背景色 15 | /// 前景色 16 | void Write(string message, ConsoleColor? background, ConsoleColor? foreground); 17 | 18 | /// 19 | /// 写入并换行 20 | /// 21 | /// 日志消息 22 | /// 背景色 23 | /// 前景色 24 | void WriteLine(string message, ConsoleColor? background, ConsoleColor? foreground); 25 | 26 | /// 27 | /// 清除缓冲区,并将缓冲数据写入 28 | /// 29 | void Flush(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Freesql/Extensions/OuterDbContextServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | 2 | using IOTCS.EdgeGateway.Freesql; 3 | using IOTCS.EdgeGateway.Freesql.Extensions; 4 | using System; 5 | 6 | namespace Microsoft.Extensions.DependencyInjection 7 | { 8 | public static class OuterDbContextServiceCollectionExtensions 9 | { 10 | public static IServiceCollection AddOuterDbContext(this IServiceCollection services, Action options) 11 | { 12 | if (services == null) 13 | { 14 | throw new ArgumentNullException(nameof(services)); 15 | } 16 | 17 | if (options == null) 18 | { 19 | throw new ArgumentNullException(nameof(options)); 20 | } 21 | 22 | services.AddOptions(); 23 | services.Configure(options); 24 | services.Add(ServiceDescriptor.Singleton()); 25 | 26 | return services; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/Models/DataLocationModel.cs: -------------------------------------------------------------------------------- 1 | using FreeSql.DataAnnotations; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace IOTCS.EdgeGateway.Domain.Models 7 | { 8 | [Table(Name = "tb_datalocation")] 9 | public class DataLocationModel 10 | { 11 | public string Id { get; set; } 12 | 13 | public string ParentId { get; set; } 14 | 15 | public string DisplayName { get; set; } 16 | 17 | public string NodePreStamp { get; set; } 18 | 19 | public string NodeAddress { get; set; } 20 | 21 | public int NodeLength { get; set; } 22 | 23 | public string NodeType { get; set; } 24 | 25 | public string Expressions { get; set; } 26 | 27 | public string CreaterBy { get; set; } 28 | 29 | public string CreateTime { get; set; } 30 | 31 | public string UpdateBy { get; set; } 32 | 33 | public string UpdateTime { get; set; } 34 | 35 | public string Attribute { get; set; } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/Models/DeviceModel.cs: -------------------------------------------------------------------------------- 1 | using FreeSql.DataAnnotations; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace IOTCS.EdgeGateway.Domain.Models 7 | { 8 | [Table(Name = "tb_device")] 9 | public class DeviceModel 10 | { 11 | public string Id { get; set; } 12 | 13 | public string DeviceName { get; set; } 14 | 15 | public string Description { get; set; } 16 | 17 | public string DriveId { get; set; } 18 | 19 | public string DeviceType { get; set; } 20 | 21 | public string CreateTime { get; set; } 22 | 23 | public string CreaterBy { get; set; } 24 | 25 | public string UpdateTime { get; set; } 26 | 27 | public string UpdateBy { get; set; } 28 | 29 | public string ParentId { get; set; } 30 | 31 | //是否启用 0关 1开 32 | public int InUse { get; set; } 33 | 34 | public string Topic { get; set; } 35 | 36 | public int Duration { get; set; } 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Server/Program.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Infrastructure.WebApi; 2 | using Microsoft.AspNetCore.Hosting; 3 | using Microsoft.Extensions.Configuration; 4 | using Microsoft.Extensions.Hosting; 5 | using System; 6 | using System.IO; 7 | using System.Threading.Tasks; 8 | 9 | namespace IOTCS.EdgeGateway.Server 10 | { 11 | class Program 12 | { 13 | static async Task Main(string[] args) 14 | { 15 | await CreateHostBuilder(args).Build().RunAsync(); 16 | } 17 | 18 | public static IHostBuilder CreateHostBuilder(string[] args) => 19 | Host.CreateDefaultBuilder(args) 20 | .UseContentRoot(Directory.GetCurrentDirectory()) 21 | .ConfigureAppConfiguration(config => 22 | { 23 | config.AddJsonFile("appSettings.json", true, true); 24 | }) 25 | .ConfigureWebHostDefaults(builder => { 26 | builder.UseStartup(); 27 | }) 28 | .UseWindowsService(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.MqttHandler/Extensions/MqttContextOptions.cs: -------------------------------------------------------------------------------- 1 | namespace IOTCS.EdgeGateway.MqttHandler.Extensions 2 | { 3 | public class MqttContextOptions 4 | { 5 | /// 6 | /// 是否使用用户名和密码 7 | /// 8 | public int IsUsingUser { get; set; } 9 | 10 | /// 11 | /// Mqtt Ip地址 12 | /// 13 | public string IpAddress { get; set; } 14 | 15 | /// 16 | /// 端口号 17 | /// 18 | public int Port { get; set; } 19 | 20 | /// 21 | /// 客户端ID号 22 | /// 23 | public string ClientId { get; set; } 24 | 25 | /// 26 | /// 用户名 27 | /// 28 | public string UserId { get; set; } 29 | 30 | /// 31 | /// 密码 32 | /// 33 | public string Password { get; set; } 34 | 35 | /// 36 | /// 超时时间 37 | /// 38 | public int Timeout { get; set; } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.WebSocketManager/Strategies/MethodInvocationStrategy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net.WebSockets; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace IOTCS.EdgeGateway.WebSocketManager.Common 9 | { 10 | /// 11 | /// The base class of all method invocation strategies. 12 | /// 13 | public abstract class MethodInvocationStrategy 14 | { 15 | /// 16 | /// Called when an invoke method call has been received. 17 | /// 18 | /// The web-socket of the client that wants to invoke a method. 19 | /// 20 | /// The invocation descriptor containing the method name and parameters. 21 | /// 22 | /// Awaitable Task. 23 | public virtual Task OnInvokeMethodReceivedAsync(WebSocket socket, InvocationDescriptor invocationDescriptor) 24 | { 25 | throw new NotImplementedException(); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/Device/DeviceDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.ValueObject 6 | { 7 | public class DeviceDto 8 | { 9 | public string Id { get; set; } 10 | 11 | public string DeviceName { get; set; } 12 | 13 | public string Description { get; set; } 14 | 15 | public string DriveId { get; set; } 16 | 17 | public string DriveName { get; set; } 18 | 19 | public string DeviceType { get; set; } 20 | 21 | public string CreateTime { get; set; } 22 | 23 | public string CreaterBy { get; set; } 24 | 25 | public string UpdateTime { get; set; } 26 | 27 | public string UpdateBy { get; set; } 28 | 29 | public string ParentId { get; set; } 30 | public int InUse { get; set; } 31 | 32 | public int Duration { get; set; } 33 | public string Topic { get; set; } 34 | public List Childrens { get; set; } 35 | 36 | // public bool HasChildren { get; set; } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/DataLocationDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace IOTCS.EdgeGateway.Domain.ValueObject 6 | { 7 | public class DataLocationDto 8 | { 9 | public string Id { get; set; } 10 | 11 | public string ParentId { get; set; } 12 | 13 | public string DisplayName { get; set; } 14 | 15 | public string NodePreStamp { get; set; } 16 | 17 | public string NodeAddress { get; set; } 18 | 19 | public int NodeLength { get; set; } 20 | 21 | public string NodeType { get; set; } 22 | 23 | public string Expressions { get; set; } 24 | 25 | public string CreaterBy { get; set; } 26 | 27 | public string CreateTime { get; set; } 28 | 29 | public string UpdateBy { get; set; } 30 | 31 | public string UpdateTime { get; set; } 32 | 33 | public string Attribute { get; set; } 34 | 35 | public string Source { get; set; } 36 | 37 | public string Sink { get; set; } 38 | 39 | public string Status { get; set; } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Diagnostics/UINotification.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Logging; 2 | using MediatR; 3 | 4 | namespace IOTCS.EdgeGateway.Diagnostics 5 | { 6 | public class UINotification : IUINotification 7 | { 8 | private readonly ILogger _logger; 9 | private readonly IMediator _mediator; 10 | 11 | public UINotification(ILogger logger, IMediator mediator) 12 | { 13 | this._logger = logger; 14 | this._mediator = mediator; 15 | } 16 | 17 | /// 18 | /// 发送数据到界面展示 19 | /// 20 | /// 21 | /// 22 | public void Publish(string message, string deviceID, string groupID) 23 | { 24 | var command = new Commands.UINotification 25 | { 26 | UIMessage = message, 27 | GroupID = groupID, 28 | DeviceID = deviceID //DeviceID 29 | }; 30 | _mediator.Publish(command).ConfigureAwait(false).GetAwaiter().GetResult(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/ValueObject/Notification/NotifyChangeVariableDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Text; 5 | 6 | namespace IOTCS.EdgeGateway.Domain.ValueObject.Notification 7 | { 8 | public class NotifyChangeVariableDto : NotifyBase 9 | { 10 | public string Id { get; set; } 11 | 12 | public string ParentId { get; set; } 13 | 14 | public string DisplayName { get; set; } 15 | 16 | public string NodePreStamp { get; set; } 17 | 18 | public string NodeAddress { get; set; } 19 | 20 | public int NodeLength { get; set; } 21 | 22 | public string NodeType { get; set; } 23 | 24 | public string Expressions { get; set; } 25 | 26 | private string _Source = string.Empty; 27 | 28 | public string Source 29 | { 30 | get { return _Source; } 31 | set 32 | { this.SetProperty(ref this._Source, value); } 33 | } 34 | 35 | public string Sink { get; set; } 36 | 37 | public string Status { get; set; } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Server/appSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Urls": "http://127.0.0.1:9001", 3 | "DataRecordingTime": "2019-09-01 00:00:00", 4 | "Debug": true, 5 | "SessionTimeOut": 60, 6 | "LogPath": "E:\\Project\\Log", 7 | "ConnectionStrings": { 8 | "DBReadWrite": { 9 | "DbType": "5", 10 | "DbIp": "192.168.0.10", 11 | "DbPort": "5321", 12 | "Database": "iotcs", 13 | "DbUid": "ssss", 14 | "DbPwd": "123456" 15 | } 16 | }, 17 | "WebSocketServer": { 18 | "IpAddress": "*", 19 | "Port": 8001, 20 | "Path": "/" 21 | }, 22 | "SystemLog": { 23 | "IsStart": false, 24 | "ExpireDays": "1", 25 | "CronExpression": "0/5 * * * * ?", 26 | "LogDirectories": [ 27 | { 28 | "SubFileType": "1", 29 | "LogPath": "E:\\Project\\Log" 30 | }, 31 | { 32 | "SubFileType": "1", 33 | "LogPath": "E:\\Project\\Log" 34 | } 35 | ] 36 | }, 37 | "Application": { 38 | "CorsOrigins": "*" 39 | }, 40 | "Jwt": { 41 | "SecurityKey": "dd%88*377f6d&f£$$£$FdddFF33fssDG^!3", 42 | "Issuer": "IOTCS", 43 | "Audience": "airclient" 44 | } 45 | } -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.WebSocketManager/Networking/RemoteException.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | 4 | namespace IOTCS.EdgeGateway.WebSocketManager.Common 5 | { 6 | /// 7 | /// An exception that occured remotely. 8 | /// 9 | public class RemoteException 10 | { 11 | /// 12 | /// Gets or sets the exception message. 13 | /// 14 | /// The exception message. 15 | [JsonProperty("message")] 16 | public string Message { get; set; } = $"A remote exception occured"; 17 | 18 | /// 19 | /// Initializes a new instance of the class. 20 | /// 21 | public RemoteException() 22 | { 23 | } 24 | 25 | /// 26 | /// Initializes a new instance of the class. 27 | /// 28 | /// The exception that occured. 29 | public RemoteException(Exception exception) 30 | { 31 | Message = $"A remote exception occured: '{exception.Message}'."; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.WebSocketManager/Networking/InvocationResult.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | 4 | namespace IOTCS.EdgeGateway.WebSocketManager.Common 5 | { 6 | /// 7 | /// Represents the return value of a method that was executed remotely. 8 | /// 9 | public class InvocationResult 10 | { 11 | /// 12 | /// Gets or sets the unique identifier associated with the invocation. 13 | /// 14 | /// The unique identifier of the invocation. 15 | [JsonProperty("identifier")] 16 | public Guid Identifier { get; set; } 17 | 18 | /// 19 | /// Gets or sets the result of the method call. 20 | /// 21 | /// The result of the method call. 22 | [JsonProperty("result")] 23 | public object Result { get; set; } 24 | 25 | /// 26 | /// Gets or sets the remote exception the method call caused. 27 | /// 28 | /// The remote exception of the method call. 29 | [JsonProperty("exception")] 30 | public RemoteException Exception { get; set; } 31 | } 32 | } -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.WebSocketManager/Networking/InvocationDescriptor.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | 4 | namespace IOTCS.EdgeGateway.WebSocketManager.Common 5 | { 6 | /// 7 | /// Represents a method name with parameters that is to be executed remotely. 8 | /// 9 | public class InvocationDescriptor 10 | { 11 | /// 12 | /// Gets or sets the name of the remote method. 13 | /// 14 | /// The name of the remote method. 15 | [JsonProperty("methodName")] 16 | public string MethodName { get; set; } 17 | 18 | /// 19 | /// Gets or sets the arguments passed to the method. 20 | /// 21 | /// The arguments passed to the method. 22 | [JsonProperty("arguments")] 23 | public object[] Arguments { get; set; } 24 | 25 | /// 26 | /// Gets or sets the unique identifier used to associate return values with this call. 27 | /// 28 | /// The unique identifier of the invocation. 29 | [JsonProperty("identifier")] 30 | public Guid Identifier { get; set; } = Guid.Empty; 31 | } 32 | } -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.CmdHandler/IOTCS.EdgeGateway.CmdHandler.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/Models/RuleModel.cs: -------------------------------------------------------------------------------- 1 | using FreeSql.DataAnnotations; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace IOTCS.EdgeGateway.Domain.Models 7 | { 8 | [Table(Name = "tb_rules")] 9 | public class RuleModel 10 | { 11 | /// 12 | /// 规则ID 13 | /// 14 | [Column(IsIdentity = true, IsPrimary = true)] 15 | public string RuleId { get; set; } 16 | 17 | /// 18 | /// 规则名称 19 | /// 20 | public string RuleName { get; set; } 21 | 22 | /// 23 | /// 处理主题 24 | /// 25 | public string Topics { get; set; } 26 | /// 27 | /// 规则Json 28 | /// 29 | [Column(DbType="longtext")] 30 | public string RuleJson { get; set; } 31 | /// 32 | ///规则引擎json 33 | /// 34 | [Column(DbType = "longtext")] 35 | public string RuleEngineJson { get; set; } 36 | /// 37 | /// 创建人 38 | /// 39 | public string Creater { get; set; } 40 | /// 41 | /// 创建时间 42 | /// 43 | public string CreateTime { get; set; } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.WebSocketManager/WebSocketManagerExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using Microsoft.AspNetCore.Builder; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.Extensions.DependencyInjection; 5 | 6 | namespace IOTCS.EdgeGateway.WebSocketManager 7 | { 8 | public static class WebSocketManagerExtensions 9 | { 10 | public static IServiceCollection AddWebSocketManager(this IServiceCollection services, Assembly assembly = null) 11 | { 12 | services.AddTransient(); 13 | 14 | Assembly ass = assembly ?? Assembly.GetEntryAssembly(); 15 | 16 | foreach (var type in ass.ExportedTypes) 17 | { 18 | if (type.GetTypeInfo().BaseType == typeof(WebSocketHandler)) 19 | { 20 | services.AddSingleton(type); 21 | } 22 | } 23 | 24 | return services; 25 | } 26 | 27 | public static IApplicationBuilder MapWebSocketManager(this IApplicationBuilder app, 28 | PathString path, 29 | WebSocketHandler handler) 30 | { 31 | return app.Map(path, (_app) => _app.UseMiddleware(handler)); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/WebApi/Filter/HttpGlobalExceptionFilter.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Logging; 2 | using Microsoft.AspNetCore.Hosting; 3 | using Microsoft.AspNetCore.Mvc; 4 | using Microsoft.AspNetCore.Mvc.Filters; 5 | 6 | using System.Net; 7 | 8 | namespace IOTCS.EdgeGateway.Infrastructure.WebApi 9 | { 10 | public class HttpGlobalExceptionFilter : IExceptionFilter 11 | { 12 | private readonly ILogger _logger; 13 | private readonly IWebHostEnvironment _env; 14 | 15 | public HttpGlobalExceptionFilter(ILoggerFactory logger, IWebHostEnvironment env) 16 | { 17 | _logger = logger.CreateLogger("SystemWebApi"); 18 | _env = env; 19 | } 20 | 21 | public void OnException(ExceptionContext context) 22 | { 23 | if(!context.ExceptionHandled) 24 | { 25 | var msg = context.Exception.Message + "||" + context.Exception.StackTrace; 26 | _logger.Error(msg); 27 | context.ExceptionHandled = true; 28 | } 29 | } 30 | } 31 | 32 | public class ApplicationErrorResult : ObjectResult 33 | { 34 | public ApplicationErrorResult(object value) : base(value) 35 | { 36 | StatusCode = (int)HttpStatusCode.InternalServerError; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Plugins/IOTCS.EdgeGateway.Plugins.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Core/Collections/IKeyValueCache.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace IOTCS.EdgeGateway.Core.Collections 5 | { 6 | /// 7 | /// 键值缓存的接口
8 | /// 它应该是线程安全的
9 | ///
10 | public interface IKeyValueCache { 11 | /// 12 | /// 插入值到缓存
13 | ///
14 | /// Cache key 15 | /// Cache value 16 | /// Keep time 17 | void Put(TKey key, TValue value, TimeSpan keepTime); 18 | 19 | /// 20 | /// 尝试获取缓存制
21 | /// 如果值不存在或者已过期则返回false
22 | ///
23 | /// Cache key 24 | /// Cache value 25 | /// 26 | bool TryGetValue(TKey key, out TValue value); 27 | 28 | bool IsContainKey(TKey key); 29 | 30 | /// 31 | /// 删除已缓存的值
32 | ///
33 | /// Cache key 34 | void Remove(TKey key); 35 | 36 | /// 37 | /// 获取缓存值的数量
38 | ///
39 | /// 40 | int Count(); 41 | 42 | /// 43 | /// 删除所有缓存值
44 | ///
45 | void Clear(); 46 | 47 | TValue this[TKey index] { get;} 48 | 49 | IEnumerable SKeys { get; } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Freesql/DbContext/AppFreeSqlDbContextModule.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Configuration; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using Volo.Abp.Modularity; 4 | 5 | namespace IOTCS.EdgeGateway.Freesql 6 | { 7 | public class AppFreeSqlDbContextModule : AbpModule 8 | { 9 | public override void ConfigureServices(ServiceConfigurationContext context) 10 | { 11 | //注册内容到容器中 12 | var serviceProvider = context.Services.BuildServiceProvider(); 13 | var configuration = serviceProvider.GetService(); 14 | context.Services.AddCommonDbContext(); 15 | context.Services.AddDbContext(options => 16 | { 17 | options.Database = configuration["ConnectionStrings:DBReadWrite:Database"]; 18 | options.DbIp = configuration["ConnectionStrings:DBReadWrite:DbIp"]; 19 | options.DbPort = configuration["ConnectionStrings:DBReadWrite:DbPort"]; 20 | options.DbType = configuration["ConnectionStrings:DBReadWrite:DbType"]; 21 | options.DbUid = configuration["ConnectionStrings:DBReadWrite:DbUid"]; 22 | options.DbPwd = configuration["ConnectionStrings:DBReadWrite:DbPwd"]; 23 | options.Debug = configuration["Debug"].ToLower() == "true"; 24 | }); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Plugins/AppPluginModule.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using System; 3 | using Volo.Abp; 4 | using IOTCS.EdgeGateway.Logging; 5 | using IOTCS.EdgeGateway.Plugins.Executor; 6 | using IOTCS.EdgeGateway.Plugins.Monitor; 7 | using IOTCS.EdgeGateway.Plugins.DataInitialize; 8 | using Volo.Abp.Modularity; 9 | 10 | namespace IOTCS.EdgeGateway.Plugins 11 | { 12 | public class AppPluginModule : AbpModule 13 | { 14 | /// 15 | /// 插件运行启动函数,同时也是插件操作的入口 16 | /// 17 | public override void OnApplicationInitialization(ApplicationInitializationContext context) 18 | { 19 | var serviceProvider = context.ServiceProvider; 20 | var logger = serviceProvider.GetService(); 21 | try 22 | { 23 | var init = serviceProvider.GetService(); 24 | init.Executing(); 25 | var executor = serviceProvider.GetService(); 26 | executor.Run(); 27 | var monitorTask = serviceProvider.GetService(); 28 | monitorTask.Executing(); 29 | } 30 | catch (Exception e) 31 | { 32 | logger.Error($"插件启动异常, 信息 => {e.Message},位置 => {e.StackTrace}"); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Logging/Logging/LogLevel.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | 3 | namespace IOTCS.EdgeGateway.Logging 4 | { 5 | /// 6 | /// 日志级别 7 | /// 8 | public enum LogLevel 9 | { 10 | /// 11 | /// 跟踪。包含最详细的日志信息,这些消息可能包含敏感的应用程序数据。这些消息都是默认禁用的,不应该在生产环境中启用。 12 | /// 13 | [Description("跟踪")] 14 | Trace = 0, 15 | /// 16 | /// 调试。在开发过程中日志用于交互式调查,这些日志应该主要包含有用的调试信息。 17 | /// 18 | [Description("调试")] 19 | Debug = 1, 20 | /// 21 | /// 信息。日志跟踪应用程序的通用流,这些日志应该长期显示。 22 | /// 23 | [Description("信息")] 24 | Information = 2, 25 | /// 26 | /// 警告。应用程序流的异常或意外事件,但不会导致应用程序停止执行。 27 | /// 28 | [Description("警告")] 29 | Warning = 3, 30 | /// 31 | /// 错误。强调在当前流的执行停止时由于失败,这些应该显示当前活动的失败,不是一个应用程序的失败。 32 | /// 33 | [Description("错误")] 34 | Error = 4, 35 | /// 36 | /// 致命错误。日志描述一个不可恢复的应用程序或系统崩溃,或者一个灾难性故障,需要立即注意。 37 | /// 38 | [Description("致命错误")] 39 | Fatal = 5, 40 | /// 41 | /// 关闭所有日志,不输出日志 42 | /// 43 | [Description("关闭日志")] 44 | None = 6 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Freesql/IOTCS.EdgeGateway.Freesql.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Logging/Console/Console/ConsoleLoggerProvider.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Logging.Console.Internal; 2 | 3 | namespace IOTCS.EdgeGateway.Logging.Console 4 | { 5 | /// 6 | /// 控制台日志提供程序 7 | /// 8 | public class ConsoleLoggerProvider : ILoggerProvider 9 | { 10 | /// 11 | /// 最小日志级别 12 | /// 13 | private readonly LogLevel _minLevel; 14 | 15 | /// 16 | /// 是否启用颜色 17 | /// 18 | private readonly bool _colorEnabled; 19 | 20 | /// 21 | /// 初始化一个类型的实例 22 | /// 23 | /// 最小日志级别 24 | /// 是否启用颜色 25 | public ConsoleLoggerProvider(LogLevel minLevel, bool colorEnabled = true) 26 | { 27 | _minLevel = minLevel; 28 | _colorEnabled = colorEnabled; 29 | } 30 | 31 | /// 32 | /// 释放资源 33 | /// 34 | public void Dispose() 35 | { 36 | } 37 | 38 | /// 39 | /// 创建一个新的实例 40 | /// 41 | /// 日志名称 42 | public ILogger CreateLogger(string name) => new ConsoleLogger(name, _minLevel) { ColorEnabled = _colorEnabled }; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Application/Imps/FreeSqlMgrService.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.Models; 2 | using IOTCS.EdgeGateway.Domain.Repositories; 3 | using IOTCS.EdgeGateway.Domain.ValueObject; 4 | using IOTCS.EdgeGateway.Freesql.Helper; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | 9 | namespace IOTCS.EdgeGateway.Application.Imps 10 | { 11 | public class FreeSqlMgrService : IFreeSqlMgrService 12 | { 13 | private readonly IFreeSqlMgrRepository _repository; 14 | 15 | public FreeSqlMgrService(IFreeSqlMgrRepository repository) 16 | { 17 | _repository = repository; 18 | } 19 | 20 | public InitailizeDatabaseDto CreateDbConnections(IEnumerable resources) 21 | { 22 | var models = from r in resources 23 | select new ResourceModel 24 | { 25 | Id = r.Id, 26 | ResourceType = r.ResourceType, 27 | ResourceName = r.ResourceName, 28 | ResourceParams = r.ResourceParams 29 | }; 30 | var database = _repository.CreateDbConnections(models); 31 | var result = database == null ? null : database.ToModel(); 32 | 33 | return result; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Repository/RepositoryModule.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.Repositories; 2 | using IOTCS.EdgeGateway.Freesql; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using Volo.Abp.Modularity; 5 | 6 | namespace IOTCS.EdgeGateway.Repository 7 | { 8 | [DependsOn(typeof(AppFreeSqlDbContextModule))] 9 | public class RepositoryModule : AbpModule 10 | { 11 | public override void ConfigureServices(ServiceConfigurationContext context) 12 | { 13 | context.Services.Add(ServiceDescriptor.Singleton()); 14 | context.Services.Add(ServiceDescriptor.Singleton()); 15 | context.Services.Add(ServiceDescriptor.Singleton()); 16 | context.Services.Add(ServiceDescriptor.Singleton()); 17 | context.Services.Add(ServiceDescriptor.Singleton()); 18 | context.Services.Add(ServiceDescriptor.Singleton()); 19 | context.Services.Add(ServiceDescriptor.Singleton()); 20 | context.Services.Add(ServiceDescriptor.Singleton()); 21 | context.Services.Add(ServiceDescriptor.Singleton()); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Freesql/Extensions/DbContextServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using IOTCS.EdgeGateway.Freesql; 4 | using IOTCS.EdgeGateway.Freesql.Extensions; 5 | using IOTCS.EdgeGateway.Logging; 6 | 7 | namespace Microsoft.Extensions.DependencyInjection 8 | { 9 | public static class DbContextServiceCollectionExtensions 10 | { 11 | public static IServiceCollection AddDbContext(this IServiceCollection services, Action options) 12 | { 13 | if (services == null) 14 | { 15 | throw new ArgumentNullException(nameof(services)); 16 | } 17 | 18 | if (options == null) 19 | { 20 | throw new ArgumentNullException(nameof(options)); 21 | } 22 | 23 | services.AddOptions(); 24 | services.Configure(options); 25 | services.Add(ServiceDescriptor.Singleton()); 26 | var serviceProvider = services.BuildServiceProvider(); 27 | var logger = serviceProvider.GetService(); 28 | logger.Info($"初始化FreeSql连接开始............!"); 29 | var dbSession = serviceProvider.GetService(); 30 | var freeSql = dbSession.CreateDbContext(); 31 | services.Add(ServiceDescriptor.Singleton(freeSql)); 32 | logger.Info($"初始化FreeSql连接结束............!"); 33 | 34 | return services; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/WebApi/Controller/SystemController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using System.Collections.Generic; 4 | using System.Threading.Tasks; 5 | using IOTCS.EdgeGateway.Domain.ValueObject; 6 | using IOTCS.EdgeGateway.Core; 7 | 8 | namespace IOTCS.EdgeGateway.Infrastructure.WebApi.Controller 9 | { 10 | public class SystemController : ControllerBase 11 | { 12 | private SystemManagerDto _publish; 13 | 14 | public SystemController() 15 | { 16 | _publish = IocManager.Instance.GetService(); 17 | } 18 | 19 | [HttpPost] 20 | [Route("config/data/publish")] 21 | public async Task> PublishConfigAsync() 22 | { 23 | var result = new DataResponseDto(); 24 | 25 | _publish.IsPublishing = true; 26 | result.Successful = true; 27 | result.ErrorMessage = string.Empty; 28 | 29 | return await Task.FromResult(result); 30 | } 31 | 32 | [HttpPost] 33 | [Route("system/reboot/task")] 34 | public async Task> RebootTasksAsync() 35 | { 36 | var result = new DataResponseDto(); 37 | 38 | _publish.Reboot = true; 39 | result.Successful = true; 40 | result.ErrorMessage = string.Empty; 41 | 42 | return await Task.FromResult(result); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Reflection/StructTuple.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace System.FastReflection 3 | { 4 | /// 5 | /// Struct type tuple 6 | /// 7 | internal struct StructTuple : IEquatable> 8 | { 9 | public TFirst First { get; private set; } 10 | public TSecond Second { get; private set; } 11 | 12 | public StructTuple(TFirst first, TSecond second) 13 | { 14 | First = first; 15 | Second = second; 16 | } 17 | 18 | public bool Equals(StructTuple obj) 19 | { 20 | return ((First == null) == (obj.First == null)) && 21 | (First == null ? true : 22 | (object.ReferenceEquals(First, obj.First) || First.Equals(obj.First))) && 23 | ((Second == null) == (obj.Second == null)) && 24 | (Second == null ? true : 25 | (object.ReferenceEquals(Second, obj.Second) || Second.Equals(obj.Second))); 26 | } 27 | 28 | public override bool Equals(object obj) 29 | { 30 | return (obj is StructTuple) && Equals((StructTuple)obj); 31 | } 32 | 33 | public override int GetHashCode() 34 | { 35 | // same with Tuple.CombineHashCodess 36 | var hash_1 = First?.GetHashCode() ?? 0; 37 | var hash_2 = Second?.GetHashCode() ?? 0; 38 | return (hash_1 << 5) + hash_1 ^ hash_2; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Core/Security/MD5Helper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Security.Cryptography; 5 | 6 | namespace IOTCS.EdgeGateway.Core.Security 7 | { 8 | public class MD5Helper 9 | { 10 | /// 11 | /// 生成32位大写MD5加密字符串 12 | /// 13 | /// 输入值 14 | /// 15 | public static string GenerateMd5String(string inputValue) 16 | { 17 | var result = string.Empty; 18 | 19 | //32位大写 20 | using (var md5 = MD5.Create()) 21 | { 22 | var hashResult = md5.ComputeHash(Encoding.UTF8.GetBytes(inputValue)); 23 | var strResult = BitConverter.ToString(hashResult); 24 | result = strResult.Replace("-", ""); 25 | } 26 | 27 | return result; 28 | } 29 | 30 | public static string GenerateMd5Token(string name) 31 | { 32 | var result = string.Empty; 33 | var saltString = "@#$%unilever*&"; 34 | 35 | //32位大写 36 | using (var md5 = MD5.Create()) 37 | { 38 | saltString = saltString + name; 39 | var hashResult = md5.ComputeHash(Encoding.UTF8.GetBytes(saltString)); 40 | var strResult = BitConverter.ToString(hashResult); 41 | result = strResult.Replace("-", ""); 42 | } 43 | 44 | return result; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Library/OpcUaStatusEventArgs.cs: -------------------------------------------------------------------------------- 1 | using Opc.Ua; 2 | using System; 3 | 4 | namespace IOTCS.EdgeGateway.Library 5 | { 6 | /// 7 | /// OPC UA的状态更新消息 8 | /// 9 | public class OpcUaStatusEventArgs 10 | { 11 | /// 12 | /// 是否异常 13 | /// 14 | public bool Error { get; set; } 15 | /// 16 | /// 时间 17 | /// 18 | public DateTime Time { get; set; } 19 | /// 20 | /// 文本 21 | /// 22 | public string Text { get; set; } 23 | 24 | /// 25 | /// 转化为字符串 26 | /// 27 | /// 28 | public override string ToString() 29 | { 30 | return Error ? "[异常]" : "[正常]" + Time.ToString(" yyyy-MM-dd HH:mm:ss ") + Text; 31 | } 32 | } 33 | 34 | /// 35 | /// 读取属性过程中用于描述的 36 | /// 37 | public class OpcNodeAttribute 38 | { 39 | /// 40 | /// 属性的名称 41 | /// 42 | public string Name { get; set; } 43 | /// 44 | /// 属性的类型描述 45 | /// 46 | public string Type { get; set; } 47 | /// 48 | /// 操作结果状态描述 49 | /// 50 | public StatusCode StatusCode { get; set; } 51 | /// 52 | /// 属性的值,如果读取错误,返回文本描述 53 | /// 54 | public object Value { get; set; } 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Core/Collections/ConcurrentHashSet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Concurrent; 4 | using System.Collections.Generic; 5 | 6 | namespace IOTCS.EdgeGateway.Core.Collections 7 | { 8 | /// 并行哈希集合 9 | /// 10 | /// 主要用于频繁添加删除而又要遍历的场合 11 | /// 12 | public class ConcurrentHashSet : IEnumerable 13 | { 14 | private ConcurrentDictionary _dic = new ConcurrentDictionary(); 15 | 16 | /// 是否空集合 17 | public Boolean IsEmpty => _dic.IsEmpty; 18 | 19 | /// 元素个数 20 | public Int32 Count => _dic.Count; 21 | 22 | /// 是否包含元素 23 | /// 24 | /// 25 | public Boolean Contain(T item) => _dic.ContainsKey(item); 26 | 27 | /// 尝试添加 28 | /// 29 | /// 30 | public Boolean TryAdd(T item) => _dic.TryAdd(item, 0); 31 | 32 | /// 尝试删除 33 | /// 34 | /// 35 | public Boolean TryRemove(T item) => _dic.TryRemove(item, out var b); 36 | 37 | #region IEnumerable 成员 38 | IEnumerator IEnumerable.GetEnumerator() => _dic.Keys.GetEnumerator(); 39 | #endregion 40 | 41 | #region IEnumerable 成员 42 | IEnumerator IEnumerable.GetEnumerator() => _dic.Keys.GetEnumerator(); 43 | #endregion 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Logging/Log4NetLoggerFactoryExtensions.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Logging.Log4Net; 2 | using IOTCS.EdgeGateway.Logging.Log4Net.Internal; 3 | 4 | namespace IOTCS.EdgeGateway.Logging 5 | { 6 | /// 7 | /// Log4Net日志工厂() 扩展 8 | /// 9 | internal static class Log4NetLoggerFactoryExtensions 10 | { 11 | /// 12 | /// 添加Log4Net日志记录器 13 | /// 14 | /// 日志工厂 15 | public static ILoggerFactory AddLog4Net(this ILoggerFactory factory) => AddLog4Net(factory, InternalConst.DefaultLogName, InternalConst.DefaultConfigFile); 16 | 17 | /// 18 | /// 添加Log4Net日志记录器 19 | /// 20 | /// 日志工厂 21 | /// 配置文件 22 | /// 23 | public static ILoggerFactory AddLog4Net(this ILoggerFactory factory, string configFile) => AddLog4Net(factory, InternalConst.DefaultLogName, configFile); 24 | 25 | /// 26 | /// 添加Log4Net日志记录器 27 | /// 28 | /// 日志工厂 29 | /// 仓储名称 30 | /// 配置文件 31 | public static ILoggerFactory AddLog4Net(this ILoggerFactory factory, string repositoryName, string configFile) 32 | { 33 | factory.AddProvider(new Log4NetLoggerProvider()); 34 | Log4NetLogger.InitRepository(repositoryName, configFile); 35 | return factory; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Freesql.Helper/Domain/IRepositoryBase.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using System.Linq.Expressions; 4 | using System.Threading.Tasks; 5 | using FreeSql; 6 | 7 | namespace IOTCS.EdgeGateway.Freesql.Helper.Domain 8 | { 9 | public interface IRepositoryBase : IBaseRepository where TEntity : class 10 | { 11 | /// 12 | /// 获得Dto 13 | /// 14 | /// 15 | /// 16 | /// 17 | Task GetAsync(TKey id); 18 | 19 | /// 20 | /// 根据条件获取实体 21 | /// 22 | /// 23 | /// 24 | Task GetAsync(Expression> exp); 25 | 26 | /// 27 | /// 根据条件获取Dto 28 | /// 29 | /// 30 | /// 31 | Task GetAsync(Expression> exp); 32 | 33 | /// 34 | /// 软删除 35 | /// 36 | /// 37 | /// 38 | Task SoftDeleteAsync(TKey id); 39 | 40 | /// 41 | /// 批量删除 42 | /// 43 | /// 44 | /// 45 | Task SoftDeleteAsync(TKey[] id); 46 | } 47 | 48 | public interface IRepositoryBase : IRepositoryBase where TEntity : class 49 | { 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Diagnostics/SystemDiagnostics.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Diagnostics.Notification; 2 | using IOTCS.EdgeGateway.Logging; 3 | using MediatR; 4 | 5 | namespace IOTCS.EdgeGateway.Diagnostics 6 | { 7 | public class SystemDiagnostics : ISystemDiagnostics 8 | { 9 | private readonly ILogger _logger; 10 | private readonly IMediator _mediator; 11 | 12 | public SystemDiagnostics(ILogger logger, IMediator mediator) 13 | { 14 | this._logger = logger; 15 | this._mediator = mediator; 16 | } 17 | 18 | /// 19 | /// 发送订阅数据到界面展示 20 | /// 21 | /// 22 | /// 23 | public void Publish(string message) 24 | { 25 | var command = new SystemNotification 26 | { 27 | Message = message, 28 | MsgType = "subLog" 29 | }; 30 | _mediator.Publish(command).ConfigureAwait(false).GetAwaiter().GetResult(); 31 | } 32 | 33 | /// 34 | /// 发送诊断信息到界面展示 35 | /// 36 | /// 37 | /// 38 | public void PublishDiagnosticsInfo(string message) 39 | { 40 | var command = new SystemNotification 41 | { 42 | Message = message, 43 | MsgType = "diagnostics" 44 | }; 45 | _mediator.Publish(command).ConfigureAwait(false).GetAwaiter().GetResult(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/Socket/AppWebSocketModule.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.DotNetty; 2 | using IOTCS.EdgeGateway.Logging; 3 | using MediatR; 4 | using Microsoft.Extensions.Configuration; 5 | using Microsoft.Extensions.DependencyInjection; 6 | using System; 7 | using Volo.Abp; 8 | using Volo.Abp.Modularity; 9 | 10 | namespace IOTCS.EdgeGateway.Infrastructure.Socket 11 | { 12 | public class AbpWebSocketModule : AbpModule 13 | { 14 | public override void PostConfigureServices(ServiceConfigurationContext context) 15 | { 16 | var serviceProvider = context.Services.BuildServiceProvider(); 17 | var configuration = serviceProvider.GetService(); 18 | SocketOptions options = new SocketOptions 19 | { 20 | IpAddress = configuration["WebSocketServer:IpAddress"], 21 | Port = Convert.ToInt32(configuration["WebSocketServer:Port"]), 22 | Path = configuration["WebSocketServer:Path"] 23 | }; 24 | var loggerFactory = serviceProvider.GetService(); 25 | var logger = loggerFactory.CreateLogger("WebSocket"); 26 | var mediator = serviceProvider.GetService(); 27 | CommunicationManager socket = new CommunicationManager(logger, mediator); 28 | var server = socket.WebSocketServerBuilder(options).GetAwaiter().GetResult(); 29 | context.Services.Add(ServiceDescriptor.Singleton(server)); 30 | } 31 | 32 | public override void OnPreApplicationInitialization(ApplicationInitializationContext context) 33 | { 34 | 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Application/Utils/TimestampHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IOTCS.EdgeGateway.Application.Utils 4 | { 5 | public class TimestampHelper 6 | { 7 | /// 8 | /// Unix时间戳转为C#格式时间 9 | /// 10 | /// Unix时间戳格式,例如:1482115779, 或long类型 11 | /// C#格式时间 12 | public static DateTime GetDateTime(string timeStamp) 13 | { 14 | DateTime startUnixTime = System.TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc), TimeZoneInfo.Local); 15 | return startUnixTime.AddSeconds(double.Parse(timeStamp)); 16 | } 17 | 18 | /// 19 | /// 时间戳转为C#格式时间 20 | /// 21 | /// Unix时间戳格式 22 | /// C#格式时间 23 | public static DateTime GetDateTime(long timeStamp) 24 | { 25 | DateTime time = new DateTime(); 26 | try 27 | { 28 | DateTime startUnixTime = System.TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc), TimeZoneInfo.Local); 29 | return startUnixTime.AddSeconds(timeStamp); 30 | } 31 | catch 32 | { 33 | time = DateTime.Now.AddDays(-30); 34 | } 35 | return time; 36 | } 37 | 38 | /// 39 | /// 获取时间戳 40 | /// 41 | /// 42 | public static string GetTimeStamp() 43 | { 44 | TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); 45 | return Convert.ToInt64(ts.TotalSeconds).ToString(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/DomainService/Impl/RelationshipDomainService.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.Models; 2 | using IOTCS.EdgeGateway.Domain.Repositories; 3 | using IOTCS.EdgeGateway.Domain.ValueObject; 4 | using IOTCS.EdgeGateway.Freesql.Helper; 5 | using IOTCS.EdgeGateway.Logging; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | 11 | namespace IOTCS.EdgeGateway.Domain.DomainService.Impl 12 | { 13 | public class RelationshipDomainService : IRelationshipDomainService 14 | { 15 | 16 | private readonly ILogger _logger; 17 | private readonly IRelationshipRepository _repository; 18 | private readonly IResourceRepository _resourceRepository; 19 | 20 | public RelationshipDomainService(ILogger logger, 21 | IRelationshipRepository relationshipRepository, 22 | IResourceRepository resourceRepository) 23 | { 24 | this._logger = logger; 25 | this._repository = relationshipRepository; 26 | this._resourceRepository = resourceRepository; 27 | } 28 | 29 | 30 | public async Task> GetRelationship() 31 | { 32 | List result = new List(); 33 | //查询Relationship 34 | var relationships = await _repository.GetRelationship(); 35 | 36 | //绑定名称 37 | foreach (var relationship in relationships) 38 | { 39 | var dto = relationship.ToModel(); 40 | 41 | var resouce = await _resourceRepository.GetById(relationship.ResourceId); 42 | dto.ResourceName = resouce.ResourceName; 43 | result.Add(dto); 44 | } 45 | return result; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Logging/LoggingServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Logging; 2 | using Microsoft.Extensions.Configuration; 3 | using System; 4 | 5 | namespace Microsoft.Extensions.DependencyInjection 6 | { 7 | public static class LoggingServiceCollectionExtensions 8 | { 9 | public static IServiceCollection AddFullLogging(this IServiceCollection services, IConfiguration configuration) 10 | { 11 | if (services == null) 12 | { 13 | throw new ArgumentNullException("services"); 14 | } 15 | string debug = configuration["Debug"]; 16 | string value = configuration["LogPath"]; 17 | if (string.IsNullOrEmpty(value)) 18 | { 19 | throw new ArgumentNullException("日志设置路径为空!"); 20 | } 21 | Environment.SetEnvironmentVariable("log_home", value); 22 | if (!string.IsNullOrEmpty(debug) && debug.ToLower() == "true") 23 | { 24 | var loggerFactory = new LoggerFactory() 25 | .AddConsole(LogLevel.Trace, true) 26 | .AddLog4Net(); 27 | var logger = loggerFactory.CreateLogger("errorAppender"); 28 | services.Add(ServiceDescriptor.Singleton(loggerFactory)); 29 | services.Add(ServiceDescriptor.Singleton(logger)); 30 | } 31 | else 32 | { 33 | var loggerFactory = new LoggerFactory() 34 | .AddLog4Net(); 35 | var logger = loggerFactory.CreateLogger("errorAppender"); 36 | services.Add(ServiceDescriptor.Singleton(loggerFactory)); 37 | services.Add(ServiceDescriptor.Singleton(logger)); 38 | } 39 | 40 | return services; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/Extensions/SwaggerExtension.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.DependencyInjection; 2 | using Microsoft.AspNetCore.Builder; 3 | using sim = System; 4 | 5 | 6 | namespace IOTCS.EdgeGateway.Infrastructure.Extensions 7 | { 8 | public static class SwaggerExtension 9 | { 10 | public static IServiceCollection AddApiDoc(this IServiceCollection services) 11 | { 12 | services.AddSwaggerGen(options => 13 | { 14 | options.SwaggerDoc("v1", 15 | new Microsoft.OpenApi.Models.OpenApiInfo 16 | { 17 | Title = "IOTCS.Api", 18 | Version = "v1", 19 | Description = "ICS de API", 20 | Contact = new Microsoft.OpenApi.Models.OpenApiContact 21 | { 22 | Name = "IOTCS", 23 | Url = new sim.Uri("https://www.iotcs.com.cn/") 24 | }, 25 | License = new Microsoft.OpenApi.Models.OpenApiLicense 26 | { 27 | Name = "www.iotcs.com.cn", 28 | Url = new sim.Uri("https://www.iotcs.com.cn/") 29 | } 30 | }); 31 | }); 32 | return services; 33 | } 34 | 35 | public static IApplicationBuilder UseApiDoc(this IApplicationBuilder app) 36 | { 37 | app.UseSwagger() 38 | .UseSwaggerUI(c => 39 | { 40 | c.RoutePrefix = "api-docs"; 41 | c.SwaggerEndpoint($"/swagger/v1/swagger.json", $"v1"); 42 | c.DocExpansion(Swashbuckle.AspNetCore.SwaggerUI.DocExpansion.List); 43 | }); 44 | return app; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Application/AppServicesModule.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Application.Imps; 2 | using IOTCS.EdgeGateway.Domain.DomainService; 3 | using IOTCS.EdgeGateway.Domain.DomainService.Impl; 4 | using IOTCS.EdgeGateway.Repository; 5 | using Microsoft.Extensions.DependencyInjection; 6 | using Volo.Abp.Modularity; 7 | 8 | namespace IOTCS.EdgeGateway.Application 9 | { 10 | [DependsOn(typeof(RepositoryModule))] 11 | public class AppServicesModule : AbpModule 12 | { 13 | public override void ConfigureServices(ServiceConfigurationContext context) 14 | { 15 | context.Services.Add(ServiceDescriptor.Singleton()); 16 | context.Services.Add(ServiceDescriptor.Singleton()); 17 | context.Services.Add(ServiceDescriptor.Singleton()); 18 | context.Services.Add(ServiceDescriptor.Singleton()); 19 | context.Services.Add(ServiceDescriptor.Singleton()); 20 | context.Services.Add(ServiceDescriptor.Singleton()); 21 | context.Services.Add(ServiceDescriptor.Singleton()); 22 | context.Services.Add(ServiceDescriptor.Singleton()); 23 | context.Services.Add(ServiceDescriptor.Singleton()); 24 | context.Services.Add(ServiceDescriptor.Singleton()); 25 | context.Services.Add(ServiceDescriptor.Singleton()); 26 | context.Services.Add(ServiceDescriptor.Singleton()); 27 | context.Services.Add(ServiceDescriptor.Singleton()); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Domain/DomainService/Impl/DeviceDomainService.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.Models; 2 | using IOTCS.EdgeGateway.Domain.Repositories; 3 | using IOTCS.EdgeGateway.Domain.ValueObject; 4 | using IOTCS.EdgeGateway.Freesql.Helper; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | 11 | namespace IOTCS.EdgeGateway.Domain.DomainService.Impl 12 | { 13 | public class DeviceDomainService : IDeviceDomainService 14 | { 15 | 16 | private readonly IDeviceRepository _repository; 17 | private readonly IDriveRepository _driveRepository; 18 | 19 | public DeviceDomainService( 20 | IDeviceRepository deviceRepository, 21 | IDriveRepository driveRepository) 22 | { 23 | this._repository = deviceRepository; 24 | this._driveRepository = driveRepository; 25 | } 26 | 27 | 28 | public async Task> GetAllDevice() 29 | { 30 | var result = new List(); 31 | //查询设备 32 | var devices = await _repository.GetDeviceGroup(); 33 | 34 | var devicesDto = from item in devices 35 | select item.ToModel(); 36 | foreach (var device in devicesDto) 37 | { 38 | //赋值Group 39 | var groups = await _repository.GetGroupByDeviceId(device.Id); 40 | var groupsDto = from item in groups 41 | select item.ToModel(); 42 | device.Childrens = groupsDto.ToList(); 43 | 44 | //赋值驱动 45 | var drive = await _driveRepository.GetDriveByDeviceId(device.Id); 46 | 47 | device.DriveName = drive.DriveName; 48 | result.Add(device); 49 | } 50 | return result; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Repository/FreeSqlMgrRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Collections.Concurrent; 5 | using IOTCS.EdgeGateway.Domain.Repositories; 6 | using IOTCS.EdgeGateway.Domain.Models; 7 | using IOTCS.EdgeGateway.Freesql.IdleBus; 8 | using IOTCS.EdgeGateway.Freesql; 9 | 10 | namespace IOTCS.EdgeGateway.Repository 11 | { 12 | public class FreeSqlMgrRepository : IFreeSqlMgrRepository 13 | { 14 | private readonly ICommonDbSessionContext _commonDbSession; 15 | 16 | public FreeSqlMgrRepository(ICommonDbSessionContext sessionContext) 17 | { 18 | _commonDbSession = sessionContext; 19 | } 20 | 21 | public InitailizeDatabaseModel CreateDbConnections(IEnumerable resources) 22 | { 23 | var database = new InitailizeDatabaseModel(); 24 | database.DBBus = new DbBus(); 25 | database.TDengine = new ConcurrentDictionary(); 26 | //var tdengine = new TDengineHelper(); 27 | 28 | foreach (var r in resources) 29 | { 30 | switch (r.ResourceType) 31 | { 32 | case "TDengine": 33 | //if (!database.TDengine.ContainsKey(r.Id)) 34 | //{ 35 | // var connector = tdengine.TDConnection(r); 36 | // database.TDengine.TryAdd(r.Id, connector); 37 | //} 38 | break; 39 | default: 40 | database.DBBus.Register(r.Id, () => { 41 | IFreeSql freeSql = _commonDbSession.CreateDbContext(r, r.ResourceType); 42 | return freeSql; 43 | }); 44 | break; 45 | } 46 | } 47 | 48 | return database; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.CmdHandler/SystemNotificationHandler.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Core; 2 | using IOTCS.EdgeGateway.Diagnostics.Notification; 3 | using IOTCS.EdgeGateway.Logging; 4 | using IOTCS.EdgeGateway.WsHandler; 5 | using MediatR; 6 | using Microsoft.Extensions.DependencyInjection; 7 | using System; 8 | using System.Threading; 9 | using System.Threading.Tasks; 10 | 11 | namespace IOTCS.EdgeGateway.CmdHandler 12 | { 13 | public class SystemNotificationHandler : INotificationHandler 14 | { 15 | private readonly ILogger _logger; 16 | private WsMessageHandler _webSocket; 17 | 18 | public SystemNotificationHandler(WsMessageHandler messageHandler) 19 | { 20 | _logger = IocManager.Instance.GetService().CreateLogger("WebSocket"); 21 | _webSocket = messageHandler; 22 | } 23 | 24 | public async Task Handle(SystemNotification notification, CancellationToken cancellationToken) 25 | { 26 | try 27 | { 28 | await Send(notification); 29 | } 30 | catch (Exception e) 31 | { 32 | _logger.Error($"系统消息通知异常,错误消息 => {e.Message},错误位置 => {e.StackTrace},"); 33 | } 34 | } 35 | 36 | private async Task Send(SystemNotification message) 37 | { 38 | try 39 | { 40 | await _webSocket.SendMessageToAllAsync(new WebSocketManager.Common.Message 41 | { 42 | MessageType = WebSocketManager.Common.MessageType.Text, 43 | RequestType = message.MsgType, 44 | Data = message.Message 45 | }).ConfigureAwait(false); 46 | } 47 | catch (Exception e) 48 | { 49 | _logger.Error($"系统消息发送WebSocket信息到UI异常,异常信息 => {e.Message},位置 => {e.StackTrace}"); 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Freesql.Helper/Domain/RepositoryBase.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using System; 4 | using System.Threading.Tasks; 5 | using System.Linq.Expressions; 6 | using FreeSql; 7 | 8 | namespace IOTCS.EdgeGateway.Freesql.Helper.Domain 9 | { 10 | public abstract class RepositoryBase : BaseRepository, IRepositoryBase where TEntity : class, new() 11 | { 12 | protected RepositoryBase(IFreeSql freeSql) : base(freeSql, null, null) 13 | { 14 | 15 | } 16 | 17 | public virtual Task GetAsync(TKey id) 18 | { 19 | return Select.WhereDynamic(id).ToOneAsync(); 20 | } 21 | 22 | public virtual Task GetAsync(Expression> exp) 23 | { 24 | return Select.Where(exp).ToOneAsync(); 25 | } 26 | 27 | public virtual Task GetAsync(Expression> exp) 28 | { 29 | return Select.Where(exp).ToOneAsync(); 30 | } 31 | 32 | public async Task SoftDeleteAsync(TKey id) 33 | { 34 | await UpdateDiy 35 | .SetDto(new { 36 | IsDeleted = true 37 | }) 38 | .WhereDynamic(id) 39 | .ExecuteAffrowsAsync(); 40 | return true; 41 | } 42 | 43 | public async Task SoftDeleteAsync(TKey[] ids) 44 | { 45 | await UpdateDiy 46 | .SetDto(new { 47 | IsDeleted = true 48 | }) 49 | .WhereDynamic(ids) 50 | .ExecuteAffrowsAsync(); 51 | return true; 52 | } 53 | } 54 | 55 | public abstract class RepositoryBase : RepositoryBase where TEntity : class, new() 56 | { 57 | public RepositoryBase(IFreeSql freeSql) : base(freeSql) 58 | { 59 | 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.CmdHandler/OpcUaNotificationHandler.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Commands; 2 | using IOTCS.EdgeGateway.Core; 3 | //using IOTCS.EdgeGateway.Dispatch; 4 | //using IOTCS.EdgeGateway.Domain.ValueObject; 5 | using IOTCS.EdgeGateway.Logging; 6 | using MediatR; 7 | using Microsoft.Extensions.DependencyInjection; 8 | using Newtonsoft.Json; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Threading; 12 | using System.Threading.Tasks; 13 | 14 | namespace IOTCS.EdgeGateway.CmdHandler 15 | { 16 | public class OpcUaNotificationHandler : INotificationHandler 17 | { 18 | private readonly ILogger _logger; 19 | //private readonly IDispatchManager _dispatchManager; 20 | 21 | public OpcUaNotificationHandler() 22 | { 23 | _logger = IocManager.Instance.GetService(); 24 | //_dispatchManager = IocManager.Instance.GetService(); 25 | 26 | } 27 | 28 | public Task Handle(OpcUaNotification notification, CancellationToken cancellationToken) 29 | { 30 | //try 31 | //{ 32 | // if (!string.IsNullOrEmpty(notification.Message)) 33 | // { 34 | // var message = JsonConvert.DeserializeObject(notification.Message); 35 | // ProcessMessage(message.Payload.Values); 36 | // } 37 | // else 38 | // { 39 | // _logger.Info($"采集的数据为=> 为空"); 40 | // } 41 | //} 42 | //catch (Exception e) 43 | //{ 44 | // _logger.Error($"数据处理异常 => 位置 => {e.Message},异常 => {e.StackTrace}"); 45 | //} 46 | 47 | return Task.CompletedTask; 48 | } 49 | 50 | private void ProcessMessage(List equipments) 51 | { 52 | //foreach (var d in equipments) 53 | //{ 54 | // _dispatchManager.RunTaskAsync(d); 55 | //} 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Repository/OpcStorageRepository.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Core.Collections; 2 | using IOTCS.EdgeGateway.Domain.Repositories; 3 | using IOTCS.EdgeGateway.Freesql.IdleBus; 4 | using IOTCS.EdgeGateway.Logging; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | 9 | namespace IOTCS.EdgeGateway.Repository 10 | { 11 | public class OpcStorageRepository : IOpcStorageRepository 12 | { 13 | private readonly ILogger _logger; 14 | private IConcurrentList _dbBuses = null; 15 | 16 | public OpcStorageRepository(IConcurrentList dbBuses, ILogger logger) 17 | { 18 | this._logger = logger; 19 | this._dbBuses = dbBuses; 20 | } 21 | 22 | public async Task Insert(string resourceId ,string sql) 23 | { 24 | var result = false; 25 | var freeSql = _dbBuses.FirstOrDefault(); 26 | IFreeSql dbFreeSql = freeSql.Get(resourceId); 27 | if (dbFreeSql != null) 28 | { 29 | var affrows = await dbFreeSql.Ado.ExecuteNonQueryAsync(sql) 30 | .ConfigureAwait(false); 31 | result = affrows > 0 ? true : false; 32 | _logger.Info($"Executing Result = {result},执行的SQL ={sql},资源ID = {resourceId}"); 33 | } 34 | else 35 | { 36 | _logger.Info($"没有找到对应的数据库资源,资源ID = {resourceId}"); 37 | } 38 | 39 | return result; 40 | } 41 | 42 | public async Task BatchInsert(string resourceId, IEnumerable sqlList) 43 | { 44 | var result = true; 45 | var tempBool = false; 46 | 47 | var freeSql = _dbBuses.FirstOrDefault(); 48 | foreach (var sql in sqlList) 49 | { 50 | var affrows = await freeSql.Get(resourceId).Ado.ExecuteNonQueryAsync(sql); 51 | tempBool = affrows > 0 ? true : false; 52 | result = result && tempBool; 53 | } 54 | 55 | return result; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Logging/Console/Console/Internal/WindowsLogConsole.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IOTCS.EdgeGateway.Logging.Console.Internal 4 | { 5 | /// 6 | /// Windows 控制台日志 7 | /// 8 | internal class WindowsLogConsole : IConsole 9 | { 10 | /// 11 | /// 写入 12 | /// 13 | /// 日志消息 14 | /// 背景色 15 | /// 前景色 16 | public void Write(string message, ConsoleColor? background, ConsoleColor? foreground) 17 | { 18 | SetColor(background, foreground); 19 | System.Console.Out.Write(message); 20 | ResetColor(); 21 | } 22 | 23 | /// 24 | /// 写入并换行 25 | /// 26 | /// 日志消息 27 | /// 背景色 28 | /// 前景色 29 | public void WriteLine(string message, ConsoleColor? background, ConsoleColor? foreground) 30 | { 31 | SetColor(background, foreground); 32 | System.Console.Out.WriteLine(message); 33 | ResetColor(); 34 | } 35 | 36 | /// 37 | /// 清除缓冲区,并将缓冲数据写入 38 | /// 39 | public void Flush() 40 | { 41 | // 什么都不用做,数据直接发送到控制台 42 | } 43 | 44 | /// 45 | /// 设置颜色 46 | /// 47 | /// 背景色 48 | /// 前景色 49 | private void SetColor(ConsoleColor? background, ConsoleColor? foreground) 50 | { 51 | if (background.HasValue) 52 | System.Console.BackgroundColor = background.Value; 53 | if (foreground.HasValue) 54 | System.Console.ForegroundColor = foreground.Value; 55 | } 56 | 57 | /// 58 | /// 重置颜色 59 | /// 60 | private void ResetColor() => System.Console.ResetColor(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/WebApi/Controller/LoginController.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Application; 2 | using IOTCS.EdgeGateway.Core; 3 | using IOTCS.EdgeGateway.Core.Security; 4 | using IOTCS.EdgeGateway.Domain.ValueObject; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.Extensions.DependencyInjection; 7 | using Newtonsoft.Json.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace IOTCS.EdgeGateway.Infrastructure.WebApi.Controller 11 | { 12 | [ApiController] 13 | public class LoginController 14 | { 15 | 16 | private readonly IAuthorizationService _service; 17 | public LoginController() 18 | { 19 | _service = IocManager.Instance.GetService(); 20 | } 21 | 22 | [HttpPost] 23 | [Route("edge/login")] 24 | public ActionResult> Login([FromBody] LoginDto user) 25 | { 26 | var result = new RestfulData(); 27 | 28 | if (user == null || string.IsNullOrEmpty(user.UserName) || string.IsNullOrEmpty(user.Password)) 29 | { 30 | result.State_Code = 500; 31 | result.Data = null; 32 | result.Message = "用户名或密码错误!"; 33 | } 34 | else 35 | { 36 | var userInfo = _service.GenerateToken(user.UserName, user.Password); 37 | if (userInfo == null) 38 | { 39 | result.State_Code = 500; 40 | result.Data = null; 41 | result.Message = "用户名或密码错误!"; 42 | } 43 | else 44 | { 45 | result.State_Code = 200; 46 | result.Data = new LoginDto() 47 | { 48 | Token = userInfo.Token, 49 | UserName = userInfo.UserName, 50 | DisplayName = userInfo.DisplayName 51 | }; 52 | result.Message = "授权成功!"; 53 | } 54 | } 55 | 56 | return result; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Application/Imps/DriveService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using System.Linq; 6 | using IOTCS.EdgeGateway.Logging; 7 | using IOTCS.EdgeGateway.Domain.Repositories; 8 | using IOTCS.EdgeGateway.Domain.ValueObject.Device; 9 | using IOTCS.EdgeGateway.Domain.Models; 10 | using IOTCS.EdgeGateway.Freesql.Helper; 11 | 12 | namespace IOTCS.EdgeGateway.Application.Imps 13 | { 14 | public class DriveService : IDriveService 15 | { 16 | 17 | private readonly ILogger _logger; 18 | private readonly IDriveRepository _repository; 19 | 20 | public DriveService(ILogger logger, 21 | IDriveRepository driveRepository) 22 | { 23 | _logger = logger; 24 | _repository = driveRepository; 25 | } 26 | public async Task Create(DriveDto driveDto) 27 | { 28 | var result = true; 29 | var model = driveDto.ToModel(); 30 | 31 | result = await _repository.Create(model); 32 | 33 | return await Task.FromResult(result); 34 | } 35 | 36 | public async Task> GetAllrive() 37 | { 38 | var list = await _repository.GetAllDrive(); 39 | 40 | var query = from item in list 41 | select item.ToModel(); 42 | 43 | return query; 44 | } 45 | 46 | public async Task Update(DriveDto driveDto) 47 | { 48 | var result = true; 49 | var model = driveDto.ToModel(); 50 | 51 | result = await _repository.Update(model); 52 | 53 | return await Task.FromResult(result); 54 | } 55 | 56 | public async Task Delete(DriveDto driveDto) 57 | { 58 | var result = true; 59 | var model = driveDto.ToModel(); 60 | 61 | result = await _repository.Delete(model); 62 | 63 | return await Task.FromResult(result); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/IOTCS.EdgeGateway.Infrastructure.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | true 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.MqttHandler/MqttSessionContext.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.MqttHandler.Extensions; 2 | using Microsoft.Extensions.Options; 3 | using System; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | using MQTTnet; 7 | using MQTTnet.Client; 8 | using MQTTnet.Client.Options; 9 | using System.Security.Authentication; 10 | 11 | namespace IOTCS.EdgeGateway.MqttHandler 12 | { 13 | public class MqttSessionContext : IMqttSessionContext 14 | { 15 | public async Task CreateMqttContextAsync(MqttContextOptions options) 16 | { 17 | var token = new CancellationToken(); 18 | var mqttClient = new MqttFactory().CreateMqttClient(); 19 | if (string.IsNullOrEmpty(options.UserId)) 20 | { 21 | var connector = await mqttClient.ConnectAsync(new MqttClientOptionsBuilder() 22 | .WithTcpServer(options.IpAddress, options.Port) 23 | .WithClientId(options.ClientId) 24 | .WithTls(new MqttClientOptionsBuilderTlsParameters 25 | { 26 | UseTls = false, 27 | AllowUntrustedCertificates = true, 28 | SslProtocol = SslProtocols.Tls12 29 | }) 30 | .WithCommunicationTimeout(TimeSpan.FromSeconds(options.Timeout)) 31 | .Build(), token); 32 | } 33 | else 34 | { 35 | var connector = await mqttClient.ConnectAsync(new MqttClientOptionsBuilder() 36 | .WithTcpServer(options.IpAddress, options.Port) 37 | .WithClientId(options.ClientId) 38 | .WithCredentials(options.UserId, options.Password) 39 | .WithTls(new MqttClientOptionsBuilderTlsParameters 40 | { 41 | UseTls = false, 42 | AllowUntrustedCertificates = true, 43 | SslProtocol = SslProtocols.Tls12 44 | }) 45 | .WithCommunicationTimeout(TimeSpan.FromSeconds(options.Timeout)) 46 | .Build(), token); 47 | } 48 | 49 | return mqttClient; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Core/Extensions/DateTimeExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace System 2 | { 3 | /// 4 | /// Date time extension methods
5 | /// 时间的扩展函数
6 | ///
7 | public static class DateTimeExtensions { 8 | 9 | /// 类型转换提供者 10 | /// 重载默认提供者并赋值给可改变所有类型转换的行为 11 | public static DefaultConvert Convert { get; set; } = new DefaultConvert(); 12 | 13 | /// 14 | /// Truncate datetime, only keep seconds
15 | /// 去掉时间中秒数后的部分
16 | ///
17 | /// The time 18 | /// 19 | /// 20 | /// 21 | /// var time = DateTime.UtcNow; 22 | /// var truncated = time.Truncate(); 23 | /// 24 | /// 25 | public static DateTime Truncate(this DateTime time) { 26 | return time.AddTicks(-(time.Ticks % TimeSpan.TicksPerSecond)); 27 | } 28 | 29 | /// 30 | /// Return unix style timestamp
31 | /// Return a minus value if the time early than 1970-1-1
32 | /// The given time will be converted to UTC time first
33 | /// 获取unix风格的时间戳
34 | /// 如果时间早于1970年1月1日则返回值是负数
35 | /// 参数会先转换为UTC时间
36 | ///
37 | /// The time 38 | /// 39 | /// 40 | /// 41 | /// var time = new DateTime(1970, 1, 2, 0, 0, 0, DateTimeKind.Utc); 42 | /// var timeStamp = (int)time.ToTimestamp().TotalSeconds; // == 86400 43 | /// 44 | /// 45 | public static TimeSpan ToTimestamp(this DateTime time) { 46 | return time.ToUniversalTime() - new DateTime(1970, 1, 1); 47 | } 48 | 49 | /// 转为时间日期,转换失败时返回最小时间。支持字符串、整数(Unix秒) 50 | /// 待转换对象 51 | /// 52 | public static DateTime ToDateTime(this Object value) => Convert.ToDateTime(value, DateTime.MinValue); 53 | 54 | /// 时间日期转为yyyy-MM-dd HH:mm:ss完整字符串,对UTC时间加后缀 55 | /// 最常用的时间日期格式,可以无视各平台以及系统自定义的时间格式 56 | /// 待转换对象 57 | /// 58 | public static String ToFullString(this DateTime value) => Convert.ToFullString(value); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Core/Extensions/CollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using JetBrains.Annotations; 3 | using Volo.Abp; 4 | 5 | namespace System.Collections.Generic 6 | { 7 | public static class CollectionExtensions 8 | { 9 | public static bool IsNullOrEmpty([CanBeNull] this ICollection source) 10 | { 11 | return source == null || source.Count <= 0; 12 | } 13 | 14 | public static bool AddIfNotContains([NotNull] this ICollection source, T item) 15 | { 16 | Check.NotNull(source, nameof(source)); 17 | 18 | if (source.Contains(item)) 19 | { 20 | return false; 21 | } 22 | 23 | source.Add(item); 24 | return true; 25 | } 26 | 27 | public static IEnumerable AddIfNotContains([NotNull] this ICollection source, IEnumerable items) 28 | { 29 | Check.NotNull(source, nameof(source)); 30 | 31 | var addedItems = new List(); 32 | 33 | foreach (var item in items) 34 | { 35 | if (source.Contains(item)) 36 | { 37 | continue; 38 | } 39 | 40 | source.Add(item); 41 | addedItems.Add(item); 42 | } 43 | 44 | return addedItems; 45 | } 46 | 47 | public static bool AddIfNotContains([NotNull] this ICollection source, [NotNull] Func predicate, [NotNull] Func itemFactory) 48 | { 49 | Check.NotNull(source, nameof(source)); 50 | Check.NotNull(predicate, nameof(predicate)); 51 | Check.NotNull(itemFactory, nameof(itemFactory)); 52 | 53 | if (source.Any(predicate)) 54 | { 55 | return false; 56 | } 57 | 58 | source.Add(itemFactory()); 59 | return true; 60 | } 61 | 62 | public static IList RemoveAll([NotNull] this ICollection source, Func predicate) 63 | { 64 | var items = source.Where(predicate).ToList(); 65 | 66 | foreach (var item in items) 67 | { 68 | source.Remove(item); 69 | } 70 | 71 | return items; 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/WebApi/Filter/ManageVerifyAttribute.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Application; 2 | using IOTCS.EdgeGateway.Core; 3 | using IOTCS.EdgeGateway.Logging; 4 | using Microsoft.AspNetCore.Http; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.AspNetCore.Mvc.Filters; 7 | using Microsoft.Extensions.DependencyInjection; 8 | using System; 9 | 10 | namespace IOTCS.EdgeGateway.Infrastructure.WebApi.Filter 11 | { 12 | public class ManageVerifyAttribute : Attribute, IActionFilter 13 | { 14 | private readonly ILogger _logger; 15 | //private readonly RequestDelegate _next; 16 | private readonly IAuthorizationService _authService; 17 | 18 | public ManageVerifyAttribute() 19 | { 20 | _logger = IocManager.Instance.GetService(); 21 | _authService = IocManager.Instance.GetService(); 22 | } 23 | 24 | public void OnActionExecuted(ActionExecutedContext context) 25 | { 26 | 27 | } 28 | 29 | public void OnActionExecuting(ActionExecutingContext context) 30 | { 31 | string authentication = context.HttpContext.Request.Headers["XC-Token"]; 32 | 33 | if (authentication != null 34 | && !string.IsNullOrEmpty(authentication)) 35 | { 36 | try 37 | { 38 | var isPassed = _authService.ValidateToken(authentication); 39 | 40 | if (!isPassed) 41 | { 42 | _logger.Error($"身份验证失败!当前token=>{authentication}"); 43 | context.Result = new JsonResult($"身份验证失败!当前token=>{authentication}"); 44 | } 45 | 46 | } 47 | catch (Exception ex) 48 | { 49 | _logger.Error($"身份验证失败!当前token=>{authentication}, Msg=>{ex.Message},Stack=>{ex.StackTrace}"); 50 | context.Result = new JsonResult($"身份验证失败!当前token=>{authentication}"); 51 | } 52 | } 53 | else 54 | { 55 | _logger.Error($"身份验证失败!当前token=>{authentication}"); 56 | context.Result = new JsonResult($"身份验证失败!当前token=>{authentication}"); 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Repository/DeviceConfigRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using IOTCS.EdgeGateway.Domain.Models; 6 | using IOTCS.EdgeGateway.Domain.Repositories; 7 | 8 | namespace IOTCS.EdgeGateway.Repository 9 | { 10 | public class DeviceConfigRepository : IDeviceConfigRepository 11 | { 12 | private readonly IFreeSql _freeSql; 13 | 14 | 15 | public DeviceConfigRepository(IFreeSql freeSql) 16 | { 17 | _freeSql = freeSql; 18 | } 19 | 20 | public async Task Create(DeviceConfigModel configModel) 21 | { 22 | var affrows = _freeSql.Insert(configModel).ExecuteAffrows(); 23 | bool result = affrows > 0; 24 | return await Task.FromResult(result); 25 | } 26 | 27 | public async Task GetAllDeviceConfigByDeviceId(string deviceId) 28 | { 29 | DeviceConfigModel result = new DeviceConfigModel(); 30 | var config = await _freeSql.Select().Where(d => d.DeviceId == deviceId).ToListAsync().ConfigureAwait(false); 31 | 32 | if (config != null && config.Count > 0) 33 | { 34 | result = config[0]; 35 | } 36 | return result; 37 | } 38 | 39 | public async Task Update(DeviceConfigModel configDto) 40 | { 41 | var result = false; 42 | 43 | var affrows = _freeSql.Update().SetSource(configDto).ExecuteAffrows(); 44 | 45 | result = affrows > 0 ? true : false; 46 | 47 | return await Task.FromResult(result); 48 | } 49 | 50 | public async Task> GetAsync() 51 | { 52 | StringBuilder stringBuilder = new StringBuilder(); 53 | List result = new List(); 54 | 55 | stringBuilder.Clear(); 56 | stringBuilder.Append("SELECT * FROM tb_deviceconfig"); 57 | 58 | var query = await _freeSql.Select().WithSql(stringBuilder.ToString()).ToListAsync().ConfigureAwait(false); 59 | if (query != null) 60 | { 61 | result.AddRange(query); 62 | } 63 | 64 | return result; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Core/Security/RC4.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IOTCS.EdgeGateway.Core.Security 4 | { 5 | /// RC4对称加密算法 6 | /// 7 | /// RC4于1987年提出,和DES算法一样,是一种对称加密算法,也就是说使用的密钥为单钥(或称为私钥)。 8 | /// 但不同于DES的是,RC4不是对明文进行分组处理,而是字节流的方式依次加密明文中的每一个字节,解密的时候也是依次对密文中的每一个字节进行解密。 9 | /// 10 | /// RC4算法的特点是算法简单,运行速度快,而且密钥长度是可变的,可变范围为1-256字节(8-2048比特), 11 | /// 在如今技术支持的前提下,当密钥长度为128比特时,用暴力法搜索密钥已经不太可行,所以可以预见RC4的密钥范围任然可以在今后相当长的时间里抵御暴力搜索密钥的攻击。 12 | /// 实际上,如今也没有找到对于128bit密钥长度的RC4加密算法的有效攻击方法。 13 | /// 14 | class RC4 15 | { 16 | /// 加密 17 | /// 数据 18 | /// 密码 19 | /// 20 | public static Byte[] Encrypt(Byte[] data, Byte[] pass) 21 | { 22 | if (data == null || data.Length == 0) return new Byte[0]; 23 | if (pass == null || pass.Length == 0) return data; 24 | 25 | var output = new Byte[data.Length]; 26 | var i = 0; 27 | var j = 0; 28 | var box = GetKey(pass, 256); 29 | // 加密 30 | for (var k = 0; k < data.Length; k++) 31 | { 32 | i = (i + 1) % box.Length; 33 | j = (j + box[i]) % box.Length; 34 | var temp = box[i]; 35 | box[i] = box[j]; 36 | box[j] = temp; 37 | var a = data[k]; 38 | var b = box[(box[i] + box[j]) % box.Length]; 39 | output[k] = (Byte)(a ^ b); 40 | } 41 | 42 | return output; 43 | } 44 | 45 | /// 打乱密码 46 | /// 密码 47 | /// 密码箱长度 48 | /// 打乱后的密码 49 | private static Byte[] GetKey(Byte[] pass, Int32 len) 50 | { 51 | var box = new Byte[len]; 52 | for (var i = 0; i < len; i++) 53 | { 54 | box[i] = (Byte)i; 55 | } 56 | var j = 0; 57 | for (var i = 0; i < len; i++) 58 | { 59 | j = (j + box[i] + pass[i % pass.Length]) % len; 60 | var temp = box[i]; 61 | box[i] = box[j]; 62 | box[j] = temp; 63 | } 64 | return box; 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Core/Collections/SystemKeyValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Collections.Concurrent; 4 | using System.Collections.Generic; 5 | 6 | namespace IOTCS.EdgeGateway.Core.Collections 7 | { 8 | public class SystemKeyValue : IKeyValueCache 9 | { 10 | private readonly object lockObject = new object(); 11 | private ConcurrentDictionary _keyValuePairs = new ConcurrentDictionary(); 12 | 13 | public IEnumerable SKeys => _keyValuePairs.Keys; 14 | 15 | public void Put(TKey key, TValue value, TimeSpan keepTime) 16 | { 17 | lock (lockObject) 18 | { 19 | if (!_keyValuePairs.ContainsKey(key)) 20 | { 21 | _keyValuePairs.TryAdd(key, value); 22 | } 23 | } 24 | } 25 | 26 | public bool TryGetValue(TKey key, out TValue value) 27 | { 28 | _keyValuePairs.TryGetValue(key, out value); 29 | 30 | return true; 31 | } 32 | 33 | public TValue this[TKey index] 34 | { 35 | get 36 | { 37 | if (_keyValuePairs.ContainsKey(index)) 38 | { 39 | return _keyValuePairs[index]; 40 | } 41 | else 42 | { 43 | return default(TValue); 44 | } 45 | } 46 | } 47 | 48 | public int Count() 49 | { 50 | return _keyValuePairs.Count; 51 | } 52 | 53 | public void Remove(TKey key) 54 | { 55 | lock (lockObject) 56 | { 57 | var value = default(TValue); 58 | if (_keyValuePairs.ContainsKey(key)) 59 | { 60 | _keyValuePairs.TryRemove(key, out value); 61 | } 62 | } 63 | } 64 | 65 | public void Clear() 66 | { 67 | _keyValuePairs.Clear(); 68 | } 69 | 70 | public bool IsContainKey(TKey key) 71 | { 72 | if (_keyValuePairs.ContainsKey(key)) 73 | { 74 | return true; 75 | } 76 | else 77 | { 78 | return false; 79 | } 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Dispatch/DispatchManager.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.ComResDriver; 2 | using IOTCS.EdgeGateway.Core; 3 | using IOTCS.EdgeGateway.Core.Collections; 4 | using IOTCS.EdgeGateway.Diagnostics; 5 | using IOTCS.EdgeGateway.Domain.ValueObject; 6 | using Microsoft.Extensions.DependencyInjection; 7 | using Microsoft.Extensions.Logging; 8 | using System; 9 | using System.Collections.Concurrent; 10 | using System.Linq; 11 | using System.Threading.Tasks; 12 | 13 | namespace IOTCS.EdgeGateway.Dispatch 14 | { 15 | public class DispatchManager : IDispatchManager 16 | { 17 | private readonly ILogger _logger; 18 | private IConcurrentList relationships; 19 | private ConcurrentDictionary resDrivers; 20 | private readonly ISystemDiagnostics _diagnostics; 21 | public DispatchManager() 22 | { 23 | _diagnostics = IocManager.Instance.GetService(); 24 | _logger = IocManager.Instance.GetService().CreateLogger("Monitor"); 25 | relationships = IocManager.Instance.GetService>(); 26 | resDrivers = IocManager.Instance.GetService>(); 27 | } 28 | 29 | public async Task RunTaskAsync(dynamic data) 30 | { 31 | var topic = Convert.ToString(data.Topic); 32 | var reslationship = relationships.Where(d => d.Topic.Equals(topic)).ToList(); 33 | if (relationships != null && relationships.Count > 0) 34 | { 35 | foreach (var res in reslationship) 36 | { 37 | if (resDrivers.ContainsKey(res.ResourceId)) 38 | { 39 | var driver = resDrivers[res.ResourceId]; 40 | driver.Run(data); 41 | } 42 | else 43 | { 44 | var msg = $"数据处理异常!Topic => {topic},未找到资源驱动!数据已舍弃"; 45 | await _diagnostics.PublishDiagnosticsInfoAsync(msg).ConfigureAwait(false); 46 | } 47 | } 48 | } 49 | else 50 | { 51 | var msg = $"数据处理异常!Topic => {topic},未找到关联资源!数据已舍弃"; 52 | await _diagnostics.PublishDiagnosticsInfoAsync(msg).ConfigureAwait(false); 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.WebSocketManager/Json/PrimitiveJsonConverter.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Runtime.Serialization.Formatters; 4 | 5 | namespace IOTCS.EdgeGateway.WebSocketManager.Common 6 | { 7 | /// 8 | /// https://stackoverflow.com/questions/25007001/json-net-does-not-preserve-primitive-type-information-in-lists-or-dictionaries-o?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa 9 | /// Shoutouts to Sacrilege for his awesome primitive json converter. 10 | /// 11 | /// 12 | public sealed class PrimitiveJsonConverter : JsonConverter 13 | { 14 | public PrimitiveJsonConverter() 15 | { 16 | } 17 | 18 | public override bool CanRead 19 | { 20 | get 21 | { 22 | return false; 23 | } 24 | } 25 | 26 | public override bool CanConvert(Type objectType) 27 | { 28 | return objectType.IsPrimitive || objectType == typeof(Guid) || objectType == typeof(string); 29 | } 30 | 31 | public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) 32 | { 33 | throw new NotImplementedException(); 34 | } 35 | 36 | public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) 37 | { 38 | switch (serializer.TypeNameHandling) 39 | { 40 | case TypeNameHandling.All: 41 | writer.WriteStartObject(); 42 | writer.WritePropertyName("$type", false); 43 | 44 | switch (serializer.TypeNameAssemblyFormatHandling) 45 | { 46 | case TypeNameAssemblyFormatHandling.Full: 47 | writer.WriteValue(value.GetType().AssemblyQualifiedName); 48 | break; 49 | 50 | default: 51 | writer.WriteValue(value.GetType().FullName); 52 | break; 53 | } 54 | 55 | writer.WritePropertyName("$value", false); 56 | writer.WriteValue(value); 57 | writer.WriteEndObject(); 58 | break; 59 | 60 | default: 61 | writer.WriteValue(value); 62 | break; 63 | } 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/WebApi/ApplicationMvcModule.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Application; 2 | using IOTCS.EdgeGateway.CmdHandler; 3 | using IOTCS.EdgeGateway.Diagnostics.DiagnosticsContext; 4 | using IOTCS.EdgeGateway.Infrastructure.Extensions; 5 | using IOTCS.EdgeGateway.Infrastructure.Serialize; 6 | using IOTCS.EdgeGateway.Infrastructure.WebApi.Middleware; 7 | using IOTCS.EdgeGateway.MqttHandler; 8 | using IOTCS.EdgeGateway.Plugins; 9 | using IOTCS.EdgeGateway.ProcPipeline; 10 | using Microsoft.AspNetCore.Builder; 11 | using Microsoft.AspNetCore.Hosting; 12 | using Microsoft.Extensions.Hosting; 13 | using Microsoft.Extensions.DependencyInjection; 14 | using System; 15 | using Volo.Abp; 16 | using Volo.Abp.Modularity; 17 | using IOTCS.EdgeGateway.WsHandler; 18 | using IOTCS.EdgeGateway.WebSocketManager; 19 | 20 | namespace IOTCS.EdgeGateway.Infrastructure.WebApi 21 | { 22 | [DependsOn( 23 | typeof(AppJsonModule), 24 | typeof(OpcHandlerModule), 25 | typeof(AbpDiagnosticsContextModule), 26 | typeof(AppServicesModule), 27 | typeof(AppPluginModule), 28 | typeof(AppPipelineModule), 29 | typeof(AppMqttHandlerModule) 30 | )] 31 | public class ApplicationMvcModule : AbpModule 32 | { 33 | public override void OnApplicationInitialization(ApplicationInitializationContext context) 34 | { 35 | var serviceProvider = context.ServiceProvider; 36 | var app = context.GetApplicationBuilder(); 37 | var env = context.GetEnvironment(); 38 | 39 | if (env.IsDevelopment()) 40 | { 41 | app.UseDeveloperExceptionPage(); 42 | } 43 | else 44 | { 45 | app.UseExceptionHandler("/Error"); 46 | } 47 | 48 | app.UseWebSockets(new WebSocketOptions { 49 | KeepAliveInterval = TimeSpan.FromDays(30) 50 | }); 51 | app.MapWebSocketManager("/ws", serviceProvider.GetService()); 52 | app.UseCors("CorsPolicy"); 53 | app.UseMiddleware(); 54 | app.UseAuthentication(); 55 | app.UseApiDoc(); 56 | app.UseMvc(mvcOptions => 57 | { 58 | mvcOptions.MapRoute(name: "default", 59 | template: "{controller=Login}/{action=Post}"); 60 | }); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Infrastructure/WebApi/Controller/DeviceConfigController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using System.Threading.Tasks; 4 | using System; 5 | using IOTCS.EdgeGateway.Application; 6 | using IOTCS.EdgeGateway.Core; 7 | using IOTCS.EdgeGateway.Domain.ValueObject; 8 | using IOTCS.EdgeGateway.Domain.ValueObject.Device; 9 | using Newtonsoft.Json; 10 | 11 | namespace IOTCS.EdgeGateway.Infrastructure.WebApi.Controller 12 | { 13 | [ApiController] 14 | public class DeviceConfigController : ControllerBase 15 | { 16 | private readonly IDeviceConfigService _service; 17 | 18 | 19 | public DeviceConfigController() 20 | { 21 | _service = IocManager.Instance.GetService(); 22 | } 23 | 24 | 25 | [HttpPost] 26 | [Route("device/config/getDeviceConfig")] 27 | 28 | public async Task> GetDeviceGroup([FromBody] DeviceConfigDto data) 29 | { 30 | var result = new DataResponseDto(); 31 | var rResult = await _service.GetAllDeviceConfigByDeviceId(data.DeviceId); 32 | result.Successful = true; 33 | result.Data = rResult; 34 | return result; 35 | } 36 | 37 | [HttpPost] 38 | [Route("device/config/insert")] 39 | public async Task> Insert([FromHeader(Name = "LoginUser")] string user,[FromBody] DeviceConfigDto data) 40 | { 41 | var result = new DataResponseDto(); 42 | data.CreateBy = JsonConvert.DeserializeObject(user).DisplayName; 43 | data.CreateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); 44 | var rResult = await _service.Create(data); 45 | result.Successful = true; 46 | result.Data = rResult; 47 | return result; 48 | } 49 | 50 | [HttpPost] 51 | [Route("device/config/update")] 52 | public async Task> Update([FromHeader(Name = "LoginUser")] string user,[FromBody] DeviceConfigDto data) 53 | { 54 | var result = new DataResponseDto(); 55 | data.UpdateBy = JsonConvert.DeserializeObject(user).DisplayName; 56 | data.UpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); 57 | var rResult = await _service.Update(data); 58 | result.Successful = true; 59 | result.Data = rResult; 60 | return result; 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Core/Collections/Pair.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace IOTCS.EdgeGateway.Core.Collections 4 | { 5 | /// 6 | /// 对类型
7 | ///
8 | public struct Pair : IEquatable> { 9 | /// 10 | /// 第一个值
11 | ///
12 | public TFirst First { get; private set; } 13 | /// 14 | /// 第二个值
15 | ///
16 | ///
17 | public TSecond Second { get; private set; } 18 | 19 | /// 20 | /// 初始化
21 | ///
22 | /// 23 | /// 24 | public Pair(TFirst first, TSecond second) { 25 | First = first; 26 | Second = second; 27 | } 28 | 29 | /// 30 | /// 检查是否与参数中对象相等
31 | ///
32 | /// Other object 33 | /// 34 | public bool Equals(Pair other) { 35 | return First.EqualsSupportsNull(other.First) && Second.EqualsSupportsNull(other.Second); 36 | } 37 | 38 | /// 39 | /// 检查是否与参数中的对象相等
40 | ///
41 | /// 42 | /// 43 | public override bool Equals(object obj) { 44 | return (obj is Pair) && Equals((Pair)obj); 45 | } 46 | 47 | /// 48 | /// 获取哈希值
49 | ///
50 | /// 51 | public override int GetHashCode() { 52 | // same with Tuple.CombineHashCodess 53 | var hash_1 = First?.GetHashCode() ?? 0; 54 | var hash_2 = Second?.GetHashCode() ?? 0; 55 | return (hash_1 << 5) + hash_1 ^ hash_2; 56 | } 57 | 58 | /// 59 | /// 转换到字符串
60 | ///
61 | /// 62 | public override string ToString() { 63 | return $"({First?.ToString() ?? "null"}, {Second.ToString() ?? "null"})"; 64 | } 65 | 66 | /// 67 | /// 支持解构
68 | ///
69 | /// 70 | /// 71 | public void Deconstruct(out TFirst first, out TSecond second) { 72 | first = First; 73 | second = Second; 74 | } 75 | } 76 | 77 | /// 78 | /// 对类型的工具函数
79 | ///
80 | public static class Pair { 81 | /// 82 | /// 创建对实例
83 | ///
84 | /// 85 | /// 86 | /// 87 | public static Pair Create(TFirst first, TSecond second) { 88 | return new Pair(first, second); 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/IOTCS.EdgeGateway.Application/Imps/RelationshipService.cs: -------------------------------------------------------------------------------- 1 | using IOTCS.EdgeGateway.Domain.DomainService; 2 | using IOTCS.EdgeGateway.Domain.Models; 3 | using IOTCS.EdgeGateway.Domain.Repositories; 4 | using IOTCS.EdgeGateway.Domain.ValueObject; 5 | using IOTCS.EdgeGateway.Freesql.Helper; 6 | using IOTCS.EdgeGateway.Logging; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | using System.Text; 11 | using System.Threading.Tasks; 12 | 13 | namespace IOTCS.EdgeGateway.Application.Imps 14 | { 15 | public class RelationshipService : IRelationshipService 16 | { 17 | private readonly ILogger _logger; 18 | private readonly IRelationshipRepository _repository; 19 | private readonly IRelationshipDomainService _relationshipDomainService; 20 | 21 | public RelationshipService(ILogger logger, 22 | IRelationshipRepository relationshipRepository, 23 | IRelationshipDomainService relationshipDomainService) 24 | { 25 | this._logger = logger; 26 | this._repository = relationshipRepository; 27 | this._relationshipDomainService = relationshipDomainService; 28 | } 29 | 30 | public async Task Create(RelationshipDto relationshipDto) 31 | { 32 | bool result; 33 | var model = relationshipDto.ToModel(); 34 | 35 | result = await _repository.Create(model); 36 | 37 | return await Task.FromResult(result); 38 | } 39 | 40 | public async Task Delete(RelationshipDto relationshipDto) 41 | { 42 | 43 | var result = true; 44 | var model = relationshipDto.ToModel(); 45 | 46 | result = await _repository.Delete(model); 47 | 48 | return await Task.FromResult(result); 49 | } 50 | 51 | public async Task> GetAllRelationship() 52 | { 53 | var list = await _relationshipDomainService.GetRelationship(); 54 | 55 | return list; 56 | } 57 | public async Task> GetTopics() 58 | { 59 | return await _repository.GetTopics(); 60 | } 61 | 62 | 63 | public async Task Update(RelationshipDto relationshipDto) 64 | { 65 | 66 | var result = true; 67 | var model = relationshipDto.ToModel(); 68 | 69 | result = await _repository.Update(model); 70 | 71 | return await Task.FromResult(result); 72 | } 73 | } 74 | } 75 | --------------------------------------------------------------------------------