public override void Execute(Guid targetInstanceId) { //Populate local variable from PropertyBag of Entity GetConfigurationValues(); //Pull the Url and Format it var webApplication = this.Parent as SPWebApplication; string rootUrl = webApplication.GetResponseUri(SPUrlZone.Default).AbsoluteUri; rootUrl = rootUrl.TrimEnd("/".ToCharArray()); try { using (var destSite = new SPSite(rootUrl + TimerDestinationSiteName)) { var targetLibrary = destSite.RootWeb.GetList(destSite.Url + Constants.approvedEstimatesListLocation); var targetFolder = targetLibrary.RootFolder; foreach (var timerSiteName in TimerSiteNamesArray) { try { using (var site = new SPSite(rootUrl + timerSiteName)) { using (var data = site.RootWeb.GetSiteData(GetAllApprovedEstimatesFromSiteCollection())) { // Add the new approved item foreach (var sourceFile in from DataRow row in data.Rows select site.MakeFullUrl(ParseFileRef(row["FileRef"].ToString())) into url select site.RootWeb.GetFile(url)) { using (Stream sourceFileStream = sourceFile.OpenBinaryStream()) { targetFolder.Files.Add(sourceFile.Name, sourceFileStream, sourceFile.Properties, true); } } } } } catch (Exception ex) { var handler = new TimerJobExceptionHandler(); handler.HandleTimerJobException(ex); } } } return; } catch (Exception e) { var handler = new TimerJobExceptionHandler(); handler.HandleTimerJobException(e); } finally { } }
/// <summary> /// Method will populate the private members with data from the PropertyBag of the Timer Job Definition /// </summary> private void GetConfigurationValues() { if (Properties[Constants.timerJobDestinationSiteAttribute] != null && !string.IsNullOrEmpty(Properties[Constants.timerJobDestinationSiteAttribute].ToString())) { TimerDestinationSiteName = Properties[Constants.timerJobDestinationSiteAttribute].ToString(); } else { var ex = new Exception(Constants.timerJobDestinationSiteAttribute + " Property has not been configured for the Timer Job:" + Constants.jobTitle); var handler = new TimerJobExceptionHandler(); handler.HandleTimerJobException(ex); } if (Properties[Constants.timerJobSiteNameAttribute] != null && !string.IsNullOrEmpty(Properties[Constants.timerJobSiteNameAttribute].ToString())) { TimerSiteNames = Properties[Constants.timerJobSiteNameAttribute].ToString(); TimerSiteNamesArray = TimerSiteNames.Split(";".ToArray()); } else { var ex = new Exception(Constants.timerJobSiteNameAttribute + " Property has not been configured for the Timer Job:" + Constants.jobTitle); var handler = new TimerJobExceptionHandler(); handler.HandleTimerJobException(ex); } if (Properties[Constants.timerJobListNameAttribute] != null && !string.IsNullOrEmpty(Properties[Constants.timerJobListNameAttribute].ToString())) { Properties[Constants.timerJobListNameAttribute].ToString(); } else { var ex = new Exception(Constants.timerJobListNameAttribute + " Property has not been configured for the Timer Job:" + Constants.jobTitle); var handler = new TimerJobExceptionHandler(); handler.HandleTimerJobException(ex); } }