1

I've a solution sharepoint 2010 for a job that i want to update. So i did in powershell an update-spsolution and restart sharepoint timer job

For testing, i changed the start hour in event of my job. I see the change when i go to my central administration where i go to run manually my job.

Unfortunately, at beginning of my method execute, i modify in ULS Log and my log didn't change. (For information i see log in my event job featureactivated) Here is how i'm writing job

public class JobMail : SPJobDefinition
{
    public JobMail()
        : base()
    {
    }
    public JobMail(string jobName, SPService service, SPServer server, SPJobLockType targetType)
        : base(jobName, service, server, targetType)
    {
    }
    public JobMail(string jobName, SPWebApplication webApplication)
        : base(jobName, webApplication, null, SPJobLockType.ContentDatabase)
    {
        this.Title = "Mailing journalier de nouveaux rapports";
    }

    public override void Execute(Guid contentDbId)
    {
        SPDiagnosticsService diagSvc = SPDiagnosticsService.Local;
        diagSvc.WriteTrace(0, new SPDiagnosticsCategory("Job mailing", TraceSeverity.High, EventSeverity.Information), TraceSeverity.High, "Start Execute");
        Sync.DoSync(this.Properties["site"].ToString());
    }
}

And here the code of my event job

    using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Administration;
using TEST.jobmailing;

namespace TEST.jobmailing.Features.MailingJob
{
    /// <summary>
    /// Cette classe gère les événements déclenchés lors de l'activation, la désactivation, l'installation, la désinstallation et la mise à niveau de fonctions.
    /// </summary>
    /// <remarks>
    /// Le GUID attaché à cette classe peut être utilisé lors de la compression et ne doit pas être modifié.
    /// </remarks>

    [Guid("35732602-3025-4d29-ad71-07806fbd6919")]
    public class MailingJobEventReceiver : SPFeatureReceiver
    {
        private static SPDiagnosticsService diagSvc = SPDiagnosticsService.Local;
        // Supprimez les marques de commentaire de la méthode ci-dessous pour gérer l'événement déclenché après l'activation d'une fonction.
        const string List_JOB_NAME = "MailingNewItem";

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            base.FeatureActivated(properties);
            // THE ORIGINAL VALUE OF REMOTE ADMINISTRATOR
            var remoteAdministratorAccessDenied = SPWebService.ContentService.RemoteAdministratorAccessDenied;

            try
            {
                // SET THE REMOTE ADMINISTATOR ACCESS DENIED FALSE
                SPWebService.ContentService.RemoteAdministratorAccessDenied = false;
                SPSite site = new SPSite("http://roma:7001");//properties.Feature.Parent as SPSite;
                diagSvc.WriteTrace(0, new SPDiagnosticsCategory("Job mailing", TraceSeverity.Monitorable, EventSeverity.Information), TraceSeverity.Monitorable, "FeatureActivated Start parenturl: " + site.Url);
                // 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
                JobMail listLoggerJob = new JobMail(List_JOB_NAME, site.WebApplication);
                SPDailySchedule schedule = new SPDailySchedule();
                schedule.BeginMinute = 0;
                schedule.BeginHour = 4;
                schedule.EndHour = 6;
                schedule.EndMinute = 1;
                listLoggerJob.Schedule = schedule;
                listLoggerJob.Properties.Add("site", site.Url);
                listLoggerJob.Update();
                site.WebApplication.JobDefinitions.Add(listLoggerJob);
                site.WebApplication.Update();
                diagSvc.WriteTrace(0, new SPDiagnosticsCategory("Job mailing", TraceSeverity.Unexpected, EventSeverity.ErrorCritical), TraceSeverity.Unexpected, "FeatureActivated End: " + site.Url);

            }
            catch(Exception ex) {
                diagSvc.WriteTrace(0, new SPDiagnosticsCategory("Job mailing", TraceSeverity.Unexpected, EventSeverity.ErrorCritical), TraceSeverity.Unexpected, "FeatureActivated: " + ex.ToString());
            }
            finally
            {

                // SET THE REMOTE ADMINISTATOR ACCESS DENIED BACK WHAT 
                // IT WAS
                SPWebService.ContentService.RemoteAdministratorAccessDenied = remoteAdministratorAccessDenied;
            }
        }


        // Supprimez les marques de commentaire de la méthode ci-dessous pour gérer l'événement déclenché avant la désactivation d'une fonction.

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            base.FeatureActivated(properties);
            // THE ORIGINAL VALUE OF REMOTE ADMINISTRATOR
            var remoteAdministratorAccessDenied = SPWebService.ContentService.RemoteAdministratorAccessDenied;
            try
            {
                // SET THE REMOTE ADMINISTATOR ACCESS DENIED FALSE
                SPWebService.ContentService.RemoteAdministratorAccessDenied = false;


                SPSite site = properties.Feature.Parent as SPSite;
                // delete the job
                foreach (SPJobDefinition job in site.WebApplication.JobDefinitions)
                {
                    if (job.Name == List_JOB_NAME)
                        job.Delete();

                }
            }
            catch (Exception ex)
            {
                diagSvc.WriteTrace(0, new SPDiagnosticsCategory("Job mailing", TraceSeverity.Unexpected, EventSeverity.ErrorCritical), TraceSeverity.Unexpected, "FeatureDeactivating: " + ex.ToString());
            }
            finally
            {

                // SET THE REMOTE ADMINISTATOR ACCESS DENIED BACK WHAT 
                // IT WAS
                SPWebService.ContentService.RemoteAdministratorAccessDenied = remoteAdministratorAccessDenied;
            }
        }


        // Supprimez les marques de commentaire de la méthode ci-dessous pour gérer l'événement déclenché après l'installation d'une fonction.

        //public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        //{
        //}


        // Supprimez les marques de commentaire de la méthode ci-dessous pour gérer l'événement déclenché avant la désinstallation d'une fonction.

        //public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        //{
        //}

        // Supprimez les marques de commentaire de la méthode ci-dessous pour gérer l'événement déclenché lors de la mise à niveau d'une fonction.

        //public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters)
        //{
        //}
    }
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.