public async Task PerformAction(AnnotationTaskContext context) { if (context.AnnotationSyncTask.BookIds == null || !context.AnnotationSyncTask.BookIds.Any()) { throw new InvalidOperationException("Book Id Shouldn't be empty."); } DownwardSyncRequests bookSpecificDownwardSyncRequest = new DownwardSyncRequests { DownwardSyncRequest = new List <DownwardSyncRequest>() }; foreach (var bookId in context.AnnotationSyncTask.BookIds) { bookSpecificDownwardSyncRequest.DownwardSyncRequest.Add(new DownwardSyncRequest { UserID = context.AnnotationSyncTask.Email, DLID = bookId, DLVersionID = context.AnnotationSyncTask.CurrentVersion[bookId], DeviceID = context.AnnotationSyncTask.DeviceId }); } await CleanTempFiles(context); await context.SyncService.DownwardSyncRequest(bookSpecificDownwardSyncRequest, context.AnnotationDownloadFile); await IoCContainer.Instance.ResolveInterface <IPackageFile>().DepressFile(context.AnnotationDownloadFile, context.AnnotationDownloadTempFolder, default(CancellationToken)); foreach (var bookId in context.AnnotationSyncTask.BookIds) { string targetDirectory = Path.Combine(context.AnnotationDownloadTempFolder, bookId.ToString()); if (!await GlobalAccess.DirectoryService.DirectoryExists(targetDirectory)) { await GlobalAccess.DirectoryService.CreateDirectory(targetDirectory); } string sourceFile = Path.Combine(context.AnnotationDownloadTempFolder, string.Format("DL_{0}.zip", bookId)); await IoCContainer.Instance.ResolveInterface <IPackageFile>().DepressFile(sourceFile, targetDirectory, default(CancellationToken)); if (await GlobalAccess.DirectoryService.FileExists(Path.Combine(targetDirectory, Constants.EmptyStreamXml))) { continue; } foreach (var fileName in await GlobalAccess.DirectoryService.GetFiles(targetDirectory)) { if (fileName.EndsWith(Constants.SDeletedAnnotationsXml)) //if the annotation had been deleted then delete from local { await DeleteAnnotation(context, fileName); } else if (!fileName.EndsWith(Constants.SRequestxml) && !fileName.EndsWith(Constants.SErrorxml)) //if it is in the request file, then merge with local file. { await MergeAnnotation(context, fileName, bookId); } } } await CleanTempFiles(context); }
public async Task <bool> DownwardSyncRequest(DownwardSyncRequests downwardSyncRequest, string fileName) { return(await ServiceAgent.RestFullServiceRequestForAnnDownwardSync(base.GetTargetUri(), ServiceConfig.AnnDownwardSyncV2, fileName, downwardSyncRequest)); }