Exemple #1
0
        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
        }
Exemple #2
0
        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
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The Dfa user object running the code example.
        /// </param>
        public override void Run(DfaUser user)
        {
            // Create SubnetworkRemoteService instance.
            SubnetworkRemoteService service = (SubnetworkRemoteService)user.GetService(
                DfaService.v1_19.SubnetworkRemoteService);

            long   networkId      = long.Parse(_T("INSERT_NETWORK_ID_HERE"));
            String subnetworkName = _T("INSERT_SUBNETWORK_NAME_HERE");
            long   permission1    = long.Parse(_T("INSERT_FIRST_PERMISSION_ID_HERE"));
            long   permission2    = long.Parse(_T("INSERT_SECOND_PERMISSION_ID_HERE"));

            // Create subnetwork structure.
            Subnetwork subnetwork = new Subnetwork();

            subnetwork.id        = 0;
            subnetwork.name      = subnetworkName;
            subnetwork.networkId = networkId;

            // Create an array of all permissions assigned to this subnetwork and add
            // it to the subnetwork structure. To get list of available permissions,
            // run GetAvailablePermissions.cs.
            subnetwork.availablePermissions = new long[] { permission1, permission2 };

            try {
                // Create subnetwork.
                SubnetworkSaveResult subnetworkSaveResult = service.saveSubnetwork(subnetwork);

                // Display subnetwork id.
                Console.WriteLine("Subnetwork with id \"{0}\" was created.", subnetworkSaveResult.id);
            } catch (Exception e) {
                Console.WriteLine("Failed to create subnetwork. Exception says \"{0}\"", e.Message);
            }
        }
Exemple #4
0
 /// <summary>Snippet for Insert</summary>
 public void Insert()
 {
     // Snippet: Insert(string, string, Subnetwork, CallSettings)
     // Create client
     SubnetworksClient subnetworksClient = SubnetworksClient.Create();
     // Initialize request argument(s)
     string     project            = "";
     string     region             = "";
     Subnetwork subnetworkResource = new Subnetwork();
     // Make the request
     Operation response = subnetworksClient.Insert(project, region, subnetworkResource);
     // End snippet
 }
