如何查看和修改项目属性(RMO 编程)

您可以使用复制管理对象 (RMO) 以编程的方式修改项目和访问其属性。 用于查看或修改项目属性的 RMO 类取决于项目所属的发布的类型。

查看或修改属于快照发布或事务发布的项目的属性

  1. 使用 ServerConnection 类创建与发布服务器的连接。

  2. 创建 TransArticle 类的实例。

  3. 设置 NamePublicationNameDatabaseName 属性。

  4. ConnectionContext 属性设置步骤 1 中的连接。

  5. 调用 LoadProperties 方法获取该对象的属性。 如果此方法返回 false,则说明步骤 3 中的项目属性定义不正确或此项目不存在。

  6. (可选)若要更改属性,请为可以设置的 TransArticle 属性中的一个设置新值。

  7. (可选)如果已将 CachePropertyChanges 的值指定为 true,则调用 CommitPropertyChanges 方法以在服务器上提交更改。 如果将 CachePropertyChanges 的值指定为 false(默认值),则会将更改立即发送到服务器。

查看或修改属于合并发布的项目的属性

  1. 使用 ServerConnection 类创建与发布服务器的连接。

  2. 创建 MergeArticle 类的实例。

  3. 设置 NamePublicationNameDatabaseName 属性。

  4. ConnectionContext 属性设置步骤 1 中的连接。

  5. 调用 LoadProperties 方法获取该对象的属性。 如果此方法返回 false,则说明步骤 3 中的项目属性定义不正确或此项目不存在。

  6. (可选)若要更改属性,请为可以设置的 MergeArticle 属性中的一个设置新值。

  7. (可选)如果已将 CachePropertyChanges 的值指定为 true,则调用 CommitPropertyChanges 方法以在服务器上提交更改。 如果将 CachePropertyChanges 的值指定为 false(默认值),则会将更改立即发送到服务器。

示例

此示例更改一个合并项目来指定该项目所使用的业务逻辑处理程序。

          // Define the Publisher, publication, and article names.
            string publisherName = publisherInstance;
            string publicationName = "AdvWorksSalesOrdersMerge";
            string publicationDbName = "AdventureWorks";
            string articleName = "SalesOrderHeader";
            
            // Set the friendly name of the business logic handler.
            string customLogic = "OrderEntryLogic";

            MergeArticle article = new MergeArticle();
            
            // Create a connection to the Publisher.
            ServerConnection conn = new ServerConnection(publisherName);

            try
            {
                // Connect to the Publisher.
                conn.Connect();

                // Set the required properties for the article.
                article.ConnectionContext = conn;
                article.Name = articleName;
                article.DatabaseName = publicationDbName;
                article.PublicationName = publicationName;

                // Load the article properties.
                if (article.LoadProperties())
                {
                    article.ArticleResolver = customLogic;
                }
                else
                {
                    // Throw an exception of the article does not exist.
                    throw new ApplicationException(String.Format(
                    "{0} is not published in {1}", articleName, publicationName));
                }
                
            }
            catch (Exception ex)
            {
                // Do error handling here and rollback the transaction.
                throw new ApplicationException(String.Format(
                    "The business logic handler {0} could not be associated with " +
                    " the {1} article.",customLogic,articleName), ex);
            }
            finally
            {
                conn.Disconnect();
            }
' Define the Publisher, publication, and article names.
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks"
Dim articleName As String = "SalesOrderHeader"

' Set the friendly name of the business logic handler.
Dim customLogic As String = "OrderEntryLogic"

Dim article As MergeArticle = New MergeArticle()

' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)

Try
    ' Connect to the Publisher.
    conn.Connect()

    ' Set the required properties for the article.
    article.ConnectionContext = conn
    article.Name = articleName
    article.DatabaseName = publicationDbName
    article.PublicationName = publicationName

    ' Load the article properties.
    If article.LoadProperties() Then
        article.ArticleResolver = customLogic
    Else
        ' Throw an exception of the article does not exist.
        Throw New ApplicationException(String.Format( _
         "{0} is not published in {1}", articleName, publicationName))
    End If

Catch ex As Exception
    ' Do error handling here and rollback the transaction.
    Throw New ApplicationException(String.Format( _
     "The business logic handler {0} could not be associated with " + _
     " the {1} article.", customLogic, articleName), ex)
Finally
    conn.Disconnect()
End Try