// 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)
        //{
        //}

        // Create Job
        private bool CreateJob(SPWebApplication site)
        {
            bool jobCreated = false;

            try
            {
                CSIPortalDump job = new CSIPortalDump(JobName, site);

                SPDailySchedule schedule = new SPDailySchedule();
                schedule.BeginHour   = 1;
                schedule.EndHour     = 2;
                schedule.BeginMinute = 0;
                schedule.EndMinute   = 0;
                schedule.BeginSecond = 0;
                schedule.EndSecond   = 0;

                job.Schedule   = schedule;
                job.IsDisabled = true;
                job.Update();
            }
            catch (Exception)
            {
                return(jobCreated);
            }
            return(jobCreated);
        }
 // Uncomment the method below to handle the event raised after a feature has been activated.
 public override void FeatureActivated(SPFeatureReceiverProperties properties)
 {
     try
     {
         var site = (SPSite)properties.Feature.Parent;
         bool timerJobFound = site.WebApplication.JobDefinitions.Any(jobDefinition => jobDefinition.Title == Utilities.TimerJobName);
         if (!timerJobFound)
         {
             var addingleavedays = new NotificationTimerJob(Utilities.TimerJobName, site.WebApplication);
             var dailySchedule = new SPDailySchedule
             {
                 BeginHour = 0,
                 BeginMinute = 0,
                 BeginSecond = 0,
                 EndHour = 1,
                 EndMinute = 59,
                 EndSecond = 59
             };
             addingleavedays.Schedule = dailySchedule;
             addingleavedays.Update();
         }
     }
     catch (Exception ex)
     {
         SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("Udateleavebalance", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable, ex.Message, new object[] { ex.StackTrace });
     }
 }
Esempio n. 3
0
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPSite site = properties.Feature.Parent as SPSite;

                // make sure the job isn't already registered
                site.WebApplication.JobDefinitions.Where(t => t.Name.Equals(List_JOB_NAME)).ToList().ForEach(j => j.Delete());

                //job por minuto

                /*
                 * MonitoraJob listLoggerJob = new MonitoraJob(List_JOB_NAME, site.WebApplication);
                 * SPMinuteSchedule schedule = new SPMinuteSchedule();
                 * //schedule.BeginSecond = 0;
                 * //schedule.EndSecond = 59;
                 * schedule.Interval = 1;
                 */

                //job por dia
                MonitoraJob listLoggerJob = new MonitoraJob(List_JOB_NAME, site.WebApplication);
                SPDailySchedule schedule  = new SPDailySchedule();
                //schedule.BeginSecond = 0;
                //schedule.EndSecond = 59;
                schedule.BeginHour = 5;
                schedule.EndHour   = 6;

                listLoggerJob.Schedule = schedule;
                listLoggerJob.Update();
            });
        }
 // Uncomment the method below to handle the event raised after a feature has been activated.
 public override void FeatureActivated(SPFeatureReceiverProperties properties)
 {
     try
     {
         if (!Constants.IsitInDevelopmentMode)
         {
             var site = properties.Feature.Parent as SPSite;
             // make sure the job isn't already registered
             if (site != null)
             {
                 foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
                 {
                     if (job.Name == Constants.TimerJobName)
                         job.Delete();
                 }
                 // install the job
                 var currencyConversionTimerJob = new CurrencyConversionTimerJob(Constants.TimerJobName,
                                                                                 site.WebApplication);
                 //To perform the task on daily basis
                 var schedule = new SPDailySchedule {BeginHour = 0, BeginMinute = 0, BeginSecond = 0};
                 currencyConversionTimerJob.Schedule = schedule;
                 currencyConversionTimerJob.Update();
             }
         }
     }
     catch (Exception ex)
     {
         ExceptionHandling.WriteUlsLog(ex);
     }
 }
Esempio n. 5
0
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            //throw new Exception("The method or operation is not implemented.");
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                // register the the current web
                SPSite site = properties.Feature.Parent as SPSite;

                // make sure the job isn't already registered
                foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
                {
                    if (job.Name == TASK_LOGGER_JOB_NAME)
                    {
                        job.Delete();
                    }
                }

                DocTimer docJob = new DocTimer(TASK_LOGGER_JOB_NAME, site.WebApplication);

                //SPWeeklySchedule weekSched = new SPWeeklySchedule();
                //weekSched.BeginDayOfWeek = DayOfWeek.Monday;
                //weekSched.EndDayOfWeek = DayOfWeek.Monday;
                //weekSched.BeginHour = 0;
                //weekSched.EndHour = 1;



                SPDailySchedule schedule = new SPDailySchedule();
                schedule.BeginHour       = 0;
                schedule.EndHour         = 1;
                docJob.Schedule          = schedule;
                docJob.Update();
            });
        }
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            RegisterLogger();

            // Make sure the job isn't there
            foreach (SPJobDefinition job in SPFarm.Local.TimerService.JobDefinitions)
            {
                if (job.Name == ADFSCertificateUpdaterJob.JobName)
                {
                    job.Delete();
                }
            }

            // Add the configuration object. Getting it for the first time forces the creation.
            var config = ADFSCertificateUpdaterConfiguration.GetFromConfigDB();

            // Install the job
            ADFSCertificateUpdaterJob newJob = new ADFSCertificateUpdaterJob();
            // Run daily at 0015
            var schedule = new SPDailySchedule();
            schedule.BeginHour = 0;
            schedule.EndHour = 0;
            schedule.BeginMinute = 15;
            schedule.EndMinute = 15;
            newJob.Schedule = schedule;

            newJob.Update();
        }
 /// <summary>
 /// Constructor
 /// </summary>
 public IdentityServiceApplicationReloadJobDefinition()
 {
     _defaultschedule             = new SPDailySchedule();
     _defaultschedule.BeginHour   = 23;
     _defaultschedule.EndHour     = 23;
     _defaultschedule.BeginMinute = 0;
     _defaultschedule.EndMinute   = 5;
     _defaultschedule.BeginSecond = 1;
     _defaultschedule.EndSecond   = 59;
     this.Schedule = _defaultschedule;
 }
        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();
        }
 /// <summary>
 /// Constructor
 /// </summary>
 public IdentityServiceApplicationReloadJobDefinition(IdentityServiceApplication serviceApplication, string name) : base(GenerateJobName(serviceApplication, name), serviceApplication.Service)
 {
     ArgumentValidator.IsNotNull(serviceApplication, "IdentityServiceApplication");
     _serviceApplicationId        = serviceApplication.Id;
     _defaultschedule             = new SPDailySchedule();
     _defaultschedule.BeginHour   = 23;
     _defaultschedule.EndHour     = 23;
     _defaultschedule.BeginMinute = 0;
     _defaultschedule.EndMinute   = 5;
     _defaultschedule.BeginSecond = 1;
     _defaultschedule.EndSecond   = 59;
     this.Schedule = _defaultschedule;
 }
