private static void ConfigureSyncTable(int galleryId, GspContext ctx) { var syncDto = ctx.Synchronizes.Find(galleryId); if (syncDto == null) { // No sync record exists. Create one. syncDto = new SynchronizeDto { FKGalleryId = galleryId, SynchId = String.Empty, SynchState = 1, TotalFiles = 0, CurrentFileIndex = 0 }; ctx.Synchronizes.Add(syncDto); } else { // Update the existing sync record to default values. syncDto.SynchId = String.Empty; syncDto.SynchState = 1; syncDto.TotalFiles = 0; syncDto.CurrentFileIndex = 0; } ctx.SaveChanges(); }
/// <summary> /// Retrieve the most recent synchronization information from the data store. /// </summary> /// <param name="galleryId">The gallery ID.</param> /// <returns> /// Returns an <see cref="ISynchronizationStatus"/> object with the most recent synchronization information from the data store. /// </returns> private ISynchronizationStatus GetFromDataStore(int galleryId) { using (var repo = new SynchronizeRepository()) { SynchronizeDto sDto = repo.Find(galleryId); if (sDto == null) { sDto = new SynchronizeDto { FKGalleryId = galleryId, SynchId = String.Empty, SynchState = SynchronizationState.Complete, CurrentFileIndex = 0, TotalFiles = 0 }; repo.Add(sDto); repo.Save(); } return(new SynchronizationStatus(galleryId, sDto.SynchId, sDto.SynchState, sDto.TotalFiles, String.Empty, sDto.CurrentFileIndex, String.Empty)); } }
/// <summary> /// Persist the current state of this instance to the data store. /// </summary> private void Save() { lock (_lockObject) { //Factory.GetDataProvider().Synchronize_SaveStatus(this); using (var repo = new SynchronizeRepository()) { var sDto = repo.Find(GalleryId); if (sDto != null) { if ((sDto.SynchId != SynchId) && ((sDto.SynchState == SynchronizationState.SynchronizingFiles) || (sDto.SynchState == SynchronizationState.PersistingToDataStore))) { throw new Events.CustomExceptions.SynchronizationInProgressException(); } else { sDto.SynchId = SynchId; sDto.SynchState = Status; sDto.TotalFiles = TotalFileCount; sDto.CurrentFileIndex = CurrentFileIndex; } } else { sDto = new SynchronizeDto { SynchId = SynchId, FKGalleryId = GalleryId, SynchState = Status, TotalFiles = TotalFileCount, CurrentFileIndex = CurrentFileIndex }; repo.Add(sDto); } repo.Save(); } } }
/// <summary> /// Persist the synchronization information to the data store. /// </summary> /// <param name="synchStatus">An <see cref="ISynchronizationStatus"/> object containing the synchronization information /// to persist to the data store.</param> /// <exception cref="GalleryServerPro.ErrorHandler.CustomExceptions.SynchronizationInProgressException">Thrown when the data /// store indicates another synchronization is already in progress for this gallery.</exception> /// <exception cref="ArgumentNullException">Thrown when <paramref name="synchStatus" /> is null.</exception> public override void Synchronize_SaveStatus(ISynchronizationStatus synchStatus) { if (synchStatus == null) throw new ArgumentNullException("synchStatus"); using (GspContext ctx = new GspContext()) { SynchronizeDto sDto = ctx.Synchronizes.Find(synchStatus.GalleryId); if (sDto != null) { if ((sDto.SynchId != synchStatus.SynchId) && ((sDto.SynchState == (int)SynchronizationState.SynchronizingFiles) || (sDto.SynchState == (int)SynchronizationState.PersistingToDataStore))) { throw new ErrorHandler.CustomExceptions.SynchronizationInProgressException(); } else { sDto.SynchId = synchStatus.SynchId; sDto.SynchState = (int)synchStatus.Status; sDto.TotalFiles = synchStatus.TotalFileCount; sDto.CurrentFileIndex = synchStatus.CurrentFileIndex; } } else { sDto = new SynchronizeDto { SynchId = synchStatus.SynchId, FKGalleryId = synchStatus.GalleryId, SynchState = (int)synchStatus.Status, TotalFiles = synchStatus.TotalFileCount, CurrentFileIndex = synchStatus.CurrentFileIndex }; ctx.Synchronizes.Add(sDto); } ctx.SaveChanges(); } }