Exemplo n.º 1
0
 /// <remarks/>
 public void FindItemAsync(FindItemType FindItem1, object userState)
 {
     if ((this.FindItemOperationCompleted == null)) {
         this.FindItemOperationCompleted = new System.Threading.SendOrPostCallback(this.OnFindItemOperationCompleted);
     }
     this.InvokeAsync("FindItem", new object[] {
                 FindItem1}, this.FindItemOperationCompleted, userState);
 }
Exemplo n.º 2
0
 /// <remarks/>
 public void FindItemAsync(FindItemType FindItem1)
 {
     this.FindItemAsync(FindItem1, null);
 }
        /// <summary>
        /// A new, improved ContactsView method (Listing 6-16)
        /// </summary>
        /// <param name="folderId">Folder to perform FindItem in</param>
        /// <param name="responseShape">ResponseShape for returned contacts</param>
        /// <param name="pathForRestriction">The property path to compare against</param>
        /// <param name="lowerBounds">lower bounds string (inclusive)</param>
        /// <param name="upperBounds">upper bounds string (exclusive)</param>
        /// <param name="offset">For indexed paging, the offset into the result set to start at</param>
        /// <param name="maxEntries">Max entries to return for each page.  Zero for unbounded</param>
        /// <returns>FindItemResponseMessageType</returns>
        /// 
        public FindItemResponseMessageType SuperContactsView(
										BaseFolderIdType folderId,
										ItemResponseShapeType responseShape,
										BasePathToElementType pathForRestriction,
										string lowerBounds,
										string upperBounds,
										int offset,
										int maxEntries)
        {
            FindItemType request = new FindItemType();
            request.ItemShape = responseShape;
            // If they set a maxEntries > 0, use indexed paging just to limit the results.
            //
            if (maxEntries > 0)
            {
                IndexedPageViewType paging = new IndexedPageViewType();
                paging.BasePoint = IndexBasePointType.Beginning;
                paging.Offset = offset;
                paging.MaxEntriesReturned = maxEntries;
                paging.MaxEntriesReturnedSpecified = true;
                request.Item = paging;
            }
            request.ParentFolderIds = new BaseFolderIdType[] { folderId };
            request.Traversal = ItemQueryTraversalType.Shallow;

            // Build up our restriction
            //
            AndType and = new AndType();
            IsGreaterThanOrEqualToType lowerBoundsFilter = new IsGreaterThanOrEqualToType();
            lowerBoundsFilter.Item = pathForRestriction;
            lowerBoundsFilter.FieldURIOrConstant = new FieldURIOrConstantType();
            ConstantValueType lowerBoundsValue = new ConstantValueType();
            lowerBoundsValue.Value = lowerBounds;
            lowerBoundsFilter.FieldURIOrConstant.Item = lowerBoundsValue;

            IsLessThanType upperBoundsFilter = new IsLessThanType();
            upperBoundsFilter.Item = pathForRestriction;
            upperBoundsFilter.FieldURIOrConstant = new FieldURIOrConstantType();
            ConstantValueType upperBoundsValue = new ConstantValueType();
            upperBoundsValue.Value = upperBounds;
            upperBoundsFilter.FieldURIOrConstant.Item = upperBoundsValue;

            and.Items = new SearchExpressionType[] { lowerBoundsFilter, upperBoundsFilter };
            request.Restriction = new RestrictionType();
            request.Restriction.Item = and;

            // Make the request
            //
            FindItemResponseType response = this.FindItem(request);
            return response.ResponseMessages.Items[0] as FindItemResponseMessageType;
        }
