コード例 #1
0
    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"));
        }));
    }
コード例 #2
0
    public Task ExecuteAsync(CancellationToken stoppingToken)
    {
        var loopScanInterval = settings?.ScanIntervalMilliSeconds ?? 500;

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

        processInfo.ReadBlocks = settings.ReadBlocks.Length;
        processInfo.TagsCount  = settings.ReadBlocks.Sum(b => b.Tags.Count());

        processInfo.LoopPublishStatistics(TimeSpan.FromSeconds(10), stoppingToken);
        connector.ConnectAsync(stoppingToken).Wait();

        return(Task.Run(async() =>
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                processInfo.RunningDateTime = DateTime.Now;
                await ReadRtTagAsync();
                await Task.Delay(TimeSpan.FromMilliseconds(loopScanInterval), stoppingToken);
            }
        }).ContinueWith(t =>
        {
            logger.LogWarning("Process Stoped at: {time}", DateTimeOffset.Now.ToString("o"));
        }));
    }
コード例 #3
0
    public Task ExecuteAsync(CancellationToken stoppingToken)
    {
        logger.LogInformation("Wait connect with {connector}...", connector);

        connector.Connected += (s, e) =>
        {
            processInfo.ConnectedDateTime = DateTime.Now;
        };
        connector.ConnectAsync(stoppingToken).Wait();

        logger.LogInformation("Load all configured tags...", connector);
        var tagsDbAdded = repository.GetListHistoricTags();

        foreach (var row in tagsDbAdded.Where(r => r.Enable))
        {
            tagChangeManager.AddTagIfNotExist(connector, row.TagName, row.Id);
        }
        processInfo.TagsCount += tagsDbAdded.Count();

        return(Task.WhenAny(
                   processInfo.LoopPublishStatistics(TimeSpan.FromSeconds(30), stoppingToken),
                   LoopDeleteOldsHistoricTagValuesAsync(stoppingToken),
                   LoopSaveDataBaseChangesAsync(stoppingToken),
                   LoopEnqueueTagsChangedAsync(stoppingToken))
               .ContinueWith((t) =>
        {
            if (t.Result.IsFaulted)
            {
                logger.LogError(t.Result.Exception, "Execution RealTimeHistoricDbWorker Stoped: {time}", DateTimeOffset.Now);
                Environment.Exit(-1);
            }
            else
            {
                logger.LogWarning("Execution RealTimeHistoricDbWorker Stoped: {time}", DateTimeOffset.Now);
            }
        }));
    }