protected void WaitForJobs(SPLongOperation longOp) { SPJobDefinitionCollection jobs = SPContext.Current.Site.WebApplication.JobDefinitions; int _seconds = 10; foreach (SPJobDefinition job in jobs) { if (job.Name == WebSiteControllerRuleWorkItem.WorkItemJobDisplayName) { TimeSpan now = new TimeSpan(DateTime.Now.Ticks); TimeSpan last = new TimeSpan(job.LastRunTime.Ticks); TimeSpan past = now.Subtract(last); int next = 60 - past.Seconds; _seconds += next; break; } } longOp.TrailingHTML = "This may take few seconds. " + _seconds.ToString() + " seconds actually."; longOp.Begin(); Thread.Sleep(_seconds * 1000); return; }
private XmlNode GetFarmServicesNode(SPServiceCollection farmServices, XmlNode farmServicesNode) { XmlNode countAttribute = FarmXml.CreateAttribute("Count"); countAttribute.Value = farmServices.Count.ToString(); farmServicesNode.Attributes.SetNamedItem(countAttribute); foreach (SPService service in farmServices) { XmlNode serviceNode = FarmXml.CreateElement("FarmService"); List <AttributeValuePair> serviceAttributes = SPAttributes.GetSPServiceAttributes(service); foreach (AttributeValuePair serviceAttribute in serviceAttributes) { serviceNode.Attributes.SetNamedItem(GetXmlAttribute(serviceAttribute)); } // Get the service's Job Definitions if it has any SPJobDefinitionCollection serviceJobDefinitions = service.JobDefinitions; serviceNode.AppendChild(GetJobDefinitionsNode(serviceJobDefinitions, "ServiceJobDefinitions")); farmServicesNode.AppendChild(serviceNode); } return(farmServicesNode); }
// Uncomment the method below to handle the event raised after a feature has been activated. private void DeleteJob(SPJobDefinitionCollection jobs) { foreach (SPJobDefinition job in jobs) { if (job.Name.Equals(SimbleJobDefinition.JobName, StringComparison.OrdinalIgnoreCase)) { job.Delete(); } } }
/// <summary> /// Удаление таймерджоба /// </summary> /// <param name="site">SPSite</param> /// <param name="DocJobName">Название таймеджоба</param> public void DeleteOldVersion(SPJobDefinitionCollection jobsCollection = null) { foreach (SPJobDefinition job in jobsCollection) { if (job.Name == this.Timerjob.Title) { job.Delete(); } } }
private void DeleteJob(SPJobDefinitionCollection jobs) { foreach (SPJobDefinition job in jobs) { if (job.Name.Equals(UoBDelMySiteLibsTimerJob.UoBMySiteJob.JobName, StringComparison.OrdinalIgnoreCase)) { job.Delete(); } } }
private void DeleteJob(SPJobDefinitionCollection jobs) { foreach (SPJobDefinition job in jobs) { if (job.Name.Equals(ReportJobDefinition.JobName, StringComparison.OrdinalIgnoreCase)) { job.Delete(); } } }
public JobDefinitionCollectionNode(Object parent, SPJobDefinitionCollection collection) { this.Text = SPMLocalization.GetString("JobDefinitions_Text"); this.ToolTipText = SPMLocalization.GetString("JobDefinitions_ToolTip"); this.Name = "Job Definitions"; this.Tag = collection; this.SPParent = parent; this.ImageIndex = 9; this.SelectedImageIndex = 9; this.Nodes.Add(new ExplorerNodeBase("Dummy")); }
private void CreateWorkItem() { Guid siteId = SPContext.Current.Site.ID; Guid webId = SPContext.Current.Web.ID; SPSecurity.RunWithElevatedPrivileges(() => { using (SPSite site = new SPSite(siteId)) { site.AddWorkItem( Guid.NewGuid(), DateTime.Now.ToUniversalTime(), WebSiteControllerModuleWorkItem.WorkItemTypeId, webId, siteId, 1, true, _guid, Guid.Empty, site.SystemAccount.ID, null, _modulename + ";" + _assembly, Guid.Empty ); SPJobDefinitionCollection jobs = site.WebApplication.JobDefinitions; foreach (SPJobDefinition job in jobs) { if (job.Name == WebSiteControllerModuleWorkItem.WorkItemJobDisplayName) { DateTime next = job.Schedule.NextOccurrence(job.LastRunTime); _seconds = next.Second.ToString(); break; } } //SPJobDefinition job = site.WebApplication.JobDefinitions[WebSiteControllerModuleWorkItem.WorkItemJobDisplayName]; //job.RunNow(); } }); }
private XmlNode GetJobDefinitionsNode(SPJobDefinitionCollection serviceJobDefinitions, string nodeName) { XmlNode jobDefinitionsNode = FarmXml.CreateElement(nodeName); XmlNode countAttribute = FarmXml.CreateAttribute("Count"); countAttribute.Value = serviceJobDefinitions.Count.ToString(); jobDefinitionsNode.Attributes.SetNamedItem(countAttribute); foreach (SPJobDefinition jobDefinition in serviceJobDefinitions) { XmlNode jobDefinitionNode = FarmXml.CreateElement("JobDefinition"); List <AttributeValuePair> jobDefAttributes = SPAttributes.GetSPJobDefinitionAttributes(jobDefinition); foreach (AttributeValuePair jobDefAttribute in jobDefAttributes) { jobDefinitionNode.Attributes.SetNamedItem(GetXmlAttribute(jobDefAttribute)); } jobDefinitionsNode.AppendChild(jobDefinitionNode); } return(jobDefinitionsNode); }
private void DeleteJob(SPJobDefinitionCollection jobs) { if (webApp != null) { foreach (SPJobDefinition job in jobs) { if (job.Id.Equals(WebSiteControllerModuleWorkItem.WorkItemTypeId)) { try { job.Delete(); } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); //ex.ToString(); } } } } }
static void Main(string[] args) { const string SiteUrl = "site_url"; const string AssamblyName = "assambly_name"; const string ClassName = "tj_class_name"; Console.OutputEncoding = Encoding.GetEncoding(1251); using (SPSite site = new SPSite(SiteUrl)) { using (SPWeb web = site.OpenWeb()) { object[] TJCtorParams = DefaultValues.GetInputParams(site); SPJobDefinitionCollection jobsCollection = DefaultValues.GetAllJobs(site); Hashtable properties = DefaultValues.GetProperties(site, web); TimerJobCreater.Create(AssamblyName, ClassName, TJCtorParams, jobsCollection, properties); TimerServiceLogic.RestartTimerService(); } } Console.WriteLine("End"); Console.ReadKey(); }
private void CreateWorkItem(string url) { Guid siteId = SPContext.Current.Site.ID; Guid webId = SPContext.Current.Web.ID; bool disabled = false; WebSiteControllerPrincipalType principalType = WebSiteControllerPrincipalType.None; bool appliesToSSL = true; int sequence = 1; String pricipal = string.Empty; StringBuilder builder = new StringBuilder(); builder.Append(url + ";"); builder.Append(disabled.ToString() + ";"); builder.Append(appliesToSSL.ToString() + ";"); builder.Append(sequence.ToString() + ";"); builder.Append(principalType.ToString() + ";"); builder.Append(pricipal + ";"); builder.Append("#"); builder.Append(String.Format("{0}:{1};", "OriginalUrl", _url)); string full = builder.ToString(); SemanticModule mod = new SemanticModule(); IWebSiteControllerModule imod = null;// WebSiteControllerConfig.GetModule(web.Site.WebApplication, mod.RuleType); while (imod == null) { System.Threading.Thread.Sleep(1000); try { imod = WebSiteControllerConfig.GetModule(SPContext.Current.Site.WebApplication, mod.RuleType); } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); //ex.ToString(); } } int item = -1; SPSecurity.RunWithElevatedPrivileges(() => { using (SPSite site = new SPSite(siteId)) { site.AddWorkItem( Guid.NewGuid(), DateTime.Now.ToUniversalTime(), WebSiteControllerRuleWorkItem.WorkItemTypeId, webId, siteId, item, true, imod.Id, Guid.Empty, site.SystemAccount.ID, null, builder.ToString(), Guid.Empty ); } SPJobDefinitionCollection jobs = SPContext.Current.Site.WebApplication.JobDefinitions; foreach (SPJobDefinition job in jobs) { if (job.Name == WebSiteControllerRuleWorkItem.WorkItemJobDisplayName) { try { DateTime next = job.Schedule.NextOccurrence(job.LastRunTime); _seconds = next.Second; break; } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory(ex.Source, TraceSeverity.High, EventSeverity.Error), TraceSeverity.High, ex.Message, ex.Data); //ex.ToString(); } } } }); }
private void CreateWorkItem(SPWebEventProperties properties) { Guid siteId = properties.SiteId; Guid webId = properties.WebId; string url = properties.ServerRelativeUrl; if (url.StartsWith("/")) { url = url.Remove(0, 1); } bool disabled = false; WebSiteControllerPrincipalType principalType = WebSiteControllerPrincipalType.None; bool appliesToSSL = true; int sequence = 1; String pricipal = string.Empty; StringBuilder builder = new StringBuilder(); builder.Append(url + ";"); builder.Append(disabled.ToString() + ";"); builder.Append(appliesToSSL.ToString() + ";"); builder.Append(sequence.ToString() + ";"); builder.Append(principalType.ToString() + ";"); builder.Append(pricipal + ";"); builder.Append("#"); builder.Append(String.Format("{0}:{1};", "OriginalUrl", url + "/default.aspx")); string full = builder.ToString(); Guid itemGuid = new Guid("386577D9-0777-4AD3-A90A-C240D8B0A49E"); int item = -1; SPSecurity.RunWithElevatedPrivileges(() => { using (SPSite site = new SPSite(siteId)) { site.AddWorkItem( Guid.NewGuid(), DateTime.Now.ToUniversalTime(), WebSiteControllerRuleWorkItem.WorkItemTypeId, webId, siteId, item, true, itemGuid, Guid.Empty, site.SystemAccount.ID, null, builder.ToString(), Guid.Empty ); } }); SPJobDefinitionCollection jobs = properties.Web.Site.WebApplication.JobDefinitions; int _seconds = 0; foreach (SPJobDefinition job in jobs) { if (job.Name == WebSiteControllerRuleWorkItem.WorkItemJobDisplayName) { DateTime next = job.Schedule.NextOccurrence(job.LastRunTime); _seconds = next.Millisecond; break; } } //System.Threading.Thread.Sleep(_seconds); }
private void CreateWorkItem() { Guid siteId = SPContext.Current.Site.ID; Guid webId = SPContext.Current.Web.ID; WebSiteControllerRuleControl control = (WebSiteControllerRuleControl)FindControlRecursive(this.Master, "moduleControl"); string url = this.pageTextBox.Text; if (_SimpleView) { url = control.DefaultUrl; } bool disabled = this.disabledCheckBox.Checked; bool appliesToSSL = this.appliesToSslCheckBox.Checked; int sequence = Convert.ToInt32(this.sequenceTextBox.Text, CultureInfo.CurrentCulture); WebSiteControllerPrincipalType principalType = WebSiteControllerPrincipalType.None; String pricipal = this.principalTextBox.Text; if (!String.IsNullOrEmpty(this.principalTextBox.Text)) { principalType = (WebSiteControllerPrincipalType)Enum.Parse(typeof(WebSiteControllerPrincipalType), this.principalTypeList.SelectedValue); } Hashtable properties = null; if (control != null) { properties = control.Properties; } StringBuilder builder = new StringBuilder(); builder.Append(url + ";"); builder.Append(disabled.ToString() + ";"); builder.Append(appliesToSSL.ToString() + ";"); builder.Append(sequence.ToString() + ";"); builder.Append(principalType.ToString() + ";"); builder.Append(pricipal + ";"); builder.Append("#"); foreach (DictionaryEntry prop in properties) { builder.Append(String.Format("{0}:{1};", prop.Key, prop.Value)); } Guid itemGuid = _guid; int item = 0; if (itemGuid.Equals(Guid.Empty)) { itemGuid = _module.Id; item = -1; } else { item = 2; } if (_event == "Delete") { item = 1; } SPSecurity.RunWithElevatedPrivileges(() => { using (SPSite site = new SPSite(siteId)) { site.AddWorkItem( Guid.NewGuid(), DateTime.Now.ToUniversalTime(), WebSiteControllerRuleWorkItem.WorkItemTypeId, webId, siteId, item, true, itemGuid, Guid.Empty, site.SystemAccount.ID, null, builder.ToString(), Guid.Empty ); SPJobDefinitionCollection jobs = site.WebApplication.JobDefinitions; foreach (SPJobDefinition job in jobs) { if (job.Name == WebSiteControllerRuleWorkItem.WorkItemJobDisplayName) { DateTime next = job.Schedule.NextOccurrence(job.LastRunTime); _seconds = next.Second.ToString(); break; } } //SPJobDefinition job = site.WebApplication.JobDefinitions[WebSiteControllerRuleWorkItem.WorkItemJobDisplayName]; //job.RunNow(); } }); }
public static void Create(string assamblyName, string className, object[] TJCtorParams, SPJobDefinitionCollection jobsCollection, Hashtable properties, SPSchedule schedule = null) { TimerJobBuilder TJBuilder = new TimerJobBuilder(); TJBuilder.CreateJob(assamblyName, className, TJCtorParams); TJBuilder.DeleteOldVersion(jobsCollection); TJBuilder.SetSchedule(schedule); TJBuilder.SetProperties(properties); TJBuilder.UpdateJob(); }