示例#1
0
 public WorkerService(
     ILogger <WorkerService> logger,
     IRtConnector connector)
 {
     _logger        = logger;
     this.connector = connector;
 }
    public RealTimeHistoricDbService(
        IRtConnector connector,
        IHistoricRepository repository,
        ILoggerFactory loggerFactory,
        ProcessInfoStatistics processInfo,
        IOptions <RealTimeHistoricDBConfiguration> options)
    {
        this.logger           = loggerFactory.CreateLogger(nameof(WorkerService));
        this.connector        = connector;
        this.repository       = repository;
        this.processInfo      = processInfo;
        this.wsTags           = new Queue <List <TagChangeTracker> >();
        this.tagChangeManager = new TagChangeTrackerManager();
        this.lastCommit       = DateTime.Now;

        var intervalRefresh = options.Value.CheckTagChangeIntervalMilliseconds ?? 1000;
        var intervalCommit  = options.Value.SaveChangeIntervalSeconds ?? 5 * 60;

        this.checkTagChangeInterval = TimeSpan.FromMilliseconds(intervalRefresh > 100 ? intervalRefresh : 100);
        this.saveChangeInterval     = TimeSpan.FromSeconds(intervalCommit > 2 ? intervalCommit : 2);

        this.daysPresistence = options.Value.DaysPresistence ?? 30;

        logger.LogInformation("Initialize RealTimeHistoricDbWorker, checkTagChangeInterval time:{checkTagChangeInterval} " +
                              "saveChangeInterval time:{saveChangeInterval} daysPresistence:{daysPresistence}",
                              checkTagChangeInterval, saveChangeInterval, daysPresistence);
    }
示例#3
0
 public RtTagMqtt(IRtConnector connector, string tagName, string topic, RtTagMqttOptions options)
 {
     Connector    = connector;
     TagName      = tagName;
     Topic        = topic;
     base.Options = options ?? new RtTagMqttOptions();
 }
示例#4
0
        public static IRtTag AddExpression(IRtConnector creator, string expresionFull, IRtTagOptions options = null)
        {
            MatchCollection matches = rgx.Matches(expresionFull);

            if (matches.Count > 0)
            {
                string expresion     = expresionFull;
                int    i             = 0;
                var    argumentsTags = new IRtTag[matches.Count];
                foreach (Match match in matches)
                {
                    var tagDefinition = match.Value.Trim().TrimStart('{').TrimEnd('}');
                    argumentsTags[i] = creator.AddTagDefinition(tagDefinition, options);
                    expresion        = expresion.Replace(match.Value, $"arg{i}");
                    i++;
                }
                return(new RtTagExpression(expresionFull, expresion, argumentsTags));
            }
            else if (expresionFull.StartsWith("="))
            {
                return(new RtTagExpression(expresionFull, expresionFull, null));
            }
            else
            {
                return(creator.AddTagDefinition(expresionFull, options));
            }
        }
示例#5
0
 public RealTimeWebSocketBridgeWorker(
     ILogger <RealTimeWebSocketBridgeWorker> logger,
     IRpcConnection rpcConnection,
     IRtConnector connector)
 {
     this.logger        = logger;
     this.rpcConnection = rpcConnection;
     this.connector     = connector;
 }
示例#6
0
    public SimulationService(
        ILogger <SimulationService> logger,
        IRtConnector rt)
    {
        this.logger = logger;
        this.rt     = rt;
        cycleTime   = TimeSpan.FromMilliseconds(200);

        Init();
    }
        public static IRtTag GetOrAddTag(this IRtConnector conn, string tagName, string topic, IRtTagOptions options = null)
        {
            var tag = conn.GetTag(tagName);

            if (tag == null)
            {
                tag = conn.AddTag(tagName, topic, options);
            }
            return(tag);
        }
 public void AddTagIfNotExist(IRtConnector connector, string tagName, int tagId)
 {
     lock (cacheTags)
     {
         if (!cacheTags.Any(t => t.TagName == tagName))
         {
             var tag = connector.AddTag(tagName, tagName);
             cacheTags.Add(new TagChangeTracker(tagName, tag, tagId));
         }
     }
 }
