You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
324 lines
23 KiB
C#
324 lines
23 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Haoliang.Models.User;
|
|
using Haoliang.Models.Device;
|
|
using Haoliang.Models.Production;
|
|
using Haoliang.Models.System;
|
|
using Haoliang.Models.Template;
|
|
using Haoliang.Models.DataCollection;
|
|
|
|
namespace Haoliang.Core.Services
|
|
{
|
|
#region ========== 用户与认证服务 ==========
|
|
public class AuthService : IAuthService
|
|
{
|
|
public Task<AuthResult> LoginAsync(LoginRequest request) => Task.FromResult<AuthResult>(null);
|
|
public Task<bool> LogoutAsync(int userId) => Task.FromResult(false);
|
|
public Task<AuthResult> RefreshTokenAsync(string refreshToken) => Task.FromResult<AuthResult>(null);
|
|
public Task<bool> UsernameExistsAsync(string username) => Task.FromResult(false);
|
|
public Task<bool> EmailExistsAsync(string email) => Task.FromResult(false);
|
|
}
|
|
|
|
public class UserService : IUserService
|
|
{
|
|
public Task<UserViewModel> CreateUserAsync(User user) => Task.FromResult<UserViewModel>(null);
|
|
public Task<UserViewModel> GetUserByIdAsync(int userId) => Task.FromResult<UserViewModel>(null);
|
|
public Task<IEnumerable<UserViewModel>> GetAllUsersAsync() => Task.FromResult<IEnumerable<UserViewModel>>(new List<UserViewModel>());
|
|
public Task<UserViewModel> UpdateUserAsync(int userId, User user) => Task.FromResult<UserViewModel>(null);
|
|
public Task<bool> ChangePasswordAsync(int userId, string oldPassword, string newPassword) => Task.FromResult(false);
|
|
public Task<bool> ActivateUserAsync(int userId) => Task.FromResult(false);
|
|
public Task<bool> DeactivateUserAsync(int userId) => Task.FromResult(false);
|
|
}
|
|
|
|
public class PermissionService : IPermissionService
|
|
{
|
|
public Task<IEnumerable<string>> GetUserPermissionsAsync(int userId) => Task.FromResult<IEnumerable<string>>(new List<string>());
|
|
public Task<bool> HasPermissionAsync(int userId, string permission) => Task.FromResult(false);
|
|
public Task AssignPermissionsToUserAsync(int userId, IEnumerable<string> permissions) => Task.CompletedTask;
|
|
public Task RemoveAllPermissionsFromUserAsync(int userId) => Task.CompletedTask;
|
|
}
|
|
#endregion
|
|
|
|
#region ========== 日志与缓存服务 ==========
|
|
public class LoggingService : ILoggingService
|
|
{
|
|
public Task LogInformationAsync(string message) { Console.WriteLine($"[INFO] {message}"); return Task.CompletedTask; }
|
|
public Task LogWarningAsync(string message) { Console.WriteLine($"[WARN] {message}"); return Task.CompletedTask; }
|
|
public Task LogErrorAsync(string message, Exception? exception = null) { Console.WriteLine($"[ERROR] {message}: {exception?.Message}"); return Task.CompletedTask; }
|
|
public Task<IEnumerable<LogEntry>> GetLogsAsync(Haoliang.Models.System.LogLevel? logLevel, DateTime? startDate, DateTime? endDate, string? category = null) => Task.FromResult<IEnumerable<LogEntry>>(new List<LogEntry>());
|
|
public Task<IEnumerable<LogEntry>> GetErrorLogsAsync(DateTime? startDate = null, DateTime? endDate = null) => Task.FromResult<IEnumerable<LogEntry>>(new List<LogEntry>());
|
|
public Task<int> GetLogCountAsync(Haoliang.Models.System.LogLevel? logLevel = null, DateTime? startDate = null, DateTime? endDate = null) => Task.FromResult(0);
|
|
public Task ArchiveLogsAsync(int daysToKeep = 90) => Task.CompletedTask;
|
|
public Task ClearLogsAsync() => Task.CompletedTask;
|
|
}
|
|
|
|
public class MemoryCacheService : ICacheService
|
|
{
|
|
private readonly Dictionary<string, object> _cache = new Dictionary<string, object>();
|
|
public T? Get<T>(string key) where T : class => _cache.TryGetValue(key, out var value) ? value as T : null;
|
|
public void Set<T>(string key, T value, TimeSpan? expiration = null) where T : class { _cache[key] = value; }
|
|
public bool Remove(string key) => _cache.Remove(key);
|
|
public bool Exists(string key) => _cache.ContainsKey(key);
|
|
public T GetOrSet<T>(string key, Func<T> factory, TimeSpan? expiration = null) where T : class { if (!_cache.TryGetValue(key, out var value)) { value = factory(); _cache[key] = value; } return (T)value; }
|
|
public void Clear() => _cache.Clear();
|
|
public CacheStats GetStatistics() => new CacheStats();
|
|
}
|
|
#endregion
|
|
|
|
#region ========== 设备采集服务 ==========
|
|
public class DeviceCollectionService : IDeviceCollectionService
|
|
{
|
|
public Task<IEnumerable<CNCDevice>> GetAllDevicesAsync() => Task.FromResult<IEnumerable<CNCDevice>>(new List<CNCDevice>());
|
|
public Task<CNCDevice?> GetDeviceByIdAsync(int deviceId) => Task.FromResult<CNCDevice?>(null);
|
|
public Task<CNCDevice> CreateDeviceAsync(CNCDevice device) => Task.FromResult(device);
|
|
public Task<CNCDevice?> UpdateDeviceAsync(CNCDevice device) => Task.FromResult<CNCDevice?>(null);
|
|
public Task<bool> DeleteDeviceAsync(int deviceId) => Task.FromResult(false);
|
|
public Task CollectDeviceAsync(int deviceId) => Task.CompletedTask;
|
|
public Task CollectAllDevicesAsync() => Task.CompletedTask;
|
|
public Task<DeviceStatus> GetDeviceStatusAsync(int deviceId) => Task.FromResult(new DeviceStatus());
|
|
public Task<DeviceHealth> GetDeviceHealthAsync(int deviceId) => Task.FromResult(new DeviceHealth());
|
|
}
|
|
|
|
public class DeviceStateMachine : IDeviceStateMachine
|
|
{
|
|
public DeviceStatus GetCurrentState(int deviceId) => new DeviceStatus();
|
|
public bool TransitionTo(int deviceId, DeviceStatus newState) => false;
|
|
public void RegisterStateChangeHandler(int deviceId, Action<int, DeviceStatus, DeviceStatus> callback) { }
|
|
public IEnumerable<DeviceStatusChange> GetStateHistory(int deviceId, DateTime fromTime, DateTime toTime) => new List<DeviceStatusChange>();
|
|
}
|
|
|
|
public class PingService : IPingService
|
|
{
|
|
public Task<PingResult> PingAsync(int deviceId, string ipAddress) => Task.FromResult(new PingResult { DeviceId = deviceId, IpAddress = ipAddress, Success = false });
|
|
public Task<IEnumerable<PingResult>> PingAllAsync(IEnumerable<(int DeviceId, string IpAddress)> devices) => Task.FromResult<IEnumerable<PingResult>>(new List<PingResult>());
|
|
public Task<bool> IsReachableAsync(string ipAddress, TimeSpan? timeout = null) => Task.FromResult(false);
|
|
}
|
|
#endregion
|
|
|
|
#region ========== 生产统计服务 ==========
|
|
public class ProductionService : IProductionService
|
|
{
|
|
public Task<ProductionSummary> GetProductionSummaryAsync(DateTime date) => Task.FromResult<ProductionSummary>(null);
|
|
public Task<ProductionStatistics> GetProductionStatisticsAsync(DateTime date) => Task.FromResult<ProductionStatistics>(null);
|
|
public Task<ProductionRecord> GetTodayProductionAsync(int deviceId) => Task.FromResult<ProductionRecord>(null);
|
|
public Task<ProductionStatistics> GetProductionStatisticsAsync(int deviceId, DateTime date) => Task.FromResult<ProductionStatistics>(null);
|
|
public Task<decimal> GetQualityRateAsync(int deviceId, DateTime date) => Task.FromResult(0m);
|
|
public Task CalculateAllProductionAsync() => Task.CompletedTask;
|
|
public Task CalculateProductionAsync(int deviceId) => Task.CompletedTask;
|
|
public Task<IEnumerable<string>> GetProductionProgramsAsync(DateTime date) => Task.FromResult<IEnumerable<string>>(new List<string>());
|
|
public Task<ProgramProductionSummary> GetProgramProductionAsync(string programName, DateTime date) => Task.FromResult<ProgramProductionSummary>(null);
|
|
public Task<byte[]> ExportProductionDataAsync(DateTime startDate, DateTime endDate) => Task.FromResult<byte[]>(null);
|
|
public Task ArchiveProductionDataAsync(int daysToKeep = 90) => Task.CompletedTask;
|
|
}
|
|
|
|
public class ProductionCalculator : IProductionCalculator
|
|
{
|
|
public Task<decimal> CalculateProductionIncrementAsync(int deviceId, decimal currentValue, string programName, DateTime timestamp) => Task.FromResult(0m);
|
|
public void ResetDeviceProductionState(int deviceId) { }
|
|
public bool ValidateProductionValue(int deviceId, decimal value) => true;
|
|
}
|
|
|
|
public class ProductionScheduler : IProductionScheduler
|
|
{
|
|
private bool _isRunning;
|
|
public Task StartAsync() { _isRunning = true; return Task.CompletedTask; }
|
|
public Task StopAsync() { _isRunning = false; return Task.CompletedTask; }
|
|
public void RegisterTask(string taskId, string schedule, Func<Task> action) { }
|
|
public void RemoveTask(string taskId) { }
|
|
public bool IsRunning => _isRunning;
|
|
}
|
|
|
|
public class ProductionStatisticsService : IProductionStatisticsService
|
|
{
|
|
public Task<ProductionTrendAnalysis> CalculateProductionTrendsAsync(int deviceId, DateTime startDate, DateTime endDate) => Task.FromResult<ProductionTrendAnalysis>(null);
|
|
public Task<ProductionReport> GenerateProductionReportAsync(ReportFilter filter) => Task.FromResult<ProductionReport>(null);
|
|
public Task<EfficiencyMetrics> CalculateEfficiencyMetricsAsync(EfficiencyFilter filter) => Task.FromResult<EfficiencyMetrics>(null);
|
|
public Task<QualityAnalysis> PerformQualityAnalysisAsync(QualityFilter filter) => Task.FromResult<QualityAnalysis>(null);
|
|
public Task<DashboardSummary> GetDashboardSummaryAsync(DashboardFilter filter) => Task.FromResult<DashboardSummary>(null);
|
|
public Task<OeeMetrics> CalculateOeeAsync(int deviceId, DateTime date) => Task.FromResult<OeeMetrics>(null);
|
|
public Task<ProductionForecast> GenerateProductionForecastAsync(ForecastFilter filter) => Task.FromResult<ProductionForecast>(null);
|
|
public Task<AnomalyAnalysis> DetectProductionAnomaliesAsync(AnomalyFilter filter) => Task.FromResult<AnomalyAnalysis>(null);
|
|
}
|
|
#endregion
|
|
|
|
#region ========== 告警服务 ==========
|
|
public class AlarmService : IAlarmService
|
|
{
|
|
public Task<IEnumerable<Alarm>> GetAllAlarmsAsync() => Task.FromResult<IEnumerable<Alarm>>(new List<Alarm>());
|
|
public Task<IEnumerable<Alarm>> GetAlarmsByTypeAsync(AlarmType type) => Task.FromResult<IEnumerable<Alarm>>(new List<Alarm>());
|
|
public Task<IEnumerable<Alarm>> GetActiveAlarmsAsync() => Task.FromResult<IEnumerable<Alarm>>(new List<Alarm>());
|
|
public Task<Alarm?> GetAlarmByIdAsync(int alarmId) => Task.FromResult<Alarm?>(null);
|
|
public Task<Alarm> CreateAlarmAsync(Alarm alarm) => Task.FromResult(alarm);
|
|
public Task<Alarm?> UpdateAlarmAsync(int alarmId, Alarm alarm) => Task.FromResult<Alarm?>(null);
|
|
public Task<bool> DeleteAlarmAsync(int alarmId) => Task.FromResult(false);
|
|
public Task<bool> ResolveAlarmAsync(int alarmId, string? resolutionNote) => Task.FromResult(false);
|
|
public Task<bool> AcknowledgeAlarmAsync(int alarmId, string? acknowledgeNote) => Task.FromResult(false);
|
|
public Task<IEnumerable<Alarm>> GetDeviceAlarmsAsync(int deviceId, int days = 7) => Task.FromResult<IEnumerable<Alarm>>(new List<Alarm>());
|
|
public Task<IEnumerable<Alarm>> GetCriticalAlarmsAsync() => Task.FromResult<IEnumerable<Alarm>>(new List<Alarm>());
|
|
public Task<AlarmStatistics> GetAlarmStatisticsAsync(DateTime date) => Task.FromResult<AlarmStatistics>(null);
|
|
public Task<IEnumerable<Alarm>> GetAlarmsByDateRangeAsync(DateTime startDate, DateTime endDate) => Task.FromResult<IEnumerable<Alarm>>(new List<Alarm>());
|
|
}
|
|
|
|
public class AlarmRuleService : IAlarmRuleService
|
|
{
|
|
public Task<IEnumerable<AlarmRule>> GetAllAlarmRulesAsync() => Task.FromResult<IEnumerable<AlarmRule>>(new List<AlarmRule>());
|
|
public Task<AlarmRule?> GetAlarmRuleByIdAsync(int ruleId) => Task.FromResult<AlarmRule?>(null);
|
|
public Task<AlarmRule> CreateAlarmRuleAsync(AlarmRule rule) => Task.FromResult(rule);
|
|
public Task<AlarmRule?> UpdateAlarmRuleAsync(int ruleId, AlarmRule rule) => Task.FromResult<AlarmRule?>(null);
|
|
public Task<bool> DeleteAlarmRuleAsync(int ruleId) => Task.FromResult(false);
|
|
public Task TestAlarmRuleAsync(int ruleId) => Task.CompletedTask;
|
|
public Task SetAlarmRuleEnabledAsync(int ruleId, bool enabled) => Task.CompletedTask;
|
|
}
|
|
|
|
public class AlarmNotificationService : IAlarmNotificationService
|
|
{
|
|
public Task SendAlarmNotificationAsync(AlarmNotification notification) => Task.CompletedTask;
|
|
public Task SendAlarmNotificationToChannelsAsync(Alarm alarm, IEnumerable<NotificationChannel> channels) => Task.CompletedTask;
|
|
public Task<NotificationStatus> GetNotificationStatusAsync(int notificationId) => Task.FromResult<NotificationStatus>(default);
|
|
public Task RetryNotificationAsync(int notificationId) => Task.CompletedTask;
|
|
public Task CancelNotificationAsync(int notificationId) => Task.CompletedTask;
|
|
}
|
|
#endregion
|
|
|
|
#region ========== 模板服务 ==========
|
|
public class TemplateService : ITemplateService
|
|
{
|
|
public Task<IEnumerable<CNCBrandTemplate>> GetAllTemplatesAsync() => Task.FromResult<IEnumerable<CNCBrandTemplate>>(new List<CNCBrandTemplate>());
|
|
public Task<CNCBrandTemplate?> GetTemplateByIdAsync(int templateId) => Task.FromResult<CNCBrandTemplate?>(null);
|
|
public Task<CNCBrandTemplate> CreateTemplateAsync(CNCBrandTemplate template) => Task.FromResult(template);
|
|
public Task<CNCBrandTemplate?> UpdateTemplateAsync(int templateId, CNCBrandTemplate template) => Task.FromResult<CNCBrandTemplate?>(null);
|
|
public Task<bool> DeleteTemplateAsync(int templateId) => Task.FromResult(false);
|
|
public Task<bool> EnableTemplateAsync(int templateId) => Task.FromResult(false);
|
|
public Task<bool> DisableTemplateAsync(int templateId) => Task.FromResult(false);
|
|
public Task<CNCBrandTemplate> CloneTemplateAsync(int templateId, string newName) => Task.FromResult<CNCBrandTemplate>(null);
|
|
public Task TestTemplateAsync(int templateId) => Task.CompletedTask;
|
|
public Task<IEnumerable<CNCBrandTemplate>> GetTemplatesByBrandAsync(string brandName) => Task.FromResult<IEnumerable<CNCBrandTemplate>>(new List<CNCBrandTemplate>());
|
|
public Task<IEnumerable<CNCBrandTemplate>> GetActiveTemplatesAsync() => Task.FromResult<IEnumerable<CNCBrandTemplate>>(new List<CNCBrandTemplate>());
|
|
public Task<bool> ValidateTemplateAsync(CNCBrandTemplate template) => Task.FromResult(false);
|
|
}
|
|
|
|
public class TagMappingService : ITagMappingService
|
|
{
|
|
public Task<IEnumerable<TagMapping>> GetMappingsByTemplateAsync(int templateId) => Task.FromResult<IEnumerable<TagMapping>>(new List<TagMapping>());
|
|
public Task<TagMapping> CreateTagMappingAsync(TagMapping mapping) => Task.FromResult(mapping);
|
|
public Task CreateTagMappingsAsync(int templateId, IEnumerable<TagMapping> mappings) => Task.CompletedTask;
|
|
public Task<TagMapping> UpdateTagMappingAsync(int mappingId, TagMapping mapping) => Task.FromResult(mapping);
|
|
public Task<bool> DeleteTagMappingAsync(int mappingId) => Task.FromResult(false);
|
|
public Task<IEnumerable<Haoliang.Models.Device.TagData>> MapDeviceTagsAsync(IEnumerable<Haoliang.Models.Device.TagData> deviceTags, int templateId) => Task.FromResult<IEnumerable<Haoliang.Models.Device.TagData>>(new List<Haoliang.Models.Device.TagData>());
|
|
public Task<TagMapping?> GetMappingBySystemFieldAsync(int templateId, string systemFieldId) => Task.FromResult<TagMapping?>(null);
|
|
}
|
|
|
|
public class TemplateValidationService : ITemplateValidationService
|
|
{
|
|
public Task<IEnumerable<string>> ValidateTemplateForDeviceAsync(int templateId, int deviceId) => Task.FromResult<IEnumerable<string>>(new List<string>());
|
|
public Task<TemplateMigrationReport> GenerateMigrationReportAsync(CNCBrandTemplate template, string targetBrand) => Task.FromResult<TemplateMigrationReport>(null);
|
|
public Task<TemplateValidationResult> ValidateTemplateCompletenessAsync(CNCBrandTemplate template) => Task.FromResult<TemplateValidationResult>(null);
|
|
}
|
|
|
|
public class TemplateMigrationService : ITemplateMigrationService
|
|
{
|
|
public Task<CNCBrandTemplate> MigrateTemplateAsync(int sourceTemplateId, string targetBrand) => Task.FromResult<CNCBrandTemplate>(null);
|
|
public Task<bool> CanMigrateAsync(int sourceTemplateId, string targetBrand) => Task.FromResult(false);
|
|
public Task<IEnumerable<TagMappingSuggestion>> GetMigrationMappingSuggestionsAsync(int sourceTemplateId, string targetBrand) => Task.FromResult<IEnumerable<TagMappingSuggestion>>(new List<TagMappingSuggestion>());
|
|
}
|
|
#endregion
|
|
|
|
#region ========== 系统服务 ==========
|
|
public class SystemService : ISystemService
|
|
{
|
|
public Task<SystemStatusInfo> GetSystemStatusAsync() => Task.FromResult<SystemStatusInfo>(null);
|
|
public Task<HealthCheckResult> PerformHealthCheckAsync() => Task.FromResult<HealthCheckResult>(null);
|
|
public Task<SystemMetrics> GetSystemMetricsAsync() => Task.FromResult<SystemMetrics>(null);
|
|
public Task RestartAsync() => Task.CompletedTask;
|
|
}
|
|
|
|
public class SystemConfigService : ISystemConfigService
|
|
{
|
|
public Task<IEnumerable<SystemConfig>> GetAllConfigsAsync() => Task.FromResult<IEnumerable<SystemConfig>>(new List<SystemConfig>());
|
|
public Task<SystemConfig?> GetConfigAsync(string key) => Task.FromResult<SystemConfig?>(null);
|
|
public Task<SystemConfig> SetConfigAsync(string key, string value) => Task.FromResult<SystemConfig>(null);
|
|
public Task<bool> DeleteConfigAsync(string key) => Task.FromResult(false);
|
|
public Task<bool> ConfigExistsAsync(string key) => Task.FromResult(false);
|
|
public Task<IEnumerable<SystemConfig>> GetConfigsByCategoryAsync(string category) => Task.FromResult<IEnumerable<SystemConfig>>(new List<SystemConfig>());
|
|
public Task RefreshConfigCacheAsync() => Task.CompletedTask;
|
|
}
|
|
|
|
public class SchedulerService : ISchedulerService
|
|
{
|
|
public Task<IEnumerable<ScheduledTask>> GetAllScheduledTasksAsync() => Task.FromResult<IEnumerable<ScheduledTask>>(new List<ScheduledTask>());
|
|
public Task<ScheduledTask?> GetTaskByIdAsync(string taskId) => Task.FromResult<ScheduledTask?>(null);
|
|
public Task ScheduleTaskAsync(ScheduledTask task) => Task.CompletedTask;
|
|
public Task ExecuteTaskAsync(string taskId) => Task.CompletedTask;
|
|
public Task<bool> RemoveTaskAsync(string taskId) => Task.FromResult(false);
|
|
public Task StartSchedulerAsync() => Task.CompletedTask;
|
|
public Task StopSchedulerAsync() => Task.CompletedTask;
|
|
}
|
|
#endregion
|
|
|
|
#region ========== 实时服务 ==========
|
|
public class RealTimeService : IRealTimeService
|
|
{
|
|
public Task<int> GetConnectedClientsCountAsync() => Task.FromResult(0);
|
|
public Task<IEnumerable<ClientInfo>> GetConnectedClientsByTypeAsync(string clientType) => Task.FromResult<IEnumerable<ClientInfo>>(new List<ClientInfo>());
|
|
public Task<DeviceMonitoringStatus> GetDeviceMonitoringStatusAsync(int deviceId) => Task.FromResult<DeviceMonitoringStatus>(null);
|
|
public Task StartDeviceStreamingAsync(int deviceId, int intervalMs = 1000) => Task.CompletedTask;
|
|
public Task StopDeviceStreamingAsync(int deviceId) => Task.CompletedTask;
|
|
public Task<IEnumerable<int>> GetActiveStreamingDevicesAsync() => Task.FromResult<IEnumerable<int>>(new List<int>());
|
|
public Task BroadcastDeviceStatusAsync(DeviceStatusUpdate statusUpdate) => Task.CompletedTask;
|
|
public Task BroadcastProductionUpdateAsync(ProductionUpdate productionUpdate) => Task.CompletedTask;
|
|
public Task BroadcastAlertAsync(AlertUpdate alertUpdate) => Task.CompletedTask;
|
|
public Task SendSystemNotificationAsync(SystemNotification notification) => Task.CompletedTask;
|
|
public Task SendDashboardUpdateAsync(DashboardUpdate dashboardUpdate) => Task.CompletedTask;
|
|
public Task SendCommandToClientAsync(string connectionId, RealTimeCommand command) => Task.CompletedTask;
|
|
public Task BroadcastCommandAsync(RealTimeCommand command) => Task.CompletedTask;
|
|
}
|
|
#endregion
|
|
|
|
#region ========== 规则与数据服务 ==========
|
|
public class RulesService : IRulesService
|
|
{
|
|
public Task<IEnumerable<BusinessRule>> GetAllRulesAsync() => Task.FromResult<IEnumerable<BusinessRule>>(new List<BusinessRule>());
|
|
public Task<BusinessRule?> GetRuleByIdAsync(int ruleId) => Task.FromResult<BusinessRule?>(null);
|
|
public Task<BusinessRule> CreateRuleAsync(BusinessRule rule) => Task.FromResult(rule);
|
|
public Task<BusinessRule?> UpdateRuleAsync(int ruleId, BusinessRule rule) => Task.FromResult<BusinessRule?>(null);
|
|
public Task<bool> DeleteRuleAsync(int ruleId) => Task.FromResult(false);
|
|
public Task<RuleExecutionResult> ExecuteRuleAsync(int ruleId, Dictionary<string, object> context) => Task.FromResult<RuleExecutionResult>(null);
|
|
public Task<RuleTestResult> TestRuleAsync(int ruleId, Dictionary<string, object> testData) => Task.FromResult<RuleTestResult>(null);
|
|
public Task<IEnumerable<RuleExecutionHistory>> GetRuleExecutionHistoryAsync(int ruleId, DateTime fromTime, DateTime toTime) => Task.FromResult<IEnumerable<RuleExecutionHistory>>(new List<RuleExecutionHistory>());
|
|
}
|
|
|
|
public class DataParserService : IDataParserService
|
|
{
|
|
public Task<ParsedDeviceData> ParseRawDataAsync(string rawData, int templateId) => Task.FromResult<ParsedDeviceData>(null);
|
|
public Task<IEnumerable<ParsedDeviceData>> ParseMultiDeviceDataAsync(string rawData, int templateId) => Task.FromResult<IEnumerable<ParsedDeviceData>>(new List<ParsedDeviceData>());
|
|
public bool ValidateDataFormat(string rawData) => false;
|
|
}
|
|
|
|
public class DataStorageService : IDataStorageService
|
|
{
|
|
public Task StoreDeviceDataAsync(ParsedDeviceData data) => Task.CompletedTask;
|
|
public Task StoreDeviceDataBatchAsync(IEnumerable<ParsedDeviceData> dataList) => Task.CompletedTask;
|
|
public Task StoreProductionRecordAsync(ProductionRecord record) => Task.CompletedTask;
|
|
public Task UpdateDeviceStatusAsync(int deviceId, DeviceStatus status) => Task.CompletedTask;
|
|
}
|
|
|
|
public class RetryService : IRetryService
|
|
{
|
|
public async Task<T> ExecuteWithRetryAsync<T>(Func<Task<T>> operation, int maxRetries = 3, TimeSpan? delay = null) { for (int i = 0; i < maxRetries; i++) { try { return await operation(); } catch { if (i == maxRetries - 1) throw; } } return default; }
|
|
public async Task ExecuteWithRetryAsync(Func<Task> operation, int maxRetries = 3, TimeSpan? delay = null) { for (int i = 0; i < maxRetries; i++) { try { await operation(); return; } catch { if (i == maxRetries - 1) throw; } } }
|
|
}
|
|
#endregion
|
|
|
|
#region ========== 后台任务服务 ==========
|
|
public class BackgroundTaskService : IHostedService
|
|
{
|
|
public Task StartAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
|
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
|
}
|
|
#endregion
|
|
}
|