コード例 #1
0
        private void MigrateItens(ref DataGridViewRow row, ExchangeServiceBinding srcService, ExchangeServiceBinding tgtService, DistinguishedFolderIdNameType folder, string srcUserMail, string tgtUserMail)
        {
            ResponseMessageType[] itemsResponse = this.GetFolderItems(srcService, folder);

            ExportItemsType exExportItems = new ExportItemsType();

            foreach (ResponseMessageType responseMessage in itemsResponse)
            {
                FindItemResponseMessageType firmt = responseMessage as FindItemResponseMessageType;
                FindItemParentType          fipt  = firmt.RootFolder;
                object obj   = fipt.Item;
                int    count = 0;

                // FindItem contains an array of items.
                if (obj is ArrayOfRealItemsType)
                {
                    ArrayOfRealItemsType items = (obj as ArrayOfRealItemsType);

                    exExportItems.ItemIds = new ItemIdType[(items.Items.Count() + 1)];

                    foreach (ItemType it in items.Items)
                    {
                        exExportItems.ItemIds[count]    = new ItemIdType();
                        exExportItems.ItemIds[count].Id = it.ItemId.Id;
                        count++;
                    }
                }
            }

            ExportItemsResponseType exResponse = srcService.ExportItems(exExportItems);

            ResponseMessageType[] rmResponses   = exResponse.ResponseMessages.Items;
            UploadItemsType       upUploadItems = new UploadItemsType();

            upUploadItems.Items = new UploadItemType[(rmResponses.Length + 1)];
            Int32 icItemCount = 0;

            foreach (ResponseMessageType rmReponse in rmResponses)
            {
                if (rmReponse.ResponseClass == ResponseClassType.Success)
                {
                    ExportItemsResponseMessageType exExportedItem = (ExportItemsResponseMessageType)rmReponse;
                    Byte[]         messageBytes = exExportedItem.Data;
                    UploadItemType upUploadItem = new UploadItemType();
                    upUploadItem.CreateAction          = CreateActionType.UpdateOrCreate;
                    upUploadItem.Data                  = messageBytes;
                    upUploadItem.IsAssociatedSpecified = true;
                    upUploadItem.IsAssociated          = false;
                    upUploadItems.Items[icItemCount]   = upUploadItem;

                    FolderIdManager folderIdMgr = new FolderIdManager();
                    FolderIdType    folderId    = new FolderIdType();
                    folderId.Id = folderIdMgr.GetFolderId(tgtUserMail, Microsoft.Exchange.WebServices.Data.WellKnownFolderName.Contacts, Microsoft.Exchange.WebServices.Data.ExchangeVersion.Exchange2010_SP2);


                    upUploadItem.ParentFolderId = folderId;
                    icItemCount += 1;
                }
            }
            //Erro de Internal Server Error nessa etapa
            UploadItemsResponseType upLoadResponse = tgtService.UploadItems(upUploadItems);
            Int32 Success = 0;
            Int32 Failure = 0;

            foreach (ResponseMessageType upResponse in upLoadResponse.ResponseMessages.Items)
            {
                if (upResponse.ResponseClass == ResponseClassType.Success)
                {
                    Success++;
                }
                if (upResponse.ResponseClass == ResponseClassType.Error)
                {
                    Failure++;
                }
            }


            string resTask = string.Format("Items Copied Sucessfull : {0} - Failure: {1}", Success, Failure);

            Tools.SetRowValue(ref row, EColumns.results, resTask);

            //iv.Offset += fiItems.Items.Count;
        }