示例#9
0
 public ModbusTcpClientService(
     IRtConnector connector,
     ILoggerFactory loggerFactory,
     ProcessInfoStatistics processInfo,
     IOptions <RealTimeModbusTcpConfiguration> settings)
 {
     this.settings     = settings.Value;
     this.modbusClient = new ModbusClient(this.settings.IpAddress, this.settings.Port, this.settings.TimeoutSeconds * 1000);
     this.connector    = connector;
     this.processInfo  = processInfo;
     this.logger       = loggerFactory.CreateLogger(nameof(ModbusTcpClientService));
 }
示例#10
0
 public TagRuleChangeExecutorService(
     IOptions <TagRuleExecutorConfiguration> settings,
     ILogger <TagRuleChangeExecutorService> logger,
     ProcessInfoStatistics statistics,
     IRtConnector connector)
 {
     this.settings               = settings.Value;
     this.logger                 = logger;
     this.processInfo            = statistics;
     this.connector              = connector;
     this.cacheTags              = new Dictionary <string, IRtTag>();
     this.tagRuleChangeEvaluator = new TagRuleChangeEvaluator <string>(ActionOnChange, this.settings.DefaultTolerance, this.settings.DefaultDiscardValue);
 }
示例#11
0
 public WorkerService(
     ILogger <WorkerService> logger,
     IRpcConnection rpcConnection,
     IRtConnector connector,
     RpcHistoryService historyService,
     Rpc rpc)
 {
     this.logger         = logger;
     this.rpcConnection  = rpcConnection;
     this.connector      = connector;
     this.historyService = historyService;
     this.rpc            = rpc;
 }
示例#12
0
 public ShiftService(
     IOptions <ShiftConfiguration> options,
     IRtConnector connector           = null,
     IServiceProvider serviceProvider = null,
     ILogger <ShiftService> logger    = null,
     IShiftNotification notification  = null)
 {
     this.configuration   = options.Value;
     this.connector       = connector;
     this.serviceProvider = serviceProvider;
     this.logger          = logger;
     this.notification    = notification;
     this.startedEvent    = new ManualResetEvent(false);
 }
示例#13
0
 public TagChangeTracker GetOrAdd(IRtConnector connector, string tagExpression)
 {
     lock (cacheTags)
     {
         var t = cacheTags.FirstOrDefault(t => t.TagName == tagExpression);
         if (t == null)
         {
             var tag = RtTagExpression.AddExpression(connector, tagExpression);
             t = new TagChangeTracker(tag, tagExpression);
             cacheTags.Add(t);
         }
         return(t);
     }
 }
 public TagRuleToDatabaseService(
     IOptions <TagRuleToDatabaseConfiguration> settings,
     IDatabaseManager database,
     ILogger <TagRuleToDatabaseService> logger,
     ProcessInfoStatistics processInfo,
     IRtConnector connector)
 {
     this.settings               = settings.Value;
     this.database               = database;
     this.logger                 = logger;
     this.processInfo            = processInfo;
     this.connector              = connector;
     this.cacheTags              = new Dictionary <string, IRtTag>();
     this.tagRuleChangeEvaluator = new TagRuleChangeEvaluator <string>(ActionOnChange, this.settings.DefaultTolerance, this.settings.DefaultDiscardValue);
 }
示例#15
0
        public RealTimeRpcWebSocketMiddleware(
            IRtConnector connector,
            WebSocketHandlerHub hub,
            TagChangeTrackerManager trackerManager,
            ILoggerFactory loggerFactory,
            ProcessInfoStatistics processInfo,
            TimeSpan?refreshInterval = default)
        {
            this.logger          = loggerFactory.CreateLogger(nameof(RealTimeRpcWebSocketMiddleware));
            this.hub             = hub;
            this.trackerManager  = trackerManager;
            this.processInfo     = processInfo;
            this.connector       = connector;
            this.wsTags          = new ConcurrentDictionary <WebSocketHandler, List <TagChangeTracker> >();
            this.refreshInterval = refreshInterval ?? TimeSpan.FromSeconds(1);

            this.connector.Connected += (s, e) => { processInfo.ConnectedDateTime = DateTime.Now; };
        }
