private PlcEvent CreateEvent([NotNull] object value, ErrorCodeSetting errorCodeSetting)
        {
            var isNotError = value.ToString().Equals(errorCodeSetting.NoErrorValue.ToString());

            var errorCodeDescription = errorCodeSetting.CodeDescriptions.FirstOrDefault(description => description.Value.ToString().Equals(value.ToString()));

            var ignored = errorCodeSetting.IgnoreNotDescribedValues && errorCodeDescription == null;

            var plcEvent = new PlcEvent()
            {
                Timestamp       = DateTime.Now,
                Source          = $"{errorCodeSetting.PlcName}::{errorCodeSetting.ErrorCodeAddress}",
                Value           = value,
                ExpectedValue   = errorCodeSetting.NoErrorValue,
                Description     = errorCodeDescription?.Description,
                LongDescription = errorCodeDescription?.LongDescription
            };

            if (isNotError)
            {
                plcEvent.Severity = Severity.NoError;
            }
            else if (ignored)
            {
                plcEvent.Severity = Severity.Ignored;
            }
            else
            {
                plcEvent.Severity = errorCodeDescription?.Severity ?? errorCodeSetting.DefaultSeverity;
            }

            return(plcEvent);
        }
        private PlcEvent CreateAndLogEvent([NotNull] object value, ErrorCodeSetting errorCodeSetting)
        {
            var plcEvent = CreateEvent(value, errorCodeSetting);

            plcEventLogService.LogEvent(plcEvent);
            return(plcEvent);
        }
 public RemoteStoreRepository(IOptions <ErrorCodeSetting> errorCodeConfiguration, ILoggerFactory loggerFactory, IJsonHelper jsonHelper)
 {
     _logger = loggerFactory.CreateLogger <RemoteStoreRepository>();
     _config = new ErrorCodeConfig();
     _errorCodeConfiguration = errorCodeConfiguration.Value;
     _jsonHelper             = jsonHelper;
 }
Esempio n. 4
0
        /// <summary>
        /// 错误码服务
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static IServiceCollection AddErrorCodeService(this IServiceCollection services, IConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var config = new ErrorCodeSetting();

            configuration.GetSection("ErrorCodeService").Bind(config);
            // 错误码中心服务地址
            services.AddSingleton(f => new RemoteStoreRepository(config, f.GetRequiredService <ILoggerFactory>(), f.GetRequiredService <IJsonHelper>()));
            services.AddSingleton <IErrorCodeStore, DefaultErrorCodeStore>();

            return(services);
        }
        /// <summary>
        /// 错误码服务
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static IServiceCollection AddErrorCodeService(this IServiceCollection services, Action <ErrorCodeSetting> configAction)
        {
            if (configAction == null)
            {
                throw new ArgumentNullException(nameof(configAction));
            }

            var config = new ErrorCodeSetting();

            configAction?.Invoke(config);
            // 移除空注入
            services.Remove(new ServiceDescriptor(typeof(IErrorCodeStore), typeof(EmptyErrorCodeStore), ServiceLifetime.Singleton));
            // 错误码中心服务地址
            services.AddSingleton(f => new RemoteStoreRepository(config, f.GetRequiredService <ILoggerFactory>(), f.GetRequiredService <IJsonHelper>()));
            services.AddSingleton <IErrorCodeStore, DefaultErrorCodeStore>();

            return(services);
        }
Esempio n. 6
0
 public BucketErrorCodeHostedService(IOptions <ErrorCodeSetting> errorCodeConfiguration, IDataRepository dataRepository)
 {
     _errorCodeConfiguration = errorCodeConfiguration.Value;
     _dataRepository         = dataRepository;
 }
        private void HandleNewErrorCode(object value, ErrorCodeSetting errorCodeSetting)
        {
            var eventInfo = CreateAndLogEvent(value, errorCodeSetting);

            SetActualEvent(eventInfo);
        }
Esempio n. 8
0
 public HttpUrlRepository(IOptions <ErrorCodeSetting> errorCodeConfiguration)
 {
     _errorCodeConfiguration = errorCodeConfiguration.Value;
 }