Exemplo n.º 4
0
 /// <remarks/>
 public System.IAsyncResult BeginFindItem(FindItemType FindItem1, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("FindItem", new object[] {
                 FindItem1}, callback, asyncState);
 }
        /// <summary>
        /// Copy items to a destination folder and return the new ids for these items (Listing 5-14)
        /// </summary>
        /// <param name="binding">Exchange binding to use for the call</param>
        /// <param name="destinationFolderId">Destination for the items</param>
        /// <param name="itemsToCopy">Items to copy</param>
        /// <returns>List of new item ids</returns>
        /// 
        public List<ItemIdType> CopyItemEx(
                             BaseFolderIdType destinationFolderId,
                             List<BaseItemIdType> itemsToCopy)
        {
            // STEP 1:  First, we need to retrieve some unique information about
            // each item.  Let's use the PR_SEARCH_KEY. Note that extended properties are
            // discussed in Chapter 13, "Extended Properties"
            //
            GetItemType getSearchKeyRequest = new GetItemType();

            PathToExtendedFieldType searchKeyPath = new PathToExtendedFieldType();
            searchKeyPath.PropertyTag = "0x300B";
            searchKeyPath.PropertyType = MapiPropertyTypeType.Binary;

            // Use ItemResponseShapeType overload from chapter 3. We want the Id and the
            // search key
            //
            ItemResponseShapeType idAndSearchKeyShape = new ItemResponseShapeType(
                                     DefaultShapeNamesType.IdOnly,
                                     searchKeyPath);
            getSearchKeyRequest.ItemShape = idAndSearchKeyShape;
            getSearchKeyRequest.ItemIds = itemsToCopy.ToArray();

            // Get the items
            //
            GetItemResponseType getSearchKeyResponse =
                       this.GetItem(getSearchKeyRequest);
            List<string> base64SearchKeys = new List<string>(
                         getSearchKeyResponse.ResponseMessages.Items.Length);

            // For each item, add the search keys to our list
            //
            foreach (ItemInfoResponseMessageType searchKeyMessage in
                          getSearchKeyResponse.ResponseMessages.Items)
            {
                ExtendedPropertyType searchKeyProperty =
                        searchKeyMessage.Items.Items[0].ExtendedProperty[0];
                base64SearchKeys.Add((string)searchKeyProperty.Item);
            }

            // Now we have a list of the search keys for the items that we want to
            // copy.
            // STEP 2:  Perform the copy

            CopyItemType copyItemRequest = new CopyItemType();
            copyItemRequest.ToFolderId = new TargetFolderIdType();
            copyItemRequest.ToFolderId.Item = destinationFolderId;

            // just copy the array from our GetItem request rather than building a
            // new one.
            //
            copyItemRequest.ItemIds = getSearchKeyRequest.ItemIds;
            CopyItemResponseType copyResponse = this.CopyItem(copyItemRequest);

            // Now, we know that we do not get new ids from the above request, but
            // we (read: you) SHOULD check the response code for each of the copies
            // operations.
            //
            // STEP 3:  For each successful copy, we want to find the items by
            // search key.
            //
            FindItemType findBySearchKey = new FindItemType();
            findBySearchKey.ItemShape = idAndSearchKeyShape;
            findBySearchKey.ParentFolderIds = new BaseFolderIdType[] {
              destinationFolderId };
            findBySearchKey.Traversal = ItemQueryTraversalType.Shallow;
            findBySearchKey.Restriction = new RestrictionType();

            // Here we need to build up our query.  Rather than issuing several
            // FindItem calls, let's build up a single OR restriction here with a
            // bunch of items. Note that EWS restricts filter depths, so we
            // might need to break this up depending on how many items we are
            // copying...
            //
            if (base64SearchKeys.Count > 1)
            {
                OrType or = new OrType();
                List<IsEqualToType> orChildren = new List<IsEqualToType>();
                foreach (string searchKey in base64SearchKeys)
                {
                    // Note that CreateIsEqualToSearchKey is implemented on the partial class
                    // extension of RestrictionType.
                    //
                    IsEqualToType isEqualTo = RestrictionType.CreateIsEqualToSearchKey(
                          searchKeyPath, searchKey);
                    orChildren.Add(isEqualTo);
                }
                or.Items = orChildren.ToArray();

                findBySearchKey.Restriction.Item = or;
            }
            else
            {
                // we only have one item.  No need for the OR clause
                //
                IsEqualToType isEqualTo = RestrictionType.CreateIsEqualToSearchKey(
                                searchKeyPath, base64SearchKeys[0]);
                findBySearchKey.Restriction.Item = isEqualTo;
            }

            FindItemResponseType findResponse = this.FindItem(findBySearchKey);

            // Since we searched in a single target folder, we will have a single
            // response message
            //
            FindItemResponseMessageType findResponseMessage =
                findResponse.ResponseMessages.Items[0] as FindItemResponseMessageType;
            ItemType[] foundItems = (findResponseMessage.RootFolder.Item as
                                        ArrayOfRealItemsType).Items;
            List<ItemIdType> newIds = new List<ItemIdType>();
            foreach (ItemType item in foundItems)
            {
                newIds.Add(item.ItemId);
            }
            return newIds;
        }