private string runImportTask(WizardDeployment wizardDeployment)
        {
            if (traceSwitch.TraceVerbose)
            {
                trace.TraceVerbose("runImportTask: Entered.");
            }

            string sResult = string.Empty;
            ImportOperationResult importResult = null;

            Console.WriteLine("Running import..");

            try
            {
                importResult = wizardDeployment.RunImport();
            }
            catch (Exception e)
            {
                if (traceSwitch.TraceError)
                {
                    trace.TraceError("runImportTask: Exception caught whilst running import: '{0}'.", e);
                }

                sResult = string.Format("An unexpected exception occurred whilst preparing and running the import. " +
                                        "\n\nException details: \n\n{0}\n\n", importResult.Message);
            }

            if (importResult.Outcome == ResultType.Success)
            {
                sResult = string.Format("Completed import of file '{0}'. Please see log file at '{1}' to check results.",
                                        wizardDeployment.ImportSettings.BaseFileName, wizardDeployment.ImportSettings.LogFilePath);
            }
            else if (importResult.Outcome == ResultType.Failure)
            {
                sResult = string.Format("An error occurred whilst running the import. " +
                                        "\n\nException details: \n\n{0}", importResult.Message);
            }

            if (traceSwitch.TraceVerbose)
            {
                trace.TraceVerbose("runImportTask: Returning '{0}'.", sResult);
            }

            return(sResult);
        }
Example #2
0
        public static WizardOperationSettings CollectSettings(XmlTextReader xReader)
        {
            WizardOperationSettings settings = null;

            while (xReader.Read())
            {
                if (xReader.Name == "ImportSettings")
                {
                    settings = WizardDeployment.CollectImportSettings(xReader);
                }
                if (xReader.Name == "ExportSettings")
                {
                    settings = WizardDeployment.CollectExportSettings(xReader);
                }
            }

            return(settings);
        }
        private string runExportTask(WizardDeployment wizardDeployment)
        {
            if (traceSwitch.TraceVerbose)
            {
                trace.TraceVerbose("runExportTask: Entered.");
            }

            ExportOperationResult exportResult;
            string sResult = string.Empty;

            Console.WriteLine("Running export..");

            try
            {
                exportResult = wizardDeployment.RunExport();

                if (traceSwitch.TraceInfo)
                {
                    string sMessage = (wizardDeployment.ExportSettings.ExportMethod == SPExportMethodType.ExportChanges) ?
                                      string.Format("Incremental export completed successfully, change token is '{0}'.", exportResult.ChangeToken) :
                                      "Full export completed successfully";
                    trace.TraceInfo("runExportTask: {0}.", sMessage);
                }

                sResult = string.Format("Completed export of file '{0}'. Please see log file at '{1}' to check results.",
                                        wizardDeployment.ExportSettings.BaseFileName, wizardDeployment.ExportSettings.LogFilePath);
            }
            catch (Exception e)
            {
                if (traceSwitch.TraceError)
                {
                    trace.TraceError("runExportTask: Exception caught whilst running export: '{0}'.", e);
                }

                sResult = ExceptionHelper.HandleDeploymentExportException(e, false);
            }

            if (traceSwitch.TraceVerbose)
            {
                trace.TraceVerbose("runExportTask: Returning '{0}'.", sResult);
            }

            return(sResult);
        }
        private string validateSettings(StringDictionary keyValues, DeploymentType deploymentType)
        {
            string sMessage = null;

            string sSettingsFilePath = keyValues[f_csSETTINGS_FILE_PARAM];

            if (string.IsNullOrEmpty(sSettingsFilePath))
            {
                sMessage = "Error - no settings file was specifed! You must specify the path to an XML settings file " +
                           "in the 'settingsFile' parameter. This file should be generated by saving import or export " +
                           "settings in the Content Deployment Wizard";
            }

            if (!File.Exists(sSettingsFilePath))
            {
                sMessage = string.Format("Error - unable to find settings file at path '{0}'!", sSettingsFilePath);
            }

            using (XmlTextReader xReader = new XmlTextReader(sSettingsFilePath))
            {
                WizardOperationSettings settings = WizardDeployment.CollectSettings(xReader);
                if (settings is WizardExportSettings && deploymentType == DeploymentType.Import)
                {
                    sMessage = string.Format("Error - settings file '{0}' contains export settings but you selected the RunWizardImport " +
                                             "command!", sSettingsFilePath);
                }

                if (settings is WizardImportSettings && deploymentType == DeploymentType.Export)
                {
                    sMessage = string.Format("Error - settings file '{0}' contains import settings but you selected the RunWizardExport " +
                                             "command!", sSettingsFilePath);
                }
            }

            return(sMessage);
        }