Exemple #5
0
 /// <summary>Snippet for Get</summary>
 public void Get()
 {
     // Snippet: Get(string, string, string, CallSettings)
     // Create client
     SubnetworksClient subnetworksClient = SubnetworksClient.Create();
     // Initialize request argument(s)
     string project    = "";
     string region     = "";
     string subnetwork = "";
     // Make the request
     Subnetwork response = subnetworksClient.Get(project, region, subnetwork);
     // End snippet
 }
        public async stt::Task GetRequestObjectAsync()
        {
            moq::Mock <Subnetworks.SubnetworksClient> mockGrpcClient = new moq::Mock <Subnetworks.SubnetworksClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClientForRegionOperations()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetSubnetworkRequest request = new GetSubnetworkRequest
            {
                Region     = "regionedb20d96",
                Project    = "projectaa6ff846",
                Subnetwork = "subnetworkf55bf572",
            };
            Subnetwork expectedResponse = new Subnetwork
            {
                Id   = 11672635353343658936UL,
                Kind = "kindf7aa39d9",
                Name = "name1c9368b0",
                Role = Subnetwork.Types.Role.Active,
                CreationTimestamp       = "creation_timestamp235e59a1",
                PrivateIpv6GoogleAccess = Subnetwork.Types.PrivateIpv6GoogleAccess.EnableOutboundVmAccessToGoogle,
                IpCidrRange             = "ip_cidr_range745a04d3",
                State             = Subnetwork.Types.State.UndefinedState,
                SecondaryIpRanges =
                {
                    new SubnetworkSecondaryRange(),
                },
                Region                = "regionedb20d96",
                ExternalIpv6Prefix    = "external_ipv6_prefix2d3e744d",
                EnableFlowLogs        = false,
                Network               = "networkd22ce091",
                Fingerprint           = "fingerprint009e6052",
                Ipv6CidrRange         = "ipv6_cidr_range0b2dc35f",
                Purpose               = Subnetwork.Types.Purpose.PrivateServiceConnect,
                LogConfig             = new SubnetworkLogConfig(),
                PrivateIpGoogleAccess = false,
                Description           = "description2cf9da67",
                StackType             = Subnetwork.Types.StackType.Ipv4Ipv6,
                SelfLink              = "self_link7e87f12d",
                GatewayAddress        = "gateway_address39dbeaef",
                Ipv6AccessType        = Subnetwork.Types.Ipv6AccessType.External,
            };

            mockGrpcClient.Setup(x => x.GetAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Subnetwork>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            SubnetworksClient client = new SubnetworksClientImpl(mockGrpcClient.Object, null);
            Subnetwork        responseCallSettings = await client.GetAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            Subnetwork responseCancellationToken = await client.GetAsync(request, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
Exemple #7
0
 public UdpNewPeerPacket(
     string Name,
     uint SubnetworkIP,
     bool RecipiantIsNew,
     PeerData[] Peers,
     Subnetwork SubnetworkData
     )
 {
     this.Name           = Name;
     this.SubnetworkIP   = SubnetworkIP;
     this.RecipientIsNew = RecipiantIsNew;
     this.Peers          = Peers;
     this.SubnetworkData = SubnetworkData;
     this.PreferedCipher = 0;
 }
        public void GetRequestObject()
        {
            moq::Mock <Subnetworks.SubnetworksClient> mockGrpcClient = new moq::Mock <Subnetworks.SubnetworksClient>(moq::MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClientForRegionOperations()).Returns(new moq::Mock <lro::Operations.OperationsClient>().Object);
            GetSubnetworkRequest request = new GetSubnetworkRequest
            {
                Region     = "regionedb20d96",
                Project    = "projectaa6ff846",
                Subnetwork = "subnetworkf55bf572",
            };
            Subnetwork expectedResponse = new Subnetwork
            {
                Id   = 11672635353343658936UL,
                Kind = "kindf7aa39d9",
                Name = "name1c9368b0",
                Role = "role64e9a729",
                CreationTimestamp       = "creation_timestamp235e59a1",
                PrivateIpv6GoogleAccess = "private_ipv6_google_access0dc5c953",
                IpCidrRange             = "ip_cidr_range745a04d3",
                State             = "state2e9ed39e",
                SecondaryIpRanges =
                {
                    new SubnetworkSecondaryRange(),
                },
                Region                = "regionedb20d96",
                ExternalIpv6Prefix    = "external_ipv6_prefix2d3e744d",
                EnableFlowLogs        = false,
                Network               = "networkd22ce091",
                Fingerprint           = "fingerprint009e6052",
                Ipv6CidrRange         = "ipv6_cidr_range0b2dc35f",
                Purpose               = "purposebb6b064d",
                LogConfig             = new SubnetworkLogConfig(),
                PrivateIpGoogleAccess = false,
                Description           = "description2cf9da67",
                StackType             = "stack_type3a495e39",
                SelfLink              = "self_link7e87f12d",
                GatewayAddress        = "gateway_address39dbeaef",
                Ipv6AccessType        = "ipv6_access_type7faa3985",
            };

            mockGrpcClient.Setup(x => x.Get(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            SubnetworksClient client   = new SubnetworksClientImpl(mockGrpcClient.Object, null);
            Subnetwork        response = client.Get(request);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Exemple #9
0
        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}");
            }
        }
Exemple #10
0
        /// <summary>Snippet for InsertAsync</summary>
        public async Task InsertAsync()
        {
            // Snippet: InsertAsync(string, string, Subnetwork, CallSettings)
            // Additional: InsertAsync(string, string, Subnetwork, CancellationToken)
            // Create client
            SubnetworksClient subnetworksClient = await SubnetworksClient.CreateAsync();

            // Initialize request argument(s)
            string     project            = "";
            string     region             = "";
            Subnetwork subnetworkResource = new Subnetwork();
            // Make the request
            Operation response = await subnetworksClient.InsertAsync(project, region, subnetworkResource);

            // End snippet
        }
Exemple #11
0
        /// <summary>Snippet for GetAsync</summary>
        public async Task GetAsync()
        {
            // Snippet: GetAsync(string, string, string, CallSettings)
            // Additional: GetAsync(string, string, string, CancellationToken)
            // Create client
            SubnetworksClient subnetworksClient = await SubnetworksClient.CreateAsync();

            // Initialize request argument(s)
            string project    = "";
            string region     = "";
            string subnetwork = "";
            // Make the request
            Subnetwork response = await subnetworksClient.GetAsync(project, region, subnetwork);

            // End snippet
        }
Exemple #12
0
 /// <summary>Snippet for Get</summary>
 public void GetRequestObject()
 {
     // Snippet: Get(GetSubnetworkRequest, CallSettings)
     // Create client
     SubnetworksClient subnetworksClient = SubnetworksClient.Create();
     // Initialize request argument(s)
     GetSubnetworkRequest request = new GetSubnetworkRequest
     {
         Subnetwork = "",
         Region     = "",
         Project    = "",
     };
     // Make the request
     Subnetwork response = subnetworksClient.Get(request);
     // End snippet
 }
Exemple #13
0
        /// <summary>Snippet for GetAsync</summary>
        public async Task GetRequestObjectAsync()
        {
            // Snippet: GetAsync(GetSubnetworkRequest, CallSettings)
            // Additional: GetAsync(GetSubnetworkRequest, CancellationToken)
            // Create client
            SubnetworksClient subnetworksClient = await SubnetworksClient.CreateAsync();

            // Initialize request argument(s)
            GetSubnetworkRequest request = new GetSubnetworkRequest
            {
                Subnetwork = "",
                Region     = "",
                Project    = "",
            };
            // Make the request
            Subnetwork response = await subnetworksClient.GetAsync(request);

            // End snippet
        }
Exemple #14
0
        /// <summary>
        /// Builds a network interface given the Network and NoExternalIp parameters.
        /// </summary>
        /// <returns>
        /// The NetworkInsterface object to use in the instance template description.
        /// </returns>
        protected virtual NetworkInterface BuildNetworkInterfaces()
        {
            var accessConfigs = new List <AccessConfig>();

            if (!NoExternalIp)
            {
                accessConfigs.Add(new AccessConfig
                {
                    Name = "External NAT",
                    Type = "ONE_TO_ONE_NAT"
                });
            }

            string networkUri = Network;

            if (string.IsNullOrEmpty(networkUri))
            {
                networkUri = "default";
            }

            networkUri = ConstructNetworkName(networkUri, Project);

            NetworkInterface result = new NetworkInterface
            {
                Network       = networkUri,
                AccessConfigs = accessConfigs
            };

            if (Subnetwork != null)
            {
                if (!Subnetwork.Contains($"regions/{Region}/subnetworks/"))
                {
                    Subnetwork = $"regions/{Region}/subnetworks/{Subnetwork}";
                }
                result.Subnetwork = Subnetwork;
            }

            return(result);
        }
Exemple #15
0
        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>
        /// Creates a subnetwork in the specified project using the data included in the request.
        /// Documentation https://developers.google.com/compute/v1/reference/subnetworks/insert
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="region">Name of the region scoping this request.</param>
        /// <param name="body">A valid Compute v1 body.</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>OperationResponse</returns>
        public static Operation Insert(ComputeService service, string project, string region, Subnetwork body, SubnetworksInsertOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (region == null)
                {
                    throw new ArgumentNullException(region);
                }

                // Building the initial request.
                var request = service.Subnetworks.Insert(body, project, region);

                // Applying optional parameters to the request.
                request = (SubnetworksResource.InsertRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Subnetworks.Insert failed.", ex);
            }
        }
Exemple #17
0
        /// <summary>
        /// Creates a subnetwork in the specified project using the data included in the request.
        /// Documentation https://developers.google.com/compute/beta/reference/subnetworks/insert
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated compute service.</param>
        /// <param name="project">Project ID for this request.</param>
        /// <param name="region">Name of the region scoping this request.</param>
        /// <param name="body">A valid compute beta body.</param>
        /// <returns>OperationResponse</returns>
        public static Operation Insert(computeService service, string project, string region, Subnetwork body)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (project == null)
                {
                    throw new ArgumentNullException(project);
                }
                if (region == null)
                {
                    throw new ArgumentNullException(region);
                }

                // Make the request.
                return(service.Subnetworks.Insert(body, project, region).Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Subnetworks.Insert failed.", ex);
            }
        }