示例#1
0
        /// <summary>
        /// Deletes the synchronization record belonging to the current gallery. When a sync is initiated it will be created.
        /// </summary>
        private void ConfigureSyncTable()
        {
            using (var repo = new SynchronizeRepository())
            {
                var syncDto = repo.Find(GalleryId);

                if (syncDto != null)
                {
                    repo.Delete(syncDto);
                    repo.Save();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Deletes the synchronization record belonging to the current gallery, but only when it's in an invalid state.
        /// When a sync is initiated it will be created.
        /// </summary>
        private void ConfigureSyncTable()
        {
            // It is very important to preserve the sync row if the state is InterruptedByAppRecycle!
            var syncStatesToDelete = new[] { SynchronizationState.SynchronizingFiles, SynchronizationState.PersistingToDataStore };

            using (var repo = new SynchronizeRepository())
            {
                var syncDto = repo.Where(s => s.FKGalleryId == GalleryId && syncStatesToDelete.Contains(s.SynchState)).FirstOrDefault();

                if (syncDto != null)
                {
                    repo.Delete(syncDto);
                    repo.Save();
                }
            }
        }
        /// <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 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>
        /// 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);
              }
        }
示例#7
0
        /// <summary>
        /// Deletes the synchronization record belonging to the current gallery. When a sync is initiated it will be created.
        /// </summary>
        private void ConfigureSyncTable()
        {
            using (var repo = new SynchronizeRepository())
            {
                var syncDto = repo.Find(GalleryId);

                if (syncDto != null)
                {
                    repo.Delete(syncDto);
                    repo.Save();
                }
            }
        }