Exemplo n.º 1
0
        // Uncomment the method below to handle the event raised after a feature has been activated.

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPFarm local = SPFarm.Local;

            var services = from s in local.Services
                           where s.Name == "SPTimerV4"
                           select s;

            var service = services.First();

            foreach (SPJobDefinition job in service.JobDefinitions)
            {
                if (job.Name == tJobName)
                {
                    job.Delete();
                }
            }

            var newTimerJob = new STSSyncMonitor(tJobName, service);

            newTimerJob.IsDisabled = true;
            newTimerJob.Schedule   = new SPYearlySchedule();
            newTimerJob.Update();

            //build the Master XML Fragment
            SPAdministrationWebApplication adminWebApp = SPAdministrationWebApplication.Local;

            using (var siteCollection = new SPSite(adminWebApp.Sites[0].Url))
            {
                using (var site = siteCollection.OpenWeb())
                {
                    SPList list = site.Lists.TryGetList("Nauplius.ADLDS.FBA - StsFarm");
                    if (list == null)
                    {
                        return;
                    }
                    if (list.ItemCount == 0)
                    {
                        var path   = SPUtility.GetGenericSetupPath(@"WebServices\SecurityToken\web.config");
                        var config = new XmlDocument();
                        config.Load(path);

                        XmlNode systemwebChild =
                            config.SelectSingleNode("configuration/system.web");

                        if (systemwebChild != null)
                        {
                            SPListItem item = list.Items.Add();
                            item["StsConfig"]    = "MasterXmlFragment";
                            item["XMLStsConfig"] = systemwebChild.OuterXml;
                            item.Update();
                        }
                    }
                }
            }
        }
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWebApplication adminWebApplication = properties.Feature.Parent as SPWebApplication;

            foreach (SPJobDefinition job in adminWebApplication.JobDefinitions)
            {
                if (job.Name == tJobName)
                {
                    job.Delete();
                }
            }

            if (((SPWebApplication)properties.Feature.Parent).IsAdministrationWebApplication)
            {
                STSSyncMonitor newTimerJob = new STSSyncMonitor(tJobName, adminWebApplication);

                var jobSchedule = new SPOneTimeSchedule();
                newTimerJob.Schedule = jobSchedule;
                newTimerJob.Update();
            }
        }