示例#16
0
 public ProcessInfoStatisticsBase(
     IRtConnector connector,
     string processName = null)
 {
     this.tags      = new Dictionary <string, StatisticsProps>();
     this.connector = connector;
     if (processName == null)
     {
         processName = Process.GetCurrentProcess().ProcessName;
         if (processName.StartsWith("DeltaX."))
         {
             processName = processName.Substring("DeltaX.".Length);
         }
     }
     this.processName   = processName;
     this.prefixTagName = $"process_info/{this.processName}";
     this.Startup       = DateTime.Now;
     this.ConnectorStr  = connector.ToString();
 }
        public static IRtTag AddTagDefinition(this IRtConnector conn, string tagDefinition, IRtTagOptions options = null)
        {
            var tsplit = tagDefinition.Split(new[] { "@" }, 2, StringSplitOptions.None);
            var topic  = tsplit[0];

            if (tsplit.Length > 1)
            {
                var tag = conn.GetOrAddTag(topic, options);

                var tagDefinitionPattern = tsplit[1];

                if (tagDefinitionPattern.StartsWith("JSON:"))
                {
                    var jsonValuePattern = tagDefinitionPattern.Remove(0, 5);
                    return(new RtTagJson(tag, jsonValuePattern));
                }
                else if (tagDefinitionPattern.StartsWith("RGX:"))
                {
                    var regexPattern = tagDefinitionPattern.Remove(0, 4);
                    return(new RtTagRegex(tag, regexPattern));
                }
                else if (tagDefinitionPattern.StartsWith("DT:"))
                {
                    var dateTimePattern = tagDefinitionPattern.Remove(0, 3);
                    return(new RtTagDateTime(tag, dateTimePattern));
                }
                else if (tagDefinitionPattern.StartsWith("UL:"))
                {
                    var ultraLightValuePattern = tagDefinitionPattern.Remove(0, 3);
                    return(new RtTagUltraLight(tag, ultraLightValuePattern));
                }
                else if (tagDefinitionPattern.StartsWith("BDP:"))
                {
                    var dataParserPattern = tagDefinitionPattern.Remove(0, 4);
                    return(new RtTagBinaryDataParser(tag, dataParserPattern));
                }
            }

            return(conn.GetOrAddTag(topic, options));
        }
示例#18
0
 public ProcessInfoStatistics(IRtConnector connector) : base(connector)
 {
 }
示例#19
0
 public WorkerService(IRtConnector connector, ILogger <WorkerService> logger)
 {
     logger.LogInformation("start pepe");
     this.connector = connector;
 }
示例#20
0
 public ProcessInfoStatistics(IRtConnector connector)
     : base(connector, "RealTimeHistoricDB")
 {
 }
 public static bool SetNumeric(this IRtConnector conn, string topic, double value, IRtTagOptions options = null)
 {
     return(conn.WriteValue(topic, RtValue.Create(value), options));
 }
示例#22
0
 public ProcessInfoStatistics(IRtConnector connector)
     : base(connector, "TagRuleExecutor")
 {
 }
 public static bool SetJson <T>(this IRtConnector conn, string topic, T json, IRtTagOptions options = null)
 {
     return(conn.WriteValue(topic, RtValue.Create(JsonSerializer.Serialize(json)), options));
 }
 public static bool SetBinary(this IRtConnector conn, string topic, byte[] value, IRtTagOptions options = null)
 {
     return(conn.WriteValue(topic, RtValue.Create(value), options));
 }
 public static IRtTag GetOrAddTag(this IRtConnector conn, string topic, IRtTagOptions options = null)
 {
     return(conn.GetOrAddTag(topic, topic, options));
 }
 public ProcessInfoStatistics(IRtConnector connector, IOptions <RealTimeModbusTcpConfiguration> options)
     : base(connector, options?.Value?.ProcessInfoName)
 {
 }
 public static RtTagType <TValue> GetOrAddTag <TValue>(this IRtConnector conn, string topic, IRtTagOptions options = null)
 {
     return(new RtTagType <TValue>(conn.GetOrAddTag(topic, topic, options)));
 }
 public static RtTagType <TValue> AddTagDefinition <TValue>(this IRtConnector conn, string tagDefinition, IRtTagOptions options = null)
 {
     return(new RtTagType <TValue>(conn.AddTagDefinition(tagDefinition, options)));
 }
示例#29
0
 public ProcessInfoStatistics(IRtConnector connector)
     : base(connector, "TagRuleToDatabase")
 {
 }