Exemplo n.º 1
0
        public async Task <IList <string> > GetPlantsFromCache()
        {
            var currentUserOid = _currentUserProvider.GetCurrentUserOid();
            var plants         = await _plantCache.GetPlantIdsWithAccessForUserAsync(currentUserOid);

            return(plants);
        }
Exemplo n.º 2
0
        public async Task Synchronize(CancellationToken cancellationToken)
        {
            var bearerToken = await _authenticator.GetBearerTokenForApplicationAsync();

            _bearerTokenSetter.SetBearerToken(bearerToken, false);

            _currentUserSetter.SetCurrentUserOid(_synchronizationUserOid);

            var currentUser    = _claimsProvider.GetCurrentUser();
            var claimsIdentity = new ClaimsIdentity();

            claimsIdentity.AddClaim(new Claim(ClaimsExtensions.Oid, _synchronizationUserOid.ToString()));
            currentUser.AddIdentity(claimsIdentity);

            foreach (var plant in await _plantCache.GetPlantIdsWithAccessForUserAsync(_synchronizationUserOid))
            {
                _logger.LogInformation($"Synchronizing plant {plant}...");

                try
                {
                    _plantSetter.SetPlant(plant);
                    await _claimsTransformation.TransformAsync(currentUser);

                    var startTime = TimeService.UtcNow;
                    if (_options.CurrentValue.AutoTransferTags)
                    {
                        await AutoTransferTagsAsync(plant);
                    }

                    var endTime = TimeService.UtcNow;

                    _logger.LogInformation($"Plant {plant} synchronized. Duration: {(endTime - startTime).TotalSeconds}s.");
                    _telemetryClient.TrackMetric("Synchronization Time", (endTime - startTime).TotalSeconds, "Plant", plant);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, $"Error synchronizing plant {plant}...");
                }
            }
        }