示例#1
0
        public async Task Enqueue(PowerofficeQueueMessage message)
        {
            string serializedMessage = JsonConvert.SerializeObject(message);

            Logger.LogTrace($"Adding message to the PowerOffice queue. Content: {serializedMessage.Truncate(2000, addEllipsis: true)}.");
            var queueMessage = new CloudQueueMessage(serializedMessage);
            await Queue.AddMessageAsync(queueMessage);
        }
示例#2
0
 private async Task EnqueueActions(
     PowerofficeQueueAction action,
     IEnumerable <BasePowerofficePayload> payloads)
 {
     foreach (var payload in payloads)
     {
         var queueMessage = new PowerofficeQueueMessage(action, payload);
         await PowerofficeQueue.Enqueue(queueMessage);
     }
 }
示例#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.");
            }
        }