void MeshNetworkLifeCycle(SubnetworkManager subnetworkManager, Tier lowVoltageMeshTier, Element elementM1, Element elementM2, Element elementM3) { #region Life cycle for a mesh subnetwork with multiple controllers // Create a subnetwork named "Mesh1" from three controllers // elementM1, elementM2, and elementM3 represent the devices that serve as subnetwork controllers (e.g., network protectors) subnetworkManager.EnableController(lowVoltageMeshTier, elementM1, "Mesh1", "M1", "my description", "my notes"); subnetworkManager.EnableController(lowVoltageMeshTier, elementM2, "Mesh1", "M2", "my description", "my notes"); Subnetwork subnetworkMesh1 = subnetworkManager.EnableController(lowVoltageMeshTier, elementM3, "Mesh1", "M3", "my description", "my notes"); subnetworkMesh1.Update(); MapView.Active.Redraw(true); // ... // When deleting the subnetwork, each controller must be disabled before the subnetwork itself is deleted subnetworkManager.DisableControllerInEditOperation(elementM1); subnetworkManager.DisableControllerInEditOperation(elementM2); subnetworkManager.DisableControllerInEditOperation(elementM3); // After the subnetwork is deleted, all of the rows that have been labeled with the subnetwork ID need to be updated subnetworkMesh1.Update(); MapView.Active.Redraw(true); // The final step is to notify external systems (if any) using the Export Subnetwork geoprocessing tool #endregion }
void RadialNetworkLifecycle(SubnetworkManager subnetworkManager, Tier mediumVoltageTier, Element elementR1) { #region Life cycle for a simple radial subnetwork with one controller // Create a subnetwork named "Radial1" with a single controller // elementR1 represents the device that serves as the subnetwork controller (e.g., circuit breaker) Subnetwork subnetworkRadial1 = subnetworkManager.EnableControllerInEditOperation(mediumVoltageTier, elementR1, "Radial1", "R1", "my description", "my notes"); // ... // Update the subnetwork and refresh the map subnetworkRadial1.Update(); MapView.Active.Redraw(true); // ... // At some point, a subnetwork will need to be deleted. // First step is to disable the controller subnetworkManager.DisableControllerInEditOperation(elementR1); // At this point, the subnetwork is deleted, but all of the rows that have been labeled with the subnetwork ID need to be updated subnetworkRadial1.Update(); MapView.Active.Redraw(true); // The final step is to notify external systems (if any) using the Export Subnetwork geoprocessing tool #endregion }
void UpdateAllDirtySubnetworks(UtilityNetwork utilityNetwork, Tier tier, MapView mapView) { #region Update all dirty subnetworks in a tier using (SubnetworkManager subnetworkManager = utilityNetwork.GetSubnetworkManager()) { subnetworkManager.UpdateAllSubnetworks(tier, true); mapView.Redraw(true); } #endregion }
protected override async void OnClick() { try { string unLayerName = "Electric Utility Network"; string domainNetworkName = "ElectricTransmission"; string tierName = "AC High Voltage"; Layer unLayer = await GetLayerByName(MapView.Active.Map, unLayerName); UtilityNetwork utilityNetwork = await GetUNByLayer(unLayer); await QueuedTask.Run(() => { using (UtilityNetworkDefinition utilityNetworkDefinition = utilityNetwork.GetDefinition()) { DomainNetwork domainNetwork = utilityNetworkDefinition.GetDomainNetwork(domainNetworkName); Tier tier = domainNetwork.GetTier(tierName); using (SubnetworkManager subnetworkManager = utilityNetwork.GetSubnetworkManager()) { Subnetwork dirtySubnetwork = subnetworkManager.GetSubnetworks(tier, SubnetworkStates.Dirty).FirstOrDefault(); try { if (dirtySubnetwork != null) { SubnetworkController subnetworkController = dirtySubnetwork.GetControllers().First(); subnetworkManager.DisableControllerInEditOperation(subnetworkController.Element); utilityNetwork.ValidateNetworkTopologyInEditOperation(); dirtySubnetwork.Update(); // Redraw map and clear cache MapView.Active.Redraw(true); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } // utilityNetwork.ValidateNetworkTopology(); }); } catch (Exception ex) { MessageBox.Show($"An exception occurred: {ex.Message}"); } }
void UpdateAllDirtySubnetworks(UtilityNetwork utilityNetwork, Tier tier, MapView mapView) { #region Update all dirty subnetworks in a tier using (SubnetworkManager subnetworkManager = utilityNetwork.GetSubnetworkManager()) { IReadOnlyList <Subnetwork> subnetworks = subnetworkManager.GetSubnetworks(tier, SubnetworkStates.Dirty | SubnetworkStates.DirtyAndDeleted); foreach (Subnetwork subnetwork in subnetworks) { subnetwork.Update(); } mapView.Redraw(true); } #endregion }
void MultifeedRadialLifeCycle(SubnetworkManager subnetworkManager, Tier mediumVoltageTier, Element elementR2, Element elementR3) { #region Life cycle for a multifeed radial subnetwork with two controllers // Create a subnetwork named "R2, R3" from two controllers // elementR2 and elementR3 represent the devices that serve as subnetwork controllers (e.g., circuit breakers) subnetworkManager.EnableControllerInEditOperation(mediumVoltageTier, elementR2, "R2, R3", "R2", "my description", "my notes"); subnetworkManager.EnableControllerInEditOperation(mediumVoltageTier, elementR3, "R2, R3", "R3", "my description", "my notes"); // If the tie switch between them is opened, the original subnetwork controllers must be disabled and re-enabled with different names // This will create two new subnetworks, named "R2" and "R3" subnetworkManager.DisableControllerInEditOperation(elementR2); subnetworkManager.DisableControllerInEditOperation(elementR3); Subnetwork subnetworkR2 = subnetworkManager.EnableControllerInEditOperation(mediumVoltageTier, elementR2, "R2", "R2", "my description", "my notes"); Subnetwork subnetworkR3 = subnetworkManager.EnableControllerInEditOperation(mediumVoltageTier, elementR3, "R3", "R3", "my description", "my notes"); subnetworkR2.Update(); subnetworkR3.Update(); MapView.Active.Redraw(true); #endregion }
/// <summary> /// Run the toggle switches process, it can be cancel /// </summary> /// <param name="cps">Cancelable Progressor Source to show the progression</param> /// <param name="mapExtent">Map Extent to zomm to the precedent extent</param> /// <returns>An error comment if needed, empty of no error</returns> internal static async Task <string> RunCancelableToggleSwwitches(CancelableProgressorSource cps, Envelope mapExtent) { string status = ""; await QueuedTask.Run(() => { cps.Progressor.Max = 6; cps.Progressor.Value += 1; cps.Progressor.Status = (cps.Progressor.Value * 100 / cps.Progressor.Max) + @" % Completed"; cps.Progressor.Message = "Step 1 – Toggle switch status"; // change selected switches attributes status = ToggleSwitchesExecute(); }, cps.Progressor); await QueuedTask.Run(() => { if (String.IsNullOrEmpty(status) && !cps.Progressor.CancellationToken.IsCancellationRequested) { cps.Progressor.Value += 1; cps.Progressor.Status = (cps.Progressor.Value * 100 / cps.Progressor.Max) + @" % Completed"; cps.Progressor.Message = "Step 2 – Validate and save edits"; // ValidateNetworkTopology need an Edit Operation if there are some editions not saved Project.Current.SaveEditsAsync(); GlobalUtilityNetwork.ValidateNetworkTopology(); // ValidateNetworkTopology create an edit operation which must be saved Project.Current.SaveEditsAsync(); cps.Progressor.Value += 1; cps.Progressor.Status = (cps.Progressor.Value * 100 / cps.Progressor.Max) + @" % Completed"; cps.Progressor.Message = "Step 3 – Update the dirty subnetwork(s)"; UtilityNetworkDefinition unDef = GlobalUtilityNetwork.GetDefinition(); Tier tier = unDef.GetDomainNetwork(cDomainNetworkName).GetTier(cTierName); SubnetworkManager subManager = GlobalUtilityNetwork.GetSubnetworkManager(); // Update subnetwork try { subManager.UpdateAllSubnetworks(tier, true); } catch (Exception ex) { status = ExceptionFormat(ex); } } }, cps.Progressor); await QueuedTask.Run(() => { if (String.IsNullOrEmpty(status) && !cps.Progressor.CancellationToken.IsCancellationRequested) { cps.Progressor.Value += 1; cps.Progressor.Status = (cps.Progressor.Value * 100 / cps.Progressor.Max) + @" % Completed"; cps.Progressor.Message = "Step 4 – Color the diagram edges per subnetwork"; ColorEdges.ExecuteReductionEdgeColorBySubnetwork(GetDiagramLayerFromMap(MapView.Active.Map)); cps.Progressor.Value += 1; cps.Progressor.Status = (cps.Progressor.Value * 100 / cps.Progressor.Max) + @" % Completed"; cps.Progressor.Message = "Step 5 – Redraw the Network Diagram"; MapView.Active.Redraw(true); MapView.Active.ZoomTo(mapExtent); // re set the selection if (GlobalMapSelection != null) { MapView.Active.Map.ClearSelection(); MapView.Active.Map.SetSelection(GlobalMapSelection); } } }, cps.Progressor); await QueuedTask.Run(() => { CleanModule(); }); return(status); }