public Task FindTask()
{
Task result = Report.TaskFolder.GetTasks().FirstOrDefault(i => i.Definition.RegistrationInfo.Source == TaskSource);
foreach (var task in Report.TaskFolder.GetTasks())
{
if (task.Definition.RegistrationInfo.Source.ToLower().Trim() == TaskSource.ToLower().Trim()) result = task;
}
if (result == null)
{
//check if the task is still existing (typically if the report was moved or renamed)
foreach (Task task in Report.TaskFolder.GetTasks().Where(i => i.Name.EndsWith(GUID) && i.Definition.RegistrationInfo.Source.EndsWith(GUID)))
{
bool ok = true;
string reportPath = GetTaskSourceDetail(task.Definition.RegistrationInfo.Source, 0);
if (File.Exists(reportPath))
{
try
{
//probably a report copy, the task should stay attached on the initial report
Report report = Report.LoadFromFile(reportPath, Report.Repository);
if (report.GUID == GetTaskSourceDetail(task.Definition.RegistrationInfo.Source, 1) && report.Schedules.Exists(i => i.GUID == GUID)) ok = false;
}
catch { }
}
if (ok)
{
//take this task
result = task;
break;
}
}
}
return result;
}