Esempio n. 10
0
    // Methods
    private SPSchedule BuildDailySchedule()
    {
        int beginHour = 0;

        if (BeginDHourTextBox.Text.Length > 0)
        {
            int.TryParse(BeginDHourTextBox.Text, out beginHour);
        }
        int beginMinute = 0;

        if (BeginDMinuteTextBox.Text.Length > 0)
        {
            int.TryParse(BeginDMinuteTextBox.Text, out beginMinute);
        }
        int beginSecond = 0;

        if (BeginDSecondTextBox.Text.Length > 0)
        {
            int.TryParse(BeginDSecondTextBox.Text, out beginSecond);
        }
        int endHour = 23;

        if (EndDHourTextBox.Text.Length > 0)
        {
            int.TryParse(EndDHourTextBox.Text, out endHour);
        }
        int endMinute = 59;

        if (EndDMinuteTextBox.Text.Length > 0)
        {
            int.TryParse(EndDMinuteTextBox.Text, out endMinute);
        }
        int endSecond = 59;

        if (EndDSecondTextBox.Text.Length > 0)
        {
            int.TryParse(EndDSecondTextBox.Text, out endSecond);
        }
        var schedule = new SPDailySchedule
        {
            BeginHour   = beginHour,
            BeginMinute = beginMinute,
            BeginSecond = beginSecond,
            EndHour     = endHour,
            EndMinute   = endMinute,
            EndSecond   = endSecond
        };

        return(schedule);
    }
Esempio n. 11
0
        // Uncomment the method below to handle the event raised after a feature has been activated.

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;

            DeleteJob(webApp.JobDefinitions);

            UoBMySiteJob simpleJob = new UoBMySiteJob(webApp);

            SPDailySchedule schedule = new SPDailySchedule();

            schedule.EndHour   = 12;
            schedule.BeginHour = 0;

            simpleJob.Schedule = schedule;
            simpleJob.Update();
        }
Esempio n. 12
0
        // Uncomment the method below to handle the event raised after a feature has been activated.

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate
            {
                using (SPSite site = properties.Feature.Parent.GetType() == typeof(SPSite) ? (SPSite)properties.Feature.Parent : (SPSite)((SPWeb)properties.Feature.Parent).Site)
                {
                    site.AllowUnsafeUpdates = true;
                    // make sure the job isn't already registered

                    foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
                    {
                        if (job.Name == List_JOB_NAME)
                        {
                            job.Delete();
                        }
                    }

                    // install the job

                    SincronizadorTimerJob listLoggerJob = new SincronizadorTimerJob(List_JOB_NAME, site.WebApplication);

                    SPDailySchedule dailySchedule = new SPDailySchedule();
                    dailySchedule.BeginHour       = 00;
                    dailySchedule.BeginMinute     = 50;
                    dailySchedule.BeginSecond     = 0;
                    dailySchedule.EndHour         = 00;
                    dailySchedule.EndMinute       = 51;
                    dailySchedule.EndSecond       = 59;

                    listLoggerJob.Schedule = dailySchedule;

                    //SPMinuteSchedule schedule = new SPMinuteSchedule();

                    //schedule.BeginSecond = 0;

                    //schedule.EndSecond = 59;

                    //schedule.Interval = 5;

                    listLoggerJob.Schedule = dailySchedule;

                    listLoggerJob.Update();

                    site.AllowUnsafeUpdates = false;
                }
            });
        }
Esempio n. 13
0
        /// <summary>
        /// This method initialize all timerjobs necessary for the solution
        /// </summary>
        /// <param name="webApp"></param>
        protected void SetupTimerJobs(SPWebApplication webApp)
        {
            // notification timer job
            Logger.WriteLog(Logger.Category.Information, this.GetType().Name, string.Format("set up:{0}", OrdersMonitoringTimerJob.TimerJobName));
            SPJobDefinition job = new OrdersMonitoringTimerJob(OrdersMonitoringTimerJob.TimerJobName, webApp);

            SPDailySchedule schedule = new SPDailySchedule();

            schedule.BeginSecond = 0;
            schedule.EndSecond   = 0;
            schedule.BeginHour   = 23;
            schedule.EndHour     = 23;
            schedule.BeginMinute = 0;
            schedule.EndMinute   = 30;

            job.Schedule = schedule;
            job.Update();
        }
        private bool CreateJob(SPWebApplication site)
        {
            bool jobCreated = false;

            try
            {
                TimerJobs.InfoFromManager job = new TimerJobs.InfoFromManager(JobName, site);
                //SPWeeklySchedule schedule = new SPWeeklySchedule();
                //schedule.BeginDayOfWeek = DayOfWeek.Saturday;
                //schedule.BeginHour = 8;
                //schedule.BeginMinute = 0;
                //schedule.BeginSecond = 0;
                //schedule.EndSecond = 0;
                //schedule.EndMinute = 10;
                //schedule.EndHour = 8;
                //schedule.EndDayOfWeek = DayOfWeek.Saturday;
                //job.Schedule = schedule;
                //job.Update();

                //SPMinuteSchedule schedule = new SPMinuteSchedule();
                //schedule.BeginSecond = 0;
                //schedule.EndSecond = 59;
                //schedule.Interval = 1;
                //job.Schedule = schedule;


                SPDailySchedule schedule = new SPDailySchedule();
                schedule.BeginHour   = 8;
                schedule.BeginMinute = 0;
                schedule.BeginSecond = 0;

                schedule.EndHour   = 8;
                schedule.EndMinute = 15;
                schedule.EndSecond = 00;

                job.Schedule = schedule;
                job.Update();
            }
            catch (Exception)
            {
                return(jobCreated);
            }
            return(jobCreated);
        }
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            var farm = SPFarm.Local;

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

            var service = services.First();

            foreach (var job in service.JobDefinitions.Where(job => job.Name == tJobName))
            {
                job.Delete();
            }

            var schedule = new SPDailySchedule {
                BeginHour = 0, EndHour = 4
            };

            try
            {
                if (!string.IsNullOrEmpty(farm.Properties.ContainsKey("FoundationSyncPreferredServer").ToString()))
                {
                    var server   = farm.Servers[farm.Properties["FoundationSyncPreferredServer"].ToString()];
                    var timerJob = new SyncJob(tJobName, service, server, SPJobLockType.Job)
                    {
                        Schedule = schedule
                    };
                    timerJob.Update();
                }
            }
            catch (NullReferenceException)
            {
                var timerJob = new SyncJob(tJobName, service)
                {
                    Schedule = schedule
                };
                timerJob.Update();
            }

            RegisterLogging(properties, true);
        }
        private bool CreateJob(SPWebApplication site)
        {
            bool jobCreated = false;

            try
            {
                RH_SiteCrachaSyncJob job      = new RH_SiteCrachaSyncJob(RH_SiteCrachaSyncJob.JobName, site);
                SPDailySchedule      schedule = new SPDailySchedule();
                schedule.BeginHour = 1;
                schedule.EndHour   = 4;
                job.Schedule       = schedule;

                job.Update();
            }
            catch (Exception)
            {
                return(jobCreated);
            }
            return(jobCreated);
        }
