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.GetPlantWithAccessForUserAsync(_synchronizationUserOid))
            {
                _logger.LogInformation($"Synchronizing plant {plant}...");

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

                var startTime = TimeService.UtcNow;

                // todo Synchronize here

                var endTime = TimeService.UtcNow;

                _logger.LogInformation($"Plant {plant} synchronized. Duration: {(endTime - startTime).TotalSeconds}s.");
                _telemetryClient.TrackMetric("Synchronization Time", (endTime - startTime).TotalSeconds, "Plant", plant);
            }
        }
Esempio n. 2
0
        public async Task ProcessMessageAsync(PcsTopic pcsTopic, string messageJson, CancellationToken cancellationToken)
        {
            _currentUserSetter.SetCurrentUserOid(_ipoApiOid);

            switch (pcsTopic)
            {
            case PcsTopic.Ipo:
                await ProcessIpoEvent(messageJson);

                break;

            case PcsTopic.Project:
                ProcessProjectEvent(messageJson);
                break;

            case PcsTopic.CommPkg:
                ProcessCommPkgEvent(messageJson);
                break;

            case PcsTopic.McPkg:
                ProcessMcPkgEvent(messageJson);
                break;

            case PcsTopic.Library:
                ProcessLibraryEvent(messageJson);
                break;
            }
            await _unitOfWork.SaveChangesAsync(cancellationToken);
        }
        public async Task ProcessMessageAsync(PcsTopic pcsTopic, string messageJson, CancellationToken cancellationToken)
        {
            _currentUserSetter.SetCurrentUserOid(_synchronizationUserOid);

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

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

            switch (pcsTopic)
            {
            case PcsTopic.Project:
                await ProcessProjectEvent(messageJson);

                break;

            case PcsTopic.Responsible:
                await ProcessResponsibleEvent(messageJson);

                break;

            case PcsTopic.TagFunction:
                await ProcessTagFunctionEvent(messageJson);

                break;

            case PcsTopic.CommPkg:
                await ProcessCommPkgEvent(messageJson);

                break;

            case PcsTopic.McPkg:
                await ProcessMcPkgEvent(messageJson);

                break;

            case PcsTopic.Tag:
                await ProcessTagEvent(messageJson);

                break;
            }

            await _unitOfWork.SaveChangesAsync(cancellationToken);
        }