public async void RequestAnnotationSync(IAnnotationSyncTask task) { if (GlobalAccess.Instance.CurrentUserInfo == null) { return; } if (GlobalAccess.Instance.CurrentUserInfo.SyncAnnotations) { annotationSyncQueue.Enqueue(task); try { await syncLock.Enter(); if (!isSyncRunning && annotationSyncQueue.Count > 0) { //Start Queue Processor.... isSyncRunning = true; PerformSync().WithNoWarning(); } } finally { syncLock.Release(); } } }
public TOCNode GetNextTOCNode(int currentTocId, int targetTocId, TOCNode sourceTOCNode, bool isNext = true) { try { nextNodeLock.Enter().Wait(); list.Clear(); return(GetTargetTOCNode(currentTocId, targetTocId, sourceTOCNode, isNext)); } finally { list.Clear(); nextNodeLock.Release(); } }
public async void RestFullServiceRequestForFileDownloadTest() { RedLock redLock = new RedLock(1); List <Task> taskList = new List <Task>(); for (int i = 0; i < 5; i++) { taskList.Add(Task.Run(async() => { await redLock.Enter(); for (int j = 0; j < 100; j++) { await Task.Delay(1000); Console.WriteLine("count:" + j); } redLock.Release(); })); } await Task.WhenAll(taskList); Console.WriteLine("ds"); }
public async Task <DownloadResult> DownloadPublicationByBookId(int bookId, CancellationToken cancelToken , DownloadProgressEventHandler downloadHandler , bool checkNetLimitation = true) { DownloadResult downloadResult = new DownloadResult { DownloadStatus = DownLoadEnum.Failure }; DlBook localDlBook = null, serverDlBook = null; int previousDownloadVersion = 0; try { var currentUser = GlobalAccess.Instance.CurrentUserInfo; var userCredential = GlobalAccess.Instance.UserCredential; await redLock.Enter().WithCancellation(cancelToken); var pingSuccess = await connectionMonitor.PingService(currentUser.Country.CountryCode, cancelToken); if (!pingSuccess) { downloadResult.DownloadStatus = DownLoadEnum.NetDisconnected; return(downloadResult); } serverDlBook = await publicationDomainService.GetLatestDlBookDetail(userCredential, GlobalAccess.DeviceId, bookId, cancelToken); if (checkNetLimitation) { publicationDomainService.VerifyNetwork(serverDlBook.Size); } await publicationDomainService.DownLoadDlBook(serverDlBook, cancelToken, downloadHandler) .WithCancellation(cancelToken); localDlBook = publicationAccess.GetDlBookByBookId(bookId, userCredential); previousDownloadVersion = localDlBook.LastDownloadedVersion; localDlBook = await publicationDomainService.RefreshLocalDlBook(serverDlBook, localDlBook, GlobalAccess.DeviceId) .WithCancellation <DlBook>(cancelToken); if (downloadHandler != null) { downloadHandler(90, serverDlBook.Size); await publicationDomainService.InstallDlBook(localDlBook, currentUser.SymmetricKey, cancelToken); downloadResult.Publication = localDlBook.ToPublication(); await DomainEvents.Publish <DownloadCompletedEvent>(new DownloadCompletedEvent(localDlBook, RecenthistoryChanged)); bool updateSuccess = (publicationAccess.Update(localDlBook) > 0); if (updateSuccess) { downloadResult.DownloadStatus = DownLoadEnum.Success; } await ClearDownloadedFiles(localDlBook, downloadResult.DownloadStatus, previousDownloadVersion); downloadHandler(100, serverDlBook.Size); } } catch (NullUserException) { } catch (ExceedLimitationException) { downloadResult.DownloadStatus = DownLoadEnum.OverLimitation; } catch (OperationCanceledException) { if (cancelToken.IsCancellationRequested) { downloadResult.DownloadStatus = DownLoadEnum.Canceled; } } catch (CusNetDisConnectedException) { downloadResult.DownloadStatus = DownLoadEnum.NetDisconnected; } catch (Exception ex) { Logger.Log("DownloadPublicationByBookId:" + ex.ToString()); } finally { redLock.Release(); ClearDownloadedFiles(localDlBook, downloadResult.DownloadStatus, previousDownloadVersion).Wait(); } return(downloadResult); }