Ik probeer binnen SharePoint 2010 een eigen timer job te schrijven. Doel van deze job is dat hij periodiek een opgegeven lijst doorloopt, kijkt of een item aan bepaalde kenmerken voldoet, en zoja voor dit object een workflow start.
Ik heb hiervoor een class geschreven die erft van SPJobDefinition.
Hierin staan verder geen schokkende zaken.
Vervolgens heb ik een feature toegevoegd (feature1), en daar een event receiver aangehangen.
Daarna wat (simpele) code geschreven voor de FeatureActivated, en FeatureDeactivating.
Compilen: probleemloos.
Bij deployen krijg ik (op een brandschone installatie!) de volgende melding:
Error 1 Error occurred in deployment step 'Activate Features': An object of the type LoopItem.LoopList2 named "Loop through 1.2" already exists under the parent Microsoft.SharePoint.Administration.SPWebApplication named "SharePoint - 80". Rename your object or delete the existing object.
0 0 LoopList
Het betreft hier echt een schone, out of the box installatie, dus ik heb geen idee hoe deze al zou kunnen bestaan.
Class
en de event receiver:
Maar ik verwacht (persoonlijk) niet zozeer dat er een fout zit in de code, alswel in de gehele aanpak.
Ik heb hiervoor een class geschreven die erft van SPJobDefinition.
Hierin staan verder geen schokkende zaken.
Vervolgens heb ik een feature toegevoegd (feature1), en daar een event receiver aangehangen.
Daarna wat (simpele) code geschreven voor de FeatureActivated, en FeatureDeactivating.
Compilen: probleemloos.
Bij deployen krijg ik (op een brandschone installatie!) de volgende melding:
Error 1 Error occurred in deployment step 'Activate Features': An object of the type LoopItem.LoopList2 named "Loop through 1.2" already exists under the parent Microsoft.SharePoint.Administration.SPWebApplication named "SharePoint - 80". Rename your object or delete the existing object.
0 0 LoopList
Het betreft hier echt een schone, out of the box installatie, dus ik heb geen idee hoe deze al zou kunnen bestaan.
Class
C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
| using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; namespace IACTLoopItem { class LoopList2 : SPJobDefinition { public LoopList2() : base() { } public LoopList2(string jobName, SPService service, SPServer server, SPJobLockType targetType) : base(jobName, service, server, targetType) { } public LoopList2(string jobName, SPWebApplication webApplication) : base(jobName, webApplication, null, SPJobLockType.ContentDatabase) { this.Title = "List Timer Job"; } public override void Execute(Guid contentDbId) { // get a reference to the current site collection's content database SPWebApplication webApplication = this.Parent as SPWebApplication; SPContentDatabase contentDb = webApplication.ContentDatabases[contentDbId]; // get a reference to the "ListTimerJob" list in the RootWeb of the first site collection in the content database SPList Listjob = contentDb.Sites[0].RootWeb.Lists["ListTimerJob"]; // create a new list Item, set the Title to the current day/time, and update the item SPListItem newList = Listjob.Items.Add(); newList["Title"] = DateTime.Now.ToString(); newList.Update(); } } } |
en de event receiver:
C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
| using System; using System.Runtime.InteropServices; using System.Security.Permissions; using Microsoft.SharePoint; using Microsoft.SharePoint.Security; using Microsoft.SharePoint.Administration; namespace LoopList.Features.Feature1 { /// <summary> /// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade. /// </summary> /// <remarks> /// The GUID attached to this class may be used during packaging and should not be modified. /// </remarks> [Guid("e68d6f6c-b9ae-41bc-b6e1-7dcfaf719901")] public class Feature1EventReceiver : SPFeatureReceiver { const string List_JOB_NAME = "Loop through 1.2"; // Uncomment the method below to handle the event raised after a feature has been activated. public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPSite site = properties.Feature.Parent as SPSite; // make sure the job isn't already registrered foreach (SPJobDefinition job in site.WebApplication.JobDefinitions) { if (job.Name == List_JOB_NAME) { job.Delete(); } // install the job IACTLoopItem.LoopList2 listLoggerJob = new IACTLoopItem.LoopList2(List_JOB_NAME, site.WebApplication); SPMinuteSchedule schedule = new SPMinuteSchedule(); schedule.BeginSecond = 0; schedule.EndSecond = 59; schedule.Interval = 5; listLoggerJob.Schedule = schedule; listLoggerJob.Update(); } } // Uncomment the method below to handle the event raised before a feature is deactivated. public override void FeatureDeactivating(SPFeatureReceiverProperties properties) { SPSite site = properties.Feature.Parent as SPSite; // delete the job foreach (SPJobDefinition job in site.WebApplication.JobDefinitions) { if (job.Name == List_JOB_NAME) { job.Delete(); } } } // Uncomment the method below to handle the event raised after a feature has been installed. //public override void FeatureInstalled(SPFeatureReceiverProperties properties) //{ //} // Uncomment the method below to handle the event raised before a feature is uninstalled. //public override void FeatureUninstalling(SPFeatureReceiverProperties properties) //{ //} // Uncomment the method below to handle the event raised when a feature is upgrading. //public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters) //{ //} } } |
Maar ik verwacht (persoonlijk) niet zozeer dat er een fout zit in de code, alswel in de gehele aanpak.