Beispiel #1
0
    /// <summary>
    /// Creates new settings object for export.
    /// </summary>
    private SiteExportSettings GetNewSettings()
    {
        SiteExportSettings result = new SiteExportSettings(MembershipContext.AuthenticatedUser);

        result.WebsitePath           = Server.MapPath("~/");
        result.TargetPath            = ImportExportHelper.GetSiteUtilsFolder() + "Export";
        result.PersistentSettingsKey = PersistentSettingsKey;

        return(result);
    }
    private void btnOk_Click(object sender, EventArgs e)
    {
        // Prepare the settings
        var exportSettings = new SiteExportSettings(MembershipContext.AuthenticatedUser)
        {
            WebsitePath = Server.MapPath("~/"),
            TargetPath  = GetTargetFolder()
        };

        // Initialize
        ImportExportHelper.InitSingleObjectExportSettings(exportSettings, ExportedObjectInfo);

        string result = ImportExportHelper.ValidateExportFileName(exportSettings, txtFileName.Text);

        // Filename is valid
        if (!String.IsNullOrEmpty(result))
        {
            ShowError(result);
        }
        else
        {
            string fileName = txtFileName.Text.Trim();

            // Add extension
            if (Path.GetExtension(fileName).ToLowerCSafe() != ".zip")
            {
                fileName = fileName.TrimEnd('.') + ".zip";
            }
            txtFileName.Text = fileName;

            // Set the filename
            lblResult.Text = String.Format(GetString("ExportObject.ExportProgress"), ExportedObjectDisplayName);
            exportSettings.TargetFileName = txtFileName.Text;

            pnlContent.Visible    = true;
            pnlDetails.Visible    = false;
            btnOk.Enabled         = false;
            ucActivityBar.Visible = true;

            try
            {
                // Export the data
                ScriptHelper.RegisterStartupScript(this, typeof(string), "StartTimer", "StartTimer();", true);

                ucAsyncControl.RunAsync(p => ExportSingleObject(exportSettings), WindowsIdentity.GetCurrent());
            }
            catch (Exception ex)
            {
                DisplayError(ex);
            }
        }
    }
    private void btnOk_Click(object sender, EventArgs e)
    {
        // Init the Mimetype helper (required for the export)
        MimeTypeHelper.LoadMimeTypes();

        // Prepare the settings
        ExportSettings = new SiteExportSettings(CMSContext.CurrentUser);

        ExportSettings.WebsitePath = Server.MapPath("~/");
        ExportSettings.TargetPath  = targetFolder;

        // Initialize
        ImportExportHelper.InitSingleObjectExportSettings(ExportSettings, exportObj);

        string result = ImportExportHelper.ValidateExportFileName(ExportSettings, txtFileName.Text);

        // Filename is valid
        if (!string.IsNullOrEmpty(result))
        {
            lblError.Text = result;
        }
        else
        {
            txtFileName.Text = txtFileName.Text.Trim();

            // Add extension
            if (Path.GetExtension(txtFileName.Text).ToLowerCSafe() != ".zip")
            {
                txtFileName.Text = txtFileName.Text.TrimEnd('.') + ".zip";
            }

            // Set the filename
            lblProgress.Text = string.Format(GetString("ExportObject.ExportProgress"), ResHelper.LocalizeString(exportObjectDisplayName));
            ExportSettings.TargetFileName = txtFileName.Text;

            pnlContent.Visible  = false;
            pnlDetails.Visible  = false;
            btnOk.Enabled       = false;
            pnlProgress.Visible = true;

            try
            {
                // Export the data
                ltlScript.Text = ScriptHelper.GetScript("StartTimer();");
                ucAsyncControl.RunAsync(ExportSingleObject, WindowsIdentity.GetCurrent());
            }
            catch (Exception ex)
            {
                DisplayError(ex);
            }
        }
    }
