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; }
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); }