Esempio n. 17
0
    private bool CreateJob(SPWebApplication site)
    {
        bool jobCreated = false;

        try
        {
            // schedule job for once a day
            CustomJob       job      = new CustomJob(JobName, site);
            SPDailySchedule schedule = new SPDailySchedule();
            schedule.BeginHour = 0;
            schedule.EndHour   = 1;
            job.Schedule       = schedule;
            job.Update();
        }
        catch (Exception)
        {
            return(jobCreated);
        }
        return(jobCreated);
    }
Esempio n. 18
0
        // 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 registered

            foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
            {
                if (job.Name == List_JOB_NAME)
                {
                    job.Delete();
                }
            }

            // install the job

            ImportadorTimerJob listLoggerJob = new ImportadorTimerJob(List_JOB_NAME, site.WebApplication);

            SPDailySchedule dailySchedule = new SPDailySchedule();

            dailySchedule.BeginHour   = 00;
            dailySchedule.BeginMinute = 50;
            dailySchedule.BeginSecond = 0;
            dailySchedule.EndHour     = 00;
            dailySchedule.EndMinute   = 51;
            dailySchedule.EndSecond   = 59;

            listLoggerJob.Schedule = dailySchedule;

            //SPMinuteSchedule schedule = new SPMinuteSchedule();

            //schedule.BeginSecond = 0;

            //schedule.EndSecond = 59;

            //schedule.Interval = 5;

            listLoggerJob.Schedule = dailySchedule;

            listLoggerJob.Update();
        }
        private bool CreateJob(SPWebApplication site)
        {
            bool jobCreated = false;

            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    CustCode job             = new CustCode(JobName, site);
                    SPDailySchedule schedule = new SPDailySchedule();
                    schedule.BeginHour       = 1;
                    schedule.EndHour         = 1;
                    job.Schedule             = schedule;
                    job.Update();
                });
            }
            catch (Exception)
            {
                return(jobCreated);
            }
            return(jobCreated);
        }
        // Uncomment the method below to handle the event raised after a feature has been activated.
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSite tmpsite = properties.Feature.Parent as SPSite;
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(tmpsite.ID))
                {
                    foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
                    {
                        if (job.Name == List_JOB_NAME)

                            job.Delete();
                    }
                    ReminderSLAPages VanickPolicySLAEmail = new ReminderSLAPages(List_JOB_NAME, site.WebApplication);
                    SPDailySchedule schedule = new SPDailySchedule();
                    schedule.BeginHour = 23;
                    schedule.BeginMinute = 0;
                    schedule.BeginSecond = 0;
                    VanickPolicySLAEmail.Schedule = schedule;
                    VanickPolicySLAEmail.Update();
                }
            });
        }
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                // remove timer job
                RemoveTimerJob();

                foreach (SPWebApplication webApplication in SPWebService.AdministrationService.WebApplications)
                {
                    if (webApplication.Status == SPObjectStatus.Online && webApplication.IsAdministrationWebApplication)
                    {
                        // create timer job
                        try
                        {
                            JOBSynContactoADPortal job = new JOBSynContactoADPortal(JobName, webApplication, null, SPJobLockType.None);
                            SPDailySchedule schedule   = new SPDailySchedule();
                            schedule.BeginHour         = 2;
                            schedule.BeginMinute       = 0;
                            schedule.EndHour           = 3;
                            job.Schedule = schedule;
                            job.Update();
                            break;
                        }
                        catch (Exception ex)
                        {
                            // error creating job
                            using (EventLog eventLog = new EventLog("Application"))
                            {
                                eventLog.Source = "Application";
                                eventLog.WriteEntry("Error en SyncContactoADP: " + ex.Message.ToString() + " \n " + ex.Data.ToString(), EventLogEntryType.Error, 6666, 1);
                            }
                        }
                    }
                }
            });
        }
 public override void FeatureActivated(SPFeatureReceiverProperties properties)
 {
     try
     {
         Logger.WriteInfo("Activating SPC Synchronization feature");
         var profileManager = new ProfileManager();
         var config         = profileManager.Configuration;
         profileManager.CreateUIDProperty();
         var         farm        = SPFarm.Local;
         SyncService syncService = null;
         foreach (var service in farm.Services)
         {
             if (String.Compare(service.Name, SyncService.ServiceName, true) == 0)
             {
                 syncService = service as SyncService;
                 break;
             }
         }
         if (syncService == null)
         {
             Logger.WriteInfo(String.Format("Creating service '{0}' on SPFarm", SyncService.ServiceName));
             syncService = new SyncService(farm);
             syncService.Update();
         }
         foreach (var server in farm.Servers)
         {
             SyncServiceInstance syncInstance = null;
             foreach (var instance in server.ServiceInstances)
             {
                 if (String.Compare(instance.Name, SyncServiceInstance.ServiceInstanceName, true) == 0)
                 {
                     syncInstance = (SyncServiceInstance)instance;
                     break;
                 }
             }
             if (syncInstance == null)
             {
                 Logger.WriteInfo(String.Format("Adding service instance '{0}' to server '{1}'", SyncServiceInstance.ServiceInstanceName, server.Name));
                 syncInstance = new SyncServiceInstance(server, syncService);
                 syncInstance.Update();
             }
         }
         var schedule = new SPDailySchedule();
         schedule.BeginHour = 1;
         schedule.EndHour   = 4;
         ProfileSyncJob job = null;
         foreach (var definition in syncService.JobDefinitions)
         {
             if (String.Compare(definition.Name, ProfileSyncJob.JobName, true) == 0)
             {
                 job = (ProfileSyncJob)definition;
             }
         }
         if (job == null)
         {
             Logger.WriteInfo("Adding job definition");
             job          = new ProfileSyncJob(syncService, null, SPJobLockType.Job);
             job.Schedule = schedule;
             job.Update();
             syncService.JobDefinitions.Add(job);
         }
         syncService.Update();
         Logger.WriteInfo("Feature activating complete");
     }
     catch (Exception ex)
     {
         Logger.WriteError(ex.ToString());
         throw;
     }
 }
        // Uncomment the method below to handle the event raised after a feature has been activated.
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb web = (SPWeb)properties.Feature.Parent;
            try
            {
                ProvisionWebParts(web);
                //Set WebPart Properties
                RemoveWebPart(web);
                AddNavigation(web);
                //CreateOverlapCalenday(web);
                EnableEmailNotify(web);

                EnsureSupervisorGroup(web);
                SetListPermission(web);

                SPWebApplication webApp = web.Site.WebApplication;
                BeachCampReminder beachCampJob = new BeachCampReminder(webApp);
                beachCampJob.Title = BeachCampReminder.BEACH_CAMP_JOB_NAME;
                DeleteJob(webApp.JobDefinitions, BeachCampReminder.BEACH_CAMP_JOB_NAME);
                SPDailySchedule dailySchedule = new SPDailySchedule();
                dailySchedule.BeginHour = 23;
                dailySchedule.BeginMinute = 0;
                dailySchedule.BeginSecond = 0;
                beachCampJob.Schedule = dailySchedule;
                beachCampJob.Update();

            }
            catch (Exception ex)
            {
                Utility.LogError(ex.Message, Util.BeachCampFeatures.BeachCamp);
            }
        }
