protected override IEnumerable <SPRunningJob> RetrieveDataObjects() { List <SPRunningJob> runningJobs = new List <SPRunningJob>(); SPJobDefinition definition = null; if (Identity != null) { definition = this.Identity.Read(); if (null == definition) { base.ThrowTerminatingError(new SPCmdletException("Job definition was not found."), ErrorCategory.ObjectNotFound, null); } } foreach (var svc in SPFarm.Local.Services) { if (svc.RunningJobs.Count == 0) { continue; } foreach (SPRunningJob job in svc.RunningJobs) { if (null == definition || job.JobDefinitionId == definition.Id) { runningJobs.Add(job); } } } return(runningJobs); }
protected virtual void MapProperties(SPJobDefinition currentJobInstance, JobDefinition jobDefinition) { if (!string.IsNullOrEmpty(jobDefinition.ScheduleString)) { currentJobInstance.Schedule = SPSchedule.FromString(jobDefinition.ScheduleString); } if (!string.IsNullOrEmpty(jobDefinition.Title)) { currentJobInstance.Title = jobDefinition.Title; } foreach (var prop in jobDefinition.Properties) { var key = prop.Key; var value = prop.Value; if (currentJobInstance.Properties.ContainsKey(key)) { currentJobInstance.Properties[key] = value; } else { currentJobInstance.Properties.Add(key, value); } } }
private void DisplayJobProperties(SPJobDefinition selectedJob) { if (selectedJob.Properties.Values.Count > 0) { //Display Summary info PropertyInfoDataList.DataSource = selectedJob.Properties; PropertyInfoDataList.DataBind(); //Set inputs to the existing values if (!string.IsNullOrEmpty(selectedJob.Properties[Constants.timerJobListNameAttribute].ToString())) { ListNameTextBox.Text = selectedJob.Properties[Constants.timerJobListNameAttribute].ToString(); } if (!string.IsNullOrEmpty(selectedJob.Properties[Constants.timerJobSiteNameAttribute].ToString())) { SiteNamesTextBox.Text = selectedJob.Properties[Constants.timerJobSiteNameAttribute].ToString(); } if (!string.IsNullOrEmpty(selectedJob.Properties[Constants.timerJobDestinationSiteAttribute].ToString())) { DestinationSiteTextBox.Text = selectedJob.Properties[Constants.timerJobDestinationSiteAttribute].ToString(); } } else { //Set the inputs Default Values ListNameTextBox.Text = ListName; SiteNamesTextBox.Text = SiteName; DestinationSiteTextBox.Text = DestinationSiteName; } ; }
internal static OutputQueue DisableJob(SPJobDefinition job) { var outputQueue = new OutputQueue(); if (job == null) { return(outputQueue); } outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, UserDisplay.DisableJob, string.IsNullOrEmpty(job.DisplayName) ? job.Name : job.DisplayName)); try { job.IsDisabled = true; job.Update(); } catch (SPUpdatedConcurrencyException) { } catch (Exception exception) { outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, Exceptions.DisableJobsUnableToDisableError, job.DisplayName, exception.Message), OutputType.Error, null, exception); } outputQueue.Add(UserDisplay.DisableJobComplete); return(outputQueue); }
private SPJobDefinition GetJobDefinition() { SPJobDefinition definition = null; string[] strArray = JobDefinitionDropDownList.SelectedValue.Split(new[] { '|' }); var guid = new Guid(strArray[0]); try { definition = WebAppSelector.CurrentItem.JobDefinitions[guid]; } catch { } if (definition == null) { try { definition = WebAppSelector.CurrentItem.WebService.JobDefinitions[guid]; } catch { } } return(definition); }
private void ConfigurateTimerJob(SPJobDefinition job) { var schedule = new SPDailySchedule(); schedule.BeginHour = 2; schedule.BeginMinute = 30; schedule.EndHour = 2; schedule.EndMinute = 45; job.Schedule = schedule; job.Update(); }
public void DisableButton_Click(object sender, EventArgs e) { SPJobDefinition jobDefinition = GetJobDefinition(); if (jobDefinition != null) { jobDefinition.IsDisabled = DisableButton.Text != "Enable"; jobDefinition.Update(); SPUtility.Redirect(SPContext.Current.Web.Url + "/_admin/operations.aspx", SPRedirectFlags.DoNotEncodeUrl, HttpContext.Current); } }
protected void JobDefinitionDropDownList_SelectedIndexChanged(object sender, EventArgs e) { AllSiteCollectionsRadioButton.Checked = true; SomeSiteCollectionsRadioButton.Checked = false; if (JobDefinitionDropDownList.SelectedIndex > 0) { SPJobDefinition jobDefinition = GetJobDefinition(); if (jobDefinition != null) { if (jobDefinition.Schedule != null) { DateTime time = jobDefinition.Schedule.NextOccurrence(DateTime.Now); NextOccurrenceLabel.Text = time.ToLongDateString() + " " + time.ToShortTimeString(); NextOccurrenceInfoLabel.Visible = true; NextOccurrenceLabel.Visible = true; DisableButton.Visible = true; if (jobDefinition.IsDisabled) { DisableButton.Text = "Enable"; } else { DisableButton.Text = "Disable"; } PopulateSchedule(jobDefinition.Schedule); SPSiteCollection sites = WebAppSelector.CurrentItem.Sites; foreach (SPSite site in sites) { var child = WebAppSelector.CurrentItem.GetChild <JobSettings>(jobDefinition.Name); if ((child != null) && child.SiteCollectionsEnabled.Contains(site.ID)) { SomeSiteCollectionsRadioButton.Checked = true; foreach (RepeaterItem item in SiteCollectionRepeater.Items) { var box = item.FindControl("SiteCollectionCheckBox") as CheckBox; box.Checked = true; break; } } } } else { DisableButton.Visible = false; NextOccurrenceInfoLabel.Visible = false; NextOccurrenceLabel.Visible = false; } } } }
public JobDefinitionNode(SPJobDefinition definition) { this.Tag = definition; this.SPParent = definition.Parent; //this.ContextMenuStrip = new SiteMenuStrip(); Setup(); if (this.Definition.Properties.Count > 0) { this.Nodes.Add(new ExplorerNodeBase("Dummy")); } }
public void DeleteFirstTimerJob(SPWeb web) { try { SPJobDefinition objFirstTimerJob = web.Site.WebApplication.JobDefinitions["$safeprojectname$ First Timer Job"]; if (objFirstTimerJob != null) { objFirstTimerJob.Delete(); } } catch (Exception ex) { throw ex; } }
protected static void RemoveExistingJob(SPSolution solution) { if (solution.JobStatus == SPRunningJobStatus.Initialized) { throw new InstallException(res.DoubleDeployment); } SPJobDefinition jobDefinition = GetSolutionJob(solution); if (jobDefinition != null) { jobDefinition.Delete(); Thread.Sleep(500); } }
private static bool IsApplicableJob(SPJobDefinition jd, SPServer server, bool isRefresh, bool logSpadminDisabledEvent) { if ((jd.Server != null) && !jd.Server.Id.Equals(server.Id)) { return(false); } if ((jd.LockType == SPJobLockType.ContentDatabase) && !SupportsContentDatabaseJobs(server)) { return(false); } if (!isRefresh) { return(false); // ((jd.Flags & 1) == 0); } return(true); }
public void Execute(SPJobDefinition jobInstance) { SPSecurity.RunWithElevatedPrivileges( delegate { using (SPSite spSite = new SPSite(this.SiteId)) { const string createDataBaseFolderPath = @"Template\SQL\Navicon.SP.DataBase.dacpac"; string connectionString = spSite.ContentDatabase.DatabaseConnectionString; string archiveDacpacPath = SPUtility.GetVersionedGenericSetupPath( createDataBaseFolderPath, 15); Logger.WriteMessage( "Путь до файла sql скрипта: {0}, connection string: {1}, учетная запись: {2} ", archiveDacpacPath, connectionString, spSite.RootWeb.CurrentUser.LoginName); DacServices dacServices = new DacServices(connectionString); dacServices.Message += (sender, args) => { Trace.WriteLine(args.Message); Logger.WriteMessage(args.Message.Message); }; dacServices.ProgressChanged += (sender, args) => { Trace.WriteLine(args.Message); Logger.WriteMessage(args.Message); }; using (DacPackage package = DacPackage.Load(archiveDacpacPath)) { DacDeployOptions options = new DacDeployOptions { CreateNewDatabase = false }; dacServices.Deploy( package, Constants.DataBaseName, true, options, new CancellationToken?()); } } }); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //Load the Job we are looking for and feedback to user List <SPJobDefinition> allJobs = GetTimerJobsByName(Constants.jobTitle); SPJobDefinition selectedJob = allJobs.FirstOrDefault(); if (selectedJob != null) { DisplayJobProperties(selectedJob); } else { PropertyInfoLabel.Text = string.Format("No Timer Job with the Display Name '{0}' was found.", Constants.jobTitle); } } }
/// <summary> /// Starts a timer job (runs it only once) /// </summary> /// <param name="site"> /// The site that will determine which web app's timer job definition will be used /// </param> /// <param name="jobName"> /// The job name (i.e. the CamelCaseTimerJobTypeName). /// </param> /// <exception cref="ArgumentException"> /// If jobName is not found, exception is thrown /// </exception> /// <returns> /// The started job id <see cref="Guid"/>. /// </returns> public Guid StartJobAndReturn(SPSite site, string jobName) { SPWebApplication webApplication = site.WebApplication; SPJobDefinition jobDefinition = (from SPJobDefinition job in webApplication.JobDefinitions where job.Name == jobName select job).FirstOrDefault(); if (jobDefinition != null) { jobDefinition.RunNow(); } else { throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Error: Can't find job {0} passed as argument.", jobName)); } return(jobDefinition.Id); }
private static bool ShouldRunAdminCmdLineJob(SPJobDefinition jd, SPServer server) { if (!(jd is SPAdministrationServiceJobDefinition)) { return(false); } if (jd.GetType().Name == "SPTimerRecycleJobDefinition") { return(false); } if (!IsApplicableJob(jd, server, false, false)) { return(false); } if (jd.LockType == SPJobLockType.ContentDatabase) { return(false); } return(true); }
protected virtual void MapProperties(SPJobDefinition currentJobInstance, JobDefinition jobDefinition) { if (!string.IsNullOrEmpty(jobDefinition.ScheduleString)) { currentJobInstance.Schedule = SPSchedule.FromString(jobDefinition.ScheduleString); } if (!string.IsNullOrEmpty(jobDefinition.Title)) currentJobInstance.Title = jobDefinition.Title; foreach (var prop in jobDefinition.Properties) { var key = prop.Key; var value = prop.Value; if (currentJobInstance.Properties.ContainsKey(key)) currentJobInstance.Properties[key] = value; else currentJobInstance.Properties.Add(key, value); } }
internal static OutputQueue EnableJob(SPJobDefinition job) { var outputQueue = new OutputQueue(); if (job == null) { return(outputQueue); } outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, UserDisplay.EnableJob, string.IsNullOrEmpty(job.DisplayName) ? job.Name : job.DisplayName)); try { job.IsDisabled = false; job.Update(); } catch (SPUpdatedConcurrencyException) { } outputQueue.Add(UserDisplay.EnableJobComplete); return(outputQueue); }
/// <summary> /// Kills previously scheduled jobs for a solution /// </summary> /// <param name="solution">solution to kill jobs on</param> private void KillRunningJobs(SPSolution solution) { if (solution == null) { return; } try { if (solution.JobExists) { // is the job already running if (solution.JobStatus == SPRunningJobStatus.Initialized) { throw new Exception("A deployment job already running for this solution."); } // find the running job SPJobDefinition definition = null; foreach (SPJobDefinition jobdefs in SPFarm.Local.TimerService.JobDefinitions) { if ((jobdefs.Title != null) && jobdefs.Title.Contains(solution.Name)) { definition = jobdefs; break; } } if (definition != null) { definition.Delete(); // kill if it was found Thread.Sleep(1000); // give it time to delete } } } catch (Exception ee) { throw new Exception("Error while trying to kill running jobs.", ee); } }
private static void WaitAppPoolJob(SPIisWebServiceApplicationPool pool) { bool wait = true; var timeOut = DateTime.Now.AddMinutes(10); while (wait) { if (DateTime.Now > timeOut) { throw new TimeoutException(); } SPJobDefinition job = GetJob(pool.Id); if (job == null) { wait = false; } //FarmExtensions.ClearFarmCache(); Thread.Sleep(1000); } }
public static List <AttributeValuePair> GetSPJobDefinitionAttributes(SPJobDefinition jobDef) { List <AttributeValuePair> jobDefAttributes = new List <AttributeValuePair>(); try { jobDefAttributes.Add(new AttributeValuePair("Title", jobDef.Title)); jobDefAttributes.Add(new AttributeValuePair("DisplayName", jobDef.DisplayName)); jobDefAttributes.Add(new AttributeValuePair("Name", jobDef.Name)); jobDefAttributes.Add(new AttributeValuePair("Id", jobDef.ToString())); jobDefAttributes.Add(new AttributeValuePair("IsDisabled", jobDef.IsDisabled.ToString())); jobDefAttributes.Add(new AttributeValuePair("LastTimeRun", jobDef.LastRunTime.ToLongDateString() + " " + jobDef.LastRunTime.ToLongTimeString())); jobDefAttributes.Add(new AttributeValuePair("LockType", jobDef.LockType.ToString())); jobDefAttributes.Add(new AttributeValuePair("Retry", jobDef.Retry.ToString())); jobDefAttributes.Add(new AttributeValuePair("Status", jobDef.Status.ToString())); jobDefAttributes.Add(new AttributeValuePair("Schedule", jobDef.Schedule.ToString())); } catch (Exception e) { jobDefAttributes.Add(new AttributeValuePair("Exception", e.ToString())); } return(jobDefAttributes); }
public void DeleteIfExistJob() { // THE ORIGINAL VALUE OF REMOTE ADMINISTRATOR var remoteAdministratorAccessDenied = SPWebService.ContentService.RemoteAdministratorAccessDenied; try { // SET THE REMOTE ADMINISTATOR ACCESS DENIED FALSE SPWebService.ContentService.RemoteAdministratorAccessDenied = false; // delete the custom timer job if it exists SPJobDefinition existsJob = WebApplication.JobDefinitions.SingleOrDefault(x => x.Name.Equals(_jobName)); if (existsJob != null) { existsJob.Delete(); } } finally { // SET THE REMOTE ADMINISTATOR ACCESS DENIED BACK WHAT // IT WAS SPWebService.ContentService.RemoteAdministratorAccessDenied = remoteAdministratorAccessDenied; } }
private void CreateJobs_DocIcons(DocIconType docType, string key, string value, string editText, string openControl, bool delete) { if (webApp != null) { string serviceName = "WSS_Administration"; SPFarm farm = SPFarm.Local; WebSiteDocItemModifier docJob = null; foreach (SPService service in farm.Services) { if (service.Name == serviceName) { docJob = new WebSiteDocItemModifier(service, docType, key, value, editText, openControl, delete); SPJobDefinition def = service.GetJobDefinitionByName(docJob.Name); if (def != null) { def.Delete(); } break; } } docJob.Schedule = new SPOneTimeSchedule(DateTime.Now); docJob.Title = string.Format("Modify {0} Icon for Mapping {1} in {2} section.", value, key, docType.ToString()); docJob.Update(); DateTime runtime; DateTime.TryParse(docJob.LastRunTime.ToString(), out runtime); while (runtime != null && (runtime == DateTime.MinValue || runtime == DateTime.MaxValue)) { DateTime.TryParse(docJob.LastRunTime.ToString(), out runtime); } } }
public void SubmitButton_Click(object sender, EventArgs e) { SPJobDefinition jobDefinition = GetJobDefinition(); if (jobDefinition != null) { string str = ScheduleField.Value; SPSchedule schedule = null; string str2 = str; if (str2 != null) { if (!(str2 == "Minutes")) { if (str2 == "Hourly") { schedule = BuildHourlySchedule(); } else if (str2 == "Daily") { schedule = BuildDailySchedule(); } else if (str2 == "Weekly") { schedule = BuildWeeklySchedule(); } else if (str2 == "Monthly") { schedule = BuildMonthlySchedule(); } else if (str2 == "Yearly") { schedule = BuildYearlySchedule(); } } else { schedule = BuildMinuteSchedule(); } } bool flag = true; if ((jobDefinition.Schedule != null) && jobDefinition.Schedule.Equals(schedule)) { flag = false; } if (flag) { jobDefinition.Schedule = schedule; if (jobDefinition.IsDisabled) { jobDefinition.IsDisabled = false; } jobDefinition.Update(); } var child = WebAppSelector.CurrentItem.GetChild <JobSettings>(jobDefinition.Name); if (child == null) { child = new JobSettings(jobDefinition.Name, WebAppSelector.CurrentItem, Guid.NewGuid()); } else { child.SiteCollectionsEnabled.Clear(); } if (SomeSiteCollectionsRadioButton.Checked) { foreach (RepeaterItem item in SiteCollectionRepeater.Items) { var box = item.FindControl("SiteCollectionCheckBox") as CheckBox; if ((box != null) && box.Checked) { var label = item.FindControl("SiteCollectionIDLabel") as Label; if (label != null) { var guid = new Guid(label.Text); child.SiteCollectionsEnabled.Add(guid); } } } } child.Update(); } SPUtility.Redirect(SPContext.Current.Web.Url + "/_admin/operations.aspx", SPRedirectFlags.DoNotEncodeUrl, HttpContext.Current); }
public void CreateJob(string assamblyName, string className, object[] ctorParameters = null) { this.Timerjob = (SPJobDefinition)ReflectionLogic.CreateClassInstance(assamblyName, className, ctorParameters); }
private static bool ShouldRunAdminCmdLineJob(SPJobDefinition jd, SPServer server) { if (!(jd is SPAdministrationServiceJobDefinition)) { return false; } if (jd.GetType().Name == "SPTimerRecycleJobDefinition") { return false; } if (!IsApplicableJob(jd, server, false, false)) { return false; } if (jd.LockType == SPJobLockType.ContentDatabase) { return false; } return true; }
private static bool IsApplicableJob(SPJobDefinition jd, SPServer server, bool isRefresh, bool logSpadminDisabledEvent) { if ((jd.Server != null) && !jd.Server.Id.Equals(server.Id)) { return false; } if ((jd.LockType == SPJobLockType.ContentDatabase) && !SupportsContentDatabaseJobs(server)) { return false; } if (!isRefresh) { return false; // ((jd.Flags & 1) == 0); } return true; }