ContentDeploymentJob - Classe

Définit les détails d'un travail de déploiement de contenu.

Hiérarchie d’héritage

System.Object
  Microsoft.SharePoint.Publishing.ListItemWrapper
    Microsoft.SharePoint.Publishing.DisposableListItemWrapper
      Microsoft.SharePoint.Publishing.Administration.ContentDeploymentJob

Espace de noms :  Microsoft.SharePoint.Publishing.Administration
Assembly :  Microsoft.SharePoint.Publishing (dans Microsoft.SharePoint.Publishing.dll)

Syntaxe

'Déclaration
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class ContentDeploymentJob _
    Inherits DisposableListItemWrapper
'Utilisation
Dim instance As ContentDeploymentJob
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class ContentDeploymentJob : DisposableListItemWrapper

Remarques

Un travail de déploiement de contenu se compose des propriétés suivantes.

Nom de la propriété

Description

Name

Fournit le nom de la tâche de déploiement de contenu.

Description

Décrit le travail de déploiement de contenu.

Path

Fournit le chemin d'accès associé à ce travail de déploiement de contenu.

JobType

Définit s'il s'agit d'un déploiement de contenu complet ou partiel.

IsRecurring

Définit s'il s'agit d'un déploiement de contenu unique ou périodique.

NotificationSettings

Définit si et quand pour envoyer des notifications de courrier électronique lors du déploiement de contenu réussit ou échoue.

ExportMethod

Détermine s'il faut exporter toutes les modifications apportées à la fois ou de manière incrémentielle.

Exemples

using System;
using Microsoft.SharePoint.Publishing.Administration;
using Microsoft.SharePoint;

