/// <summary> /// Retrieves contacts from exchange database. /// </summary> /// <returns></returns> public IEnumerable <ContactItemType> GetContacts() { var binding = ChannelHelper.BuildChannel(hostname, username, password); var findItemRequest = new FindItemType { ItemShape = new ItemResponseShapeType { BaseShape = DefaultShapeNamesType.AllProperties }, ParentFolderIds = new[] { new DistinguishedFolderIdType { Id = DistinguishedFolderIdNameType.contacts } } }; FindItemResponseType findItemResponse = binding.FindItem(findItemRequest); // Determine whether the request was a success. if (findItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Error) { throw new Exception(findItemResponse.ResponseMessages.Items[0].MessageText); } var responseMessage = (FindItemResponseMessageType)findItemResponse.ResponseMessages.Items[0]; var contactItems = (ArrayOfRealItemsType)responseMessage.RootFolder.Item; return(contactItems.Items.Cast <ContactItemType>()); }
/// <summary> /// Find all the items in the specified folder. /// </summary> /// <param name="folderName">Name of the specified folder.</param> /// <returns>An array of found items.</returns> private ItemType[] FindAllItems(DistinguishedFolderIdNameType folderName) { // Create an array of ItemType. ItemType[] items = null; // Create an instance of FindItemType. FindItemType findItemRequest = new FindItemType(); findItemRequest.ParentFolderIds = new BaseFolderIdType[1]; DistinguishedFolderIdType parentFolder = new DistinguishedFolderIdType(); parentFolder.Id = folderName; findItemRequest.ParentFolderIds[0] = parentFolder; // Get properties that are defined as the default for the items. findItemRequest.ItemShape = new ItemResponseShapeType(); findItemRequest.ItemShape.BaseShape = DefaultShapeNamesType.Default; // Invoke the FindItem operation. FindItemResponseType findItemResponse = this.exchangeServiceBinding.FindItem(findItemRequest); if (findItemResponse != null && findItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Success) { // Get the found items from the response. FindItemResponseMessageType findItemMessage = findItemResponse.ResponseMessages.Items[0] as FindItemResponseMessageType; ArrayOfRealItemsType findItems = findItemMessage.RootFolder.Item as ArrayOfRealItemsType; items = findItems.Items; } return(items); }
/// <summary> /// Проверяет успешность подключения к серверу Exchange с указанными параметрами /// </summary> /// <param name="ex">Параметры подключения</param> /// <param name="message">Возвращает текст ошибки подключения при ее наличии</param> /// <returns></returns> public static bool CheckConnection(Configuration.Exchange ex, out string message) { try { message = string.Empty; ExchangeServiceBinding bind = new ExchangeServiceBinding(); bind.Credentials = new NetworkCredential(ex.Username, ex.Password, ex.Domain); bind.Url = "https://" + ex.ServerName + "/EWS/Exchange.asmx"; FindItemType findType = new FindItemType(); findType.Traversal = ItemQueryTraversalType.Shallow; findType.ItemShape = new ItemResponseShapeType(); findType.ItemShape.BaseShape = DefaultShapeNamesType.IdOnly; DistinguishedFolderIdType folder = new DistinguishedFolderIdType(); folder.Id = DistinguishedFolderIdNameType.inbox; findType.ParentFolderIds = new BaseFolderIdType[] { folder }; FindItemResponseType findResp = bind.FindItem(findType); } catch (Exception error) { message = error.Message; return(false); } return(true); }
/// <summary> /// Search specified items. /// </summary> /// <param name="findRequest">A request to the FindItem operation.</param> /// <returns>The response message returned by FindItem operation.</returns> public FindItemResponseType FindItem(FindItemType findRequest) { FindItemResponseType findResponse = this.exchangeServiceBinding.FindItem(findRequest); ArrayOfRealItemsType items = ((FindItemResponseMessageType)findResponse.ResponseMessages.Items[0]).RootFolder.Item as ArrayOfRealItemsType; this.VerifyAbchPersonItemTypeComplexType((AbchPersonItemType)items.Items[0], this.exchangeServiceBinding.IsSchemaValidated); return(findResponse); }
/// <summary> /// The operation searches the specified user's mailbox and returns the result whether the valid items are found after the MoveItem or DeleteItem operation completed. /// </summary> /// <param name="userName">Name of the user.</param> /// <param name="password">Password of the user.</param> /// <param name="domain">Domain of the user.</param> /// <param name="folderName">A string that specifies the folder to search.</param> /// <param name="value">A string that specifies the value for a search restriction.</param> /// <param name="field">A string that specifies the type of referenced field URI.</param> /// <returns>If the item existed in the specific folder, return true; otherwise, return false.</returns> protected bool IsItemAvailableAfterMoveOrDelete(string userName, string password, string domain, string folderName, string value, string field) { this.SRCHAdapter.SwitchUser(userName, password, domain); // Construct a request for FindItem operation. FindItemType findRequest = this.ConstructFindItemRequest(folderName, value, field); #region Invoke FindItem operation int counter = 0; int upperBound = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site)); int waitTime = int.Parse(Common.GetConfigurationPropertyValue("WaitTime", this.Site)); FindItemResponseType findResponse = new FindItemResponseType(); while (counter < upperBound) { Thread.Sleep(waitTime); findResponse = this.SRCHAdapter.FindItem(findRequest); if (findResponse != null && findResponse.ResponseMessages != null && findResponse.ResponseMessages.Items != null && findResponse.ResponseMessages.Items.Length > 0) { foreach (ResponseMessageType item in findResponse.ResponseMessages.Items) { if (item.ResponseClass == ResponseClassType.Success) { FindItemResponseMessageType findItem = item as FindItemResponseMessageType; if (findItem.RootFolder.Item != null) { ArrayOfRealItemsType realItems = findItem.RootFolder.Item as ArrayOfRealItemsType; if (realItems.Items != null && realItems.Items.Length > 0) { counter++; } else { return(false); } } else { return(false); } } } } } Site.Log.Add(LogEntryKind.Debug, "Even after retrying {0} times, Message with specified subject is still available, this means previous call to MoveItem or DeleteItem has not worked yet.", counter); return(true); #endregion }
/// <summary> /// The operation searches the mailbox and returns the result whether one or more valid items are found. /// </summary> /// <param name="userName">The userName of the user used to communicate with server</param> /// <param name="password">The password of the user used to communicate with server</param> /// <param name="domain">The domain of the user used to communicate with server</param> /// <param name="folderName">A string that specifies the folder to search.</param> /// <param name="value">A string that specifies the value for a search restriction.</param> /// <param name="field">A string that specifies the type of referenced field URI.</param> /// <returns>If the operation succeeds, return the specific item; otherwise, return null.</returns> protected ItemType FindSpecificItem(string userName, string password, string domain, string folderName, string value, string field) { this.SRCHAdapter.SwitchUser(userName, password, domain); // Construct a request for FindItem operation. FindItemType findRequest = this.ConstructFindItemRequest(folderName, value, field); #region Invoke FindItem operation int counter = 0; int upperBound = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site)); int waitTime = int.Parse(Common.GetConfigurationPropertyValue("WaitTime", this.Site)); FindItemResponseType findResponse = new FindItemResponseType(); while (counter < upperBound) { Thread.Sleep(waitTime); findResponse = this.SRCHAdapter.FindItem(findRequest); if (findResponse != null && findResponse.ResponseMessages != null && findResponse.ResponseMessages.Items != null && findResponse.ResponseMessages.Items.Length > 0) { foreach (ResponseMessageType item in findResponse.ResponseMessages.Items) { if (item.ResponseClass == ResponseClassType.Success) { FindItemResponseMessageType findItem = item as FindItemResponseMessageType; if (findItem.RootFolder.Item != null) { ArrayOfRealItemsType realItems = findItem.RootFolder.Item as ArrayOfRealItemsType; if (realItems.Items != null && realItems.Items.Length > 0) { return(realItems.Items[0]); } } } } } counter++; } Site.Log.Add(LogEntryKind.Debug, "Even after retrying {0} times, operation FindItem could not find any message.", counter); return(null); #endregion }
private ResponseMessageType[] GetFolderItems(ExchangeServiceBinding svc, DistinguishedFolderIdNameType folder) { // Form the FindItem request. FindItemType findItemRequest = new FindItemType(); findItemRequest.Traversal = ItemQueryTraversalType.Shallow; // Define which item properties are returned in the response. ItemResponseShapeType itemProperties = new ItemResponseShapeType(); itemProperties.BaseShape = DefaultShapeNamesType.AllProperties; //Define propriedade que armazena antigo ID PathToExtendedFieldType netShowUrlPath = new PathToExtendedFieldType(); netShowUrlPath.PropertyTag = "0x3A4D"; netShowUrlPath.PropertyType = MapiPropertyTypeType.String; //Adiciona propriedade na busca itemProperties.AdditionalProperties = new BasePathToElementType[1]; itemProperties.AdditionalProperties[0] = netShowUrlPath; // Add properties shape to the request. findItemRequest.ItemShape = itemProperties; // Identify which folders to search to find items. DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[2]; folderIDArray[0] = new DistinguishedFolderIdType(); folderIDArray[0].Id = folder; // Add folders to the request. findItemRequest.ParentFolderIds = folderIDArray; // Send the request and get the response. FindItemResponseType findItemResponse = svc.FindItem(findItemRequest); // Get the response messages. ResponseMessageType[] rmta = findItemResponse.ResponseMessages.Items; return(rmta); }
/// <summary> /// Gets the nr of items in a given folder /// </summary> /// <returns></returns> public long GetNrItemsInFolder(ChannelFolder folder) { var binding = ChannelHelper.BuildChannel(hostname, username, password); var findItemRequest = new FindItemType { Traversal = ItemQueryTraversalType.Shallow }; var itemProperties = new ItemResponseShapeType { BaseShape = DefaultShapeNamesType.AllProperties }; findItemRequest.ItemShape = itemProperties; var folderIdArray = new DistinguishedFolderIdType[2]; folderIdArray[0] = new DistinguishedFolderIdType { Id = DistinguishedFolderIdNameType.inbox }; findItemRequest.ParentFolderIds = folderIdArray; FindItemResponseType findItemResponse = binding.FindItem(findItemRequest); // Determine whether the request was a success. if (findItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Error) { throw new Exception(findItemResponse.ResponseMessages.Items[0].MessageText); } var responseMessage = (FindItemResponseMessageType)findItemResponse.ResponseMessages.Items[0]; var mailboxItems = (ArrayOfRealItemsType)responseMessage.RootFolder.Item; if (mailboxItems.Items == null) { return(0); } return(mailboxItems.Items.Length); }
/// <summary> /// Gets a list of all the items in the mailbox with all their properties. /// </summary> /// <returns></returns> public IEnumerable <MessageType> GetHeaders(ChannelFolder folder) { var binding = ChannelHelper.BuildChannel(hostname, username, password); var findItemRequest = new FindItemType { Traversal = ItemQueryTraversalType.Shallow }; var itemProperties = new ItemResponseShapeType { BaseShape = DefaultShapeNamesType.AllProperties }; findItemRequest.ItemShape = itemProperties; findItemRequest.ParentFolderIds = new BaseFolderIdType[] { new FolderIdType { Id = folder.FolderId } }; FindItemResponseType findItemResponse = binding.FindItem(findItemRequest); foreach (FindItemResponseMessageType responseMessage in findItemResponse.ResponseMessages.Items) { if (responseMessage.ResponseClass == ResponseClassType.Success) { ArrayOfRealItemsType mailboxItems = (ArrayOfRealItemsType)responseMessage.RootFolder.Item; if (mailboxItems.Items == null) { yield break; } foreach (MessageType inboxItem in mailboxItems.Items) { yield return(inboxItem); } } } }
/// <summary> /// The method searches the mailbox and returns the items that meet a specified search restriction. /// </summary> /// <param name="folder">A string that specifies the folder to search.</param> /// <param name="value">A string that specifies the value for a search restriction.</param> /// <returns>If the method succeeds, return an array of item; otherwise, return null.</returns> private ItemIdType[] GetItemIds(string folder, string value) { #region Construct FindItem request FindItemType findRequest = new FindItemType(); if (string.IsNullOrEmpty(folder) || string.IsNullOrEmpty(value)) { Site.Assert.Fail("Invalid argument: one or more invalid arguments passed to GetItemIds method."); } findRequest.ItemShape = new ItemResponseShapeType(); findRequest.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties; DistinguishedFolderIdType folderId = new DistinguishedFolderIdType(); DistinguishedFolderIdNameType folderIdName; if (Enum.TryParse <DistinguishedFolderIdNameType>(folder, out folderIdName)) { folderId.Id = folderIdName; } else { Site.Assert.Fail("The value of the first argument (foldIdNameType) of FindItem operation is invalid."); } findRequest.ParentFolderIds = new BaseFolderIdType[1]; findRequest.ParentFolderIds[0] = folderId; PathToUnindexedFieldType itemClass = new PathToUnindexedFieldType(); itemClass.FieldURI = UnindexedFieldURIType.itemSubject; ContainsExpressionType expressionType = new ContainsExpressionType(); expressionType.Item = itemClass; expressionType.ContainmentMode = ContainmentModeType.Substring; expressionType.ContainmentModeSpecified = true; expressionType.ContainmentComparison = ContainmentComparisonType.IgnoreCaseAndNonSpacingCharacters; expressionType.ContainmentComparisonSpecified = true; expressionType.Constant = new ConstantValueType(); expressionType.Constant.Value = value; RestrictionType restriction = new RestrictionType(); restriction.Item = expressionType; findRequest.Restriction = restriction; #endregion #region Get the ids of all ItemId instances int counter = 0; int upperBound = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site)); int waitTime = int.Parse(Common.GetConfigurationPropertyValue("WaitTime", this.Site)); FindItemResponseType findResponse = new FindItemResponseType(); while (counter < upperBound) { Thread.Sleep(waitTime); findResponse = this.exchangeServiceBinding.FindItem(findRequest); if (findResponse != null && findResponse.ResponseMessages != null && findResponse.ResponseMessages.Items != null && findResponse.ResponseMessages.Items.Length > 0) { ArrayOfRealItemsType items = ((FindItemResponseMessageType)findResponse.ResponseMessages.Items[0]).RootFolder.Item as ArrayOfRealItemsType; if (items.Items != null && items.Items.Length > 0) { List <ItemIdType> itemIds = new List <ItemIdType>(); foreach (ItemType item in items.Items) { if (item.ItemId != null) { itemIds.Add(item.ItemId); } } if (itemIds.Count > 0) { return(itemIds.ToArray()); } } } counter++; } Site.Log.Add(LogEntryKind.Debug, "When there is not any message found by FindItem operation, the retry count is {0}", counter); return(null); #endregion }
/// <summary> /// The method searches the mailbox and returns the items that meet a specified search restriction. /// </summary> /// <param name="folder">A string that specifies the folder to search.</param> /// <param name="value">A string that specifies the value for a search restriction.</param> /// <returns>If the method succeeds, return an array of item; otherwise, return null.</returns> private ItemIdType[] GetItemIds(string folder, string value) { #region Construct FindItem request FindItemType findRequest = new FindItemType(); if (string.IsNullOrEmpty(folder) || string.IsNullOrEmpty(value)) { Site.Assert.Fail("Invalid argument: one or more invalid arguments passed to GetItemIds method."); } findRequest.ItemShape = new ItemResponseShapeType(); findRequest.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties; DistinguishedFolderIdType folderId = new DistinguishedFolderIdType(); DistinguishedFolderIdNameType folderIdName; if (Enum.TryParse<DistinguishedFolderIdNameType>(folder, out folderIdName)) { folderId.Id = folderIdName; } else { Site.Assert.Fail("The value of the first argument (foldIdNameType) of FindItem operation is invalid."); } findRequest.ParentFolderIds = new BaseFolderIdType[1]; findRequest.ParentFolderIds[0] = folderId; PathToUnindexedFieldType itemClass = new PathToUnindexedFieldType(); itemClass.FieldURI = UnindexedFieldURIType.itemSubject; ContainsExpressionType expressionType = new ContainsExpressionType(); expressionType.Item = itemClass; expressionType.ContainmentMode = ContainmentModeType.Substring; expressionType.ContainmentModeSpecified = true; expressionType.ContainmentComparison = ContainmentComparisonType.IgnoreCaseAndNonSpacingCharacters; expressionType.ContainmentComparisonSpecified = true; expressionType.Constant = new ConstantValueType(); expressionType.Constant.Value = value; RestrictionType restriction = new RestrictionType(); restriction.Item = expressionType; findRequest.Restriction = restriction; #endregion #region Get the ids of all ItemId instances int counter = 0; int upperBound = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site)); int waitTime = int.Parse(Common.GetConfigurationPropertyValue("WaitTime", this.Site)); FindItemResponseType findResponse = new FindItemResponseType(); while (counter < upperBound) { Thread.Sleep(waitTime); findResponse = this.exchangeServiceBinding.FindItem(findRequest); if (findResponse != null && findResponse.ResponseMessages != null && findResponse.ResponseMessages.Items != null && findResponse.ResponseMessages.Items.Length > 0) { ArrayOfRealItemsType items = ((FindItemResponseMessageType)findResponse.ResponseMessages.Items[0]).RootFolder.Item as ArrayOfRealItemsType; if (items.Items != null && items.Items.Length > 0) { List<ItemIdType> itemIds = new List<ItemIdType>(); foreach (ItemType item in items.Items) { if (item.ItemId != null) { itemIds.Add(item.ItemId); } } if (itemIds.Count > 0) { return itemIds.ToArray(); } } } counter++; } Site.Log.Add(LogEntryKind.Debug, "When there is not any message found by FindItem operation, the retry count is {0}", counter); return null; #endregion }
/// <summary> /// The operation searches the mailbox and returns the result whether one or more valid items are found. /// </summary> /// <param name="userName">The userName of the user used to communicate with server</param> /// <param name="password">The password of the user used to communicate with server</param> /// <param name="domain">The domain of the user used to communicate with server</param> /// <param name="folderName">A string that specifies the folder to search.</param> /// <param name="value">A string that specifies the value for a search restriction.</param> /// <param name="field">A string that specifies the type of referenced field URI.</param> /// <returns>If the operation succeeds, return the specific item; otherwise, return null.</returns> protected ItemType FindSpecificItem(string userName, string password, string domain, string folderName, string value, string field) { this.SRCHAdapter.SwitchUser(userName, password, domain); // Construct a request for FindItem operation. FindItemType findRequest = this.ConstructFindItemRequest(folderName, value, field); #region Invoke FindItem operation int counter = 0; int upperBound = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site)); int waitTime = int.Parse(Common.GetConfigurationPropertyValue("WaitTime", this.Site)); FindItemResponseType findResponse = new FindItemResponseType(); while (counter < upperBound) { Thread.Sleep(waitTime); findResponse = this.SRCHAdapter.FindItem(findRequest); if (findResponse != null && findResponse.ResponseMessages != null && findResponse.ResponseMessages.Items != null && findResponse.ResponseMessages.Items.Length > 0) { foreach (ResponseMessageType item in findResponse.ResponseMessages.Items) { if (item.ResponseClass == ResponseClassType.Success) { FindItemResponseMessageType findItem = item as FindItemResponseMessageType; if (findItem.RootFolder.Item != null) { ArrayOfRealItemsType realItems = findItem.RootFolder.Item as ArrayOfRealItemsType; if (realItems.Items != null && realItems.Items.Length > 0) { return realItems.Items[0]; } } } } } counter++; } Site.Log.Add(LogEntryKind.Debug, "Even after retrying {0} times, operation FindItem could not find any message.", counter); return null; #endregion }
/// <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); }
private ItemType[] GetRemoteCalendarItems(List <SearchExpressionType> searchItems) { FindItemType findItemType = new FindItemType(); findItemType.ItemShape = CalendarItemFields.CalendarQueryShape; findItemType.ParentFolderIds = new BaseFolderIdType[] { new DistinguishedFolderIdType { Id = DistinguishedFolderIdNameType.calendar } }; findItemType.Restriction = new RestrictionType { Item = new OrType { Items = searchItems.ToArray() } }; FindItemResponseType response = this.binding.FindItem(findItemType); ItemType[] array = this.HandleFindItemResponse(response); if (array == null) { Globals.ConsistencyChecksTracer.TraceDebug((long)this.GetHashCode(), "FindItem returned NULL ArrayOfRealItemsType."); return(null); } List <ItemIdType> list = new List <ItemIdType>(); foreach (ItemType itemType in array) { if (itemType is CalendarItemType) { CalendarItemType calendarItemType = itemType as CalendarItemType; if (calendarItemType.CalendarItemType1 == CalendarItemTypeType.Single) { list.Add(itemType.ItemId); } else { OccurrencesRangeType occurrencesRangeType = new OccurrencesRangeType { Start = base.ValidateFrom.UniversalTime, StartSpecified = true, End = base.ValidateUntil.UniversalTime, EndSpecified = true, Count = 100, CountSpecified = true }; RecurringMasterItemIdRangesType item = new RecurringMasterItemIdRangesType { Id = itemType.ItemId.Id, ChangeKey = itemType.ItemId.ChangeKey, Ranges = new OccurrencesRangeType[] { occurrencesRangeType } }; list.Add(item); } } else { Globals.ConsistencyChecksTracer.TraceDebug((long)this.GetHashCode(), "FindItem returned an item which is not a CalendarItemType. Skipping it."); } } if (list.Count < 1) { Globals.ConsistencyChecksTracer.TraceDebug((long)this.GetHashCode(), "FindItem didn't return valid items."); return(null); } GetItemType getItem = new GetItemType { ItemShape = CalendarItemFields.CalendarItemShape, ItemIds = list.ToArray() }; GetItemResponseType item2 = this.binding.GetItem(getItem); ItemType[] array3 = this.HandleGetItemResponse(item2); if (array3 == null) { Globals.ConsistencyChecksTracer.TraceDebug((long)this.GetHashCode(), "GetItem returned NULL ItemType[]."); } return(array3); }
/// <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); }
/// <summary> /// Search specified items. /// </summary> /// <param name="findRequest">A request to the FindItem operation.</param> /// <returns>The response message returned by FindItem operation.</returns> public FindItemResponseType FindItem(FindItemType findRequest) { FindItemResponseType findResponse = this.exchangeServiceBinding.FindItem(findRequest); return(findResponse); }
/// <summary> /// The operation searches the specified user's mailbox and returns the result whether the valid items are found after the MoveItem or DeleteItem operation completed. /// </summary> /// <param name="userName">Name of the user.</param> /// <param name="password">Password of the user.</param> /// <param name="domain">Domain of the user.</param> /// <param name="folderName">A string that specifies the folder to search.</param> /// <param name="value">A string that specifies the value for a search restriction.</param> /// <param name="field">A string that specifies the type of referenced field URI.</param> /// <returns>If the item existed in the specific folder, return true; otherwise, return false.</returns> protected bool IsItemAvailableAfterMoveOrDelete(string userName, string password, string domain, string folderName, string value, string field) { this.SRCHAdapter.SwitchUser(userName, password, domain); // Construct a request for FindItem operation. FindItemType findRequest = this.ConstructFindItemRequest(folderName, value, field); #region Invoke FindItem operation int counter = 0; int upperBound = int.Parse(Common.GetConfigurationPropertyValue("RetryCount", this.Site)); int waitTime = int.Parse(Common.GetConfigurationPropertyValue("WaitTime", this.Site)); FindItemResponseType findResponse = new FindItemResponseType(); while (counter < upperBound) { Thread.Sleep(waitTime); findResponse = this.SRCHAdapter.FindItem(findRequest); if (findResponse != null && findResponse.ResponseMessages != null && findResponse.ResponseMessages.Items != null && findResponse.ResponseMessages.Items.Length > 0) { foreach (ResponseMessageType item in findResponse.ResponseMessages.Items) { if (item.ResponseClass == ResponseClassType.Success) { FindItemResponseMessageType findItem = item as FindItemResponseMessageType; if (findItem.RootFolder.Item != null) { ArrayOfRealItemsType realItems = findItem.RootFolder.Item as ArrayOfRealItemsType; if (realItems.Items != null && realItems.Items.Length > 0) { counter++; } else { return false; } } else { return false; } } } } } Site.Log.Add(LogEntryKind.Debug, "Even after retrying {0} times, Message with specified subject is still available, this means previous call to MoveItem or DeleteItem has not worked yet.", counter); return true; #endregion }