public Task ExecuteAsync(CancellationToken stoppingToken)
    {
        var LoopEvaluateInterval = settings?.LoopEvaluateIntervalMilliseconds ?? 500;

        connector.Connected += (s, c) =>
        {
            processInfo.ConnectedDateTime = DateTime.Now;
        };

        connector.ConnectAsync(stoppingToken).Wait();
        var tagNow = connector.AddTag(settings.TagDateTimeNow);

        if (!stoppingToken.IsCancellationRequested)
        {
            LoadTagsToCache();
            LoadRules();
            processInfo.LoopPublishStatistics(TimeSpan.FromSeconds(10), stoppingToken);
            WaitTagsStatusAsync(stoppingToken).Wait();
        }

        return(Task.Run(async() =>
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                processInfo.RunningDateTime = DateTime.Now;
                tagNow.SetDateTime(processInfo.RunningDateTime);
                tagRuleChangeEvaluator.EvaluateChanges();
                await Task.Delay(TimeSpan.FromMilliseconds(LoopEvaluateInterval), stoppingToken);
            }
        }).ContinueWith(t =>
        {
            logger.LogWarning("Process Stoped at: {time}", DateTimeOffset.Now.ToString("o"));
        }));
    }
        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));
         }
     }
 }
示例#4
0
    protected override Task ExecuteAsync(CancellationToken stoppingToken)
    {
        connector.ConnectAsync().Wait();

        var pepe = connector.AddTag("pepe");

        var stats = pepe.Status;

        pepe.SetNumeric(1);

        stats = pepe.Status;

        var value = pepe.Value.Numeric;

        return(Task.CompletedTask);
    }
 public static IRtTag AddTag(this IRtConnector conn, string topic, IRtTagOptions options = null)
 {
     return(conn.AddTag(topic, topic, options));
 }