public async Task <IActionResult> Create(CategoryView categoryView) { if (!ModelState.IsValid) { return(View(categoryView)); } var category = UtilityCategory.Create(categoryView); _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
private void CategoryClicked(object sender, EventArgs e) { UIAlertController prompt = UIAlertController.Create("Choose category for filter barrier", null, UIAlertControllerStyle.Alert); // Build the choice list for categories populated with the `Name` property of each `UtilityCategory` in the `UtilityNetworkDefinition`. foreach (var category in _utilityNetwork.Definition.Categories) { prompt.AddAction(UIAlertAction.Create(category.Name, UIAlertActionStyle.Default, (a) => { _selectedCategory = category; _categoryButton.Title = category.Name; })); } prompt.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null)); PresentViewController(prompt, true, null); }
private async void Initialize() { try { _loadingView.StartAnimating(); // Disable the UI. _categoryButton.Enabled = _traceButton.Enabled = false; // Create and load the utility network. _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServiceUrl)); // Create a map with layers in this utility network. _myMapView.Map = new Map(Basemap.CreateStreetsNightVector()); _myMapView.Map.OperationalLayers.Add(new FeatureLayer(new Uri($"{FeatureServiceUrl}/{LineLayerId}"))); _myMapView.Map.OperationalLayers.Add(new FeatureLayer(new Uri($"{FeatureServiceUrl}/{DeviceLayerId}"))); // Get a trace configuration from a tier. UtilityDomainNetwork domainNetwork = _utilityNetwork.Definition.GetDomainNetwork(DomainNetworkName) ?? throw new ArgumentException(DomainNetworkName); UtilityTier tier = domainNetwork.GetTier(TierName) ?? throw new ArgumentException(TierName); _configuration = tier.TraceConfiguration; // Create a trace filter. _configuration.Filter = new UtilityTraceFilter(); // Get a default starting location. UtilityNetworkSource networkSource = _utilityNetwork.Definition.GetNetworkSource(NetworkSourceName) ?? throw new ArgumentException(NetworkSourceName); UtilityAssetGroup assetGroup = networkSource.GetAssetGroup(AssetGroupName) ?? throw new ArgumentException(AssetGroupName); UtilityAssetType assetType = assetGroup.GetAssetType(AssetTypeName) ?? throw new ArgumentException(AssetTypeName); Guid globalId = Guid.Parse(GlobalId); _startingLocation = _utilityNetwork.CreateElement(assetType, globalId); // Create a graphics overlay. GraphicsOverlay overlay = new GraphicsOverlay(); _myMapView.GraphicsOverlays.Add(overlay); // Display starting location. IEnumerable <ArcGISFeature> elementFeatures = await _utilityNetwork.GetFeaturesForElementsAsync(new List <UtilityElement> { _startingLocation }); MapPoint startingLocationGeometry = elementFeatures.FirstOrDefault().Geometry as MapPoint; Symbol symbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Cross, System.Drawing.Color.LimeGreen, 25d); Graphic graphic = new Graphic(startingLocationGeometry, symbol); overlay.Graphics.Add(graphic); // Set the starting viewpoint. await _myMapView.SetViewpointAsync(new Viewpoint(startingLocationGeometry, 3000)); // Build the choice list for categories populated with the `Name` property of each `UtilityCategory` in the `UtilityNetworkDefinition`. _selectedCategory = _utilityNetwork.Definition.Categories.First(); _categoryButton.Title = _selectedCategory.Name; // Enable the UI. _categoryButton.Enabled = _traceButton.Enabled = true; } catch (Exception ex) { new UIAlertView(ex.GetType().Name, ex.Message, (IUIAlertViewDelegate)null, "OK", null).Show(); } finally { _loadingView.StopAnimating(); } }
private async void Initialize() { // As of ArcGIS Enterprise 10.8.1, using utility network functionality requires a licensed user. The following login for the sample server is licensed to perform utility network operations. AuthenticationManager.Current.ChallengeHandler = new ChallengeHandler(async(info) => { try { // WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample. string sampleServer7User = "******"; string sampleServer7Pass = "******"; return(await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass)); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); return(null); } }); try { _loadingView.StartAnimating(); // Disable the UI. _categoryButton.Enabled = _traceButton.Enabled = false; // Create and load the utility network. _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServiceUrl)); // Create a map with layers in this utility network. _myMapView.Map = new Map(BasemapStyle.ArcGISStreetsNight); _myMapView.Map.OperationalLayers.Add(new FeatureLayer(new Uri($"{FeatureServiceUrl}/{LineLayerId}"))); _myMapView.Map.OperationalLayers.Add(new FeatureLayer(new Uri($"{FeatureServiceUrl}/{DeviceLayerId}"))); // Get a trace configuration from a tier. UtilityDomainNetwork domainNetwork = _utilityNetwork.Definition.GetDomainNetwork(DomainNetworkName) ?? throw new ArgumentException(DomainNetworkName); UtilityTier tier = domainNetwork.GetTier(TierName) ?? throw new ArgumentException(TierName); _configuration = tier.TraceConfiguration; // Create a trace filter. _configuration.Filter = new UtilityTraceFilter(); // Get a default starting location. UtilityNetworkSource networkSource = _utilityNetwork.Definition.GetNetworkSource(NetworkSourceName) ?? throw new ArgumentException(NetworkSourceName); UtilityAssetGroup assetGroup = networkSource.GetAssetGroup(AssetGroupName) ?? throw new ArgumentException(AssetGroupName); UtilityAssetType assetType = assetGroup.GetAssetType(AssetTypeName) ?? throw new ArgumentException(AssetTypeName); Guid globalId = Guid.Parse(GlobalId); _startingLocation = _utilityNetwork.CreateElement(assetType, globalId); // Create a graphics overlay. GraphicsOverlay overlay = new GraphicsOverlay(); _myMapView.GraphicsOverlays.Add(overlay); // Display starting location. IEnumerable <ArcGISFeature> elementFeatures = await _utilityNetwork.GetFeaturesForElementsAsync(new List <UtilityElement> { _startingLocation }); MapPoint startingLocationGeometry = elementFeatures.FirstOrDefault().Geometry as MapPoint; Symbol symbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Cross, System.Drawing.Color.LimeGreen, 25d); Graphic graphic = new Graphic(startingLocationGeometry, symbol); overlay.Graphics.Add(graphic); // Set the starting viewpoint. await _myMapView.SetViewpointAsync(new Viewpoint(startingLocationGeometry, 3000)); // Build the choice list for categories populated with the `Name` property of each `UtilityCategory` in the `UtilityNetworkDefinition`. _selectedCategory = _utilityNetwork.Definition.Categories.First(); _categoryButton.Title = _selectedCategory.Name; // Enable the UI. _categoryButton.Enabled = _traceButton.Enabled = true; } catch (Exception ex) { new UIAlertView(ex.GetType().Name, ex.Message, (IUIAlertViewDelegate)null, "OK", null).Show(); } finally { _loadingView.StopAnimating(); } }