// ***********************************************************************************
        // * User selected a barrier layer... Get the barrier layer name and query
        // * for that layer
        // ***********************************************************************************
        private async void cmbBarriers_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ResourceLayer barriertType = (ResourceLayer)cmbBarriers.SelectedItem;

            if (barriertType.Name == "Select Barrier")
            {
                return;
            }


            var query = new ESRI.ArcGIS.OperationsDashboard.Query();

            query.ReturnGeometry = true;
            query.SpatialFilter  = _mapWidget.Map.Extent;
            query.WhereClause    = "1=1";
            query.Fields         = new string[] { "OBJECTID" };

            var result = await barriertType.DataSource.ExecuteQueryAsync(query);

            if (result == null || result.Features == null)
            {
                return;
            }
            else
            {
                queryBarrierType_ExecuteCompleted(result);
            }
        }
        // ***********************************************************************************
        // * User selected a facility type... query for that facility type
        // ***********************************************************************************
        private async void cmbFacility_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ResourceType resourceType = (ResourceType)cmbFacility.SelectedItem;

            if (resourceType.Name == "Select Type")
            {
                return;
            }

            _facilityType = resourceType.Name;
            FacilityType  = _facilityType;

            var query = new ESRI.ArcGIS.OperationsDashboard.Query();

            query.WhereClause    = _resourceTypeField + "='" + _facilityType + "'";
            query.ReturnGeometry = true;
            query.SpatialFilter  = _mapWidget.Map.Extent;
            query.Fields         = new string[] { "*" };

            ResourceLayer layer = (ResourceLayer)cmbLayers.SelectedItem;

            var result = await layer.DataSource.ExecuteQueryAsync(query);

            if (result == null || result.Features == null)
            {
                return;
            }
            else
            {
                queryResourceType_ExecuteCompleted(result);
            }
        }
        public FindClosestResourceToolbar(MapWidget mapWidget, ObservableCollection <ESRI.ArcGIS.OperationsDashboard.DataSource> resourceDatasources, String resourceTypeField,
                                          ObservableCollection <ESRI.ArcGIS.OperationsDashboard.DataSource> barriersDataSources)
        {
            InitializeComponent();
            this.DataContext = this;

            // Store a reference to the MapWidget that the toolbar has been installed to.
            _mapWidget = mapWidget;

            //set up the route task with find closest facility option
            _routeTask = new RouteTask("http://route.arcgis.com/arcgis/rest/services/World/ClosestFacility/NAServer/ClosestFacility_World/solveClosestFacility");
            _routeTask.SolveClosestFacilityCompleted += SolveClosestFacility_Completed;
            _routeTask.Failed += SolveClosestFacility_Failed;

            //check if the graphicslayers need to be added to the map.
            setupGraphicsLayer();

            //set up the resources/facilities datasource in the combobox
            setupResourcesDataSource(resourceDatasources);

            ResourceTypes      = new ObservableCollection <ResourceType>();
            _resourceTypeField = resourceTypeField;

            //set up the barriers types combobox
            //this will have to be read from the config file...
            BarriersDataSouces = new ObservableCollection <ResourceLayer>();
            //set up facilities type dropdown
            ResourceLayer barrierLayer = new ResourceLayer();

            barrierLayer.Name       = "Select Barrier";
            barrierLayer.DataSource = null;
            BarriersDataSouces.Add(barrierLayer);

            //Barriers - passed from the configurar
            foreach (ESRI.ArcGIS.OperationsDashboard.DataSource datasource in barriersDataSources)
            {
                barrierLayer            = new ResourceLayer();
                barrierLayer.Name       = datasource.Name;
                barrierLayer.DataSource = datasource;
                BarriersDataSouces.Add(barrierLayer);
            }

            cmbBarriers.ItemsSource = BarriersDataSouces;

            _incidentMarkerSymbol = new SimpleMarkerSymbol
            {
                Size  = 20,
                Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle
            };

            //polyline barrier layer symbol
            _polylineBarrierSymbol = new client.Symbols.SimpleLineSymbol()
            {
                Color = new SolidColorBrush(Color.FromRgb(138, 43, 226)),
                Width = 5
            };
        }
 // ***********************************************************************************
 // * Setup resources datasource for the map tool.
 // ***********************************************************************************
 private void setupResourcesDataSource(ObservableCollection <ESRI.ArcGIS.OperationsDashboard.DataSource> resourceDatasources)
 {
     if (resourceDatasources.Count == 0)
     {
         return;
     }
     else
     {
         ////set up resources/facilities layer
         ResourceLayers = new ObservableCollection <ResourceLayer>();
         var resourceLayer = new ResourceLayer();
         resourceLayer.Name       = resourceDatasources[0].Name;
         resourceLayer.DataSource = resourceDatasources[0];
         ResourceLayers.Add(resourceLayer);
     }
 }
 // ***********************************************************************************
 // * Setup resources datasource for the map tool. 
 // ***********************************************************************************
 private void setupResourcesDataSource(ObservableCollection<ESRI.ArcGIS.OperationsDashboard.DataSource> resourceDatasources)
 {
     if (resourceDatasources.Count == 0)
         return;
     else
     {
         ////set up resources/facilities layer  
         ResourceLayers = new ObservableCollection<ResourceLayer>();
         var resourceLayer = new ResourceLayer();
         resourceLayer.Name = resourceDatasources[0].Name;
         resourceLayer.DataSource = resourceDatasources[0];
         ResourceLayers.Add(resourceLayer);
     }
 }
        public FindClosestResourceToolbar(MapWidget mapWidget, ObservableCollection<ESRI.ArcGIS.OperationsDashboard.DataSource> resourceDatasources, String resourceTypeField, 
            ObservableCollection<ESRI.ArcGIS.OperationsDashboard.DataSource> barriersDataSources)
        {

            InitializeComponent();
            this.DataContext = this; 

            // Store a reference to the MapWidget that the toolbar has been installed to.
            _mapWidget = mapWidget;

            //set up the route task with find closest facility option 
            _routeTask = new RouteTask("http://route.arcgis.com/arcgis/rest/services/World/ClosestFacility/NAServer/ClosestFacility_World/solveClosestFacility");
            _routeTask.SolveClosestFacilityCompleted += SolveClosestFacility_Completed;
            _routeTask.Failed += SolveClosestFacility_Failed;

            //check if the graphicslayers need to be added to the map. 
            setupGraphicsLayer(); 

            //set up the resources/facilities datasource in the combobox 
            setupResourcesDataSource(resourceDatasources); 

            ResourceTypes = new ObservableCollection<ResourceType>();
            _resourceTypeField = resourceTypeField; 

            //set up the barriers types combobox 
            //this will have to be read from the config file...
            BarriersDataSouces = new ObservableCollection<ResourceLayer>();
            //set up facilities type dropdown 
            ResourceLayer barrierLayer = new ResourceLayer();
            barrierLayer.Name = "Select Barrier";
            barrierLayer.DataSource = null;
            BarriersDataSouces.Add(barrierLayer);

            //Barriers - passed from the configurar
            foreach (ESRI.ArcGIS.OperationsDashboard.DataSource datasource in barriersDataSources)
            {
                barrierLayer = new ResourceLayer();
                barrierLayer.Name = datasource.Name; 
                barrierLayer.DataSource = datasource; 
                BarriersDataSouces.Add(barrierLayer);
            }

            cmbBarriers.ItemsSource = BarriersDataSouces;

            _incidentMarkerSymbol = new SimpleMarkerSymbol
            {
                Size = 20,
                Style = SimpleMarkerSymbol.SimpleMarkerStyle.Circle
            };

            //polyline barrier layer symbol
            _polylineBarrierSymbol = new client.Symbols.SimpleLineSymbol()
            {
                Color = new SolidColorBrush(Color.FromRgb(138, 43, 226)),
                Width = 5
            };

        }
        // ***********************************************************************************
        // * Query the selected resource layer to get the different resource types...
        // ***********************************************************************************
        private void cmbLayers_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ResourceLayer layer = (ResourceLayer)cmbLayers.SelectedItem;

            queryResourceLayer(layer.DataSource);
        }