Example #5
0
        public int Run(string command, StringDictionary keyValues, out string output)
        {
            if (traceSwitch.TraceVerbose)
            {
                trace.TraceVerbose("Run(): Entered.");
            }

#if DEBUG
            // comment back in to debug..
            //Console.WriteLine("Attach debugger and/or press enter to continue..");
            //Console.ReadLine();
#endif

            int iReturn = 0;
            string sResult = string.Empty;
            DeploymentType deploymentType;
            WizardDeployment wizardDeployment = null;

            // determine command type..
            switch (command)
            {
                case f_csIMPORT_COMMAND:
                    deploymentType = DeploymentType.Import;
                    break;
                case f_csEXPORT_COMMAND:
                    deploymentType = DeploymentType.Export;
                    break;
                default:
                    throw new ConfigurationErrorsException("Error - unexpected command! Supported commands are 'RunWizardImport' and 'RunWizardExport'.");
                    break;
            }

            // validate passed settings..
            string sValidationMessage = validateSettings(keyValues, deploymentType);

            if (string.IsNullOrEmpty(sValidationMessage))
            {
                string sSettingsFilePath = keyValues[f_csSETTINGS_FILE_PARAM];
                if (keyValues[f_csQUIET_PARAM] != null)
                {
                    f_quiet = true;
                }
                
                using (XmlTextReader xReader = new XmlTextReader(sSettingsFilePath))
                {
                    wizardDeployment = new WizardDeployment(xReader, deploymentType);
                 
                    // ask deployment API to validate settings..
                    try
                    {
                        wizardDeployment.ValidateSettings();
                        if (traceSwitch.TraceInfo)
                        {
                            trace.TraceInfo("Run(): Settings validated successfully.");
                        }
                    }
                    catch (Exception e)
                    {
                        if (traceSwitch.TraceWarning)
                        {
                            trace.TraceWarning("Run(): Failed to validate deployment settings! Deployment will not be done, showing error message.");
                        }

                        sResult = string.Format("Error - unable to validate the deployment settings you chose. Please ensure, for example, you are not exporting a web " +
                            "and specific child objects in the same operation. Message = '{0}'.", e.Message);
                    }

                    if (string.IsNullOrEmpty(sResult))
                    {
                        // now run job..
                        wizardDeployment.ProgressUpdated += new EventHandler<SPDeploymentEventArgs>(wizardDeployment_ProgressUpdated);

                        if (deploymentType == DeploymentType.Export)
                        {
                            wizardDeployment.ValidChangeTokenNotFound += new EventHandler<InvalidChangeTokenEventArgs>(wizardDeployment_ValidChangeTokenNotFound);
                            sResult = runExportTask(wizardDeployment);
                        }
                        else if (deploymentType == DeploymentType.Import)
                        {
                            sResult = runImportTask(wizardDeployment);
                        }    
                    }
                }
            }
            else
            {
                sResult = sValidationMessage;
            }

            if (traceSwitch.TraceVerbose)
            {
                trace.TraceVerbose("Run(): Returning '{0}'.", iReturn);
            }

            output = sResult;
            return iReturn;
        }
