/// <summary> /// Creates an IsEqualTo clause for our search key (Listing 5-14 cont'd) /// </summary> /// <param name="searchKeyPath">Search key path</param> /// <param name="value">base64 search key to look for</param> /// <returns>IsEqualTo clause</returns> /// public static IsEqualToType CreateIsEqualToSearchKey( PathToExtendedFieldType searchKeyPath, string value) { IsEqualToType isEqualTo = new IsEqualToType(); isEqualTo.Item = searchKeyPath; isEqualTo.FieldURIOrConstant = new FieldURIOrConstantType(); ConstantValueType constant = new ConstantValueType(); constant.Value = value; isEqualTo.FieldURIOrConstant.Item = constant; return isEqualTo; }
/******************************************************************** * GET UNREAD FOLDER ITEMS ********************************************************************/ private static List<ItemType> GetUnReadFolderItems(String folderName) { FindItemType findRequest = new FindItemType(); findRequest.ItemShape = new ItemResponseShapeType(); ItemResponseShapeType itemProperties = new ItemResponseShapeType(); // Use the Default shape for the response. itemProperties.BaseShape = DefaultShapeNamesType.AllProperties; itemProperties.BodyType = BodyTypeResponseType.Text; itemProperties.BodyTypeSpecified = true; RestrictionType restrict = new RestrictionType(); IsEqualToType isEqTo = new IsEqualToType(); PathToUnindexedFieldType ptuift = new PathToUnindexedFieldType(); ptuift.FieldURI = UnindexedFieldURIType.messageIsRead; isEqTo.Item = ptuift; FieldURIOrConstantType msgReadYes = new FieldURIOrConstantType(); msgReadYes.Item = new ConstantValueType(); (msgReadYes.Item as ConstantValueType).Value = "0"; //1= boolean yes; so you'll get the list of read messages isEqTo.FieldURIOrConstant = msgReadYes; restrict.Item = isEqTo; findRequest.Restriction = restrict; findRequest.ItemShape = itemProperties; //Set the inbox as the parent search folder in search attachementRequest. BaseFolderIdType p_folder = FindFolderID(folderName); findRequest.ParentFolderIds = new BaseFolderIdType[] { p_folder }; findRequest.Traversal = ItemQueryTraversalType.Shallow; // Perform the inbox search FindItemResponseType response = service.FindItem(findRequest); FindItemResponseMessageType responseMessage = response.ResponseMessages.Items[0] as FindItemResponseMessageType; if (responseMessage.ResponseCode != ResponseCodeType.NoError) { throw new Exception(responseMessage.MessageText); } else { // find items details GetItemResponseType response2 = service.GetItem(new GetItemType { ItemIds = ((response as FindItemResponseType) .ResponseMessages .Items .Select(n => n as FindItemResponseMessageType) .Select(n => n.RootFolder).Single().Item as ArrayOfRealItemsType) .Items .Select(n => new ItemIdType { Id = n.ItemId.Id }) .ToArray() , ItemShape = new ItemResponseShapeType { BaseShape = DefaultShapeNamesType.Default, BodyType = BodyTypeResponseType.Text } }); List<ItemType> messages = new List<ItemType>(); for (int j = 0; j < response2.ResponseMessages.Items.Count(); j++) messages.Add(((ItemInfoResponseMessageType)response2.ResponseMessages.Items[j]).Items.Items[0]); return messages; } }
/// <summary> /// Выполняет поиск входящих писем с подтверждением об обработке файлов за указанный период /// </summary> /// <param name="begin">Дата начиная с которой будет происходить поиск писем</param> /// <returns></returns> public static ItemType[] GetMessages(DateTime begin) { ExchangeServiceBinding bind = new ExchangeServiceBinding(); bind.Credentials = new NetworkCredential(AppHelper.Configuration.Exchange.Username.GetDecryptedString(), AppHelper.Configuration.Exchange.Password.GetDecryptedString(), AppHelper.Configuration.Exchange.Domain); bind.Url = "https://" + AppHelper.Configuration.Exchange.ServerName + "/EWS/Exchange.asmx"; FindItemType findType = new FindItemType(); findType.Traversal = ItemQueryTraversalType.Shallow; findType.ItemShape = new ItemResponseShapeType(); findType.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties; DistinguishedFolderIdType folder = new DistinguishedFolderIdType(); folder.Id = DistinguishedFolderIdNameType.inbox; findType.ParentFolderIds = new BaseFolderIdType[] { folder }; IsEqualToType isEq = new IsEqualToType(); PathToUnindexedFieldType uPath = new PathToUnindexedFieldType(); uPath.FieldURI = UnindexedFieldURIType.messageFrom; FieldURIOrConstantType constType = new FieldURIOrConstantType(); ConstantValueType constValue = new ConstantValueType(); constValue.Value = AppHelper.Configuration.Exchange.SenderName; constType.Item = constValue; isEq.Item = uPath; isEq.FieldURIOrConstant = constType; IsGreaterThanOrEqualToType isGrEq = new IsGreaterThanOrEqualToType(); PathToUnindexedFieldType uPath2 = new PathToUnindexedFieldType(); uPath2.FieldURI = UnindexedFieldURIType.itemDateTimeSent; FieldURIOrConstantType constType2 = new FieldURIOrConstantType(); ConstantValueType constValue2 = new ConstantValueType(); constValue2.Value = string.Format("{0}-{1}-{2}T00:00:00Z", begin.Year, begin.Month.ToString("D2"), begin.Day.ToString("D2")); constType2.Item = constValue2; isGrEq.Item = uPath2; isGrEq.FieldURIOrConstant = constType2; AndType and = new AndType(); and.Items = new SearchExpressionType[] { isEq, isGrEq }; findType.Restriction = new RestrictionType(); findType.Restriction.Item = and; FindItemResponseType findResp = bind.FindItem(findType); FindItemResponseMessageType resMes = findResp.ResponseMessages.Items[0] as FindItemResponseMessageType; if (resMes.ResponseClass != ResponseClassType.Success) { throw new Exception("Ошибка при получении ответа от сервера Exchange:\n" + resMes.MessageText); } ItemType[] messages = (resMes.RootFolder.Item as ArrayOfRealItemsType).Items; return(messages); }
static FolderIdType FindFolder(ExchangeServiceBinding esb, DistinguishedFolderIdType fiFolderID, String fnFldName) { FolderIdType rvFolderID = new FolderIdType(); // Create the request and specify the travesal type FindFolderType findFolderRequest = new FindFolderType(); findFolderRequest.Traversal = FolderQueryTraversalType.Deep; // Define the properties returned in the response FolderResponseShapeType responseShape = new FolderResponseShapeType(); responseShape.BaseShape = DefaultShapeNamesType.Default; findFolderRequest.FolderShape = responseShape; // Identify which folders to search DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1]; folderIDArray[0] = new DistinguishedFolderIdType(); folderIDArray[0].Id = fiFolderID.Id; //Add Restriction for DisplayName RestrictionType ffRestriction = new RestrictionType(); IsEqualToType ieToType = new IsEqualToType(); PathToUnindexedFieldType diDisplayName = new PathToUnindexedFieldType(); diDisplayName.FieldURI = UnindexedFieldURIType.folderDisplayName; FieldURIOrConstantType ciConstantType = new FieldURIOrConstantType(); ConstantValueType cvConstantValueType = new ConstantValueType(); cvConstantValueType.Value = fnFldName; ciConstantType.Item = cvConstantValueType; ieToType.Item = diDisplayName; ieToType.FieldURIOrConstant = ciConstantType; ffRestriction.Item = ieToType; findFolderRequest.Restriction = ffRestriction; // Add the folders to search to the request findFolderRequest.ParentFolderIds = folderIDArray; try { // Send the request and get the response FindFolderResponseType findFolderResponse = esb.FindFolder(findFolderRequest); // Get the response messages ResponseMessageType[] rmta = findFolderResponse.ResponseMessages.Items; foreach (ResponseMessageType rmt in rmta) { // Cast to the correct response message type FindFolderResponseMessageType ffResponse = (FindFolderResponseMessageType)rmt; foreach (FolderType fFoundFolder in ffResponse.RootFolder.Folders) { rvFolderID = fFoundFolder.FolderId; } } } catch (Exception e) { string problem = e.Message; } return rvFolderID; }
internal override void ValidateMeetings(ref Dictionary <GlobalObjectId, List <Attendee> > organizerRumsSent, Action <long> onItemRepaired) { bool shouldProcessMailbox = CalendarParticipant.InternalShouldProcessMailbox(this.ExchangePrincipal); try { List <SearchExpressionType> list = new List <SearchExpressionType>(); foreach (CalendarInstanceContext calendarInstanceContext in base.ItemList.Values) { calendarInstanceContext.ValidationContext.CalendarInstance = new CalendarRemoteItem(this.ExchangePrincipal, this.binding); calendarInstanceContext.ValidationContext.CalendarInstance.ShouldProcessMailbox = shouldProcessMailbox; GlobalObjectId globalObjectId = calendarInstanceContext.ValidationContext.BaseItem.GlobalObjectId; string value = Convert.ToBase64String(globalObjectId.CleanGlobalObjectIdBytes); SearchExpressionType item = new IsEqualToType { Item = CalendarItemFields.CleanGlobalObjectIdProp, FieldURIOrConstant = new FieldURIOrConstantType { Item = new ConstantValueType { Value = value } } }; list.Add(item); } ItemType[] remoteCalendarItems = this.GetRemoteCalendarItems(list); if (remoteCalendarItems != null) { Dictionary <GlobalObjectId, CalendarItemType> dictionary = new Dictionary <GlobalObjectId, CalendarItemType>(); foreach (ItemType itemType in remoteCalendarItems) { CalendarItemType calendarItemType = itemType as CalendarItemType; GlobalObjectId globalObjectId2 = CalendarItemFields.GetGlobalObjectId(calendarItemType); dictionary.Add(globalObjectId2, calendarItemType); } foreach (KeyValuePair <GlobalObjectId, CalendarInstanceContext> keyValuePair in base.ItemList) { if (dictionary.ContainsKey(keyValuePair.Key)) { CalendarItemType remoteItem = dictionary[keyValuePair.Key]; CalendarInstanceContext value2 = keyValuePair.Value; try { try { CalendarItemBase calendarItemBase = CalendarItem.Create(this.localSession, this.localSession.GetDefaultFolderId(DefaultFolderType.Calendar)); Globals.ConsistencyChecksTracer.TraceDebug((long)this.GetHashCode(), "Converting the EWS item to XSO."); this.calendarConverter.ConvertItem(calendarItemBase, remoteItem); value2.ValidationContext.OppositeItem = calendarItemBase; } catch (FormatException ex) { string text = string.Format("Could not convert the remote item, exception = {0}", ex.GetType()); Globals.ConsistencyChecksTracer.TraceError((long)this.GetHashCode(), text); value2.ValidationContext.CalendarInstance.LoadInconsistency = Inconsistency.CreateInstance(value2.ValidationContext.OppositeRole, text, CalendarInconsistencyFlag.StorageException, value2.ValidationContext); } catch (CorruptDataException ex2) { string text2 = string.Format("Could not convert the remote item, exception = {0}", ex2.GetType()); Globals.ConsistencyChecksTracer.TraceError((long)this.GetHashCode(), text2); value2.ValidationContext.CalendarInstance.LoadInconsistency = Inconsistency.CreateInstance(value2.ValidationContext.OppositeRole, text2, CalendarInconsistencyFlag.StorageException, value2.ValidationContext); } catch (StorageTransientException ex3) { string text3 = string.Format("Could not convert the remote item, exception = {0}", ex3.GetType()); Globals.ConsistencyChecksTracer.TraceError((long)this.GetHashCode(), text3); value2.ValidationContext.CalendarInstance.LoadInconsistency = Inconsistency.CreateInstance(value2.ValidationContext.OppositeRole, text3, CalendarInconsistencyFlag.StorageException, value2.ValidationContext); } continue; } finally { base.ValidateInstance(value2, organizerRumsSent, onItemRepaired); if (value2.ValidationContext.OppositeItem != null) { value2.ValidationContext.OppositeItem.Dispose(); value2.ValidationContext.OppositeItem = null; } } } Globals.ConsistencyChecksTracer.TraceDebug((long)this.GetHashCode(), "GetItem didn't return an expected GlobalObjectId."); } } foreach (CalendarInstanceContext calendarInstanceContext2 in base.ItemList.Values) { if (!calendarInstanceContext2.IsValidationDone) { if (calendarInstanceContext2.ValidationContext.OppositeRole == RoleType.Organizer && calendarInstanceContext2.ValidationContext.OppositeItem == null) { calendarInstanceContext2.ValidationContext.OppositeRoleOrganizerIsValid = true; } base.ValidateInstance(calendarInstanceContext2, organizerRumsSent, onItemRepaired); } } } catch (ProtocolViolationException exception) { this.HandleRemoteException(exception); } catch (SecurityException exception2) { this.HandleRemoteException(exception2); } catch (ArgumentException exception3) { this.HandleRemoteException(exception3); } catch (InvalidOperationException exception4) { this.HandleRemoteException(exception4); } catch (NotSupportedException exception5) { this.HandleRemoteException(exception5); } catch (XmlException exception6) { this.HandleRemoteException(exception6); } catch (XPathException exception7) { this.HandleRemoteException(exception7); } catch (SoapException exception8) { this.HandleRemoteException(exception8); } catch (IOException exception9) { this.HandleRemoteException(exception9); } }