/// <summary>
        /// Handles the Click event of the btnExportData control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void btnExportData_Click(object sender, EventArgs e)
        {
            string backupFilename = "GalleryServerBackup_" + DateTime.Now.ToString("yyyy-MM-dd_HHmmss", CultureInfo.InvariantCulture);

            IBackupFile bak = new BackupFile();

            bak.IncludeMembershipData = chkExportMembership.Checked;
            bak.IncludeGalleryData = chkExportGalleryData.Checked;

            var galleryData = bak.Create();

            IMimeType mimeType = Factory.LoadMimeType("dummy.zip");

            int bufferSize = AppSetting.Instance.MediaObjectDownloadBufferSize;
            byte[] buffer = new byte[bufferSize];

            Stream stream = null;
            try
            {
                // Create an in-memory ZIP file.
                stream = ZipUtility.CreateZipStream(galleryData, backupFilename + ".xml");

                // Send to user.
                Response.AddHeader("Content-Disposition", "attachment; filename=" + backupFilename + ".zip");

                Response.Clear();
                Response.ContentType = (mimeType != null ? mimeType.FullType : "application/octet-stream");
                Response.Buffer = false;

                stream.Position = 0;
                int byteCount;
                while ((byteCount = stream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    if (Response.IsClientConnected)
                    {
                        Response.OutputStream.Write(buffer, 0, byteCount);
                        Response.Flush();
                    }
                    else
                    {
                        return;
                    }
                }
            }
            finally
            {
                if (stream != null)
                    stream.Close();

                Response.End();
            }
        }
Beispiel #2
0
		protected void Upload1_Uploaded(object sender, UploadUploadedEventArgs e)
		{
			//string[] importOptions = Upload1.CallbackParameter.Split(new char[] { '|' });
			//bool importMembership = Convert.ToBoolean(importOptions[0]);
			//bool importGalleryData = Convert.ToBoolean(importOptions[1]);

			DeletePreviouslyUploadedFile();

			string filePath = SaveFileToTempDirectory(e.UploadedFiles[0]);

			IBackupFile backupFile = new BackupFile(filePath);
			ValidateRestoreFile(backupFile);

			ConfigureBackupFileInfo(backupFile);

			if (!backupFile.IsValid)
				File.Delete(filePath);
		}
        protected void uploadButton_Click(object sender, EventArgs e)
        {
            DeletePreviouslyUploadedFile();
            FileUpload uploadedFile = (FileUpload)phUpload.FindControl("fuUpload1");
            string filePath = SaveFileToTempDirectory(uploadedFile);

            IBackupFile backupFile = new BackupFile(filePath);
            ValidateRestoreFile(backupFile);

            ConfigureBackupFileInfo(backupFile);

            if (!backupFile.IsValid)
                File.Delete(filePath);
        }
        /// <summary>
        /// Handles the Click event of the btnRestore control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void btnRestore_Click(object sender, EventArgs e)
        {
            string filePath = ViewState["FilePath"].ToString();
            Page.MaintainScrollPositionOnPostBack = false;

            try
            {
                if (File.Exists(filePath))
                {
                    IBackupFile bak = new BackupFile(filePath);

                    bak.IncludeMembershipData = chkImportMembership.Checked;
                    bak.IncludeGalleryData = chkImportGalleryData.Checked;

                    bak.Import();
                    UserController.LogOffUser();

                    ClientMessage = new ClientMessageOptions
                                                        {
                                                            Title = "Restore Complete",
                                                            Message = Resources.GalleryServerPro.Admin_Backup_Restore_Db_Successfully_Restored_Msg,
                                                            Style = MessageStyle.Success,
                                                            AutoCloseDelay = 0
                                                        };
                }
                else
                {
                    ClientMessage = new ClientMessageOptions
                                                        {
                                                            Title = "Restore Aborted",
                                                            Message = Resources.GalleryServerPro.Admin_Backup_Restore_Cannot_Restore_File_File_Not_Found_Msg,
                                                            Style = MessageStyle.Error
                                                        };
                }
            }
            catch (Exception ex)
            {
                LogError(ex);
                ClientMessage = new ClientMessageOptions
                                                    {
                                                        Title = "Restore Aborted",
                                                        Message = String.Concat(Resources.GalleryServerPro.Admin_Backup_Restore_Cannot_Restore_File_Label, ex.Message),
                                                        Style = MessageStyle.Error
                                                    };
            }
            finally
            {
                DeletePreviouslyUploadedFile();

                ConfigureBackupFileInfo(null);

                HelperFunctions.PurgeCache();

                bool adviseUserToManuallyRestartApp = false;
                try
                {
                    // Recycle the app to force the providers to re-initialize. This will query the application ID from the database, which
                    // may have changed during the restore. If any errors occur, advise the user to manually restart the app.
                    Utils.ForceAppRecycle();
                }
                catch (IOException) { adviseUserToManuallyRestartApp = true; }
                catch (UnauthorizedAccessException) { adviseUserToManuallyRestartApp = true; }
                catch (PlatformNotSupportedException) { adviseUserToManuallyRestartApp = true; }

                if (adviseUserToManuallyRestartApp)
                {
                    ClientMessage = new ClientMessageOptions
                                                        {
                                                            Title = "Restore Complete",
                                                            Message = Resources.GalleryServerPro.Admin_Backup_Restore_Db_Successfully_Restored_AppNotRecycled_Msg,
                                                            Style = MessageStyle.Info
                                                        };
                }
            }
        }
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            DeletePreviouslyUploadedFile();
            string filePath = SaveFileToTempDirectory(fuRestoreFile);

            IBackupFile backupFile = new BackupFile(filePath);
            ValidateRestoreFile(backupFile);

            ConfigureBackupFileInfo(backupFile);

            if (!backupFile.IsValid && File.Exists(filePath))
                File.Delete(filePath);
        }