Trabalhando com Tarefas no Exchange Server

Trabalhando com Tarefas

Aspose.Email suporta o processamento de tarefas no Exchange Server usando a classe ExchangeTask. Diferentes propriedades expostas pelo ExchangeTask, como Subject, Status, DueDate e Priority, podem ser usadas para configurar a tarefa no Exchange. A classe IEWSClient expõe funções como CreateTask, UpdateTask e DeleteTask que são usados para processar tarefas no Exchange Server. Este artigo mostra como:

  • Criar uma nova tarefa.
  • Definir o fuso horário de uma tarefa.
  • Atualizar uma tarefa.
  • Excluir uma tarefa.
  • Enviar solicitação de tarefa.
  • Salvar a tarefa no disco.

Criar Nova Tarefa

O seguinte trecho de código mostra como criar uma nova tarefa.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C
// Create instance of EWSClient class by giving credentials
System::SharedPtr<IEWSClient> client = GetExchangeEWSClient(GetExchangeTestUser());
// Create Exchange task object
System::SharedPtr<ExchangeTask> task = System::MakeObject<ExchangeTask>();
// Set task subject and status to In progress
task->set_Subject(u"New-Test");
task->set_Status(Aspose::Email::Clients::Exchange::WebService::ExchangeTaskStatus::InProgress);
client->CreateTask(client->get_MailboxInfo()->get_TasksUri(), task);

Especificando o Fuso Horário

A interface IEWSClient e ExchangeTask fornecem a propriedade TimeZoneId para definir informações de fuso horário ao criar uma tarefa. O seguinte trecho de código mostra como especificar o fuso horário.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C
client->set_TimezoneId(u"Central Europe Standard Time");

Atualizar Tarefa

O seguinte trecho de código mostra como atualizar uma tarefa no servidor Exchange.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C
// Create instance of ExchangeClient class by giving credentials
System::SharedPtr<IEWSClient> client = GetExchangeEWSClient(GetExchangeTestUser());
// Get all tasks info collection from exchange
System::SharedPtr<ExchangeMessageInfoCollection> tasks = client->ListMessages(client->get_MailboxInfo()->get_TasksUri());
// Parse all the tasks info in the list
for (auto info : System::IterateOver(tasks))
{
// Fetch task from exchange using current task info
System::SharedPtr<ExchangeTask> task = client->FetchTask(info->get_UniqueUri());
// Update the task status to NotStarted
task->set_Status(Aspose::Email::Clients::Exchange::WebService::ExchangeTaskStatus::NotStarted);
// Set the task due date
task->set_DueDate(System::DateTime(2013, 2, 26));
// Set task priority
task->set_Priority(Aspose::Email::MailPriority::Low);
// Update task on exchange
client->UpdateTask(task);
}

Excluir Tarefa

O seguinte trecho de código mostra como excluir uma tarefa no servidor Exchange.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C
// Create instance of ExchangeClient class by giving credentials
System::SharedPtr<IEWSClient> client = GetExchangeEWSClient(GetExchangeTestUser());
// Get all tasks info collection from exchange
System::SharedPtr<ExchangeMessageInfoCollection> tasks = client->ListMessages(client->get_MailboxInfo()->get_TasksUri());
// Parse all the tasks info in the list
for (auto info : System::IterateOver(tasks))
{
// Fetch task from exchange using current task info
System::SharedPtr<ExchangeTask> task = client->FetchTask(info->get_UniqueUri());
// Check if the current task fulfills the search criteria
if (System::ObjectExt::Equals(task->get_Subject(), u"test"))
{
//Delete task from exchange
client->DeleteTask(task->get_UniqueUri(), Aspose::Email::Clients::Exchange::WebService::DeleteTaskOptions::DeletePermanently);
}
}

Enviando Solicitação de Tarefa

O serviço Exchange do Aspose.Email fornece a capacidade de enviar solicitações de tarefa semelhantes ao Outlook. O seguinte trecho de código mostra como carregar uma mensagem de solicitação de tarefa do disco e enviá-la usando o IEWSClient.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C
System::String dataDir = GetDataDir_Exchange();
// Create instance of ExchangeClient class by giving credentials
System::SharedPtr<IEWSClient> client = GetExchangeEWSClient(GetExchangeTestUser());
System::SharedPtr<MsgLoadOptions> options = System::MakeObject<MsgLoadOptions>();
options->set_PreserveTnefAttachments(true);
// load task from .msg file
System::SharedPtr<MailMessage> eml = MailMessage::Load(dataDir + u"task.msg", options);
eml->set_From(MailAddress::to_MailAddress(u"firstname.lastname@domain.com"));
eml->get_To()->Clear();
eml->get_To()->Add(System::MakeObject<MailAddress>(u"firstname.lastname@domain.com"));
client->Send(eml);

Salvando Tarefa no Disco

Aspose.Email também permite salvar Tarefas do Exchange no disco no formato MSG do Outlook. O seguinte trecho de código mostra como salvar uma tarefa no disco.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-C
System::SharedPtr<ExchangeTask> task = System::MakeObject<ExchangeTask>();
task->set_Subject(System::String(u"TASK-ID - ") + System::Guid::NewGuid());
task->set_Status(Aspose::Email::Clients::Exchange::WebService::ExchangeTaskStatus::InProgress);
task->set_StartDate(System::DateTime::get_Now());
task->set_DueDate(task->get_StartDate().AddDays(3));
System::StaticCast<Calendar::Task>(task)->Save(dstEmail);