public ImportOperationResult RunImport() { if (traceSwitch.TraceVerbose) { trace.TraceVerbose("RunImport: Entered RunImport()."); } ImportOperationResult importResult; SPChangeToken startChangeToken = null; SPChangeToken endChangeToken = null; string destinationRootWebUrl = null; if (traceSwitch.TraceInfo) { trace.TraceInfo("RunImport: Initialising SPSite object with URL '{0}'.", ImportSettings.SiteUrl); } using (SPSite destinationSite = new SPSite(ImportSettings.SiteUrl)) { // Get the change token from the destination site.. startChangeToken = destinationSite.CurrentChangeToken; if (traceSwitch.TraceInfo) { trace.TraceInfo("RunImport: StartChangeToken is '{0}'.", startChangeToken.ToString()); } // Save the root Web URL for future use.. destinationRootWebUrl = destinationSite.RootWeb.ServerRelativeUrl; using (SPImport import = new SPImport(ImportSettings)) { import.Started += new EventHandler <SPDeploymentEventArgs>(import_Started); import.ObjectImported += new EventHandler <SPObjectImportedEventArgs>(import_ObjectImported); import.ProgressUpdated += new EventHandler <SPDeploymentEventArgs>(import_ProgressUpdated); import.Completed += new EventHandler <SPDeploymentEventArgs>(import_Completed); if (traceSwitch.TraceInfo) { trace.TraceInfo("RunImport: Wired event handlers, about to call Run().."); } // initialise to default.. importResult = new ImportOperationResult(ResultType.Failure); try { import.Run(); if (traceSwitch.TraceInfo) { trace.TraceInfo("RunImport: Import completed successfully."); } importResult = new ImportOperationResult(ResultType.Success); } catch (Exception e) { if (traceSwitch.TraceError) { trace.TraceError("RunImport: Exception caught whilst running import: '{0}'.", e); } importResult = new ImportOperationResult(ResultType.Failure, e.ToString()); } // Get the change token from the destination site AFTER import.. endChangeToken = destinationSite.CurrentChangeToken; if (traceSwitch.TraceInfo) { trace.TraceInfo("RunImport: End change token is '{0}', attempting to set publish schedule.", endChangeToken.ToString()); } attemptPublishScheduleSet(startChangeToken, endChangeToken, destinationSite); } } if (traceSwitch.TraceVerbose) { trace.TraceVerbose("RunImport: Exiting RunImport()."); } return(importResult); }
private void attemptPublishScheduleSet(SPChangeToken startChangeToken, SPChangeToken endChangeToken, SPSite destinationSite) { if (traceSwitch.TraceVerbose) { trace.TraceVerbose("attemptPublishScheduleSet: Entered with site '{0}', start change token '{1}' and " + "end change token '{2}'.", destinationSite.Url, startChangeToken.ToString(), endChangeToken.ToString()); } if (traceSwitch.TraceInfo) { trace.TraceInfo("attemptPublishScheduleSet: About to reflect 'ScheduledItem' type."); } Type t = getScheduledItemType(); if (t != null) { if (traceSwitch.TraceInfo) { trace.TraceInfo("attemptPublishScheduleSet: Successfully reflected 'ScheduledItem' type, about to search " + "'EnableSchedulingOnDeployedItems' method."); } MethodInfo method = null; bool bFoundMethod = false; try { method = t.GetMethod("EnableSchedulingOnDeployedItems"); bFoundMethod = true; if (traceSwitch.TraceInfo) { trace.TraceInfo("attemptPublishScheduleSet: Successfully found 'EnableSchedulingOnDeployedItems' method."); } } catch (AmbiguousMatchException ame) { if (traceSwitch.TraceWarning) { trace.TraceWarning("attemptPublishScheduleSet: Caught exception when reflecting 'EnableSchedulingOnDeployedItems' method. " + "Unable to find method, exception details '{0}'.", ame); } } catch (ArgumentNullException ane) { if (traceSwitch.TraceWarning) { trace.TraceWarning("attemptPublishScheduleSet: Caught exception when reflecting 'EnableSchedulingOnDeployedItems' method. " + "Unable to find method, exception details '{0}'.", ane); } } if (!bFoundMethod && traceSwitch.TraceWarning) { trace.TraceWarning("attemptPublishScheduleSet: Publishing schedule of deployed items will not be honoured!"); } if (traceSwitch.TraceInfo) { trace.TraceInfo("attemptPublishScheduleSet: About to call method."); } try { object[] aParams = new object[4] { destinationSite, startChangeToken, endChangeToken, "Succeeded" }; method.Invoke(t, aParams); } catch (Exception e) { if (traceSwitch.TraceWarning) { trace.TraceWarning("attemptPublishScheduleSet: Caught exception when running method. Publishing schedule " + "of deployed items will not be honoured! Exception details '{0}.", e); } } } else { if (traceSwitch.TraceWarning) { trace.TraceWarning("attemptPublishScheduleSet: Type was not found, unable to call method. Publishing schedule " + "of deployed items will not be honoured!"); } } if (traceSwitch.TraceVerbose) { trace.TraceVerbose("attemptPublishScheduleSet: Leaving."); } }