Trabajando con Tareas en Exchange Server
Trabajando con Tareas
Aspose.Email admite el procesamiento de tareas en Exchange utilizando la clase ExchangeTask. Diferentes propiedades expuestas por ExchangeTask, como Subject, Status, DueDate y Priority, se pueden usar para configurar la tarea en Exchange. La clase EWSClient expone funciones como CreateTask, UpdateTask y DeleteTask que se utilizan para procesar tareas en Exchange. Este artículo muestra cómo:
- Crear una nueva tarea.
- Establecer la zona horaria de una tarea.
- Actualizar una tarea.
- Eliminar una tarea.
- Enviar una Solicitud de Tarea
- Guardar Tarea en Disco
Crear Nueva Tarea
El siguiente fragmento de código muestra cómo crear una nueva tarea.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of EWSClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Create Exchange task object | |
ExchangeTask task = new ExchangeTask(); | |
// Set task subject and status to In progress | |
task.Subject = "New-Test"; | |
task.Status = ExchangeTaskStatus.InProgress; | |
client.CreateTask(client.MailboxInfo.TasksUri, task); |
Especificar Zona Horaria
La interfaz IEWSClient y ExchangeTask proporcionan la propiedad TimeZoneId para establecer la información de zona horaria al crear una tarea. El siguiente fragmento de código muestra cómo especificar la Zona Horaria.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
client.TimezoneId = "Central Europe Standard Time"; |
Actualizar Tarea
Los siguientes fragmentos de código muestran cómo actualizar una tarea en un servidor Exchange.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create and initialize credentials | |
var credentials = new NetworkCredential("username", "12345"); | |
// Create instance of ExchangeClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get all tasks info collection from exchange | |
ExchangeMessageInfoCollection tasks = client.ListMessages(client.MailboxInfo.TasksUri); | |
// Parse all the tasks info in the list | |
foreach (ExchangeMessageInfo info in tasks) | |
{ | |
// Fetch task from exchange using current task info | |
ExchangeTask task = client.FetchTask(info.UniqueUri); | |
// Update the task status to NotStarted | |
task.Status = ExchangeTaskStatus.NotStarted; | |
// Set the task due date | |
task.DueDate = new DateTime(2013, 2, 26); | |
// Set task priority | |
task.Priority = MailPriority.Low; | |
// Update task on exchange | |
client.UpdateTask(task); | |
} |
Eliminar Tarea
El siguiente fragmento de código muestra cómo eliminar una tarea en un servidor Exchange.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Create instance of ExchangeClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
// Get all tasks info collection from exchange | |
ExchangeMessageInfoCollection tasks = client.ListMessages(client.MailboxInfo.TasksUri); | |
// Parse all the tasks info in the list | |
foreach (ExchangeMessageInfo info in tasks) | |
{ | |
// Fetch task from exchange using current task info | |
ExchangeTask task = client.FetchTask(info.UniqueUri); | |
// Check if the current task fulfills the search criteria | |
if (task.Subject.Equals("test")) | |
{ | |
//Delete task from exchange | |
client.DeleteItem(task.UniqueUri, DeletionOptions.DeletePermanently); | |
} | |
} |
Enviando Solicitud de Tarea
El servicio de Exchange de Aspose.Email proporciona la capacidad de enviar solicitudes de tareas similares a Outlook. El siguiente fragmento de código muestra cómo cargar un mensaje de solicitud de tarea desde el disco y enviarlo utilizando el IEWSClient.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
string dataDir = RunExamples.GetDataDir_Exchange(); | |
// Create instance of ExchangeClient class by giving credentials | |
IEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "testUser", "pwd", "domain"); | |
MsgLoadOptions options = new MsgLoadOptions(); | |
options.PreserveTnefAttachments = true; | |
// load task from .msg file | |
MailMessage eml = MailMessage.Load(dataDir + "task.msg", options); | |
eml.From = "firstname.lastname@domain.com"; | |
eml.To.Clear(); | |
eml.To.Add(new MailAddress("firstname.lastname@domain.com")); | |
client.Send(eml); |
Guardar Tarea en Disco
Aspose.Email también permite guardar Tareas de Exchange en disco en formato MSG de Outlook. El siguiente fragmento de código muestra cómo guardar una tarea en disco.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
ExchangeTask task = new ExchangeTask(); | |
task.Subject = "TASK-ID - " + Guid.NewGuid(); | |
task.Status = ExchangeTaskStatus.InProgress; | |
task.StartDate = DateTime.Now; | |
task.DueDate = task.StartDate.AddDays(3); | |
task.Save(dstEmail); |
Listando Tareas desde el Servidor de Exchange
IEWSClient proporciona el método ListTasks que se puede utilizar para obtener tareas de un Servicio Web de Exchange. Tiene varias sobrecargas que se pueden usar para recuperar la lista de tareas de una carpeta específica o utilizando algunos criterios de búsqueda. El siguiente ejemplo de código ilustra cómo obtener todas o tareas específicas de la carpeta de Tareas.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET | |
// Set mailboxURI, Username, password, domain information | |
string mailboxUri = "https://ex2010/ews/exchange.asmx"; | |
string username = "test.exchange"; | |
string password = "pwd"; | |
string domain = "ex2010.local"; | |
NetworkCredential credentials = new NetworkCredential(username, password, domain); | |
IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials); | |
//Listing Tasks from Server | |
client.TimezoneId = "Central Europe Standard Time"; | |
TaskCollection taskCollection = client.ListTasks(client.MailboxInfo.TasksUri); | |
//print retrieved tasks' details | |
foreach (ExchangeTask task in taskCollection) | |
{ | |
Console.WriteLine(client.TimezoneId); | |
Console.WriteLine(task.Subject); | |
Console.WriteLine(task.StartDate); | |
Console.WriteLine(task.DueDate); | |
} | |
//Listing Tasks from server based on Query - Completed and In-Progress | |
ExchangeQueryBuilder builder = new ExchangeQueryBuilder(); | |
ExchangeTaskStatus[] selectedStatuses = new ExchangeTaskStatus[] | |
{ | |
ExchangeTaskStatus.Completed, | |
ExchangeTaskStatus.InProgress | |
}; | |
builder.TaskStatus.In(selectedStatuses); | |
MailQuery query = builder.GetQuery(); | |
taskCollection = client.ListTasks(client.MailboxInfo.TasksUri, query); | |
//print retrieved tasks' details | |
foreach (ExchangeTask task in taskCollection) | |
{ | |
Console.WriteLine(client.TimezoneId); | |
Console.WriteLine(task.Subject); | |
Console.WriteLine(task.StartDate); | |
Console.WriteLine(task.DueDate); | |
} |
Filtrando Tareas desde el Servidor de Exchange
Aspose.Email proporciona la capacidad de recuperar tareas específicas del servidor en lugar de recuperar todas las tareas del servidor. La API se puede utilizar para recuperar tareas por estado de tarea como Completadas, Diferidas, En Progreso, No iniciadas o Esperando a otros. La clase ExchangeQueryBuilder se puede utilizar para especificar el criterio deseado utilizando la propiedad Status. También permite especificar múltiples condiciones para recuperar tareas deseadas del Servidor de Exchange. Esto se demuestra en el siguiente ejemplo de código.