以下のような交換サーバーを使用して、受信トレイの新しいメッセージを読み取るメソッドを作成しました。これらの IEnumerable コレクションをキューに追加し、キュー内のアイテムの各リストを非同期的に処理する方法は?
private static IEnumerable<ExchangeEmailInformation> GetInboxItems(ExchangeService service)
{
var emailInformations = new List<ExchangeEmailInformation>();
try
{
SearchFilter searchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
var itemview = new ItemView(int.MaxValue);
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, searchFilter, itemview);
Console.WriteLine("\n-------------Result found:-------------");
service.LoadPropertiesForItems(findResults, PropertySet.FirstClassProperties);
foreach (var item in findResults)
{
emailInformations.Add(new ExchangeEmailInformation
{
Attachment = item.Attachments ?? null,
Body = item.Body.BodyType == BodyType.HTML ? ConvertHtml.ToText(item.Body.Text) : item.Body.Text,
Subject = item.Subject,
RecievedDate = item.DateTimeReceived
});
}
}
catch (Exception ee)
{
Console.WriteLine("\n-------------Error occured:-------------");
Console.WriteLine(ee.Message.ToString());
Console.WriteLine(ee.InnerException.ToString());
Console.ReadKey();
}
return emailInformations;
}
以下は、キュー内の各アイテムを使用して非同期に呼び出す必要があるプロセスです
static void AddAttachment(string subject ,string docId, string user, string fileName)
{
var url = new StringBuilder();
url.Append(string.Format("https://webdemo-t.test.com:8443/Services/Service/MyService.svc/AddAttachment?User={0}&Engagement={1}&FileName={2}&DocumentTrasferID={3}", user, subject, fileName, docId));
Console.WriteLine(url.ToString());
WebRequest request = WebRequest.Create(url.ToString());
var credential = new NetworkCredential("user", "xxxx", "xxxx");
request.Credentials = credential;
WebResponse ws = request.GetResponse();
Encoding enc = System.Text.Encoding.GetEncoding(1252);
var responseStream = new StreamReader(ws.GetResponseStream());
string response = responseStream.ReadToEnd();
responseStream.Close();
Console.WriteLine(response);
}