任务

检索项目中的所有任务项

1
2
3
4
5
IEnumerable<TaskProjectItem> taskItems = Project.Current.GetItems<TaskProjectItem>();
foreach (var item in taskItems)
{
// do something
}

打开任务文件 - .esriTasks 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Open a task file
try
{
// TODO - substitute your own .esriTasks file to be opened
string taskFile = @"c:\Tasks\Get Started.esriTasks";
//At 2.x -
//System.Guid guid = await TaskAssistantModule.OpenTaskAsync(taskFile);
var guid = await TaskAssistantFactory.Instance.OpenTaskFileAsync(taskFile);

// TODO - retain the guid returned for use with CloseTaskItemAsync
}
catch (OpenTaskException e)
{
// exception thrown if task file doesn't exist or has incorrect format
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(e.Message);
}

打开项目任务项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// get the first project task item
var taskItem = Project.Current.GetItems<TaskProjectItem>().FirstOrDefault();
// if there isn't a project task item, return
if (taskItem == null)
return;

try
{
// Open it
//At 2.x -
//System.Guid guid = await TaskAssistantModule.OpenTaskItemAsync(taskItem.TaskItemGuid);
var guid = await TaskAssistantFactory.Instance.OpenTaskItemAsync(taskItem.TaskItemGuid);

// TODO - retain the guid returned for use with CloseTaskItemAsync
}
catch (OpenTaskException e)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(e.Message);
}

关闭任务项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// find the first project task item which is open
var taskItem = Project.Current.GetItems<TaskProjectItem>().FirstOrDefault(t => t.IsOpen == true);
// if there isn't a project task item, return
if (taskItem == null)
return;

if (taskItem.IsOpen)
{
// close it
// NOTE : The task item will also be removed from the project
//At 2.x -
//TaskAssistantModule.CloseTaskAsync(taskItem.TaskItemGuid);
TaskAssistantFactory.Instance.CloseTaskItemAsync(taskItem.TaskItemGuid);
}

导出任务项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// get the first project task item
var taskItem = Project.Current.GetItems<TaskProjectItem>().FirstOrDefault();
// if there isn't a project task item, return
if (taskItem == null)
return;

try
{
// export the task item to the c:\Temp folder
string exportFolder = @"c:\temp";
//At 2.x -
//string fileName = await TaskAssistantModule.ExportTaskAsync(taskItem.TaskItemGuid, exportFolder);
string fileName = await TaskAssistantFactory.Instance.ExportTaskItemAsync(taskItem.TaskItemGuid, exportFolder);
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Task saved to " + fileName);
}
catch (ExportTaskException e)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Error saving task " + e.Message);
}

获取任务信息 - 从任务项目项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var taskItem = Project.Current.GetItems<TaskProjectItem>().FirstOrDefault();
// if there isn't a project task item, return
if (taskItem == null)
return;

string message = await QueuedTask.Run(async () =>
{
bool isOpen = taskItem.IsOpen;
Guid taskGuid = taskItem.TaskItemGuid;

string msg = "";
try
{
TaskItemInfo taskItemInfo = 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 item
IEnumerable<TaskInfo> taskInfos = taskItemInfo.GetTasks();
foreach (TaskInfo taskInfo in taskInfos)
{
string name = taskInfo.Name;
Guid guid = taskInfo.Guid;

// do something
}
}
catch (OpenTaskException e)
{
// exception thrown if task file doesn't exist or has incorrect format
msg = e.Message;
}
catch (TaskFileVersionException e)
{
// exception thrown if task file does not support returning task information
msg = e.Message;
}
return msg;
});

ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(message, "Task Information");

获取任务信息 - 从 .esriTasks 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// TODO - substitute your own .esriTasks file
string taskFile = @"c:\Tasks\Get Started.esriTasks";

string message = await QueuedTask.Run(async () =>
{
string msg = "";
try
{
// retrieve the task item information
//At 2.x -
//TaskItemInfo taskItemInfo = await TaskAssistantModule.GetTaskItemInfoAsync(taskFile);
TaskItemInfo taskItemInfo = await TaskAssistantFactory.Instance.GetTaskItemInfoAsync(taskFile);

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();

}
catch (OpenTaskException e)
{
// exception thrown if task file doesn't exist or has incorrect format
msg = e.Message;
}
catch (TaskFileVersionException e)
{
// exception thrown if task file does not support returning task information
msg = e.Message;
}
return msg;
});

ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(message, "Task Information");

在任务文件中打开特定任务 - .esriTasks 文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// TODO - substitute your own .esriTasks file to be opened
string taskFile = @"c:\Tasks\Get Started.esriTasks";

await QueuedTask.Run(async () =>
{
try
{
// retrieve the task item information
//At 2.x -
//TaskItemInfo taskItemInfo = await TaskAssistantModule.GetTaskItemInfoAsync(taskFile);
var taskItemInfo = await TaskAssistantFactory.Instance.GetTaskItemInfoAsync(taskFile);

// find the first task
TaskInfo taskInfo = taskItemInfo.GetTasks().FirstOrDefault();

Guid guid = Guid.Empty;
if (taskInfo != null)
{
// if a task exists, open it
//At 2.x -
//guid = await TaskAssistantModule.OpenTaskAsync(taskFile, taskInfo.Guid);
guid = await TaskAssistantFactory.Instance.OpenTaskFileAsync(taskFile, taskInfo.Guid);
}
else
{
// else just open the task item
//At 2.x -
//guid = await TaskAssistantModule.OpenTaskAsync(taskFile);
guid = await TaskAssistantFactory.Instance.OpenTaskFileAsync(taskFile);
}

// TODO - retain the guid returned for use with CloseTaskItemAsync
}
catch (OpenTaskException e)
{
// exception thrown if task file doesn't exist or has incorrect format
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(e.Message);
}
catch (TaskFileVersionException e)
{
// exception thrown if task file does not support returning task information
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(e.Message);
}

});

订阅任务事件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
public void TaskEvents()
{
TaskStartedEvent.Subscribe(OnTaskStarted);
TaskEndedEvent.Subscribe(OnTaskCompletedOrCancelled);
}

private void OnTaskStarted(TaskStartedEventArgs args)
{
string userName = 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.
string projectName = args.ProjectName;

Guid taskItemGuid = args.TaskItemGuid;
string taskItemName = args.TaskItemName;
string taskItemVersion = args.TaskItemVersion;

Guid taskGuid = args.TaskGuid;
string taskName = args.TaskName;

DateTime startTime = args.StartTime;
}

private void OnTaskCompletedOrCancelled(TaskEndedEventArgs args)
{
string userName = 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.
string projectName = args.ProjectName;

Guid taskItemGuid = args.TaskItemGuid;
string taskItemName = args.TaskItemName;
string taskItemVersion = args.TaskItemVersion;

Guid taskGuid = args.TaskGuid;
string taskName = args.TaskName;

DateTime startTime = args.StartTime;
DateTime endTime = args.EndTime;
double duration = args.Duration;

bool completed = args.Completed; // completed or cancelled
}

}