Exemplo n.º 1
0
        protected virtual async Task <ImportVehiclesShapshot> InnerImportVehiclesAsync()
        {
            string           message;
            ImportStatusEnum status;
            IEnumerable <ImportVehiclesForSiteResult> importResults;
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            try
            {
                using (var uow = UowManager.CurrentOrCreateNew(true))
                {
                    importResults = await((ISiteDomainService)DomainService).ImportVehiclesAsync();
                    await uow.CompleteAsync();
                }
                status  = ImportStatusEnum.Success;
                message = null;
            }
            catch (Exception ex)
            {
                status        = ImportStatusEnum.Failed;
                message       = ex.Message;
                importResults = null;
            }
            stopWatch.Stop();
            ImportVehiclesShapshot importSnapshot = new ImportVehiclesShapshot(
                stopWatch.Elapsed, status, message,
                importResults.Select(importResult => new ImportVehiclesForSiteResultDto(importResult)));

            // do not await this
            LogImportSnapshot(importSnapshot);
            return(importSnapshot);
        }
Exemplo n.º 2
0
        public async Task <ImportVehiclesShapshot> ImportVehiclesAsync(int siteId)
        {
            string                      message;
            ImportStatusEnum            status;
            ImportVehiclesForSiteResult importResult;
            Stopwatch                   stopWatch = new Stopwatch();

            stopWatch.Start();
            try
            {
                using (var uow = UowManager.CurrentOrCreateNew(true))
                {
                    importResult = await((ISiteDomainService)DomainService).ImportVehiclesAsync(siteId);
                    await uow.CompleteAsync();
                }
                status  = ImportStatusEnum.Success;
                message = null;
            }
            catch (Exception ex)
            {
                status       = ImportStatusEnum.Failed;
                message      = ex.Message;
                importResult = null;
            }
            stopWatch.Stop();
            ImportVehiclesShapshot importSnapshot = new ImportVehiclesShapshot(
                stopWatch.Elapsed, status, message,
                new List <ImportVehiclesForSiteResultDto>()
            {
                new ImportVehiclesForSiteResultDto(importResult)
            });

            return(importSnapshot);
        }
Exemplo n.º 3
0
        protected async Task LogImportSnapshot(ImportVehiclesShapshot snapshot)
        {
#warning stub implementation - should be reworked
            try
            {
                using (var httpClient = new HttpClient())
                {
                    await httpClient.PostAsync($"{RemoteReportingConfiguration.VehicleImportForAllSitesReportingUrl}/{JsonConvert.SerializeObject(snapshot)}", null);
                }
            }
            catch { }
        }