private async void OnTrace(object sender, RoutedEventArgs e) { if (_utilityNetwork == null || _startingLocation == null) { return; } try { // Create utility trace parameters for the starting location. UtilityTraceParameters parameters = new UtilityTraceParameters(UtilityTraceType.Subnetwork, new[] { _startingLocation }); parameters.TraceConfiguration = _configuration; // Trace the utility network. IEnumerable <UtilityTraceResult> results = await _utilityNetwork.TraceAsync(parameters); // Get the first result. UtilityElementTraceResult elementResult = results?.FirstOrDefault() as UtilityElementTraceResult; // Display the number of elements found by the trace. MessageBox.Show($"`{elementResult?.Elements?.Count ?? 0}` elements found.", "Trace Result", MessageBoxButton.OK, MessageBoxImage.Information); } catch (Exception ex) { MessageBox.Show( $"{ex.Message}\nFor a working barrier condition, try \"Transformer Load\" Equal \"15\".", ex.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error); } }
private async void OnTrace(object sender, System.EventArgs e) { if (_utilityNetwork == null || _startingLocation == null) { return; } try { // Create utility trace parameters for the starting location. UtilityTraceParameters parameters = new UtilityTraceParameters(UtilityTraceType.Subnetwork, new[] { _startingLocation }); parameters.TraceConfiguration = _sourceTier.TraceConfiguration; // Trace the utility network. IEnumerable <UtilityTraceResult> results = await _utilityNetwork.TraceAsync(parameters); // Get the first result. UtilityElementTraceResult elementResult = results?.FirstOrDefault() as UtilityElementTraceResult; // Display the number of elements found by the trace. await Application.Current.MainPage.DisplayAlert("Trace Result", $"`{elementResult?.Elements?.Count ?? 0}` elements found.", "OK"); } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert("Error", $"{ex.Message}\nFor a working barrier condition, try \"Transformer Load\" Equal \"15\".", "OK"); } }
private async void TraceClick(object sender, EventArgs e) { if (_utilityNetwork == null || _startingLocation == null) { return; } try { // Create utility trace parameters for the starting location. UtilityTraceParameters parameters = new UtilityTraceParameters(UtilityTraceType.Subnetwork, new[] { _startingLocation }); parameters.TraceConfiguration = _configuration; // Trace the utility network. IEnumerable <UtilityTraceResult> results = await _utilityNetwork.TraceAsync(parameters); // Get the first result. UtilityElementTraceResult elementResult = results?.FirstOrDefault() as UtilityElementTraceResult; // Display the number of elements found by the trace. new UIAlertView("Trace Result", $"`{elementResult?.Elements?.Count ?? 0}` elements found.", (IUIAlertViewDelegate)null, "OK", null).Show(); } catch (Exception ex) { new UIAlertView(ex.GetType().Name, ex.Message, (IUIAlertViewDelegate)null, "OK", null).Show(); } }
private async void OnTrace(object sender, EventArgs e) { try { // Update the UI. _activityIndicator.StartAnimating(); _statusLabel.Text = $"Running {_utilityTraceType.ToString().ToLower()} trace..."; // Clear previous selection from the layers. _myMapView.Map.OperationalLayers.OfType <FeatureLayer>().ToList().ForEach(layer => layer.ClearSelection()); // Build trace parameters. UtilityTraceParameters parameters = new UtilityTraceParameters(_utilityTraceType, _startingLocations); foreach (UtilityElement barrier in _barriers) { parameters.Barriers.Add(barrier); } // Set the trace configuration using the tier from the utility domain network. parameters.TraceConfiguration = _mediumVoltageTier.TraceConfiguration; // Get the trace result from the utility network. IEnumerable <UtilityTraceResult> traceResult = await _utilityNetwork.TraceAsync(parameters); UtilityElementTraceResult elementTraceResult = traceResult?.FirstOrDefault() as UtilityElementTraceResult; // Check if there are any elements in the result. if (elementTraceResult?.Elements?.Count > 0) { foreach (FeatureLayer layer in _myMapView.Map.OperationalLayers.OfType <FeatureLayer>()) { IEnumerable <UtilityElement> elements = elementTraceResult.Elements.Where(element => element.NetworkSource.Name == layer.FeatureTable.TableName); IEnumerable <Feature> features = await _utilityNetwork.GetFeaturesForElementsAsync(elements); layer.SelectFeatures(features); } } _statusLabel.Text = "Trace completed."; } catch (Exception ex) { _statusLabel.Text = "Trace failed..."; if (ex is ArcGISWebException && ex.Message == null) { new UIAlertView(ex.GetType().Name, "Trace failed.", (IUIAlertViewDelegate)null, "OK", null).Show(); } else { new UIAlertView(ex.GetType().Name, ex.Message, (IUIAlertViewDelegate)null, "OK", null).Show(); } } finally { _activityIndicator.StopAnimating(); } }
private async void Trace_Click(object sender, EventArgs e) { try { _progressBar.Visibility = Android.Views.ViewStates.Visible; _status.Text = "Running connected trace..."; // Verify that the parameters contain a starting location. if (_parameters == null || !_parameters.StartingLocations.Any()) { throw new Exception("No starting locations set."); } // Get the trace result from the utility network. IEnumerable <UtilityTraceResult> traceResult = await _utilityNetwork.TraceAsync(_parameters); UtilityElementTraceResult elementTraceResult = traceResult?.FirstOrDefault() as UtilityElementTraceResult; if (elementTraceResult?.Elements?.Count > 0) { // Clear previous selection from the layer. _myMapView.Map.OperationalLayers.OfType <FeatureLayer>().ToList().ForEach(layer => layer.ClearSelection()); // Group the utility elements by their network source. IEnumerable <IGrouping <string, UtilityElement> > groupedElementsResult = from element in elementTraceResult.Elements group element by element.NetworkSource.Name into groupedElements select groupedElements; foreach (IGrouping <string, UtilityElement> elementGroup in groupedElementsResult) { // Get the layer for the utility element. FeatureLayer layer = (FeatureLayer)_myMapView.Map.OperationalLayers.FirstOrDefault(l => l is FeatureLayer && ((FeatureLayer)l).FeatureTable.TableName == elementGroup.Key); if (layer == null) { continue; } // Convert elements to features to highlight result. IEnumerable <Feature> features = await _utilityNetwork.GetFeaturesForElementsAsync(elementGroup); layer.SelectFeatures(features); } } _status.Text = "Trace completed."; } catch (Exception ex) { _status.Text = "Trace failed..."; CreateDialog(ex.Message); } finally { _progressBar.Visibility = Android.Views.ViewStates.Invisible; } }
private async void OnTrace(object sender, RoutedEventArgs e) { try { LoadingBar.Visibility = Visibility.Visible; // Clear previous selection from the layers. MyMapView.Map.OperationalLayers.OfType <FeatureLayer>().ToList().ForEach(layer => layer.ClearSelection()); if (Categories.SelectedItem is UtilityCategory category) { // NOTE: UtilityNetworkAttributeComparison or UtilityCategoryComparison with Operator.DoesNotExists // can also be used. These conditions can be joined with either UtilityTraceOrCondition or UtilityTraceAndCondition. UtilityCategoryComparison categoryComparison = new UtilityCategoryComparison(category, UtilityCategoryComparisonOperator.Exists); // Add the filter barrier. _configuration.Filter.Barriers = categoryComparison; } // Set the include isolated features property. _configuration.IncludeIsolatedFeatures = IncludeIsolatedFeatures.IsChecked == true; // Build parameters for isolation trace. UtilityTraceParameters parameters = new UtilityTraceParameters(UtilityTraceType.Isolation, new[] { _startingLocation }); parameters.TraceConfiguration = _configuration; // Get the trace result from trace. IEnumerable <UtilityTraceResult> traceResult = await _utilityNetwork.TraceAsync(parameters); UtilityElementTraceResult elementTraceResult = traceResult?.FirstOrDefault() as UtilityElementTraceResult; // Select all the features from the result. if (elementTraceResult?.Elements?.Count > 0) { foreach (FeatureLayer layer in MyMapView.Map.OperationalLayers.OfType <FeatureLayer>()) { IEnumerable <UtilityElement> elements = elementTraceResult.Elements.Where(element => element.NetworkSource.Name == layer.FeatureTable.TableName); IEnumerable <Feature> features = await _utilityNetwork.GetFeaturesForElementsAsync(elements); layer.SelectFeatures(features); } } } catch (Exception ex) { await new MessageDialog(ex.Message, ex.GetType().Name).ShowAsync(); } finally { LoadingBar.Visibility = Visibility.Collapsed; } }
private async void OnTrace(object sender, EventArgs e) { try { _loadingView.StartAnimating(); // Clear previous selection from the layers. _myMapView.Map.OperationalLayers.OfType <FeatureLayer>().ToList().ForEach(layer => layer.ClearSelection()); if (_selectedCategory != null) { // NOTE: UtilityNetworkAttributeComparison or UtilityCategoryComparison with Operator.DoesNotExists // can also be used. These conditions can be joined with either UtilityTraceOrCondition or UtilityTraceAndCondition. UtilityCategoryComparison categoryComparison = new UtilityCategoryComparison(_selectedCategory, UtilityCategoryComparisonOperator.Exists); // Add the filter barrier. _configuration.Filter.Barriers = categoryComparison; } // Set the include isolated features property. _configuration.IncludeIsolatedFeatures = _featuresSwitch.On; // Build parameters for isolation trace. UtilityTraceParameters parameters = new UtilityTraceParameters(UtilityTraceType.Isolation, new[] { _startingLocation }); parameters.TraceConfiguration = _configuration; // Get the trace result from trace. IEnumerable <UtilityTraceResult> traceResult = await _utilityNetwork.TraceAsync(parameters); UtilityElementTraceResult elementTraceResult = traceResult?.FirstOrDefault() as UtilityElementTraceResult; // Select all the features from the result. if (elementTraceResult?.Elements?.Count > 0) { foreach (FeatureLayer layer in _myMapView.Map.OperationalLayers.OfType <FeatureLayer>()) { IEnumerable <UtilityElement> elements = elementTraceResult.Elements.Where(element => element.NetworkSource.Name == layer.FeatureTable.TableName); IEnumerable <Feature> features = await _utilityNetwork.GetFeaturesForElementsAsync(elements); layer.SelectFeatures(features); } } } catch (Exception ex) { new UIAlertView(ex.GetType().Name, ex.Message, (IUIAlertViewDelegate)null, "OK", null).Show(); } finally { _loadingView.StopAnimating(); } }
private async void OnTrace(object sender, RoutedEventArgs e) { try { // Get the selected trace type. UtilityTraceType traceType = (UtilityTraceType)TraceTypes.SelectedItem; // Update the UI. MainUI.IsEnabled = false; IsBusy.Visibility = Visibility.Visible; Status.Text = $"Running {traceType.ToString().ToLower()} trace..."; // Clear previous selection from the layers. MyMapView.Map.OperationalLayers.OfType <FeatureLayer>().ToList().ForEach(layer => layer.ClearSelection()); // Build trace parameters. UtilityTraceParameters parameters = new UtilityTraceParameters(traceType, _startingLocations); foreach (UtilityElement barrier in _barriers) { parameters.Barriers.Add(barrier); } // Set the trace configuration using the tier from the utility domain network. parameters.TraceConfiguration = _mediumVoltageTier.TraceConfiguration; // Get the trace result from the utility network. IEnumerable <UtilityTraceResult> traceResult = await _utilityNetwork.TraceAsync(parameters); UtilityElementTraceResult elementTraceResult = traceResult?.FirstOrDefault() as UtilityElementTraceResult; // Check if there are any elements in the result. if (elementTraceResult?.Elements?.Count > 0) { foreach (FeatureLayer layer in MyMapView.Map.OperationalLayers.OfType <FeatureLayer>()) { IEnumerable <UtilityElement> elements = elementTraceResult.Elements.Where(element => element.NetworkSource.Name == layer.FeatureTable.TableName); IEnumerable <Feature> features = await _utilityNetwork.GetFeaturesForElementsAsync(elements); layer.SelectFeatures(features); } } Status.Text = "Trace completed."; } catch (Exception ex) { Status.Text = "Trace failed..."; if (ex is ArcGISWebException && ex.Message == null) { MessageBox.Show("Trace failed.", ex.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error); } else { MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error); } } finally { MainUI.IsEnabled = true; IsBusy.Visibility = Visibility.Hidden; } }