Beispiel #1
0
        public async Task <UploadFileResult> UploadFile(byte[] image, string fileName, bool isCreatePDF,
                                                        string PDFFileName, string watermarkText)
        {
            var reply = await new MyServiceClient().UploadFile(image, fileName, isCreatePDF, PDFFileName, watermarkText);

            if (!reply.IsSuccess)
            {
                Helpers.LogEvent("UploadFileFailed", new Dictionary <string, string>()
                {
                    { "Error", reply.Data },
                    { "File", fileName }
                });
                return(new UploadFileResult()
                {
                    Data = reply.Data
                });
                //throw new DataLoadException(reply.Data);
            }

            return(new UploadFileResult()
            {
                IsSuccess = true, Data = reply.Data
            });
        }
Beispiel #2
0
        public static async Task Execute(bool isQA)
        {
            var notSuccessAddresses = new List <Address>();

            if (!isQA)
            {
                var addresses = await new DbService().GetNotSyncedEntities <Address>();

                foreach (var ad in addresses)
                {
                    var addressesResult = await new DataLoaderService().SaveAddresses(new List <Address>()
                    {
                        ad
                    });

                    if (!addressesResult[0].IsSuccess)
                    {
                        notSuccessAddresses.Add(ad);
                        var pars = new Dictionary <string, string>();
                        pars.Add("UPRN", ad.UPRN);
                        pars.Add("Id", ad.Id.ToString());
                        Helpers.LogEvent("AddressSaveFail", pars);
                    }
                }


                //
                var addressStatuses = await new DbService().GetNotSyncedEntities <AddressStatus>();
                await new DataLoaderService().SaveAddressStatuses(addressStatuses.Where(x => notSuccessAddresses.All(y => y.Id != x.AddressId)).ToList());
                //
                var addressQuestionGroupStatuses = await new DbService().GetNotSyncedEntities <AddressQuestionGroupStatus>();
                await new DataLoaderService().SaveAddressQuestionGroupStatus(addressQuestionGroupStatuses.Where(x => notSuccessAddresses.All(y => y.Id != x.AddressId)).ToList());
                //

                var notSyncedSurvelems = await new DbService().GetNotSyncedEntities <Survelem>();
                var syncResult         = await new DataLoaderService().SaveSurvelems(notSyncedSurvelems.Where(x => notSuccessAddresses.All(y => string.Compare(y.UPRN, x.UPRN, StringComparison.InvariantCultureIgnoreCase) != 0)).ToList());

                var syncFailedSurvelemCount = syncResult.Count(x => !x.IsSuccess);

                Helpers.DebugMessage(string.Format("Total survelems failed: {0}-{1}", syncFailedSurvelemCount, notSyncedSurvelems.Count));



                var addressesToRemove = await new DbService().GetAddressesToRemove();

                foreach (var ad in addressesToRemove)
                {
                    await new DbService().Delete(ad);
                }

                var survelemsToRemove = await new DbService().GetSurvelemsToRemove();

                foreach (var s in survelemsToRemove)
                {
                    await new DbService().Delete(s);
                }
            }

            var medias = await new DbService().GetNotSyncedEntities <RichMedia>();

            if (!isQA)
            {
                medias = medias.Where(x => notSuccessAddresses.All(y => string.Compare(y.UPRN, x.UPRN, StringComparison.InvariantCultureIgnoreCase) != 0)).ToList();
            }


            foreach (var media in medias)
            {
                Helpers.DebugMessage(string.Format("Media: {0}-{1}", medias.IndexOf(media), medias.Count));
                await UploadMediaFile(media);
            }



            var qaaddresses = await new DbService().GetNotSyncedEntities <QAAddress>();

            await new DataLoaderService().SaveQAAddresses(qaaddresses);


            var qaaddressesComments = await new DbService().GetNotSyncedEntities <QAAddressComment>();

            await new DataLoaderService().SaveQAAddressComments(qaaddressesComments);

            ///Remove isLoadToPhoneAddresses = false

            var addressesToRemoveIsNotLoadToPhone = await new DbService().GetAddressesToRemoveIsNotLoadToPhone();

            foreach (var ad in addressesToRemoveIsNotLoadToPhone)
            {
                var survelems = await new DbService().GetSyncedSurvelemsByAddressUPRN(ad.UPRN);

                foreach (var s in survelems)
                {
                    await new DbService().Delete(s);
                }


                await new DbService().Delete(ad);
            }
            ///
        }