// Uncomment the method below to handle the event raised after a feature has been activated. public override void FeatureActivated(SPFeatureReceiverProperties properties) { try { SPContext.Current.Web.AllowUnsafeUpdates = true; SPAdministrationWebApplication caWebApp = SPAdministrationWebApplication.Local; //Delete any existing jobs string jobName = "Check License"; foreach (SPJobDefinition job in caWebApp.JobDefinitions) { if (job.Name.ToUpper().Equals(jobName.ToUpper())) { job.Delete(); } } //Schedule new job SPMonthlySchedule schedule4 = new SPMonthlySchedule(); schedule4.BeginDay = 1; schedule4.EndDay = 1; schedule4.BeginHour = 2; schedule4.EndHour = 6; LicenseChecker newJob4 = new LicenseChecker(jobName, caWebApp); newJob4.Schedule = schedule4; newJob4.Update(); } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); } }
public override void Execute(Guid targetInstanceId) { try { foreach (SPSite site in WebApplication.Sites) { long lastmod = site.LastContentModifiedDate.Ticks; long lastrun = LastRunTime.Ticks; SPMonthlySchedule schedule = Schedule as SPMonthlySchedule; //Schedule.GetType() SiteMapSettings settings = new SiteMapSettings(); settings = settings.Load(site); foreach (string searchengine in settings.SearchEngines) { string sitemap = string.Format("{0}/indexmap.xml", site.RootWeb.Url); SubmitMap(searchengine, sitemap); if (settings.UseMobile) { sitemap = string.Format("{0}/mobilemap.xml", site.RootWeb.Url); SubmitMap(searchengine, sitemap); } if (settings.UseNews) { sitemap = string.Format("{0}/newsmap.xml", site.RootWeb.Url); SubmitMap(searchengine, sitemap); } if (settings.UseVideo) { sitemap = string.Format("{0}/videomap.xml", site.RootWeb.Url); SubmitMap(searchengine, sitemap); } } } this.UpdateProgress(100); } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); } finally { } }
private bool CreateJob(SPWebApplication site) { bool jobCreated = false; try { SendEmailTimerJob job = new SendEmailTimerJob(JobName, site); SPMonthlySchedule schedule = new SPMonthlySchedule(); schedule.EndDay = 1; job.Schedule = schedule; job.Update(); } catch (Exception) { return(jobCreated); } return(jobCreated); }
protected void OK_Click(object sender, EventArgs e) { try { SPContext.Current.Web.AllowUnsafeUpdates = true; SPAdministrationWebApplication caWebApp = SPAdministrationWebApplication.Local; AppData.Local.Entries[AppData.SELECTED_INDEX] = lstSchedule.SelectedIndex.ToString(); AppData.Local.Update(); //Delete any existing jobs string jobName = "SiteMap Ping"; foreach (SPJobDefinition job in caWebApp.JobDefinitions) { if (job.Name.ToUpper().Equals(jobName.ToUpper())) { job.Delete(); } } //Schedule new job switch (lstSchedule.SelectedIndex) { case 1: //Immediate SPOneTimeSchedule schedule1 = new SPOneTimeSchedule(DateTime.Now); Worker newJob1 = new Worker(jobName, caWebApp); newJob1.Schedule = schedule1; newJob1.Update(); break; case 2: //Daily SPDailySchedule schedule2 = new SPDailySchedule(); schedule2.BeginHour = 2; schedule2.EndHour = 6; Worker newJob2 = new Worker(jobName, caWebApp); newJob2.Schedule = schedule2; newJob2.Update(); break; case 3: //Weekly SPWeeklySchedule schedule3 = new SPWeeklySchedule(); schedule3.BeginDayOfWeek = DayOfWeek.Saturday; schedule3.EndDayOfWeek = DayOfWeek.Saturday; schedule3.BeginHour = 2; schedule3.EndHour = 6; Worker newJob3 = new Worker(jobName, caWebApp); newJob3.Schedule = schedule3; newJob3.Update(); break; case 4: //Monthly SPMonthlySchedule schedule4 = new SPMonthlySchedule(); schedule4.BeginDay = 1; schedule4.EndDay = 1; schedule4.BeginHour = 2; schedule4.EndHour = 6; Worker newJob4 = new Worker(jobName, caWebApp); newJob4.Schedule = schedule4; newJob4.Update(); break; } SPUtility.Redirect(caWebApp.Sites[0].Url, SPRedirectFlags.Default, HttpContext.Current); } catch (Exception x) { lblMessages.Text = x.Message; } }
private SPSchedule BuildMonthlySchedule() { int beginDay = 1; if (BeginMDayTextBox.Text.Length > 0) { int.TryParse(BeginMDayTextBox.Text, out beginDay); } int beginHour = 0; if (BeginMHourTextBox.Text.Length > 0) { int.TryParse(BeginMHourTextBox.Text, out beginHour); } int beginMinute = 0; if (BeginMMinuteTextBox.Text.Length > 0) { int.TryParse(BeginMMinuteTextBox.Text, out beginMinute); } int beginSecond = 0; if (BeginMSecondTextBox.Text.Length > 0) { int.TryParse(BeginMSecondTextBox.Text, out beginSecond); } int endDay = 31; if (EndMDayTextBox.Text.Length > 0) { int.TryParse(EndMDayTextBox.Text, out endDay); } int endHour = 23; if (EndMHourTextBox.Text.Length > 0) { int.TryParse(EndMHourTextBox.Text, out endHour); } int endMinute = 59; if (EndMMinuteTextBox.Text.Length > 0) { int.TryParse(EndMMinuteTextBox.Text, out endMinute); } int endSecond = 59; if (EndMSecondTextBox.Text.Length > 0) { int.TryParse(EndMSecondTextBox.Text, out endSecond); } var schedule = new SPMonthlySchedule { BeginDay = beginDay, BeginHour = beginHour, BeginMinute = beginMinute, BeginSecond = beginSecond, EndDay = endDay, EndHour = endHour, EndMinute = endMinute, EndSecond = endSecond }; return(schedule); }