0

SharePoint Web アプリケーションの 1 つのタイマー ジョブを開発しました。SPJobdefinition クラスからジョブを作成しました。

public class EraseUsersJob : SPJobDefinition
    {
        #region constants
        public struct Constantes
        {
            public const string JOB_NAME = "EraseUsers";
            public const string JOB_TITLE = "Erase Users";
        }
        #endregion

        #region constructors
        public EraseUsersJob() : base() { }

        public EraseUsersJob(string jobName,
                       SPService service,
                       SPServer server,
                       SPJobLockType targetType)
            : base(jobName, service, server, targetType) { }

        public EraseUsersJob(SPWebApplication webApplication)
            : this(Constantes.JOB_NAME, webApplication)
        {
        }

        public EraseUsersJob(string jobName, SPWebApplication webApplication)
            : base(jobName, webApplication, null, SPJobLockType.Job)
        {
            this.Title = Constantes.JOB_TITLE;
        }
        #endregion

        #region override
        public override void Execute(Guid targetInstanceId)
        {
        //my code
        }
        // my private methods used in execute() method

次に、コンソール プログラム内で、SPWebApplication 引数を指定したコンストラクターを使用して、このジョブの新しいインスタンスを作成します。次に、仕事のスケジュールを設定して更新します。私の問題は、タイマー ジョブが SharePoint 管理で作成されているかどうかを確認すると、作成されていないことがわかります。何か不足していますか?詳細または追加情報が必要な場合は、それを提供します。

編集: これが私の Program.cs です:

class Program
{
    static void Main(string[] args)
    {
        try
        {
            SPWebApplication webApplication = SPWebApplication.Lookup(new Uri("http://XXXXX:80"));
            //Console.WriteLine("Installing EraseUsers job  ...");
            JobManager jobsManager = new JobManager();
            jobsManager.ApplyJobs(webApplication);
        }
        catch (Exception e)
        {
            Console.WriteLine("ERROR: "+e.Message);
        }

    }

これが私のジョブマネージャークラスです:

public class JobManager : DeployJobHelper 
{
    public void ApplyJobs(SPWebApplication webApplication) 
    {            
        try
        {
            Console.WriteLine("         Installing EraseUsersJob");
            EraseUsersJob eraseUsersJob= new EraseUsersJob(webApplication);
            this.ApplyJob(webApplication, eraseUsersJob);
        }
        catch (Exception ex)
        {
            Console.WriteLine("                 Error: " + ex.Message + " // " + ex.StackTrace);
        }

        Console.WriteLine("         Job installation finished.");
    }
}

これが私のDeployHelper.csです:

public class DeployJobHelper
{
 protected void ApplyJob(SPWebApplication webApplication, SPJobDefinition jobDefinition)
    {
        string jobName = jobDefinition.Name;
        // delete previous Job definition
        webApplication.DeleteJobByName(jobName);
        //Install Job
        jobDefinition.Schedule = new SPMinuteSchedule() { BeginSecond=0, EndSecond=50,Interval=2 }; //GetScheduleValue(jobName);
        jobDefinition.Update();
    }
}

さらに、ULS で次のエラーが表示されました。

SharePoint cannot deserialize an object of type XyZ.AbC.EraseUsersJob.EraseUsersJob, XyZ.AbC.EraseUsersJob, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null on this machine.  This typically occurs because the assembly containing this type is not installed on this machine.  In this case, this message can be safely ignored.  Otherwise, the assembly needs to be installed on this machine in a location that can be discovered by the .NET Framework.

このエラーは、Windows Sharepoint Services タイマーの再起動または名前空間の問題と関係があると読みました。既に Windows SharePoint Services タイマーを再起動しており、すべてのクラスが XyZ.AbC.EraseUsersJob 名前空間内にラップされています。

4

0 に答える 0