Поделиться через


SyncFolderHierarchyType Class

The SyncFolderHierarchyType class represents a request to synchronize a client folder hierarchy with the computer that is running Microsoft Exchange Server 2007.

Inheritance Hierarchy

System.Object
  ExchangeWebServices.BaseRequestType
    ExchangeWebServices.SyncFolderHierarchyType

Namespace:  ExchangeWebServices
Assembly:  EWS (in EWS.dll)

Syntax

'Declaration
<SerializableAttribute> _
Public Class SyncFolderHierarchyType _
    Inherits BaseRequestType
'Usage
Dim instance As SyncFolderHierarchyType
[SerializableAttribute]
public class SyncFolderHierarchyType : BaseRequestType

Remarks

To synchronize the items in each folder, use the SyncFolderItemsType proxy object.

Examples

The following example shows you how to synchronize a folder hierarchy. Because the SyncState property is set, this folder hierarchy has been synchronized before. This SyncFolderHierarchy operation will return all changes that were made since the synchronization call that is represented by the SyncState property. This call will return all the properties that are defined by the AllProperties folder shape.

static void SyncFolderHierarchy(ExchangeServiceBinding esb)
{ 
    // Create the request.
    SyncFolderHierarchyType request = new SyncFolderHierarchyType();

    // Identify the properties that are synchronized.
    FolderResponseShapeType shape = new FolderResponseShapeType();
    shape.BaseShape = DefaultShapeNamesType.AllProperties;

    // Add synchronized properties to request.
    request.FolderShape = shape;

    // Add the synchronization state to the request. This
    // property should be null for the initial synchronization.
    request.SyncState = "H4sIAAAAAAAEAO29B2AcSZYlJi9tynt/";

    // Send the request and get the response.
    SyncFolderHierarchyResponseType response = esb.SyncFolderHierarchy(request);

    ArrayOfResponseMessagesType aormt = response.ResponseMessages;
    ResponseMessageType[] rmta = aormt.Items;

    foreach (ResponseMessageType rmt in rmta)
    {
        if (rmt.ResponseClass == ResponseClassType.Success)
        {
            SyncFolderHierarchyResponseMessageType sfhrmt = rmt as SyncFolderHierarchyResponseMessageType;
            
            // Get the sync state string to use in later synchronization calls.
            string syncState = sfhrmt.SyncState;

            // Get the array of changes that are returned in the response. 
            SyncFolderHierarchyChangesType changeArray = sfhrmt.Changes;

            // This contains the array of folder changes.
            object[] changes = changeArray.Items;

            // This identifies the type of change that occurred on a folder.
            ItemsChoiceType1 changeType; 
            
            for (int count = 0; count < changes.Length; count++)
            {
                // This identifies the type of change that is represented by the objects
                // in the changes object[].
                changeType = changeArray.ItemsElementName[count];

                // Check for the change type of each folder that is returned in the response.
                switch (changeType)
                { 
                    case ItemsChoiceType1.Create:
                        SyncFolderHierarchyCreateOrUpdateType createdFolder = changes[count] as SyncFolderHierarchyCreateOrUpdateType;
                        // TODO: Handle the created folder.
                        if (createdFolder.Item is CalendarFolderType)
                        {
                            // TODO: Cast to calendar folder and handle properties.
                        }
                        else;
                            // TODO: Check and cast to SearchFolderType, TasksFolderType,
                            //       ContactsFolderType, or FolderType.
                        break;

                    case ItemsChoiceType1.Update:
                        SyncFolderHierarchyCreateOrUpdateType updatedFolder = changes[count] as SyncFolderHierarchyCreateOrUpdateType; ;
                        // TODO: Handle the updated folder.    
                        // TODO: Check and cast to one of the five folder types.
                        break;

                    case ItemsChoiceType1.Delete:
                        SyncFolderHierarchyDeleteType deletedFolder = changes[count] as SyncFolderHierarchyDeleteType;
                        // TODO: Get the identifier of the deleted folder.
                        break;
                }
            }
        }
    }
}

The SyncState property returned in the response should be saved for later synchronization requests. Also be aware that the folders that are returned in the response must be cast to the appropriate folder type so that the client application can access all the properties that are available to each folder type.

Important

If updates are returned, the client application must compare the difference between the folders in the response and on the client to determine which changes have occurred.

Because all the change objects do not have the same base type, an object array is returned.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.