/// <summary> /// Get the alerts changed after last sync /// </summary> /// <param name="since"></param> /// <returns></returns> internal Dictionary <int, Alert> GetAlertsChangesSince(DateTime since) { Dictionary <int, Alert> modifiedAlerts = new Dictionary <int, Alert>(); try { if (since < alertList.Created || since < DateTime.UtcNow.AddDays(-60)) { //By default, the change log retains data for 60 days. You can configure the retention period by setting the ChangeLogRetentionPeriod property. since = alertList.Created; //since = DateTime.UtcNow.AddDays(-30); } //SPChangeToken startToken = new SPChangeToken(SPChangeCollection.CollectionScope.List, list.ID, DateTime.UtcNow); //SPChangeToken endToken = new SPChangeToken(SPChangeCollection.CollectionScope.List,list.ID, new DateTime(2008, 10, 18)); SPChangeToken token = new SPChangeToken(SPChangeCollection.CollectionScope.List, this.alertList.ID, since.ToUniversalTime()); //Dictionary<int,Alert> modifiedAlerts = new Dictionary<int,Alert>(); foreach (SPChange change in alertList.GetChanges(token)) { if (!(change is SPChangeItem)) { continue; } SPChangeItem item = change as SPChangeItem; if (!modifiedAlerts.ContainsKey(item.Id)) { Alert alert = null; //if(item.ChangeType != 3) try { alert = new Alert(alertList.GetItemById(item.Id), new MailTemplateManager(alertList.ParentWeb)); } catch { //item has been deleted } //if (alert != null && !alert.ImmidiateAlways) //{ // alert = null; //} modifiedAlerts.Add(item.Id, alert); } //Check if the alert is not immediate and all the stuff which are not eligible for timer based alerts } } catch { } return(modifiedAlerts); }
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."); } }
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); }
/// <summary> /// Get the alerts changed after last sync /// </summary> /// <param name="since"></param> /// <returns></returns> internal Dictionary<int, Alert> GetAlertsChangesSince(DateTime since) { Dictionary<int, Alert> modifiedAlerts = new Dictionary<int, Alert>(); try { if (since < alertList.Created || since < DateTime.UtcNow.AddDays(-60)) { //By default, the change log retains data for 60 days. You can configure the retention period by setting the ChangeLogRetentionPeriod property. since = alertList.Created; //since = DateTime.UtcNow.AddDays(-30); } //SPChangeToken startToken = new SPChangeToken(SPChangeCollection.CollectionScope.List, list.ID, DateTime.UtcNow); //SPChangeToken endToken = new SPChangeToken(SPChangeCollection.CollectionScope.List,list.ID, new DateTime(2008, 10, 18)); SPChangeToken token = new SPChangeToken(SPChangeCollection.CollectionScope.List, this.alertList.ID, since.ToUniversalTime()); //Dictionary<int,Alert> modifiedAlerts = new Dictionary<int,Alert>(); foreach (SPChange change in alertList.GetChanges(token)) { if (!(change is SPChangeItem)) { continue; } SPChangeItem item = change as SPChangeItem; if (!modifiedAlerts.ContainsKey(item.Id)) { Alert alert = null; //if(item.ChangeType != 3) try { alert = new Alert(alertList.GetItemById(item.Id), new MailTemplateManager(alertList.ParentWeb)); } catch { //item has been deleted } //if (alert != null && !alert.ImmidiateAlways) //{ // alert = null; //} modifiedAlerts.Add(item.Id, alert); } //Check if the alert is not immediate and all the stuff which are not eligible for timer based alerts } } catch { } return modifiedAlerts; }