Esempio n. 24
0
        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;
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Occurs after a Feature is activated.
        /// </summary>
        /// <param name="properties">An <see cref="T:Microsoft.SharePoint.SPFeatureReceiverProperties"></see> object that represents the properties of the event.</param>
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            // register the the current web
              //SPSite site = properties.Feature.Parent as SPSite;

            SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
              // make sure the job isn't already registered
              //foreach (SPJobDefinition job in site.WebApplication.JobDefinitions) {
            foreach (SPJobDefinition job in webApp.JobDefinitions)
            {
            if (job.Name == JOB_NAME)
              job.Delete();
              }

              // install the job
              //TimerJob myTimerJob = new TimerJob(JOB_NAME, site.WebApplication);
            TimerJob myTimerJob = new TimerJob(JOB_NAME, webApp);

            /*
              SPMinuteSchedule schedule = new SPMinuteSchedule();
              schedule.BeginSecond = 0;
              schedule.EndSecond = 59;
              schedule.Interval = 1;
              myTimerJob.Schedule = schedule;
              */

              SPSchedule schedule = null;
              SPDailySchedule dailySchedule = new SPDailySchedule();
              dailySchedule.BeginHour = 0;
              dailySchedule.BeginMinute = 0;
              dailySchedule.BeginSecond = 0;
              dailySchedule.EndHour = 0;
              dailySchedule.EndMinute =1;
              dailySchedule.EndSecond = 0;
              schedule = dailySchedule;
              myTimerJob.Schedule = schedule;

              myTimerJob.Update();
        }
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            try
            {
                var site = (SPSite)properties.Feature.Parent;
                using (var web = site.OpenWeb())
                {
                    web.AllowUnsafeUpdates = true;

                    SPList skillLabConfiglist = null;
                    SPList skillLabList = null;
                    SPList calendar = null;

                    // Skill Lab list operations
                    try
                    {
                        skillLabList = web.Lists.TryGetList(Utilities.SkillLabListName);
                        if (skillLabList == null)
                        {
                            //creating new list
                            var listUID = web.Lists.Add(Utilities.SkillLabListName, string.Empty,
                                                        SPListTemplateType.GenericList);
                            skillLabList = web.Lists[listUID];
                            skillLabList.OnQuickLaunch = true;
                            skillLabList.Update();
                        }

                        // adding columns to the list
                        SPField textField;
                        if (!skillLabList.Fields.ContainsField(Utilities.SkillColumnName))
                        {
                            skillLabList.Fields.Add(Utilities.SkillColumnName, SPFieldType.Text, true);
                            textField = skillLabList.Fields[Utilities.SkillColumnName];
                            textField.StaticName = Utilities.SkillColumnName;
                            textField.Update();
                            AddFieldOnView(skillLabList, skillLabList.Fields[Utilities.SkillColumnName]);
                        }

                        SPFieldUser studentUserField = null;
                        if (!skillLabList.Fields.ContainsField(Utilities.StudentColumnName))
                        {
                            skillLabList.Fields.Add(Utilities.StudentColumnName, SPFieldType.User, true);
                            studentUserField = (SPFieldUser)skillLabList.Fields[Utilities.StudentColumnName];
                            if (studentUserField != null)
                            {
                                studentUserField.AllowMultipleValues = false;
                                studentUserField.Presence = true;
                                studentUserField.SelectionMode = SPFieldUserSelectionMode.PeopleOnly;
                                studentUserField.StaticName = Utilities.StudentColumnName;
                                studentUserField.Update();
                            }
                            AddFieldOnView(skillLabList, skillLabList.Fields[Utilities.StudentColumnName]);
                        }
                        else
                            studentUserField = (SPFieldUser)skillLabList.Fields[Utilities.StudentColumnName];

                        SPFieldDateTime scheduleDateField = null;
                        if (!skillLabList.Fields.ContainsField(Utilities.ScheduleDateColumnName))
                        {
                            skillLabList.Fields.Add(Utilities.ScheduleDateColumnName, SPFieldType.DateTime, true);
                            scheduleDateField = (SPFieldDateTime)skillLabList.Fields[Utilities.ScheduleDateColumnName];
                            if (scheduleDateField != null)
                            {
                                scheduleDateField.DisplayFormat = SPDateTimeFieldFormatType.DateOnly;
                                scheduleDateField.StaticName = Utilities.ScheduleDateColumnName;
                                scheduleDateField.Update();
                            }
                            AddFieldOnView(skillLabList, skillLabList.Fields[Utilities.ScheduleDateColumnName]);
                        }
                        else
                            scheduleDateField = (SPFieldDateTime)skillLabList.Fields[Utilities.ScheduleDateColumnName];

                        if (!skillLabList.Fields.ContainsField(Utilities.TimeColumnName))
                        {
                            skillLabList.Fields.Add(Utilities.TimeColumnName, SPFieldType.Text, true);
                            textField = skillLabList.Fields[Utilities.TimeColumnName];
                            textField.StaticName = Utilities.TimeColumnName;
                            textField.Update();
                            AddFieldOnView(skillLabList, skillLabList.Fields[Utilities.TimeColumnName]);
                        }

                        //try
                        //{
                        // creating the view for students
                        //var viewFound =skillLabList.Views.Cast<SPView>().Any(spView =>spView.Title.ToLower().Trim() == Utilities.StudentsViewName.ToLower().Trim());
                        //if (!viewFound)
                        //{
                        //var stringCollection = new StringCollection
                        //                           {
                        //                               "Title",
                        //                               Utilities.SkillColumnName,
                        //                               Utilities.ScheduleDateColumnName,
                        //                               Utilities.TimeColumnName
                        //                           };
                        //if (scheduleDateField != null && studentUserField != null)
                        //{
                        //                                    string query = @"
                        //                                <Where>
                        //                                    <And>
                        //                                        <Gt>
                        //                                            <FieldRef Name='" +
                        //                                                   scheduleDateField.InternalName + @"' />
                        //                                            <Value IncludeTimeValue='FALSE' Type='DateTime'>[Today]</Value>
                        //                                        </Gt>
                        //                                        <Eq>
                        //                                            <FieldRef Name='" +
                        //                                                   studentUserField.InternalName + @"' /><Value Type='User'>[Me]</Value>
                        //                                        </Eq>
                        //                                    </And>
                        //                                </Where>";
                        //skillLabList.Views.Add(Utilities.StudentsViewName, stringCollection, query, 50, true,true);
                        //}
                        //}

                        // finally update the list for saving view
                        //skillLabList.Update();
                        //}
                        //catch (Exception ex)
                        //{
                        //    SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("BethesdaSkillLab", TraceSeverity.Medium, EventSeverity.Information), TraceSeverity.Medium, ex.Message);
                        //}
                    }
                    catch (Exception ex)
                    {
                        SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("BethesdaSkillLab", TraceSeverity.Medium, EventSeverity.Information), TraceSeverity.Medium, ex.Message);
                    }

                    try
                    {
                        // now need to create skill lab config list
                        skillLabConfiglist = web.Lists.TryGetList(Utilities.SkillLabConfigListName);
                        if (skillLabConfiglist == null)
                        {
                            //create list first
                            var listUid = web.Lists.Add(Utilities.SkillLabConfigListName, string.Empty,
                                                        SPListTemplateType.GenericList);
                            skillLabConfiglist = web.Lists[listUid];
                            skillLabConfiglist.OnQuickLaunch = true;
                            skillLabConfiglist.Update();
                        }

                        // adding fields here
                        if (!skillLabConfiglist.Fields.ContainsField(Utilities.SkillColumnName))
                        {
                            var titleField = (SPFieldText)skillLabConfiglist.Fields["Title"];
                            titleField.StaticName = "Skill";
                            titleField.Update();
                        }

                        SPFieldDateTime dateField = null;
                        if (!skillLabConfiglist.Fields.ContainsField(Utilities.StartDateColumnName))
                        {
                            skillLabConfiglist.Fields.Add(Utilities.StartDateColumnName, SPFieldType.DateTime, true);
                            dateField = (SPFieldDateTime)skillLabConfiglist.Fields[Utilities.StartDateColumnName];
                            dateField.DisplayFormat = SPDateTimeFieldFormatType.DateOnly;
                            dateField.StaticName = Utilities.StartDateColumnName;
                            dateField.Update();
                            AddFieldOnView(skillLabConfiglist, dateField);
                        }

                        if (!skillLabConfiglist.Fields.ContainsField(Utilities.EndDateColumnName))
                        {
                            skillLabConfiglist.Fields.Add(Utilities.EndDateColumnName, SPFieldType.DateTime, true);
                            dateField = (SPFieldDateTime)skillLabConfiglist.Fields[Utilities.EndDateColumnName];
                            dateField.DisplayFormat = SPDateTimeFieldFormatType.DateOnly;
                            dateField.StaticName = Utilities.EndDateColumnName;
                            dateField.Update();
                            AddFieldOnView(skillLabConfiglist, dateField);
                        }

                        /*if (!skillLabConfiglist.Fields.ContainsField(Utilities.TimeSlotColumnName))
                        {
                            skillLabConfiglist.Fields.Add(Utilities.TimeSlotColumnName, SPFieldType.Text, true);
                            textField = skillLabConfiglist.Fields[Utilities.TimeSlotColumnName];
                            textField.StaticName = Utilities.TimeSlotColumnName;
                            textField.Update();
                            AddFieldOnView(skillLabConfiglist, skillLabConfiglist.Fields[Utilities.TimeSlotColumnName]);
                        }*/

                        if (!skillLabConfiglist.Fields.ContainsField(Utilities.TimeSlotStartTimeColumnName))
                        {
                            skillLabConfiglist.Fields.Add(Utilities.TimeSlotStartTimeColumnName, SPFieldType.Choice,
                                                          true);
                            var choiceField =
                                (SPFieldChoice)skillLabConfiglist.Fields[Utilities.TimeSlotStartTimeColumnName];
                            choiceField.StaticName = Utilities.TimeSlotStartTimeColumnName;
                            choiceField.EditFormat = SPChoiceFormatType.Dropdown;
                            for (int time = 9; time < 13; time++)
                                choiceField.Choices.Add(time + " AM");
                            for (int time = 1; time < 6; time++)
                                choiceField.Choices.Add(time + " PM");
                            choiceField.Update();
                            AddFieldOnView(skillLabConfiglist,
                                           skillLabConfiglist.Fields[Utilities.TimeSlotStartTimeColumnName]);
                        }

                        if (!skillLabConfiglist.Fields.ContainsField(Utilities.TimeSlotEndTimeColumnName))
                        {
                            skillLabConfiglist.Fields.Add(Utilities.TimeSlotEndTimeColumnName, SPFieldType.Choice, true);
                            var choiceField =
                                (SPFieldChoice)skillLabConfiglist.Fields[Utilities.TimeSlotEndTimeColumnName];
                            choiceField.StaticName = Utilities.TimeSlotEndTimeColumnName;
                            choiceField.EditFormat = SPChoiceFormatType.Dropdown;
                            for (int time = 9; time < 13; time++)
                                choiceField.Choices.Add(time + " AM");
                            for (int time = 1; time < 6; time++)
                                choiceField.Choices.Add(time + " PM");
                            choiceField.Update();
                            AddFieldOnView(skillLabConfiglist,
                                           skillLabConfiglist.Fields[Utilities.TimeSlotEndTimeColumnName]);
                        }

                        skillLabConfiglist.Update();
                    }
                    catch (Exception ex)
                    {
                        SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("BethesdaSkillLab", TraceSeverity.Medium, EventSeverity.Information), TraceSeverity.Medium, ex.Message);
                    }

                    // creating user groups here
                    try
                    {
                        web.SiteGroups.Add(Utilities.StudentsGroupName, web.AllUsers[0], web.AllUsers[0], string.Empty);
                        web.SiteGroups.Add(Utilities.FacultyGroupName, web.AllUsers[0], web.AllUsers[0], string.Empty);
                        web.Update();
                    }
                    catch (Exception ex)
                    {
                        SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("BethesdaSkillLab", TraceSeverity.Medium, EventSeverity.Information), TraceSeverity.Medium, ex.Message);
                    }

                    // Creating Calendar and a view for viewing schedules
                    try
                    {
                        calendar = web.Lists.TryGetList(Utilities.CalendarListName);
                        if (calendar == null)
                        {
                            var uid = web.Lists.Add(Utilities.CalendarListName, string.Empty, SPListTemplateType.Events);
                            calendar = web.Lists[uid];
                            calendar.Fields.Add(Utilities.EventOwnerColumnName, SPFieldType.User, true);
                            var userField = (SPFieldUser)calendar.Fields[Utilities.EventOwnerColumnName];
                            userField.AllowMultipleValues = false;
                            userField.SelectionMode = SPFieldUserSelectionMode.PeopleOnly;
                            userField.Update();
                            calendar.OnQuickLaunch = true;
                            calendar.Update();

                            // creating a view for users
                            var viewFound = calendar.Views.Cast<SPView>().Any(spView => spView.Title.ToLower().Trim() == Utilities.StudentsViewName.ToLower().Trim());
                            if (!viewFound)
                            {
                                string query = @"
                                <Where>
                                        <Eq>
                                            <FieldRef Name='" + userField.InternalName + @"' /><Value Type='User'>[Me]</Value>
                                        </Eq>
                                </Where>";
                                SPView view = calendar.Views.Add(Utilities.StudentsViewName, calendar.DefaultView.ViewFields.ToStringCollection(), query, 50, true, true, SPViewCollection.SPViewType.Calendar, false);
                                view.Update();
                            }

                            // finally updating the list
                            calendar.Update();
                        }
                    }
                    catch (Exception ex)
                    {
                        SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("BethesdaSkillLab", TraceSeverity.Medium, EventSeverity.Information), TraceSeverity.Medium, ex.Message);
                    }

                    // modifying list permissions here
                    try
                    {
                        ModifyListPermissions(skillLabList);
                        ModifyListPermissions(skillLabConfiglist);
                        ModifyListPermissions(calendar);
                    }
                    catch (Exception ex)
                    {
                        SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("BethesdaSkillLab", TraceSeverity.Medium, EventSeverity.Information), TraceSeverity.Medium, ex.Message);
                    }

                    web.AllowUnsafeUpdates = false;
                }
            }
            catch (Exception ex)
            {
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("BethesdaSkillLab", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable, ex.Message, new object[] { ex.StackTrace });
            }

            // creating timer job for notification sending
            try
            {
                var site = (SPSite)properties.Feature.Parent;
                bool timerJobFound = site.WebApplication.JobDefinitions.Any(jobDefinition => jobDefinition.Title == Utilities.TimerJobName);
                if (!timerJobFound)
                {
                    var notificationJob = new NotificationTimerJob(Utilities.TimerJobName, site.WebApplication);
                    var dailySchedule = new SPDailySchedule
                                            {
                                                BeginHour = 0,
                                                BeginMinute = 0,
                                                BeginSecond = 0,
                                                EndHour = 1,
                                                EndMinute = 59,
                                                EndSecond = 59
                                            };
                    notificationJob.Schedule = dailySchedule;
                    notificationJob.Update();
                }
            }
            catch (Exception ex)
            {
                SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("BethesdaSkillLab", TraceSeverity.Monitorable, EventSeverity.Error), TraceSeverity.Monitorable, ex.Message, new object[] { ex.StackTrace });
            }
        }
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            //Adding Project Published Event Handling Code starts here
            MyUtilities.ErrorLog("Feature Event-Activated Started", EventLogEntryType.SuccessAudit);
            SPSite site = null;

            if (properties.Definition.Scope == SPFeatureScope.Site)
            {
                site = (SPSite)properties.Feature.Parent;
                var spWebApplication = site.WebApplication;
                // Creating the Project Server Events
                try
                {
                    using (var Site = new SPSite(site.Url))
                    {
                        var Events_Svc = new Events
                        {
                            UseDefaultCredentials = true,
                            AllowAutoRedirect     = true,
                            Url = (Site.Url + @"/_vti_bin/psi/Events.asmx")
                        };
                        string FilePath = SPUtility.GetGenericSetupPath(string.Empty) +
                                          @"\Template\layouts\ITXProjectGovernanceReport\ITXPGReportUtilities.dll";
                        if (!Utilities.CreatePSEvent(Events_Svc, FilePath, "WssInterop", "WssWorkspaceCreated",
                                                     "ITXPGReportconfigurationSync",
                                                     "For updating Project Governance Report, configuration list when a project workspace is created."))
                        {
                            MyUtilities.ErrorLog(
                                "Unable to Register WssInterop-WSssWorkspaceCreated event handler to project server. Please add manually using with the following details Assembly - ITXPGReportUtilities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=488363079fbfb28c , Class Name - ITXPGReportUtilities.ProjectWssWorkspaceCreatedEvent ",
                                EventLogEntryType.Error);
                        }
                    }
                }
                catch (Exception Ex1)
                {
                    MyUtilities.ErrorLog("Error at Registering event handler to project server due to : " + Ex1.Message, EventLogEntryType.Error);
                }

                if (spWebApplication != null)
                {
                    // Adding a Timejob in web application workspace permission synchronization
                    try
                    {
                        // Creating Timer Job if it not exists, otherwise skip
                        bool IsTimerJobFound = false;
                        // Make sure the job isn't already registered.
                        foreach (SPJobDefinition job in spWebApplication.JobDefinitions)
                        {
                            if (job.Name == PGReportJobDefinition._JOBNAME)
                            {
                                IsTimerJobFound = true;
                                break;
                            }
                        }
                        if (IsTimerJobFound == false)
                        {
                            // Install the job.
                            var jobDefinition = new PGReportJobDefinition(spWebApplication);
                            var Daily         = new SPDailySchedule {
                                BeginHour = 0
                            };
                            jobDefinition.Schedule = Daily;
                            jobDefinition.Update();
                        }
                    }
                    catch (Exception ex)
                    {
                        MyUtilities.ErrorLog("Error at Creating a Timer Job due to : " + ex.Message, EventLogEntryType.Error);
                    }
                }
            }
        }
        public override void Provision(SPWebProvisioningProperties props)
        {
            SPWeb  eCaseRootWeb  = props.Web;
            SPSite eCaseRootSite = eCaseRootWeb.Site;

            eCaseRootWeb.ApplyWebTemplate("SusDebRootWeb");

            #region Create & Configure the eCase FAST Search Site
            SPWebTemplate eCaseFastSrchCtrSiteDef = eCaseRootSite.GetWebTemplates(1033)["SusDebFastSearchSiteDef#0"];
            using (SPWeb eCaseFastSrchCtr = eCaseRootWeb.Webs.Add(ECASE_SRCH_CTR_URL, ECASE_SRCH_CTR_TITLE, ECASE_SRCH_CTR_DESC, 1033, eCaseFastSrchCtrSiteDef, false, false))
            {
                // Display Ribbon by default
                eCaseFastSrchCtr.AllProperties["__DisplayShowHideRibbonActionId"] = false.ToString();

                #region Configure Site Collection Search Center settings
                eCaseRootWeb.AllProperties["SRCH_ENH_FTR_URL"]         = eCaseFastSrchCtr.Url + "/pages";
                eCaseRootWeb.AllProperties["SRCH_SITE_DROPDOWN_MODE"]  = "ShowDD";
                eCaseRootWeb.AllProperties["SRCH_TRAGET_RESULTS_PAGE"] = eCaseFastSrchCtr.Url + "/pages/results.aspx";
                eCaseRootWeb.Update();
                #endregion

                #region Set MasterPage
                try
                {
                    // Get the masterpage
                    SPFile eCaseSrchMaster = eCaseRootWeb.GetFile(eCaseRootWeb.Url + "/_catalogs/masterpage/eCase_minimal.master");
                    // eCaseFastSrchCtr.MasterUrl = eCaseSrchMaster.ServerRelativeUrl; /* DO NOT APPLY TO SYSTEM PAGES */
                    eCaseFastSrchCtr.CustomMasterUrl = eCaseSrchMaster.ServerRelativeUrl;
                    eCaseFastSrchCtr.Update();
                }
                catch (Exception x)
                {
                    Logger.Instance.Error(string.Format("Failed to set master page in SusDeb FAST Search Center at {0}", eCaseFastSrchCtr.Url),
                                          x, DiagnosticsCategories.eCaseSearch);
                }
                #endregion

                #region Populate Search Tabs Lists
                try
                {
                    #region Create SearchResults Tabs List
                    Guid srchResultsGuid = eCaseFastSrchCtr.Lists.Add("Tabs in Search Results", "Use this list to store the tabs displayed in search results.",
                                                                      "SearchResults", "285dfda8-ae65-4ac1-8f6a-39ff7187bba9", 301, "100", SPListTemplate.QuickLaunchOptions.Off);
                    SPList     srchResultsList = eCaseFastSrchCtr.Lists[srchResultsGuid];
                    SPListItem resultsAspx     = srchResultsList.AddItem();
                    resultsAspx[eCaseConstants.FieldGuids.TABS_LIST_TAB_NAME] = "All Sites";
                    resultsAspx[eCaseConstants.FieldGuids.TABS_LIST_PAGE]     = "results.aspx";
                    resultsAspx[eCaseConstants.FieldGuids.TABS_LIST_TOOLTIP]  = "Click for results from All Sites";
                    resultsAspx.Update();
                    SPListItem peopleResultsAspx = srchResultsList.AddItem();
                    peopleResultsAspx[eCaseConstants.FieldGuids.TABS_LIST_TAB_NAME] = "People";
                    peopleResultsAspx[eCaseConstants.FieldGuids.TABS_LIST_PAGE]     = "peopleresults.aspx";
                    peopleResultsAspx[eCaseConstants.FieldGuids.TABS_LIST_TOOLTIP]  = "Click for people results";
                    peopleResultsAspx.Update();
                    #endregion

                    #region Create SearchCenter Tabs List
                    Guid srchCenterGuid = eCaseFastSrchCtr.Lists.Add("Tabs in Search Pages", "Use this list to store the tabs displayed in the default blank search pages.",
                                                                     "SearchCenter", "285dfda8-ae65-4ac1-8f6a-39ff7187bba9", 301, "100", SPListTemplate.QuickLaunchOptions.Off);
                    SPList     srchCenterList = eCaseFastSrchCtr.Lists[srchCenterGuid];
                    SPListItem defaultAspx    = srchCenterList.AddItem();
                    defaultAspx[eCaseConstants.FieldGuids.TABS_LIST_TAB_NAME] = "All Sites";
                    defaultAspx[eCaseConstants.FieldGuids.TABS_LIST_PAGE]     = "default.aspx";
                    defaultAspx[eCaseConstants.FieldGuids.TABS_LIST_TOOLTIP]  = "Click for results from All Sites";
                    defaultAspx.Update();
                    SPListItem advancedAspx = srchCenterList.AddItem();
                    advancedAspx[eCaseConstants.FieldGuids.TABS_LIST_TAB_NAME] = "All Sites";
                    advancedAspx[eCaseConstants.FieldGuids.TABS_LIST_PAGE]     = "advanced.aspx";
                    advancedAspx[eCaseConstants.FieldGuids.TABS_LIST_TOOLTIP]  = "Click for results from All Sites";
                    advancedAspx.Update();
                    SPListItem peopleAspx = srchCenterList.AddItem();
                    peopleAspx[eCaseConstants.FieldGuids.TABS_LIST_TAB_NAME] = "People";
                    peopleAspx[eCaseConstants.FieldGuids.TABS_LIST_PAGE]     = "people.aspx";
                    peopleAspx[eCaseConstants.FieldGuids.TABS_LIST_TOOLTIP]  = "Click for people results";
                    peopleAspx.Update();
                    #endregion
                }
                catch (Exception x)
                {
                    Logger.Instance.Error(string.Format("Failed to create Tabs lists in eCase FAST Search Center at {0}", eCaseFastSrchCtr.Url), x, DiagnosticsCategories.eCaseSearch);
                }
                #endregion
            }
            #endregion

            #region Create a Daily Schedule for the UpdateNextDueDate Timer Job
            string jobName = string.Format(UPDATE_NEXT_DUE_DATE_TIMER_JOB_NAME, eCaseRootSite.ServerRelativeUrl);
            foreach (SPJobDefinition job in eCaseRootSite.WebApplication.JobDefinitions)
            {
                if (job.Name == jobName)
                {
                    job.Delete();
                }
            }

            // Install the job.
            UpdateNextDueDateTimerJob unddTimerJob = new UpdateNextDueDateTimerJob(jobName, eCaseRootSite.WebApplication, null, SPJobLockType.Job, eCaseRootSite.ID.ToString());

            SPDailySchedule schedule = new SPDailySchedule();
            schedule.BeginHour    = 1;
            schedule.EndHour      = 2;
            unddTimerJob.Schedule = schedule;
            unddTimerJob.Update();

            #endregion
        }
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            //Adding Project Published Event Handling Code starts here
            MyUtilities.ErrorLog("Feature Event-Activated Started", EventLogEntryType.SuccessAudit);
            SPSite site = null;
            if (properties.Definition.Scope == SPFeatureScope.Site)
            {
                site = (SPSite)properties.Feature.Parent;
                var spWebApplication = site.WebApplication;
                // Creating the Project Server Events
                try
                {
                    using (var Site = new SPSite(site.Url))
                    {
                        var Events_Svc = new Events
                                             {
                                                 UseDefaultCredentials = true,
                                                 AllowAutoRedirect = true,
                                                 Url = (Site.Url + @"/_vti_bin/psi/Events.asmx")
                                             };
                        string FilePath = SPUtility.GetGenericSetupPath(string.Empty) +
                                          @"\Template\layouts\ITXProjectGovernanceReport\ITXPGReportUtilities.dll";
                        if (!Utilities.CreatePSEvent(Events_Svc, FilePath, "WssInterop", "WssWorkspaceCreated",
                                                     "ITXPGReportconfigurationSync",
                                                     "For updating Project Governance Report, configuration list when a project workspace is created."))
                        {
                            MyUtilities.ErrorLog(
                                "Unable to Register WssInterop-WSssWorkspaceCreated event handler to project server. Please add manually using with the following details Assembly - ITXPGReportUtilities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=488363079fbfb28c , Class Name - ITXPGReportUtilities.ProjectWssWorkspaceCreatedEvent ",
                                EventLogEntryType.Error);
                        }
                    }
                }
                catch (Exception Ex1)
                {
                    MyUtilities.ErrorLog("Error at Registering event handler to project server due to : " + Ex1.Message, EventLogEntryType.Error);
                }

                if (spWebApplication != null)
                {
                    // Adding a Timejob in web application workspace permission synchronization
                    try
                    {
                        // Creating Timer Job if it not exists, otherwise skip
                        bool IsTimerJobFound = false;
                        // Make sure the job isn't already registered.
                        foreach (SPJobDefinition job in spWebApplication.JobDefinitions)
                        {
                            if (job.Name == PGReportJobDefinition._JOBNAME)
                            {
                                IsTimerJobFound = true;
                                break;
                            }
                        }
                        if (IsTimerJobFound == false)
                        {
                            // Install the job.
                            var jobDefinition = new PGReportJobDefinition(spWebApplication);
                            var Daily = new SPDailySchedule { BeginHour = 0 };
                            jobDefinition.Schedule = Daily;
                            jobDefinition.Update();
                        }
                    }
                    catch (Exception ex)
                    {
                        MyUtilities.ErrorLog("Error at Creating a Timer Job due to : " + ex.Message, EventLogEntryType.Error);
                    }
                }
            }
        }