Beispiel #4
0
        static void Main(string[] args)
        {
            string packagePath     = args[0] ?? "";
            string userName        = args[1] ?? "";
            string applicationPath = args[2] ?? "";
            bool   moduleExport    = false;
            string moduleName      = "";

            if (string.IsNullOrEmpty(packagePath))
            {
                Console.Error.WriteLine("No package path provided");
                return;
            }

            if (string.IsNullOrEmpty(applicationPath))
            {
                Console.Error.WriteLine("No main application path provided");
                return;
            }

            //Initialize Kentico API for external application
            CMSApplication.Init();

            SystemContext.WebApplicationPhysicalPath = applicationPath;

            ImportModule(packagePath, userName);

            ImportObject(packagePath, userName);

            string objectType = "";
            int    objectID   = 0;

            SiteExportSettings siteExportSettings = new SiteExportSettings(UserInfoProvider.GetUserInfo(userName))
            {
                WebsitePath        = SystemContext.WebApplicationPhysicalPath,
                TargetPath         = packagePath + "Export",
                CreatePackage      = true,
                TargetFileName     = $"ExportPackage_{DateTime.Now.ToString()}",
                TemporaryFilesPath = "/path",
            };
            //switch on one object vs global object selection
            var selectedObjects = ObjectSelections(objectType);

            if (objectID > 0)
            {
                var singleObject = SingleObjectSelection(objectID, selectedObjects);
                siteExportSettings.Select(singleObject.TypeInfo.ObjectType, singleObject.TypeInfo.ObjectClassName, singleObject.TypeInfo.IsSiteObject);
            }

            if (moduleExport)
            {
                siteExportSettings.SetInfo(ImportExportHelper.MODULE_NAME, moduleName);
            }

            siteExportSettings.Select(selectedObjects.TypeInfo.ObjectType, selectedObjects.TypeInfo.ObjectClassName, selectedObjects.TypeInfo.IsSiteObject);

            //Preset for global object selection
            siteExportSettings.SelectGlobalObjects(new List <string>(), "");

            // Make sure no data is in temp folder (possibly from previous unsuccessful export)
            ExportProvider.DeleteTemporaryFiles(siteExportSettings, true);
            ExportManager exportManager = new ExportManager(siteExportSettings);

            exportManager.Export(null);

            //Cleanup
            ExportProvider.DeleteTemporaryFiles(siteExportSettings, true);

            return;
        }
