예제 #1
0
 public override void Execute(Guid targetInstanceId)
 {
     MyUtilities.ErrorLog("The Process Started at " + DateTime.Now.ToString(), EventLogEntryType.SuccessAudit);
     try
     {
         foreach (SPSite Site in WebApplication.Sites)
         {
             foreach (SPFeature Feature in Site.Features)
             {
                 try
                 {
                     if (Feature.Definition.DisplayName == MyUtilities.SPFeatureName)
                     {
                         if (Feature.Definition.ActivateOnDefault)
                         {
                             SPList configurationList = MyUtilities.GetConfigurationList(Site);
                             if (configurationList != null)
                             {
                                 // define project server web service
                                 var Project_Svc = new Project
                                 {
                                     Url = Site.Url + "/_vti_bin/psi/project.asmx",
                                     UseDefaultCredentials = true,
                                     AllowAutoRedirect     = true
                                 };
                                 ProjectDataSet ProjectList = Project_Svc.ReadProjectList();
                                 foreach (ProjectDataSet.ProjectRow PRow in ProjectList.Project.Rows)
                                 {
                                     MyUtilities.CheckandAddEntry(configurationList, PRow.PROJ_UID, Project_Svc);
                                 }
                             }
                             break;
                         }
                     }
                 }
                 catch (Exception) { }
             }
         }
     }
     catch (Exception ex)
     {
         MyUtilities.ErrorLog("Error at timer job while synchronizing configuration list due to " + ex.Message, EventLogEntryType.Error);
     }
     try
     {
         var weeklySchedule = new SPWeeklySchedule()
         {
             BeginHour = 0, BeginDayOfWeek = DayOfWeek.Sunday
         };
         Schedule = weeklySchedule;
         Update();
         base.Execute(targetInstanceId);
     }
     catch (Exception ex)
     {
         MyUtilities.ErrorLog("Error at timer job while updating its schedule due to " + ex.Message, EventLogEntryType.Error);
     }
 }
 public override void Execute(Guid targetInstanceId)
 {
     MyUtilities.ErrorLog("The Process Started at " + DateTime.Now.ToString(), EventLogEntryType.SuccessAudit);
     try
     {
         foreach (SPSite Site in WebApplication.Sites)
         {
             foreach (SPFeature Feature in Site.Features)
             {
                 try
                 {
                     if (Feature.Definition.DisplayName == MyUtilities.SPFeatureName)
                     {
                         if (Feature.Definition.ActivateOnDefault)
                         {
                             SPList configurationList = MyUtilities.GetConfigurationList(Site);
                             if (configurationList != null)
                             {
                                 // define project server web service
                                 var Project_Svc = new Project
                                 {
                                     Url = Site.Url + "/_vti_bin/psi/project.asmx",
                                     UseDefaultCredentials = true,
                                     AllowAutoRedirect = true
                                 };
                                 ProjectDataSet ProjectList = Project_Svc.ReadProjectList();
                                 foreach (ProjectDataSet.ProjectRow PRow in ProjectList.Project.Rows)
                                 {
                                     MyUtilities.CheckandAddEntry(configurationList, PRow.PROJ_UID, Project_Svc);
                                 }
                             }
                             break;
                         }
                     }
                 }
                 catch (Exception) { }
             }
         }
     }
     catch (Exception ex)
     {
         MyUtilities.ErrorLog("Error at timer job while synchronizing configuration list due to " + ex.Message, EventLogEntryType.Error);
     }
     try
     {
         var weeklySchedule = new SPWeeklySchedule() { BeginHour = 0, BeginDayOfWeek = DayOfWeek.Sunday };
         Schedule = weeklySchedule;
         Update();
         base.Execute(targetInstanceId);
     }
     catch (Exception ex)
     {
         MyUtilities.ErrorLog("Error at timer job while updating its schedule due to " + ex.Message, EventLogEntryType.Error);
     }
 }
예제 #3
0
        // Uncomment the method below to handle the event raised after a feature has been activated.

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

            RemoveFeatureIfExist(webApp);

            var schedule = new ProcessInstructorSchedules(JobName, webApp, SPServer.Local, SPJobLockType.Job)
            {
                Title = JobName
            };
            var weekly = new SPWeeklySchedule();

            weekly.BeginDayOfWeek = DayOfWeek.Friday;
            weekly.BeginHour      = 16;
            weekly.EndDayOfWeek   = DayOfWeek.Friday;
            weekly.EndHour        = 17;
            schedule.Schedule     = weekly;
            schedule.Update();
        }
예제 #4
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.");
            }
        }
예제 #5
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;
            }
        }
 public MigrationContentJob(string jobName, SPWebApplication webApplication)
     : base(jobName, webApplication, null, SPJobLockType.ContentDatabase)
 {
     Title = Constants.MigrationContentJobTitle;
     Schedule = new SPWeeklySchedule { BeginDayOfWeek = DayOfWeek.Sunday, EndDayOfWeek = DayOfWeek.Sunday, BeginHour = 21, EndHour = 23 };
 }
예제 #7
0
    private SPSchedule BuildWeeklySchedule()
    {
        int beginHour = 0;

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

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

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

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

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

        if (EndWSecondTextBox.Text.Length > 0)
        {
            int.TryParse(EndWSecondTextBox.Text, out endSecond);
        }

        var schedule = new SPWeeklySchedule {
            BeginDayOfWeek = DayOfWeek.Monday
        };

        switch (BeginWDayDropDownList.SelectedIndex)
        {
        case 0:
            schedule.BeginDayOfWeek = DayOfWeek.Monday;
            break;

        case 1:
            schedule.BeginDayOfWeek = DayOfWeek.Tuesday;
            break;

        case 2:
            schedule.BeginDayOfWeek = DayOfWeek.Wednesday;
            break;

        case 3:
            schedule.BeginDayOfWeek = DayOfWeek.Thursday;
            break;

        case 4:
            schedule.BeginDayOfWeek = DayOfWeek.Friday;
            break;

        case 5:
            schedule.BeginDayOfWeek = DayOfWeek.Saturday;
            break;

        case 6:
            schedule.BeginDayOfWeek = DayOfWeek.Sunday;
            break;
        }

        switch (EndWDayDropDownList.SelectedIndex)
        {
        case 1:
            schedule.EndDayOfWeek = DayOfWeek.Monday;
            break;

        case 2:
            schedule.EndDayOfWeek = DayOfWeek.Tuesday;
            break;

        case 3:
            schedule.EndDayOfWeek = DayOfWeek.Wednesday;
            break;

        case 4:
            schedule.EndDayOfWeek = DayOfWeek.Thursday;
            break;

        case 5:
            schedule.EndDayOfWeek = DayOfWeek.Friday;
            break;

        case 6:
            schedule.EndDayOfWeek = DayOfWeek.Saturday;
            break;

        case 7:
            schedule.EndDayOfWeek = DayOfWeek.Sunday;
            break;
        }

        schedule.BeginHour    = beginHour;
        schedule.BeginMinute  = beginMinute;
        schedule.BeginSecond  = beginSecond;
        schedule.EndDayOfWeek = DayOfWeek.Monday;
        schedule.EndHour      = endHour;
        schedule.EndMinute    = endMinute;
        schedule.EndSecond    = endSecond;

        return(schedule);
    }