Esempio n. 30
0
        // Uncomment the method below to handle the event raised after a feature has been activated.

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            WBLogging.Generic.HighLevel("TimerJobsEventReceiver.FeatureActivated(): Activating the WBF Timer Jobs feature");

            SPWebApplication webApplication = properties.Feature.Parent as SPWebApplication;

            bool onSharePointHub = false;

            if (webApplication.Name.ToLower().Contains("sharepointhub"))
            {
                onSharePointHub = true;
            }

            foreach (SPAlternateUrl alternateUrl in webApplication.AlternateUrls)
            {
                if (alternateUrl.IncomingUrl.ToString().ToLower() == "http://sharepointhub/")
                {
                    onSharePointHub = true;
                    break;
                }
            }

            // So if we're not on the SharePointHub web application then we'll just end the activation process here:
            if (!onSharePointHub)
            {
                WBLogging.Generic.HighLevel("TimerJobsEventReceiver.FeatureActivated(): No activation is being done as we are on: " + webApplication.Name);
                return;
            }

            WBLogging.Generic.Verbose("TimerJobsEventReceiver.FeatureActivated(): Activation is happening on SharePointHub.");

            // make sure the job isn't already registered
            foreach (SPJobDefinition job in webApplication.JobDefinitions)
            {
                if (job.Name == WBTimerTasksJob.DAILY_TIMER_TASKS__TIMER_JOB_NAME)
                {
                    job.Delete();
                }

                if (job.Name == WBTimerTasksJob.FREQUENT_TIMER_TASKS__TIMER_JOB_NAME)
                {
                    job.Delete();
                }

                if (job.Name == WBMigrationTimerJob.MIGRATION_TIMER_JOB__TIMER_JOB_NAME)
                {
                    job.Delete();
                }
            }

            SPServer server = null;
            WBFarm   farm   = WBFarm.Local;

            if (farm.TimerJobsServerName != "")
            {
                server = farm.SPFarm.Servers[farm.TimerJobsServerName];

                if (server != null)
                {
                    /* */
                    /* First adding the Daily Timer Job  */
                    /* */

                    WBLogging.Generic.HighLevel("TimerJobsEventReceiver.FeatureActivated(): Adding a timer job to server : " + server.Name + " with name: " + WBTimerTasksJob.DAILY_TIMER_TASKS__TIMER_JOB_NAME);

                    WBTimerTasksJob timerJob = new WBTimerTasksJob(
                        WBTimerTasksJob.DAILY_TIMER_TASKS__TIMER_JOB_NAME,
                        WBTimerTasksJob.DAILY_TIMER_TASKS__LIST_NAME,
                        WBTimerTasksJob.DAILY_TIMER_TASKS__ORDERED_VIEW_NAME,
                        webApplication,
                        server,
                        SPJobLockType.Job);

                    SPDailySchedule schedule = new SPDailySchedule();

                    schedule.BeginHour   = 5;
                    schedule.BeginMinute = 0;
                    schedule.BeginSecond = 0;

                    schedule.EndHour   = 5;
                    schedule.EndMinute = 10;
                    schedule.EndSecond = 0;

                    timerJob.Schedule = schedule;

                    timerJob.Update();

                    /* */
                    /* Now adding the Frequent Timer Job  */
                    /* */

                    WBLogging.Generic.HighLevel("TimerJobsEventReceiver.FeatureActivated(): Adding a timer job to server : " + server.Name + " with name: " + WBTimerTasksJob.FREQUENT_TIMER_TASKS__TIMER_JOB_NAME);

                    WBTimerTasksJob frequentTimerJob = new WBTimerTasksJob(
                        WBTimerTasksJob.FREQUENT_TIMER_TASKS__TIMER_JOB_NAME,
                        WBTimerTasksJob.FREQUENT_TIMER_TASKS__LIST_NAME,
                        WBTimerTasksJob.FREQUENT_TIMER_TASKS__ORDERED_VIEW_NAME,
                        webApplication,
                        server,
                        SPJobLockType.Job);

                    SPMinuteSchedule frequentSchedule = new SPMinuteSchedule();

                    frequentSchedule.BeginSecond = 0;
                    frequentSchedule.EndSecond   = 59;
                    frequentSchedule.Interval    = 10;

                    frequentTimerJob.Schedule = frequentSchedule;

                    frequentTimerJob.Update();


                    /* */
                    /* Now adding the Mirgation Timer Job  */
                    /* */

                    WBLogging.Generic.HighLevel("TimerJobsEventReceiver.FeatureActivated(): Adding a timer job to server : " + server.Name + " with name: " + WBMigrationTimerJob.MIGRATION_TIMER_JOB__TIMER_JOB_NAME);

                    WBMigrationTimerJob migrationTimerJob = new WBMigrationTimerJob(
                        WBMigrationTimerJob.MIGRATION_TIMER_JOB__TIMER_JOB_NAME,
                        webApplication,
                        server,
                        SPJobLockType.Job);

                    SPWeeklySchedule migrationTimerJobSchedule = new SPWeeklySchedule();
                    migrationTimerJobSchedule.BeginDayOfWeek = System.DayOfWeek.Monday;
                    migrationTimerJobSchedule.BeginHour      = 5;
                    migrationTimerJobSchedule.BeginMinute    = 0;
                    migrationTimerJobSchedule.BeginSecond    = 0;

                    migrationTimerJobSchedule.EndDayOfWeek = System.DayOfWeek.Monday;
                    migrationTimerJobSchedule.EndHour      = 5;
                    migrationTimerJobSchedule.EndMinute    = 10;
                    migrationTimerJobSchedule.EndSecond    = 0;

                    migrationTimerJob.Schedule = migrationTimerJobSchedule;

                    migrationTimerJob.Update();
                }
                else
                {
                    WBLogging.Generic.Unexpected("TimerJobsEventReceiver.FeatureActivated(): Couldn't find the server with the name: " + farm.TimerJobsServerName);
                }
            }
            else
            {
                WBLogging.Generic.Unexpected("TimerJobsEventReceiver.FeatureActivated(): The WBF farm wide setting of which server to use for the timer job has not been set.");
            }
        }