コード例 #1
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);
    }
コード例 #2
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;
        }
コード例 #3
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;
    }