Partager via


Example: Handling Attribute Value Accumulation

An MVEntry object can have an attribute that contains multiple values that are imported from several connected CSEntry objects. When the attribute values from the connected CSEntry objects are imported into the metaverse, the values are added to the appropriate MVEntry object attribute.

When the attributes in the connected CSEntry objects are changed and then imported into the MVEntry object, the new values are added to the existing list of attribute values, thereby accumulating a number of values. With the addition of new values, some of the existing values may become obsolete. If numerous changes occur, the MVEntry object can have a number of values in the multi-valued attributes that are not correct. Further, the list of values can become large and unwieldy.

There are two solutions for this issue:

  • Use accumulation of values only with attributes that remain static.
  • Use a rules extension to delete the existing values and import the new and remaining correct values back into the attribute. By deleting and importing, you can make sure that the values in the multi-valued attribute are correct.

These code examples suggests a way of using a rules extension to delete existing values and import the new and remaining correct values during a delta import run. The MVEntry object has an attribute called otherMailbox that accepts values from all connected CSEntry objects with a mail attribute. In this example, there are several connected directories with a mail attribute that has values that need to be flowed into the metaverse.

When a flow rule called "Mail to Other Mailboxes" is used, the existing attribute values are deleted and then the mail attribute value from all connected directories, including the one with a new value, are imported into the otherMailbox attribute.

The following example shows how to handle attribute value accumulation:

    Public Sub MapAttributesForImport(ByVal FlowRuleName As String, _
        ByVal csentry As CSEntry, _
        ByVal mventry As MVEntry) _
        Implements IMASynchronization.MapAttributesForImport
        Dim ConnectedManagementAgent As ConnectedMA
        Dim ConnectorSpaceEntry As CSEntry
    
        Select Case (FlowRuleName)
    
            Case "Mail to Other Mailboxes"
                Dim csAttr As String
                ' Clear all of the "otherMailbox" attribute values from the MV object.
                mventry("otherMailbox").Delete()
    
                ' Enumerate all of the connectors and add the "mail" attribute for each 
                ' one to the "otherMailbox" attribute of the MV entry. The set of existing 
                ' connectors includes the connector represented by csentry.
                For Each ConnectedManagementAgent In mventry.ConnectedMAs
                    If ConnectedManagementAgent.Name = "MA1" Then
                        csAttr = "email"
                    ElseIf ConnectedManagementAgent.Name = "MA2" Then
                        csAttr = "mail"
                    End If
                    For Each ConnectorSpaceEntry In ConnectedManagementAgent.Connectors
                        Try
                            If ConnectorSpaceEntry(csAttr).IsPresent Then
                                mventry("otherMailbox").Values.Add(ConnectorSpaceEntry(csAttr).Value)
                            End If
                        Catch attrEx As NoSuchAttributeException
                            ' The NoSuchAttributeException exception will be thrown if 
                            ' the "mail" attribute is not defined for the CSEntry object. 
                            ' In this case, just handle the exception and continue.
                        End Try
                    Next
                Next
    
            Case Else
                Throw New EntryPointNotImplementedException()
    
        End Select
    End Sub
    void IMASynchronization.MapAttributesForImport (string FlowRuleName, 
    CSEntry csentry, MVEntry mventry)
    {
        switch (FlowRuleName)
        {
            case "Mail to Other Mailboxes":
            {
                string csAttr = null;   
                mventry[ "otherMailbox" ].Delete();
                foreach(ConnectedMA ConnectedManagementAgent in mventry.ConnectedMAs)
                {
                    if( ConnectedManagementAgent.Name == "MA1" )
                    csAttr = "email";
                    else if ( ConnectedManagementAgent.Name == "MA2" )
                    csAttr = "mail";
                    foreach(CSEntry ConnectorSpaceEntry in ConnectedManagementAgent.Connectors)
                    {
                        if(ConnectorSpaceEntry[csAttr].IsPresent)
                        {
                            mventry["otherMailbox"].Values.Add(ConnectorSpaceEntry[csAttr].Value);
                        }
                    }   
                }
                break;
            }
            default:
            {
                throw new EntryPointNotImplementedException();
            }
        }
    }

Send comments about this topic to Microsoft

Build date: 2/16/2009