Example #1
0
        /// <summary>
        /// Starts a synchronization on a background thread for the album specified in <paramref name="syncOptions" />.
        /// </summary>
        /// <param name="syncOptions">The synchronization options.</param>
        /// <param name="password">The password that allows remote access to the synchronization API.</param>
        private static void StartRemoteSync(SyncOptions syncOptions, string password)
        {
            IAlbum album = AlbumController.LoadAlbumInstance(syncOptions.AlbumIdToSynchronize);

            if (!ValidateRemoteSync(album, password))
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
            }

            Task.Factory.StartNew(() => GalleryController.BeginSync(syncOptions), TaskCreationOptions.LongRunning);
        }
Example #2
0
        /// <overloads>
        /// Synchronize the files in the media objects directory with the data store.
        /// </overloads>
        /// <summary>
        /// Invoke a synchronization having the specified options. It is initiated on a background thread and the current thread
        /// is immediately returned.
        /// </summary>
        /// <param name="syncOptions">An object containing settings for the synchronization.</param>
        /// <returns>An instance of <see cref="HttpResponseMessage" />.</returns>
        /// <exception cref="System.Web.Http.HttpResponseException">Thrown when the caller does not have permission to start a
        /// synchronization.</exception>
        public HttpResponseMessage StartSync(SyncOptions syncOptions)
        {
            try
            {
                #region Check user authorization

                if (!Utils.IsAuthenticated)
                {
                    var url = Utils.GetUrl(PageId.login, "ReturnUrl={0}", Utils.UrlEncode(Utils.GetCurrentPageUrl(true)));
                    throw new GallerySecurityException($"You are not logged in. <a href='{url}'>Log in</a>");
                    //throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
                }

                IAlbum album = AlbumController.LoadAlbumInstance(syncOptions.AlbumIdToSynchronize);

                if (!Utils.IsUserAuthorized(SecurityActions.Synchronize, RoleController.GetGalleryServerRolesForUser(), syncOptions.AlbumIdToSynchronize, album.GalleryId, false, album.IsVirtualAlbum))
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
                }

                #endregion

                syncOptions.SyncId   = GetSyncId();
                syncOptions.UserName = Utils.UserName;

                Task.Factory.StartNew(() => GalleryController.BeginSync(syncOptions), TaskCreationOptions.LongRunning);

                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent("Synchronization started...")
                });
            }
            catch (GallerySecurityException ex)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden)
                {
                    Content      = new StringContent(ex.Message),
                    ReasonPhrase = "Log In Required"
                });
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = Utils.GetExStringContent(ex),
                    ReasonPhrase = "Server Error"
                });
            }
        }
Example #3
0
        /// <summary>
        /// Starts a synchronization on a background thread for all galleries.
        /// </summary>
        /// <param name="syncOptions">The synchronization options.</param>
        /// <param name="password">The password that allows remote access to the synchronization API.</param>
        private static void StartRemoteSyncForAllGalleries(SyncOptions syncOptions, string password)
        {
            // User is requesting that all galleries be synchronized.
            foreach (var gallery in Factory.LoadGalleries())
            {
                var rootAlbum = Factory.LoadRootAlbumInstance(gallery.GalleryId, false);

                if (!ValidateRemoteSync(rootAlbum, password))
                {
                    continue;
                }

                var copiedSyncOptions = CopySyncOptions(syncOptions);
                copiedSyncOptions.AlbumIdToSynchronize = rootAlbum.Id;

                Task.Factory.StartNew(() => GalleryController.BeginSync(copiedSyncOptions), TaskCreationOptions.LongRunning);
            }
        }
        /// <overloads>
        /// Synchronize the files in the media objects directory with the data store.
        /// </overloads>
        /// <summary>
        /// Invoke a synchronization having the specified options. It is initiated on a background thread and the current thread
        /// is immediately returned.
        /// </summary>
        /// <param name="syncOptions">An object containing settings for the synchronization.</param>
        /// <returns>An instance of <see cref="HttpResponseMessage" />.</returns>
        /// <exception cref="System.Web.Http.HttpResponseException">Thrown when the caller does not have permission to start a
        /// synchronization.</exception>
        public HttpResponseMessage StartSync(SyncOptions syncOptions)
        {
            try
            {
                #region Check user authorization

                if (!Utils.IsAuthenticated)
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
                }

                IAlbum album = AlbumController.LoadAlbumInstance(syncOptions.AlbumIdToSynchronize, true, true, false);

                if (!Utils.IsUserAuthorized(SecurityActions.Synchronize, RoleController.GetGalleryServerRolesForUser(), syncOptions.AlbumIdToSynchronize, album.GalleryId, false, album.IsVirtualAlbum))
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
                }

                #endregion

                syncOptions.SyncId   = GetSyncId();
                syncOptions.UserName = Utils.UserName;

                Task.Factory.StartNew(() => GalleryController.BeginSync(syncOptions), TaskCreationOptions.LongRunning);

                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent("Synchronization started...")
                });
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = Utils.GetExStringContent(ex),
                    ReasonPhrase = "Server Error"
                });
            }
        }