Example #6
0
        private string runExportTask(WizardDeployment wizardDeployment)
        {
            if (traceSwitch.TraceVerbose)
            {
                trace.TraceVerbose("runExportTask: Entered.");
            }

            ExportOperationResult exportResult;
            string sResult = string.Empty;
            Console.WriteLine("Running export..");
            
            try
            {
                exportResult = wizardDeployment.RunExport();

                if (traceSwitch.TraceInfo)
                {
                    string sMessage = (wizardDeployment.ExportSettings.ExportMethod == SPExportMethodType.ExportChanges) ?
                        string.Format("Incremental export completed successfully, change token is '{0}'.", exportResult.ChangeToken) :
                        "Full export completed successfully";
                    trace.TraceInfo("runExportTask: {0}.", sMessage);
                }

                sResult = string.Format("Completed export of file '{0}'. Please see log file at '{1}' to check results.",
                    wizardDeployment.ExportSettings.BaseFileName, wizardDeployment.ExportSettings.LogFilePath);
            }
            catch (Exception e)
            {
                if (traceSwitch.TraceError)
                {
                    trace.TraceError("runExportTask: Exception caught whilst running export: '{0}'.", e);
                }

                sResult = ExceptionHelper.HandleDeploymentExportException(e, false);
            }

            if (traceSwitch.TraceVerbose)
            {
                trace.TraceVerbose("runExportTask: Returning '{0}'.", sResult);
            }

            return sResult;
        }
Example #7
0
        private string runImportTask(WizardDeployment wizardDeployment)
        {
            if (traceSwitch.TraceVerbose)
            {
                trace.TraceVerbose("runImportTask: Entered.");
            }

            string sResult = string.Empty;
            ImportOperationResult importResult = null;
            Console.WriteLine("Running import..");
            
            try
            {
                importResult = wizardDeployment.RunImport();
            }
            catch (Exception e)
            {
                if (traceSwitch.TraceError)
                {
                    trace.TraceError("runImportTask: Exception caught whilst running import: '{0}'.", e);
                }

                sResult = string.Format("An unexpected exception occurred whilst preparing and running the import. " +
                    "\n\nException details: \n\n{0}\n\n", importResult.Message);
            }

            if (importResult.Outcome == ResultType.Success)
            {
                sResult = string.Format("Completed import of file '{0}'. Please see log file at '{1}' to check results.",
                    wizardDeployment.ImportSettings.BaseFileName, wizardDeployment.ImportSettings.LogFilePath);
            }
            else if (importResult.Outcome == ResultType.Failure)
            {
                sResult = string.Format("An error occurred whilst running the import. " +
                    "\n\nException details: \n\n{0}", importResult.Message);
            }

            if (traceSwitch.TraceVerbose)
            {
                trace.TraceVerbose("runImportTask: Returning '{0}'.", sResult);
            }

            return sResult;
        }
        public int Run(string command, StringDictionary keyValues, out string output)
        {
            if (traceSwitch.TraceVerbose)
            {
                trace.TraceVerbose("Run(): Entered.");
            }

#if DEBUG
            // comment back in to debug..
            //Console.WriteLine("Attach debugger and/or press enter to continue..");
            //Console.ReadLine();
#endif

            int              iReturn = 0;
            string           sResult = string.Empty;
            DeploymentType   deploymentType;
            WizardDeployment wizardDeployment = null;

            // determine command type..
            switch (command)
            {
            case f_csIMPORT_COMMAND:
                deploymentType = DeploymentType.Import;
                break;

            case f_csEXPORT_COMMAND:
                deploymentType = DeploymentType.Export;
                break;

            default:
                throw new ConfigurationErrorsException("Error - unexpected command! Supported commands are 'RunWizardImport' and 'RunWizardExport'.");
                break;
            }

            // validate passed settings..
            string sValidationMessage = validateSettings(keyValues, deploymentType);

            if (string.IsNullOrEmpty(sValidationMessage))
            {
                string sSettingsFilePath = keyValues[f_csSETTINGS_FILE_PARAM];
                if (keyValues[f_csQUIET_PARAM] != null)
                {
                    f_quiet = true;
                }

                using (XmlTextReader xReader = new XmlTextReader(sSettingsFilePath))
                {
                    wizardDeployment = new WizardDeployment(xReader, deploymentType);

                    // ask deployment API to validate settings..
                    try
                    {
                        wizardDeployment.ValidateSettings();
                        if (traceSwitch.TraceInfo)
                        {
                            trace.TraceInfo("Run(): Settings validated successfully.");
                        }
                    }
                    catch (Exception e)
                    {
                        if (traceSwitch.TraceWarning)
                        {
                            trace.TraceWarning("Run(): Failed to validate deployment settings! Deployment will not be done, showing error message.");
                        }

                        sResult = string.Format("Error - unable to validate the deployment settings you chose. Please ensure, for example, you are not exporting a web " +
                                                "and specific child objects in the same operation. Message = '{0}'.", e.Message);
                    }

                    if (string.IsNullOrEmpty(sResult))
                    {
                        // now run job..
                        wizardDeployment.ProgressUpdated += new EventHandler <SPDeploymentEventArgs>(wizardDeployment_ProgressUpdated);

                        if (deploymentType == DeploymentType.Export)
                        {
                            wizardDeployment.ValidChangeTokenNotFound += new EventHandler <InvalidChangeTokenEventArgs>(wizardDeployment_ValidChangeTokenNotFound);
                            sResult = runExportTask(wizardDeployment);
                        }
                        else if (deploymentType == DeploymentType.Import)
                        {
                            sResult = runImportTask(wizardDeployment);
                        }
                    }
                }
            }
            else
            {
                sResult = sValidationMessage;
            }

            if (traceSwitch.TraceVerbose)
            {
                trace.TraceVerbose("Run(): Returning '{0}'.", iReturn);
            }

            output = sResult;
            return(iReturn);
        }
