Beispiel #1
0
        public static async Task <PowerofficeDataCopier> Create(
            ILogger logger,
            WebcrmClientFactory webcrmClientFactory,
            PowerofficeClientFactory powerofficeClientFactory,
            PowerofficeConfiguration configuration)
        {
            var powerofficeClient = await powerofficeClientFactory.Create(configuration.PowerofficeClientKey);

            var webcrmClient = await webcrmClientFactory.Create(configuration.WebcrmApiKey);

            return(new PowerofficeDataCopier(logger, configuration, powerofficeClient, webcrmClient));
        }
        public async Task EnqueueUpsertedItemsForOneSystem(
            DateTime upsertedAfterUtc,
            PowerofficeConfiguration configuration)
        {
            Logger.LogTrace($"Finding items in PowerOffice upserted after {upsertedAfterUtc:O}.");

            var powerofficeClient = await PowerofficeClientFactory.Create(configuration.PowerofficeClientKey);

            await EnqueueUpsertedOrganisations(upsertedAfterUtc, powerofficeClient, configuration.WebcrmSystemId);
            await EnqueueUpsertedPersons(upsertedAfterUtc, powerofficeClient, configuration.WebcrmSystemId);

            if (configuration.SynchroniseProducts)
            {
                await EnqueueUpsertedProducts(upsertedAfterUtc, powerofficeClient, configuration.WebcrmSystemId);
            }

            if (configuration.SynchroniseDeliveries == SynchroniseDeliveries.FromErp)
            {
                await EnqueueUpsertedDeliveries(upsertedAfterUtc, powerofficeClient, configuration.WebcrmSystemId);
            }
        }
Beispiel #3
0
        public async Task HandleDequeuedMessage(PowerofficeQueueMessage message)
        {
            switch (message.Action)
            {
            case PowerofficeQueueAction.UpsertPowerofficeDelivery:
            {
                var(payload, dataCopier) = await GetPayloadAndDataCopier <UpsertDeliveryToPowerofficePayload>(message);

                await dataCopier.CopyDeliveryToPoweroffice(payload.WebcrmDelivery, payload.WebcrmDeliveryLines);
            }
            break;

            case PowerofficeQueueAction.UpsertPowerofficeOrganisation:
            {
                var(payload, dataCopier) = await GetPayloadAndDataCopier <UpsertOrganisationToPowerofficePayload>(message);

                await dataCopier.CopyOrganisationToPoweroffice(payload.WebcrmOrganisation);
            }
            break;

            case PowerofficeQueueAction.UpsertPowerofficePerson:
            {
                var(payload, dataCopier) = await GetPayloadAndDataCopier <UpsertPersonToPowerofficePayload>(message);

                await dataCopier.CopyPersonToPoweroffice(payload.WebcrmPerson);
            }
            break;

            case PowerofficeQueueAction.UpsertWebcrmDelivery:
            {
                var(payload, dataCopier) = await GetPayloadAndDataCopier <UpsertDeliveryFromPowerofficePayload>(message);

                var configuration     = PowerofficeConfigService.LoadPowerofficeConfiguration(payload.WebcrmSystemId);
                var powerofficeClient = await PowerofficeClientFactory.Create(configuration.PowerofficeClientKey);

                var powerofficeDeliveryWithDeliveryLines = await powerofficeClient.GetInvoice(payload.PowerofficeDelivery.Id);

                await dataCopier.CopyDeliveryFromPoweroffice(powerofficeDeliveryWithDeliveryLines);
            }
            break;

            case PowerofficeQueueAction.UpsertWebcrmOrganisation:
            {
                var(payload, dataCopier) = await GetPayloadAndDataCopier <UpsertOrganisationFromPowerofficePayload>(message);

                await dataCopier.CopyOrganisationFromPoweroffice(payload.PowerofficeOrganisation);
            }
            break;

            case PowerofficeQueueAction.UpsertWebcrmPerson:
            {
                var(payload, dataCopier) = await GetPayloadAndDataCopier <UpsertPersonFromPowerofficePayload>(message);

                await dataCopier.CopyPersonFromPoweroffice(payload.PowerofficePerson, payload.PowerofficeOrganisationId);
            }
            break;

            case PowerofficeQueueAction.UpsertWebcrmProduct:
            {
                var(payload, dataCopier) = await GetPayloadAndDataCopier <UpsertProductFromPowerofficePayload>(message);

                await dataCopier.CopyProductFromPoweroffice(payload.PowerofficeProduct);
            }
            break;

            case PowerofficeQueueAction.Unknown:
            default:
                throw new ApplicationException($"The action '{message.Action}' is not supported.");
            }
        }