private async void DiscoverResourcesAsync ()
{
_discoverResourcesCommand.SetCanExecute (false);
try
{
var serverResources = await _serverSettingsViewModel.GetServerResources (_networkSettingsViewModel, _generalOptions);
var calendars = serverResources.Calendars.Select (c => new CalendarDataViewModel (c)).ToArray();
var addressBooks = serverResources.AddressBooks.Select (a => new AddressBookDataViewModel (a)).ToArray();
var taskLists = serverResources.TaskLists.Select (d => new TaskListDataViewModel (d)).ToArray();
using (var selectResourcesForm = SelectResourceForm.CreateForFolderAssignment(_optionTasks, ConnectionTests.ResourceType.Calendar, calendars, addressBooks, taskLists))
{
if (selectResourcesForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
List<Contracts.Options> optionList = new List<Contracts.Options>();
foreach (var resource in calendars.Where (c => c.SelectedFolder != null))
{
var options = CreateOptions(resource);
_serverSettingsViewModel.FillOptions (options, resource.Model);
optionList.Add (options);
}
foreach (var resource in addressBooks.Where (c => c.SelectedFolder != null))
{
var options = CreateOptions (resource);
_serverSettingsViewModel.FillOptions (options, resource.Model);
optionList.Add (options);
}
foreach (var resource in taskLists.Where (c => c.SelectedFolder != null))
{
var options = CreateOptions (resource);
_serverSettingsViewModel.FillOptions (options, resource.Model);
optionList.Add (options);
}
_parent.RequestAdd (optionList);
_parent.RequestRemoval (this);
}
}
}
catch (Exception x)
{
s_logger.Error ("Exception while DiscoverResourcesAsync.", x);
string message = null;
for (Exception ex = x; ex != null; ex = ex.InnerException)
message += ex.Message + Environment.NewLine;
MessageBox.Show (message, OptionTasks.ConnectionTestCaption);
}
finally
{
_discoverResourcesCommand.SetCanExecute (true);
}
}