private void Initialize(string synchId, IAlbum album, string userName)
        {
            if (album == null)
            {
                throw new ArgumentNullException("album");
            }

            if (String.IsNullOrEmpty(userName))
            {
                throw new ArgumentNullException("userName");
            }

            if (!album.IsWritable)
            {
                throw new WebException(String.Format(CultureInfo.CurrentCulture, "The album is not writable (ID {0}, Title='{1}')", album.Id, album.Title));
            }

            UserName = userName;

            // Tell the status instance we are starting a new synchronization. It will throw
            // SynchronizationInProgressException if another is in progress.
            _synchStatus = SynchronizationStatus.Start(synchId, album.GalleryId);

            _synchStatus.Update(SynchronizationState.NotSet, CountFiles(album.FullPhysicalPathOnDisk), null, null, null, null, true);
        }
示例#2
0
            /// <summary>
            /// Retrieves a singleton object that represents the current state of a synchronization in the specified gallery. Each gallery uses the
            /// same instance, so any callers must use appropriate locking when updating the object. Guaranteed to not return null.
            /// Note that the properties are NOT updated with the latest values from the data store; to do this call
            /// <see cref="SynchronizationStatus.RefreshFromDataStore" />.
            /// </summary>
            /// <param name="galleryId">The gallery ID.</param>
            /// <returns>Returns an instance of <see cref="ISynchronizationStatus" /> that represents the current state of a
            /// synchronization in a particular gallery.</returns>
            public static ISynchronizationStatus LoadSynchronizationStatus(int galleryId)
            {
            ISynchronizationStatus syncStatus;

            lock (_sharedLock)
            {
                if (!_syncStatuses.TryGetValue(galleryId, out syncStatus))
                {
                    // There is no item matching the desired gallery ID. Create a new one and add to the dictionary.
                    syncStatus = new SynchronizationStatus(galleryId);

                    if (!_syncStatuses.ContainsKey(galleryId))
                    {
                        _syncStatuses.Add(galleryId, syncStatus);
                    }
                }
            }

            return syncStatus;
            }