IEnumerable<TaskProjectItem>taskItems= Project.Current.GetItems<TaskProjectItem>();foreach(var item in taskItems){// do something}
Open a Task File - .esriTasks file
// Open a task filetry{// TODO - substitute your own .esriTasks file to be openedstringtaskFile=@"c:\Tasks\Get Started.esriTasks";
System.Guid guid=await TaskAssistantModule.OpenTaskAsync(taskFile);// TODO - retain the guid returned for use with CloseTaskAsync}catch(OpenTaskExceptione){// exception thrown if task file doesn't exist or has incorrect format
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(e.Message);}
Open a Project Task Item
// get the first project task itemvartaskItem= Project.Current.GetItems<TaskProjectItem>().FirstOrDefault();// if there isn't a project task item, returnif(taskItem==null)return;try{// Open it
System.Guid guid=await TaskAssistantModule.OpenTaskItemAsync(taskItem.TaskItemGuid);// TODO - retain the guid returned for use with CloseTaskAsync}catch(OpenTaskExceptione){
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(e.Message);}
Close a Task Item
// find the first project task item which is openvartaskItem= Project.Current.GetItems<TaskProjectItem>().FirstOrDefault(t => t.IsOpen ==true);// if there isn't a project task item, returnif(taskItem==null)return;// close it// NOTE : The task item will also be removed from the project
TaskAssistantModule.CloseTaskAsync(taskItem.TaskItemGuid);
Export a Task Item
// get the first project task itemvartaskItem= Project.Current.GetItems<TaskProjectItem>().FirstOrDefault();// if there isn't a project task item, returnif(taskItem==null)return;try{// export the task item to the c:\Temp folderstringexportFolder=@"c:\temp";stringfileName=await TaskAssistantModule.ExportTaskAsync(taskItem.TaskItemGuid, exportFolder);
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Task saved to "+fileName);}catch(ExportTaskExceptione){
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Error saving task "+ e.Message);}
Get Task Information - from a TaskProjectItem
vartaskItem= Project.Current.GetItems<TaskProjectItem>().FirstOrDefault();// if there isn't a project task item, returnif(taskItem==null)return;stringmessage=await QueuedTask.Run(async()=>{boolisOpen= taskItem.IsOpen;GuidtaskGuid= taskItem.TaskItemGuid;stringmsg="";try{TaskItemInfotaskItemInfo=await taskItem.GetTaskItemInfoAsync();msg="Name : "+ taskItemInfo.Name;msg+="\r\n"+"Description : "+ taskItemInfo.Description;msg+="\r\n"+"Guid : "+ taskItemInfo.Guid.ToString("B");msg+="\r\n"+"Task Count : "+ taskItemInfo.GetTasks().Count();// iterate the tasks in the task itemIEnumerable<TaskInfo>taskInfos= taskItemInfo.GetTasks();foreach(TaskInfo taskInfo in taskInfos){stringname= taskInfo.Name;Guidguid= taskInfo.Guid;// do something }}catch(OpenTaskExceptione){// exception thrown if task file doesn't exist or has incorrect formatmsg= e.Message;}catch(TaskFileVersionExceptione){// exception thrown if task file does not support returning task informationmsg= e.Message;}returnmsg;});
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(message,"Task Information");
Get Task Information - from an .esriTasks file
// TODO - substitute your own .esriTasks filestringtaskFile=@"c:\Tasks\Get Started.esriTasks";try{// retrieve the task item informationTaskItemInfotaskItemInfo=await TaskAssistantModule.GetTaskItemInfoAsync(taskFile);stringmessage="Name : "+ taskItemInfo.Name;message+="\r\n"+"Description : "+ taskItemInfo.Description;message+="\r\n"+"Guid : "+ taskItemInfo.Guid.ToString("B");message+="\r\n"+"Task Count : "+ taskItemInfo.GetTasks().Count();
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(message,"Task Information");}catch(OpenTaskExceptione){// exception thrown if task file doesn't exist or has incorrect format
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(e.Message,"Task Information");}catch(TaskFileVersionExceptione){// exception thrown if task file does not support returning task information
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(e.Message,"Task Information");}
Open a specific Task in a Task File - .esriTasks file
// TODO - substitute your own .esriTasks file to be openedstringtaskFile=@"c:\Tasks\Get Started.esriTasks";try{// retrieve the task item informationTaskItemInfotaskItemInfo=await TaskAssistantModule.GetTaskItemInfoAsync(taskFile);// find the first taskTaskInfotaskInfo= taskItemInfo.GetTasks().FirstOrDefault();Guidguid= Guid.Empty;if(taskInfo!=null){// if a task exists, open itguid=await TaskAssistantModule.OpenTaskAsync(taskFile, taskInfo.Guid);}else{// else just open the task itemguid=await TaskAssistantModule.OpenTaskAsync(taskFile);}// TODO - retain the guid returned for use with CloseTaskAsync }catch(OpenTaskExceptione){// exception thrown if task file doesn't exist or has incorrect format
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(e.Message);}catch(TaskFileVersionExceptione){// exception thrown if task file does not support returning task information
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(e.Message);}
Subscribe to Task Events
publicvoidTaskEvents(){
TaskStartedEvent.Subscribe(OnTaskStarted);
TaskEndedEvent.Subscribe(OnTaskCompletedOrCancelled);}privatevoidOnTaskStarted(TaskStartedEventArgsargs){stringuserName= args.UserID;// ArcGIS Online signed in userName. If not signed in to ArcGIS Online then returns the name of the user logged in to the Windows OS.stringprojectName= args.ProjectName;GuidtaskItemGuid= args.TaskItemGuid;stringtaskItemName= args.TaskItemName;stringtaskItemVersion= args.TaskItemVersion;GuidtaskGuid= args.TaskGuid;stringtaskName= args.TaskName;DateTimestartTime= args.StartTime;}privatevoidOnTaskCompletedOrCancelled(TaskEndedEventArgsargs){stringuserName= args.UserID;// ArcGIS Online signed in userName. If not signed in to ArcGIS Online then returns the name of the user logged in to the Windows OS.stringprojectName= args.ProjectName;GuidtaskItemGuid= args.TaskItemGuid;stringtaskItemName= args.TaskItemName;stringtaskItemVersion= args.TaskItemVersion;GuidtaskGuid= args.TaskGuid;stringtaskName= args.TaskName;DateTimestartTime= args.StartTime;DateTimeendTime= args.EndTime;doubleduration= args.Duration;boolcompleted= args.Completed;// completed or cancelled}