Пример #1
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);
        }
Пример #2
0
        public ExportOperationResult RunExport()
        {
            if (traceSwitch.TraceVerbose)
            {
                trace.TraceVerbose("runExportTask: Entered runExportTask().");
            }

            ExportOperationResult exportResult;

            // set change token to use if incremental export selected..
            if (ExportSettings.ExportMethod == SPExportMethodType.ExportChanges)
            {
                // first check if we are exporting any site/web objects..
                if (!hasSiteOrWebObject(ExportSettings.ExportObjects))
                {
                    // raise event here if we didn't find a site or web being exported..
                    if (ValidChangeTokenNotFound != null)
                    {
                        ValidChangeTokenNotFound(this, new InvalidChangeTokenEventArgs
                        {
                            EventMessage = WizardDeployment.InvalidObjectsForIncrementalDeploymentMessage
                        });
                    }
                }
                else
                {
                    string lastToken = IncrementalManager.GetLastToken(ExportSettings);
                    if (!string.IsNullOrEmpty(lastToken))
                    {
                        if (traceSwitch.TraceInfo)
                        {
                            trace.TraceInfo(
                                string.Format("runExportTask: Incremental export selected, using change token '{0}'.",
                                              lastToken));
                        }

                        ExportSettings.ExportChangeToken = lastToken;
                    }
                    else
                    {
                        if (traceSwitch.TraceWarning)
                        {
                            trace.TraceWarning(
                                "runExportTask: Attempted to use incremental export selected but no valid change tokens have " +
                                "yet been stored. Defaulting to full export, *current* change token will be stored for future incremental deployments.");
                        }

                        // raise event here if we didn't find a suitable stored change token..
                        if (ValidChangeTokenNotFound != null)
                        {
                            ValidChangeTokenNotFound(this, new InvalidChangeTokenEventArgs
                            {
                                EventMessage = WizardDeployment.ChangeTokenNotFoundMessage
                            });
                        }

                        ExportSettings.ExportMethod = SPExportMethodType.ExportAll;
                    }
                }
            }

            using (SPExport export = new SPExport(ExportSettings))
            {
                export.ProgressUpdated += new EventHandler <SPDeploymentEventArgs>(export_ProgressUpdated);
                export.Completed       += new EventHandler <SPDeploymentEventArgs>(export_Completed);

                if (traceSwitch.TraceInfo)
                {
                    trace.TraceInfo("runExportTask: Wired event handlers, about to call Run()..");
                }

                try
                {
                    // initialise to default..
                    exportResult = new ExportOperationResult(ResultType.Failure);

                    export.Run();

                    if (traceSwitch.TraceInfo)
                    {
                        trace.TraceInfo("runExportTask: Export completed successfully.");
                    }

                    // this distinction is to support incremental exports in case the client cares about the token..
                    if (ExportSettings.ExportMethod == SPExportMethodType.ExportAll)
                    {
                        exportResult = new ExportOperationResult(ResultType.Success);
                    }
                    else if (ExportSettings.ExportMethod == SPExportMethodType.ExportChanges)
                    {
                        exportResult = new ExportOperationResult(ResultType.Success, ExportSettings.CurrentChangeToken);
                    }

                    IncrementalManager.SaveToken(ExportSettings.CurrentChangeToken);
                }
                catch (Exception e)
                {
                    if (traceSwitch.TraceError)
                    {
                        trace.TraceError("runExportTask: Exception caught whilst running export: '{0}'.", e);
                    }

                    throw;
                }
            }

            if (traceSwitch.TraceVerbose)
            {
                trace.TraceVerbose("runExportTask: Exiting runExportTask().");
            }

            return(exportResult);
        }