private static void DeleteSubnet(VpcClient client)
        {
            var req = new DeleteSubnetRequest
            {
                VpcId    = "0fae9377-f51c-430e-ba16-9bdd619b1d97",
                SubnetId = "efa0d2e2-314f-44f2-99f6-ecfeaab3ba9d"
            };

            try
            {
                DeleteSubnetResponse resp = client.DeleteSubnet(req);
                Console.WriteLine(resp.HttpStatusCode);
            }
            catch (RequestTimeoutException requestTimeoutException)
            {
                Console.WriteLine(requestTimeoutException.ErrorMessage);
            }
            catch (ServiceResponseException clientRequestException)
            {
                Console.WriteLine(clientRequestException.HttpStatusCode);
                Console.WriteLine(clientRequestException.ErrorCode);
                Console.WriteLine(clientRequestException.ErrorMsg);
            }
            catch (ConnectionException connectionException)
            {
                Console.WriteLine(connectionException.ErrorMessage);
            }
        }
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            DeleteSubnetResponse response = new DeleteSubnetResponse();

            while (context.Read())
            {
            }


            return(response);
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>  
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            DeleteSubnetResponse response = new DeleteSubnetResponse();

            int originalDepth = context.CurrentDepth;
            int targetDepth = originalDepth + 1;
            if (context.IsStartOfDocument) 
               targetDepth = 2;

            while (context.ReadAtDepth(originalDepth))
            {
                if (context.IsStartElement || context.IsAttribute)
                {

                } 
            }

            return response;
        }
Exemple #4
0
        public async Task <IActionResult> Index(string action, string subnetID)
        {
            if (action.Equals("Delete") && !String.IsNullOrEmpty(subnetID))
            {
                Subnet Deletesubnet = await _context.Subnets.FindAsync(Int32.Parse(subnetID));

                if (Deletesubnet == null)
                {
                    TempData["Result"] = "Invaild Subnet!";
                    ChallengeNetworkParentViewModel model = new ChallengeNetworkParentViewModel
                    {
                        RetrievedSubnets = await _context.Subnets.ToListAsync(),
                        RetrievedRoutes  = await _context.Routes.ToListAsync()
                    };
                    return(View(model));
                }
                else if (Deletesubnet.editable == false)
                {
                    TempData["Result"] = "You cannot delete a default subnet!";
                    ChallengeNetworkParentViewModel model = new ChallengeNetworkParentViewModel
                    {
                        RetrievedSubnets = await _context.Subnets.ToListAsync(),
                        RetrievedRoutes  = await _context.Routes.ToListAsync()
                    };
                    return(View(model));
                }
                else
                {
                    DescribeSubnetsResponse response = await EC2Client.DescribeSubnetsAsync(new DescribeSubnetsRequest
                    {
                        Filters = new List <Amazon.EC2.Model.Filter>
                        {
                            new Filter("vpc-id", new List <string>
                            {
                                Deletesubnet.LinkedVPC.AWSVPCReference
                            })
                        }
                    });

                    Boolean flag = false;
                    for (int i = 0; i < response.Subnets.Count; i++)
                    {
                        Amazon.EC2.Model.Subnet subnet = response.Subnets[i];
                        String retrievedID             = subnet.SubnetId;
                        if (Deletesubnet.AWSVPCSubnetReference.Equals(retrievedID))
                        {
                            flag = true;
                            break;
                        }
                    }
                    if (flag == false)
                    {
                        ViewData["Result"] = "Subnet not found! The subnet may have been modified by another user";
                        ChallengeNetworkParentViewModel model = new ChallengeNetworkParentViewModel
                        {
                            RetrievedSubnets = await _context.Subnets.ToListAsync(),
                            RetrievedRoutes  = await _context.Routes.ToListAsync()
                        };
                        return(View(model));
                    }
                    else
                    {
                        try
                        {
                            List <RouteTable> RTs = await _context.RouteTables.ToListAsync();

                            DeleteSubnetRequest  request     = new DeleteSubnetRequest(Deletesubnet.AWSVPCSubnetReference);
                            DeleteSubnetResponse responseEC2 = await EC2Client.DeleteSubnetAsync(request);

                            if (responseEC2.HttpStatusCode == HttpStatusCode.OK)
                            {
                                _context.Subnets.Remove(Deletesubnet);
                                await _context.SaveChangesAsync();

                                TempData["Result"] = "Successfully Deleted!";
                                ChallengeNetworkParentViewModel model = new ChallengeNetworkParentViewModel
                                {
                                    RetrievedSubnets = await _context.Subnets.ToListAsync(),
                                    RetrievedRoutes  = await _context.Routes.ToListAsync()
                                };
                                return(View(model));
                            }
                            else
                            {
                                TempData["Result"] = "Failed!";
                                ChallengeNetworkParentViewModel model = new ChallengeNetworkParentViewModel
                                {
                                    RetrievedSubnets = await _context.Subnets.ToListAsync(),
                                    RetrievedRoutes  = await _context.Routes.ToListAsync()
                                };
                                return(View(model));
                            }
                        }
                        catch (AmazonEC2Exception e)
                        {
                            TempData["Result"] = e.Message;
                            ChallengeNetworkParentViewModel model = new ChallengeNetworkParentViewModel
                            {
                                RetrievedSubnets = await _context.Subnets.ToListAsync(),
                                RetrievedRoutes  = await _context.Routes.ToListAsync()
                            };
                            return(View(model));
                        }
                    }
                }
            }
            else if (action.Equals("Modify") && !String.IsNullOrEmpty(subnetID))
            {
                var Modifysubnet = await _context.Subnets.FindAsync(Int32.Parse(subnetID));

                if (Modifysubnet.editable == false)
                {
                    ViewData["Result"] = "You cannot modify a default subnet!";
                    ChallengeNetworkParentViewModel model = new ChallengeNetworkParentViewModel
                    {
                        RetrievedSubnets = await _context.Subnets.ToListAsync(),
                        RetrievedRoutes  = await _context.Routes.ToListAsync()
                    };
                    return(View(model));
                }
                return(RedirectToAction("Edit", new { id = subnetID }));
            }
            else
            {
                ChallengeNetworkParentViewModel model = new ChallengeNetworkParentViewModel
                {
                    RetrievedSubnets = await _context.Subnets.ToListAsync(),
                    RetrievedRoutes  = await _context.Routes.ToListAsync()
                };
                return(View(model));
            }
        }