Example #9
0
        /// <summary>
        /// Handle step changed event of wizard control.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void wizardControl1_CurrentStepIndexChanged(object sender, EventArgs e)
        {
            switch (wizardControl1.CurrentStepIndex)
            {
                case (f_ciWELCOME_STEP_INDEX):
                    if (wizardControl1.BackButtonEnabled == false)
                    {
                        wizardControl1.BackButtonEnabled = true;
                        wizardControl1.NextButtonEnabled = true;
                    }
                    break;
                case (f_ciFINISH_STEP_INDEX):
                    btnReturnToStart.Visible = false;
                    lblExportLogFilePathValue.Enabled = false;
                    lblExportPathValue.Enabled = false;
                    lblImportPathValueFinish.Enabled = false;
                    lblImportLogFilePathValueFinish.Enabled = false;

                    if (f_action == WizardAction.Export)
                    {
                        using (MemoryStream exportMemStream = collectExportSettings())
                        {
                            exportMemStream.Position = 0;

                            // pass settings to deployment class..
                            f_wizardDeployment = new WizardDeployment(new XmlTextReader(exportMemStream),
                                                                      DeploymentType.Export);

                            displayExportSettings();
                        }
                    }
                    else if (f_action == WizardAction.Import)
                    {
                        using (MemoryStream importMemStream = collectImportSettings())
                        {
                            importMemStream.Position = 0;

                            // pass settings to deployment class..
                            f_wizardDeployment = new WizardDeployment(new XmlTextReader(importMemStream),
                                                                      DeploymentType.Import);

                            displayImportSettings();
                        }
                    }

                    break;
                case (f_ciEXPORT_SETTINGS_STEP_INDEX):
                    // need to dispose of all SPWeb references used to build TreeView..
                    f_iDisposedWebsFromMenuCount = 0;
                    f_iDisposedWebsCount = 0;
                    disposeWebs(trvContent.Nodes[0], true);
                    break;
                default:

                    break;
            }
        }