Compartir a través de


Clase ContentDeploymentJob

Define los detalles de un trabajo de distribución de contenido.

Jerarquía de la herencia

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

Espacio de nombres:  Microsoft.SharePoint.Publishing.Administration
Ensamblado:  Microsoft.SharePoint.Publishing (en Microsoft.SharePoint.Publishing.dll)

Sintaxis

'Declaración
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class ContentDeploymentJob _
    Inherits DisposableListItemWrapper
'Uso
Dim instance As ContentDeploymentJob
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class ContentDeploymentJob : DisposableListItemWrapper

Comentarios

Un trabajo de distribución de contenido consta de las siguientes propiedades.

Nombre de propiedad

Description

Name

Proporciona el nombre del trabajo de distribución de contenido.

Description

Describe el trabajo de distribución de contenido.

Path

Proporciona la ruta de acceso asociado con este trabajo de distribución de contenido.

JobType

Define si se trata de una implementación de contenido completa o parcial.

IsRecurring

Define si se trata de una implementación de contenido única o periódica.

NotificationSettings

Define si y cuándo van a enviar notificación de correo electrónico cuando la distribución de contenido se haya realizado correctamente o se produce un error.

ExportMethod

Determina si se va a exportar todos los cambios a la vez o de forma incremental.

Ejemplos

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();
        }
    }
}

Seguridad para subprocesos

Los miembros static (Shared en Visual Basic) públicos de este tipo son seguros para subprocesos. No se garantiza que los miembros de instancias sean seguros para los subprocesos.

Vea también

Referencia

Miembros ContentDeploymentJob

Espacio de nombres Microsoft.SharePoint.Publishing.Administration