Creating a custom task for a Windows application

Complexity: Beginner Data Requirement: Installed with software

This walkthrough describes how to use a Visual Studio project template to develop a task and deploy it using Mobile Project Center (MPC).

ArcGIS for Windows Mobile ships with two Visual Studio 2008 C# project templates to help you create Visual Studio projects for building a Windows application task or project extension. These templates are integrated with Visual Studio 2008 and can be used in the same way as the Visual Studio built-in project templates. A project created based on the template contains classes for your task or project extension, assembly reference, and project properties.

In this walkthrough, you'll learn how to create a Hello World task using the Visual Studio project template and deploy it with MPC.

The steps involved include the following:

Where to get the sample

Download the HelloWorldTask sample.

Prerequisites

To complete this walkthrough, you need the following:

Creating an ArcGIS Mobile application task using a Visual Studio project template

The Hello World task appears as a menu item on the View Map page menu. Tap this task menu item, and the application starts the Hello World task workflow and navigates to another page.

Steps:
  1. Start Visual Studio .NET 2008 and click File > New > Project.
  2. Click ArcGIS Mobile under Visual C# in the Project types pane on the New Project dialog box.
  3. Choose .NET Framework 3.5 from the drop-down list at the top right of the dialog box.
  4. Choose Task in the Templates pane.
  5. Name the project HelloWorldTask, specify the location for the project, then click OK.

    New Project menu to choose a template

  6. Since you do not need the Windows Mobile project, you can delete it from the solution.

    Visual Studio creates three projects in the solution using this template: one for the Windows application, one for the Windows Mobile application, and one for MPC.

    • The Windows and Windows Mobile projects are for developing task assemblies used with the Windows application and Windows Mobile application.
    • The MPC project is for developing an assembly for describing the application's HelloWorldTask assembly. MPC needs it to deploy the Hello World task to mobile projects.

    List of Mobile projects in solution.

  7. Review the HelloWorldTask_Win project. It contains a HelloWorldTask class derived from Task. Task is the base class for all tasks within the ArcGIS Mobile for Windows application. In the constructor, it defines task name and description.

    This HelloWorldTask class also has a function called Execute(), which is called when the Hello World task is launched in the application, it should be created as follows:

    MobileApplication.Current.Transition(new Page1());
    

    Page1 is an empty Mobile Application page created from the Task project template.

    Now the HelloWorldTask_Win.cs file looks like this:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using ESRI.ArcGIS.Mobile;
    using ESRI.ArcGIS.Mobile.Client;
    
    namespace HelloWorldTask
    {
      /// <summary>
      /// TODO: Make the following attributes the same for all 
      /// the projects in this solution
      /// 1. Current Namespace
      /// 2. Task class name and project center class name
      /// 3. Assembly name (through Project's Property dialog)
      /// 4. Default Namespace (through Project's Property dialog)
      /// </summary>
      public class HelloWorldTaskClass : Task
      {
        // TODO: Update constructor name after you change task name
        public HelloWorldTaskClass()
        {
          //Name
          Name = "HelloWorldTaskClass";
          //Description
          Description = "My Custom Task description";
        }
    
        // task icon, 
        // need the same way as for page icon
        // TODO: If you change task assembly name, replace the "HelloWorldTask" 
        // in the Uri with new Task assembly name.
        protected override System.Windows.Media.ImageSource GetImageSource()
        {
          Uri uri = new Uri("pack://application:,,,/HelloWorldTask;Component/TaskIcon72.png");
          return new System.Windows.Media.Imaging.BitmapImage(uri);
        }
    
        public override void Execute()
        {
          MobileApplication.Current.Transition(new Page1());
        }
      }
    }
    

  8. Add a button to the empty Page1 by opening the Page1.xaml file and adding a button within the grid as follows:

    <ArcGISMobileApplication:MobileApplicationPage
        x:Class="HelloWorldTask.Page1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:ArcGISMobileApplication="clr-namespace:ESRI.ArcGIS.Mobile.Client;assembly=ESRI.ArcGIS.Mobile.Client"             
        Height="300" Width="300">
      <Grid>
         <Button Height="100" Width="200" Name="button1" >Hello again</Button>         
        </Grid>
    </ArcGISMobileApplication:MobileApplicationPage>
    

  9. Now, this simple Hello World task is done, compile it to make HelloWorldTask.dll.
  10. To deploy this Hello World task to a mobile project using MPC, the *_ProjectCenter project will be used. Ensure that it compiles correctly.
  11. Copy the compiled assemblies to the Program Data folder to be used by MPC.
    1. Copy the Windows assembly HelloWorldTask.dll from C:\COGS\HelloWorldTask\HelloWorldTask\HelloWorldTask_Win\bin\Debug to C:\ProgramData\ESRI\MobileProjectCenter\Extensions\Win32.
    2. Copy the MPC assembly HelloWorldTask.dll from the build location to the MPC folder. Your build location should be <working folder>HelloWorldTask\HelloWorldTask_ProjectCenter\bin\Debug, and the MPC folder for the Windows task C:\ProgramData\ESRI\MobileProjectCenter\Extensions.
  12. Add the Hello World task to a mobile project using MPC.
    1. Launch MPC and create a new project, or open an existing project.
    2. Click the Tasks tab and click Add. The Hello World task is listed here. Add it to the project and save the project.

      Use MPC to add the custom task.

  13. Test the Hello World task in the Windows application.
    1. Share your project with the HelloWorld task to ArcGIS Online or your own ArcGIS Server.
    2. Start the ArcGIS Mobile application, and download the project with your custom task.
    3. Open the Task Menu; the Hello World task should be added to the View Map page menu.
    4. Launch the ArcGIS Mobile for Windows application, and open the project you just created.

      Customized Task menu with Hello World Task.

    5. Click Hello World Task; the application navigates to the Hello World Page.

      Hello world task displays a page with a button.

1/7/2015