Beispiel #5
0
    public bool ApplySettings()
    {
        txtFileName.Text = txtFileName.Text.Trim();

        // Validate the file name
        string result = ImportExportHelper.ValidateExportFileName(Settings, txtFileName.Text);

        if (string.IsNullOrEmpty(result))
        {
            if (Path.GetExtension(txtFileName.Text).ToLower() != ".zip")
            {
                txtFileName.Text = txtFileName.Text.TrimEnd('.') + ".zip";
            }

            // Set current user information
            Settings.CurrentUser = CMSContext.CurrentUser;

            Settings.SiteId = SiteId;
            Settings.DefaultProcessObjectType = ProcessObjectEnum.Selected;

            // Additional setings
            Settings.SetSettings(ImportExportHelper.SETTINGS_BIZFORM_DATA, true);
            Settings.SetSettings(ImportExportHelper.SETTINGS_CUSTOMTABLE_DATA, true);
            Settings.SetSettings(ImportExportHelper.SETTINGS_FORUM_POSTS, true);
            Settings.SetSettings(ImportExportHelper.SETTINGS_BOARD_MESSAGES, true);
            Settings.SetSettings(ImportExportHelper.SETTINGS_GLOBAL_FOLDERS, true);
            Settings.SetSettings(ImportExportHelper.SETTINGS_SITE_FOLDERS, true);
            Settings.SetSettings(ImportExportHelper.SETTINGS_COPY_ASPX_TEMPLATES_FOLDER, true);

            ExportTypeEnum exportType = (SiteId != 0) ? ExportTypeEnum.Site : ExportTypeEnum.All;

            // Init default values
            if (radNone.Checked)
            {
                // None objects
                Settings.TimeStamp  = DateTimeHelper.ZERO_TIME;
                Settings.ExportType = ExportTypeEnum.None;
            }
            else if (radAll.Checked)
            {
                // All objects
                Settings.TimeStamp  = DateTimeHelper.ZERO_TIME;
                Settings.ExportType = exportType;
            }
            else if (radDate.Checked)
            {
                if (dtDate.SelectedDateTime != DateTimeHelper.ZERO_TIME)
                {
                    if (!dtDate.IsValidRange())
                    {
                        lblError.Text = GetString("general.errorinvaliddatetimerange");
                        return(false);
                    }
                    else
                    {
                        // From specified date
                        Settings.TimeStamp  = dtDate.SelectedDateTime;
                        Settings.ExportType = exportType;
                    }
                }
                else
                {
                    lblError.Text = GetString("ExportSite.SelectDateTime");
                    return(false);
                }
            }
            else
            {
                // From previous export
                int historyId = ValidationHelper.GetInteger(lstExports.SelectedValue, 0);
                if (historyId == 0)
                {
                    lblError.Text = GetString("ExportSite.SelectExportHistory");
                    return(false);
                }
                else
                {
                    ExportHistoryInfo history = ExportHistoryInfoProvider.GetExportHistoryInfo(historyId);
                    if (history != null)
                    {
                        // Load history settings
                        SiteExportSettings settings = new SiteExportSettings(CMSContext.CurrentUser);
                        settings.SetInfo(ImportExportHelper.INFO_HISTORY_NAME, history.ExportFileName);
                        settings.SetInfo(ImportExportHelper.INFO_HISTORY_DATE, history.ExportDateTime);
                        settings.LoadFromXML(history.ExportSettings);
                        settings.TargetPath            = Settings.TargetPath;
                        settings.PersistentSettingsKey = Settings.PersistentSettingsKey;
                        Settings      = settings;
                        ExportHistory = true;
                    }
                    else
                    {
                        lblError.Text = GetString("ExportSite.ErrorLoadingExportHistory");
                        return(false);
                    }
                }
            }

            // Keep current file name
            Settings.TargetFileName = txtFileName.Text;
        }
        else
        {
            lblError.Text = result;
            return(false);
        }

        return(true);
    }
    public bool ApplySettings()
    {
        txtFileName.Text = txtFileName.Text.Trim();

        // Validate the file name
        string result = ImportExportHelper.ValidateExportFileName(Settings, txtFileName.Text);

        if (string.IsNullOrEmpty(result))
        {
            if (Path.GetExtension(txtFileName.Text).ToLower() != ".zip")
            {
                txtFileName.Text = txtFileName.Text.TrimEnd('.') + ".zip";
            }

            // Set current user information
            Settings.CurrentUser = CMSContext.CurrentUser;

            Settings.SiteId = SiteId;
            Settings.DefaultProcessObjectType = ProcessObjectEnum.Selected;

            // Additional setings
            Settings.SetSettings(ImportExportHelper.SETTINGS_BIZFORM_DATA, true);
            Settings.SetSettings(ImportExportHelper.SETTINGS_CUSTOMTABLE_DATA, true);
            Settings.SetSettings(ImportExportHelper.SETTINGS_FORUM_POSTS, true);
            Settings.SetSettings(ImportExportHelper.SETTINGS_BOARD_MESSAGES, true);
            Settings.SetSettings(ImportExportHelper.SETTINGS_GLOBAL_FOLDERS, true);
            Settings.SetSettings(ImportExportHelper.SETTINGS_SITE_FOLDERS, true);
            Settings.SetSettings(ImportExportHelper.SETTINGS_COPY_ASPX_TEMPLATES_FOLDER, true);

            ExportTypeEnum exportType = (SiteId != 0) ? ExportTypeEnum.Site : ExportTypeEnum.All;

            // Init default values
            if (radNone.Checked)
            {
                // None objects
                Settings.TimeStamp = DateTimeHelper.ZERO_TIME;
                Settings.ExportType = ExportTypeEnum.None;
            }
            else if (radAll.Checked)
            {
                // All objects
                Settings.TimeStamp = DateTimeHelper.ZERO_TIME;
                Settings.ExportType = exportType;
            }
            else if (radDate.Checked)
            {
                if (dtDate.SelectedDateTime != DateTimeHelper.ZERO_TIME)
                {
                    if (!dtDate.IsValidRange())
                    {
                        lblError.Text = GetString("general.errorinvaliddatetimerange");
                        return false;
                    }
                    else
                    {
                        // From specified date
                        Settings.TimeStamp = dtDate.SelectedDateTime;
                        Settings.ExportType = exportType;
                    }
                }
                else
                {
                    lblError.Text = GetString("ExportSite.SelectDateTime");
                    return false;
                }
            }
            else
            {
                // From previous export
                int historyId = ValidationHelper.GetInteger(lstExports.SelectedValue, 0);
                if (historyId == 0)
                {
                    lblError.Text = GetString("ExportSite.SelectExportHistory");
                    return false;
                }
                else
                {
                    ExportHistoryInfo history = ExportHistoryInfoProvider.GetExportHistoryInfo(historyId);
                    if (history != null)
                    {
                        // Load history settings
                        SiteExportSettings settings = new SiteExportSettings(CMSContext.CurrentUser);
                        settings.SetInfo(ImportExportHelper.INFO_HISTORY_NAME, history.ExportFileName);
                        settings.SetInfo(ImportExportHelper.INFO_HISTORY_DATE, history.ExportDateTime);
                        settings.LoadFromXML(history.ExportSettings);
                        settings.TargetPath = Settings.TargetPath;
                        settings.PersistentSettingsKey = Settings.PersistentSettingsKey;
                        Settings = settings;
                        ExportHistory = true;
                    }
                    else
                    {
                        lblError.Text = GetString("ExportSite.ErrorLoadingExportHistory");
                        return false;
                    }
                }
            }

            // Keep current file name
            Settings.TargetFileName = txtFileName.Text;
        }
        else
        {
            lblError.Text = result;
            return false;
        }

        return true;
    }
    /// <summary>
    /// Creates new settings object for export.
    /// </summary>
    private SiteExportSettings GetNewSettings()
    {
        SiteExportSettings result = new SiteExportSettings(CMSContext.CurrentUser);

        result.WebsitePath = Server.MapPath("~/");
        result.TargetPath = ImportExportHelper.GetSiteUtilsFolder() + "Export";
        result.PersistentSettingsKey = PersistentSettingsKey;

        return result;
    }
    private void btnOk_Click(object sender, EventArgs e)
    {
        // Init the Mimetype helper (required for the export)
        MimeTypeHelper.LoadMimeTypes();

        // Prepare the settings
        var exportSettings = new SiteExportSettings(MembershipContext.AuthenticatedUser)
        {
            WebsitePath = Server.MapPath("~/"),
            TargetPath = GetTargetFolder()
        };

        // Initialize
        ImportExportHelper.InitSingleObjectExportSettings(exportSettings, ExportedObjectInfo);

        string result = ImportExportHelper.ValidateExportFileName(exportSettings, txtFileName.Text);

        // Filename is valid
        if (!String.IsNullOrEmpty(result))
        {
            ShowError(result);
        }
        else
        {
            string fileName = txtFileName.Text.Trim();

            // Add extension
            if (Path.GetExtension(fileName).ToLowerCSafe() != ".zip")
            {
                fileName = fileName.TrimEnd('.') + ".zip";
            }
            txtFileName.Text = fileName;

            // Set the filename
            lblResult.Text = String.Format(GetString("ExportObject.ExportProgress"), ExportedObjectDisplayName);
            exportSettings.TargetFileName = txtFileName.Text;

            pnlContent.Visible = true;
            pnlDetails.Visible = false;
            btnOk.Enabled = false;
            ucActivityBar.Visible = true;

            try
            {
                // Export the data
                ScriptHelper.RegisterStartupScript(this, typeof(string), "StartTimer", "StartTimer();", true);
                ucAsyncControl.Parameter = exportSettings;
                ucAsyncControl.RunAsync(ExportSingleObject, WindowsIdentity.GetCurrent());
            }
            catch (Exception ex)
            {
                DisplayError(ex);
            }
        }
    }
    void btnOk_Click(object sender, EventArgs e)
    {
        // Init the Mimetype helper (required for the export)
        MimeTypeHelper.LoadMimeTypes();

        // Prepare the settings
        ExportSettings = new SiteExportSettings(CMSContext.CurrentUser);

        ExportSettings.WebsitePath = Server.MapPath("~/");
        ExportSettings.TargetPath = targetFolder;

        // Initialiye
        ImportExportHelper.InitSingleObjectExportSettings(ExportSettings, exportObj);

        string result = ImportExportHelper.ValidateExportFileName(ExportSettings, txtFileName.Text);

        // Filename is valid
        if (!string.IsNullOrEmpty(result))
        {
            lblError.Text = result;
        }
        else
        {
            txtFileName.Text = txtFileName.Text.Trim();

            // Add extension
            if (Path.GetExtension(txtFileName.Text).ToLower() != ".zip")
            {
                txtFileName.Text = txtFileName.Text.TrimEnd('.') + ".zip";
            }

            // Set the filename
            lblProgress.Text = string.Format(GetString("ExportObject.ExportProgress"), ResHelper.LocalizeString(exportObjectDisplayName));
            ExportSettings.TargetFileName = txtFileName.Text;

            pnlContent.Visible = false;
            pnlDetails.Visible = false;
            btnOk.Enabled = false;
            pnlProgress.Visible = true;

            try
            {
                // Export the data
                ltlScript.Text = ScriptHelper.GetScript("StartTimer();");
                ucAsyncControl.RunAsync(ExportSingleObject, WindowsIdentity.GetCurrent());
            }
            catch (Exception ex)
            {
                DisplayError(ex);
            }
        }
    }