public static async Task CopyFromPoweroffice( // Trigger every six minutes. [TimerTrigger("30 */6 * * * *")] TimerInfo timer, ILogger logger) { try { var configService = await PowerofficeConfigService.Create(TypedEnvironment.DatabaseCredentials); var powerofficeClientFactory = new PowerofficeClientFactory(TypedEnvironment.PowerofficeApiSettings); var powerofficeQueueFactory = new PowerofficeQueueFactory(logger, TypedEnvironment.AzureWebJobsStorage); var powerofficeChangeTracker = await PowerofficeChangeTracker.Create(logger, powerofficeClientFactory, powerofficeQueueFactory); var configurations = configService.LoadEnabledPowerofficeConfigurations(); foreach (var configuration in configurations) { var dateTimeBeforeSync = DateTime.UtcNow; await powerofficeChangeTracker.EnqueueUpsertedItemsForOneSystem(configuration.LastSuccessfulCopyFromErpHeartbeat, configuration); await configService.UpdateLastSuccessfulCopyFromErpHeartbeat(configuration.WebcrmSystemId, dateTimeBeforeSync); } } catch (SwaggerException ex) { SwaggerExceptionLogger.Log(ex); } }
protected BaseTester(ITestOutputHelper output) { OutputLogger = new XunitLogger(output); TestPowerofficeClientFactory = new PowerofficeClientFactory(TestTypedEnvironment.PowerofficeApiSettings); TestPowerofficeQueueFactory = new PowerofficeQueueFactory(OutputLogger, TestTypedEnvironment.AzureWebJobsStorage); TestWebcrmClientFactory = new WebcrmClientFactory(OutputLogger, TestTypedEnvironment.WebcrmApiBaseUrl); }
public static async Task <PowerofficeChangeTracker> Create( ILogger logger, PowerofficeClientFactory powerofficeClientFactory, PowerofficeQueueFactory powerofficeQueueFactory) { var powerofficeQueue = await powerofficeQueueFactory.Create(); return(new PowerofficeChangeTracker(logger, powerofficeClientFactory, powerofficeQueue)); }
private PowerofficeChangeTracker( ILogger logger, PowerofficeClientFactory powerofficeClientFactory, PowerofficeQueue powerofficeQueue) { Logger = logger; PowerofficeClientFactory = powerofficeClientFactory; PowerofficeQueue = powerofficeQueue; }
public static async Task <PowerofficeChangeTracker> Create( ILogger logger, string storageAccountConnectionString, PowerofficeClientFactory powerofficeClientFactory) { var powerofficeQueue = await PowerofficeQueue.Create(logger, storageAccountConnectionString); return(new PowerofficeChangeTracker(logger, powerofficeClientFactory, powerofficeQueue)); }
public static async Task <PowerofficeMessageDispatcher> Create( ILogger logger, WebcrmClientFactory webcrmClientFactory, DatabaseCredentials databaseCredentials, PowerofficeClientFactory powerofficeClientFactory) { var powerofficeConfigService = await PowerofficeConfigService.Create(databaseCredentials); return(new PowerofficeMessageDispatcher(logger, webcrmClientFactory, powerofficeClientFactory, powerofficeConfigService)); }
private PowerofficeMessageDispatcher( ILogger logger, WebcrmClientFactory webcrmClientFactory, PowerofficeClientFactory powerofficeClientFactory, PowerofficeConfigService powerofficeConfigService) { Logger = logger; WebcrmClientFactory = webcrmClientFactory; PowerofficeClientFactory = powerofficeClientFactory; PowerofficeConfigService = powerofficeConfigService; }
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 static async Task Run( [QueueTrigger(Constants.PowerofficeQueueName)] string queueItem, ILogger logger) { logger.LogTrace($"Dequeuing message from the '{Constants.PowerofficeQueueName}' queue."); try { var webcrmClientFactory = new WebcrmClientFactory(logger, TypedEnvironment.WebcrmApiBaseUrl); var powerofficeClientFactory = new PowerofficeClientFactory(TypedEnvironment.PowerofficeApiSettings); var dispatcher = await PowerofficeMessageDispatcher.Create(logger, webcrmClientFactory, TypedEnvironment.DatabaseCredentials, powerofficeClientFactory); var message = JsonConvert.DeserializeObject <PowerofficeQueueMessage>(queueItem); await dispatcher.HandleDequeuedMessage(message); } catch (SwaggerException ex) { SwaggerExceptionLogger.Log(ex); } }
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); } }
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."); } }