コード例 #2
0
        /// <summary>
        /// Finds all Calendar Items for the current User's Mailbox.
        /// </summary>
        /// <returns></returns>
        //protected internal CalendarItemType[] FindCalendarItems()
        //{
        //    // Identify which folders to search.
        //    DistinguishedFolderIdType[] parentFolderIds = new DistinguishedFolderIdType[1];

        //    parentFolderIds[0] = new DistinguishedFolderIdType();
        //    parentFolderIds[0].Id = DistinguishedFolderIdNameType.calendar;

        //    return FindCalendarItems(parentFolderIds);
        //}

        protected internal CalendarItemType[] FindCalendarItems(DistinguishedFolderIdType[] parentFolderIds)
        {
            // Form the FindItem request.
            FindItemType findItemRequest = new FindItemType();

            // Define the item properties that are returned in the response.
            ItemResponseShapeType itemProperties = new ItemResponseShapeType();

            itemProperties.BaseShape = DefaultShapeNamesType.IdOnly;

            PathToUnindexedFieldType calendarIsRecurringFieldPath = new PathToUnindexedFieldType();

            calendarIsRecurringFieldPath.FieldURI = UnindexedFieldURIType.calendarIsRecurring;

            PathToUnindexedFieldType calendarItemTypeFieldPath = new PathToUnindexedFieldType();

            calendarIsRecurringFieldPath.FieldURI = UnindexedFieldURIType.calendarCalendarItemType;

            PathToUnindexedFieldType calendarStartFieldPath = new PathToUnindexedFieldType();

            calendarStartFieldPath.FieldURI = UnindexedFieldURIType.calendarStart;

            PathToUnindexedFieldType calendarEndFieldPath = new PathToUnindexedFieldType();

            calendarEndFieldPath.FieldURI = UnindexedFieldURIType.calendarEnd;

            //location
            //PathToUnindexedFieldType calendarLocation = new PathToUnindexedFieldType();
            //calendarLocation.FieldURI = UnindexedFieldURIType.calendarLocation;
            //// body
            //PathToUnindexedFieldType itemBody = new PathToUnindexedFieldType();
            //itemBody.FieldURI = UnindexedFieldURIType.itemBody;

            itemProperties.AdditionalProperties = new PathToUnindexedFieldType[]
            {
                calendarIsRecurringFieldPath,
                calendarItemTypeFieldPath,
                calendarStartFieldPath,
                calendarEndFieldPath
            };
            findItemRequest.ItemShape = itemProperties;

            findItemRequest.ParentFolderIds = parentFolderIds;

            // Define the sort order of items.
            FieldOrderType[] fieldsOrder = new FieldOrderType[1];
            fieldsOrder[0] = new FieldOrderType();
            PathToUnindexedFieldType subjectOrder = new PathToUnindexedFieldType();

            subjectOrder.FieldURI     = UnindexedFieldURIType.calendarStart;
            fieldsOrder[0].Item       = subjectOrder;
            fieldsOrder[0].Order      = SortDirectionType.Ascending;
            findItemRequest.SortOrder = fieldsOrder;

            // Define the traversal type.
            findItemRequest.Traversal = ItemQueryTraversalType.Shallow;

            // Send the FindItem request and get the response.
            FindItemResponseType findItemResponse = Service.FindItem(findItemRequest);

            // Access the response message.
            ArrayOfResponseMessagesType responseMessages = findItemResponse.ResponseMessages;
            ResponseMessageType         responseMessage  = responseMessages.Items[0];

            if (responseMessage is FindItemResponseMessageType)
            {
                FindItemResponseMessageType firmt = (responseMessage as FindItemResponseMessageType);
                FindItemParentType          fipt  = firmt.RootFolder;
                object obj = fipt.Item;

                if (obj is ArrayOfRealItemsType)
                {
                    ArrayOfRealItemsType items = (obj as ArrayOfRealItemsType);

                    if (items.Items != null)
                    {
                        List <CalendarItemType> calendarItems = new List <CalendarItemType>(items.Items.Length);
                        foreach (ItemType item in items.Items)
                        {
                            CalendarItemType calendarItem = item as CalendarItemType;

                            if (calendarItem != null)
                            {
                                calendarItems.Add(calendarItem);
                            }
                        }

                        return(calendarItems.ToArray());
                    }

                    return(new CalendarItemType[0]);
                }
            }

            return(null);
        }