namespace Microsoft.SDK.SharePoint.Samples.ContentDeployemnt
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("--------------------------------------");
            Console.WriteLine("starting sample tests execution...");

            #region ContentDeploymentJob.SqlSnapshotSetting example
            
            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.SqlSnapshotSetting example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            //
            // To compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                // set the job to create and use a Sql Snapshot for export
                job.SqlSnapshotSetting = ContentDeploymentSqlSnapshotSetting.CreateNew;
                job.Update();

                try
                {
                    // the job will run using a newly created sql snapshot for export operation
                    job.Run();

                    Console.WriteLine("Job's execution completed. Job's status is: " + job.LastStatus.ToString() + "; Job's status message is: " + job.LastStatusMessage);
                }
                catch (ContentDeploymentException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (SPException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());

                    throw;
                }
            }

            #endregion

            // ---------------------------------------------------------------------------------------
            // restore the job's settings back to default
            // ---------------------------------------------------------------------------------------
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                job.SqlSnapshotSetting = ContentDeploymentSqlSnapshotSetting.None;
                job.Update();
            }

            #region ContentDeploymentJob.HostingSupportEnabled example

            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.HostingSupportEnabled example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            //
            // To compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                job.HostingSupportEnabled = true;
                job.Update();
            }

            #endregion

            // ---------------------------------------------------------------------------------------
            // restore the job's settings back to default
            // ---------------------------------------------------------------------------------------
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                job.HostingSupportEnabled = false;
                job.Update();
            }

            #region ContentDeploymentJob.Run() example

            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.Run() example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            //
            // to compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                try
                {
                    // execute this Content Deployment Job synchronously
                    job.Run();

                    Console.WriteLine("Job's execution completed. Job's status is: " + job.LastStatus.ToString() + "; Job's status message is: " + job.LastStatusMessage);
                }
                catch (ContentDeploymentException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (SPException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());

                    throw;
                }
            }

            #endregion

            #region ContentDeploymentJob.Run(bool, DateTime) example
            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.Run(bool, DateTime) example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            // - a job was recently successfully executed (so that the time of the
            //   last successfull run - 1 hour falls within the WSS change log window)
            //
            // to compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                try
                {
                    // executing the content deployment job synchronously, specifying the 
                    // deploySinceTime 1 hour prior to the last successfull run
                    job.Run(false, job.LastSuccessfulDeploymentTime.Subtract(new TimeSpan(1, 0, 0)));

                    Console.WriteLine("Job's execution completed. Job's status is: " + job.LastStatus.ToString() + "; Job's status message is: " + job.LastStatusMessage);
                }
                catch (ContentDeploymentException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (SPException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());

                    throw;
                }
            }

            #endregion

            #region ContentDeploymentJob.Run(bool, string) example

            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.Run(bool, string) example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            // - a Sql snapshot (of the source content DB) named 'yourSnapshot' was created
            //
            // to compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                try
                {
                    // execute the content deployment job synchronously, specifying an existing
                    // Sql snapshot to run export against
                    job.Run(false, "yourSnapshot");

                    Console.WriteLine("Job's execution completed. Job's status is: " + job.LastStatus.ToString() + "; Job's status message is: " + job.LastStatusMessage);
                }
                catch (ContentDeploymentException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (SPException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());

                    throw;
                }
            }
            
            #endregion

            #region ContentDeploymentJob.Run(bool, DateTime, string) example

            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.Run(bool, DateTime, string) example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            // - a Sql snapshot (of the source content DB) named 'yourSnapshot' was created
            //
            // to compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                // set the job to create and use a Sql Snapshot for export
                job.SqlSnapshotSetting = ContentDeploymentSqlSnapshotSetting.CreateNew;
                job.Update();

                try
                {
                    // execute this Content Deployment job synchronously, using a specified Sql Snapshot for export,
                    // with the default behavior in regard to what changes are propagated to target
                    // even through the SqlSnapshotSetting is set to ContentDeploymentSqlSnapshotSetting.CreateNew
                    // for this job, it will be ignored and the specified snapshot will be used instead.
                    job.Run(false, DateTime.MinValue, "yourSnapshot");

                    Console.WriteLine("Job's execution completed. Job's status is: " + job.LastStatus.ToString() + "; Job's status message is: " + job.LastStatusMessage);
                }
                catch (ContentDeploymentException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (SPException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());

                    throw;
                }
            }

            #endregion

            // ---------------------------------------------------------------------------------------
            // restore the job's settings back to default
            // ---------------------------------------------------------------------------------------
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                job.SqlSnapshotSetting = ContentDeploymentSqlSnapshotSetting.None;
                job.Update();
            }

            #region ContentDeploymentJob.Test() example

            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.Test() example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            //
            // to compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                try
                {
                    // performs a synchronous test run for this job
                    job.Test();

                    Console.WriteLine("Job's test run completed. Job's status is: " + job.LastStatus.ToString() + "; Job's status message is: " + job.LastStatusMessage);
                }
                catch (ContentDeploymentException ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());
                }
                catch (SPException ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());

                    throw;
                }
            }

            #endregion

            #region ContentDeploymentJob.Test(string) example

            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.Test(string) example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            // - a Sql snapshot (of the source content DB) named 'yourSnapshot' was created
            //
            // to compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                try
                {
                    // performs a synchronous test run for this job, specifying an existing
                    // Sql snapsjhot to run export against
                    job.Test("yourSnapshot");

                    Console.WriteLine("Job's test run completed. Job's status is: " + job.LastStatus.ToString() + "; Job's status message is: " + job.LastStatusMessage);
                }
                catch (ContentDeploymentException ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());
                }
                catch (SPException ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());

                    throw;
                }
            }

            #endregion

            #region ContentDeploymentJob.Test(bool, string) example

            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.Test(bool, string) example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            // - a Sql snapshot (of the source content DB) named 'yourSnapshot' was created
            //
            // to compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                // set the job to create and use a Sql Snapshot for export
                job.SqlSnapshotSetting = ContentDeploymentSqlSnapshotSetting.CreateNew;
                job.Update();

                try
                {
                    // performs a synchronous test run for this job, using a specified Sql Snapshot for export
                    // even through the SqlSnapshotSetting is set to ContentDeploymentSqlSnapshotSetting.CreateNew
                    // for this job run, it will be ignored and the specified snapshot will be used instead.
                    job.Test(false, "yourSnapshot");

                    Console.WriteLine("Job's test run completed. Job's status is: " + job.LastStatus.ToString() + "; Job's status message is: " + job.LastStatusMessage);
                }
                catch (ContentDeploymentException ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());
                }
                catch (SPException ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());

                    throw;
                }
            }

            #endregion

            // ---------------------------------------------------------------------------------------
            // restore the job's settings back to default
            // ---------------------------------------------------------------------------------------
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                job.SqlSnapshotSetting = ContentDeploymentSqlSnapshotSetting.None;
                job.Update();
            }

            #region ContentDeploymentJob.Test(bool) example

            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.Test(bool) example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            //
            // to compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                try
                {
                    // performs a test run for this job asynchronously
                    // when the call returns the job might not have finished yet
                    job.Test(true);

                    Console.WriteLine("Job's test run started. Job's status is: " + job.LastStatus.ToString());
                }
                catch (ContentDeploymentException ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());
                }
                catch (SPException ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Job's test run failed. Error details :" + ex.ToString());

                    throw;
                }
            }

            #endregion

            // ---------------------------------------------------------------------------------------
            // wait till the job's done
            // ---------------------------------------------------------------------------------------
            ContentDeploymentJobStatus status = ContentDeploymentJobStatus.NotAvailable;
            do
            {
                using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
                {
                    status = job.LastStatus;
                }

                System.Threading.Thread.Sleep(30 * 1000); // 30 secs
            }
            while ((status == ContentDeploymentJobStatus.TestSuccess || status == ContentDeploymentJobStatus.TestFailure) == false );

            #region ContentDeploymentJob.Run(bool) example

            // ---------------------------------------------------------------------------------------
            // ContentDeploymentJob.Run(bool) example
            // ---------------------------------------------------------------------------------------
            // The sample assumes that
            // - Content Deployment was configured,  
            // - a Content Deployment Path was created
            // - a Content Deployment Job named 'yourJob' was created
            //
            // to compile add additional references to 
            // - Microsoft.SharePoint.dll
            // - Microsoft.SharePoint.Publishing.dll
            //
            // To compile add the following using directives
            // using System;
            // using Microsoft.SharePoint.Publishing.Administration;
            // using Microsoft.SharePoint;
            using (ContentDeploymentJob job = ContentDeploymentJob.GetInstance("yourJob"))
            {
                try
                {
                    // execute this Content Deployment Job asynchronously
                    // when the call returns the job might not have finished yet
                    job.Run(true);

                    Console.WriteLine("Job's execution started. Job's status is: " + job.LastStatus.ToString());
                }
                catch (ContentDeploymentException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (SPException ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Job's execution failed. Error details :" + ex.ToString());

                    throw;
                }
            }

            #endregion

            Console.WriteLine("--------------------------------------");
            Console.WriteLine("sample tests completed. Press any key:");
            Console.ReadKey();
        }
    }
}

Cohérence de thread

Tous les membres statique (Partagé dans Visual Basic)s publics de ce type sont thread-safe. Cela n’est pas garanti pour les membres d’instance.

Voir aussi

Référence

ContentDeploymentJob - Membres

Microsoft.SharePoint.Publishing.Administration - Espace de noms