コード例 #1
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            CreateImageResponse response = new CreateImageResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("clientToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.ClientToken = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("imageBuildVersionArn", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.ImageBuildVersionArn = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("requestId", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.RequestId = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
コード例 #2
0
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            CreateImageResponse response = new CreateImageResponse();

            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            if (context.IsStartOfDocument)
            {
                targetDepth = 2;
            }

            while (context.ReadAtDepth(originalDepth))
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("imageId", targetDepth))
                    {
                        var unmarshaller = StringUnmarshaller.Instance;
                        response.ImageId = unmarshaller.Unmarshall(context);
                        continue;
                    }
                }
            }

            return(response);
        }
コード例 #3
0
        public static CreateImageResponse Unmarshall(UnmarshallerContext context)
        {
            CreateImageResponse createImageResponse = new CreateImageResponse();

            createImageResponse.HttpResponse = context.HttpResponse;
            createImageResponse.RequestId    = context.StringValue("CreateImage.RequestId");
            createImageResponse.ImageId      = context.StringValue("CreateImage.ImageId");

            return(createImageResponse);
        }
コード例 #4
0
        public async Task <IActionResult> SubmitCreateTemplate([Bind("serverID", "Name", "TemplateDescription")] ServerTemplateCreationFormModel submission)
        {
            Server given = await _context.Servers.FindAsync(int.Parse(submission.serverID));

            if (given != null)
            {
                Template newlyCreated = new Template
                {
                    Name = submission.Name,
                    TemplateDescription = submission.TemplateDescription,
                    DateCreated         = DateTime.Now,
                    OperatingSystem     = given.OperatingSystem,
                    SpecificMinimumSize = true,
                    MinimumStorage      = given.StorageAssigned,
                    Type = TemplateType.Custom
                };
                CreateImageResponse response = await EC2Client.CreateImageAsync(new CreateImageRequest
                {
                    BlockDeviceMappings = new List <BlockDeviceMapping> {
                        new BlockDeviceMapping {
                            DeviceName = "/dev/xvda",
                            Ebs        = new EbsBlockDevice {
                                VolumeSize = given.StorageAssigned
                            }
                        }
                    },
                    Name        = submission.Name + " - Created on Platform",
                    Description = submission.TemplateDescription,
                    NoReboot    = false,
                    InstanceId  = given.AWSEC2Reference
                });

                if (response.HttpStatusCode == HttpStatusCode.OK)
                {
                    newlyCreated.AWSAMIReference = response.ImageId;
                    _context.Templates.Add(newlyCreated);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(""));
                }
                else
                {
                    return(StatusCode(500));
                }
            }
            else
            {
                return(StatusCode(500));
            }
        }
コード例 #5
0
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            CreateImageResponse response = new CreateImageResponse();

            int targetDepth = 2;

            while (context.Read())
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("imageId", targetDepth))
                    {
                        response.ImageId = StringUnmarshaller.GetInstance().Unmarshall(context);

                        continue;
                    }
                }
            }


            return(response);
        }
コード例 #6
0
        public string CreateImage(IAmazonEC2 ec2, string instidstr)
        //stop ec2 instance
        {
            CreateImageRequest  ImgReq;
            CreateImageResponse ImageResponse = null;

            string DT;

            DT = DateTime.Now.ToString("yyyy-MM-dd_hh.mm.ss");


            //ec2.DescribeImages


            // RebootInstancesRequest rebootreq;
            // RebootInstancesResponse rebootInstancesResponse = null;

            try
            {
                ImgReq = new CreateImageRequest();

                ImgReq.InstanceId  = instidstr;
                ImgReq.Name        = instidstr + "_" + DT;
                ImgReq.NoReboot    = true;
                ImgReq.Description = "Created By AWSPowerManager";



                ImageResponse = ec2.CreateImage(ImgReq);

                return("Image ID was created " + ImageResponse.ImageId);
            }
            catch (Exception ex)
            {
                return(ex.Message + "\n" + ex.StackTrace);
            }
        }
コード例 #7
0
        private static void AddImageToSlide(string presentationId, string slideId, string textBoxId)
        {
            SlidesService slidesService = GetSlideServiceClient();
            // Create a new square text box, using a supplied object ID.
            List <Request> requests = new List <Request>();
            Dimension      pt350    = new Dimension()
            {
                Magnitude = 350.0, Unit = "PT"
            };
            var afflineTransform = new AffineTransform()
            {
                ScaleX     = (1.0),
                ScaleY     = (1.0),
                TranslateX = (350.0),
                TranslateY = (100.0),
                Unit       = ("PT")
            };
            Size size = new Size()
            {
                Height = (pt350),
                Width  = (pt350)
            };
            var pageElementProperties = new PageElementProperties()
            {
                PageObjectId = slideId,
                Size         = size,
                Transform    = afflineTransform
            };

            //requests.Add(new Request()
            //{
            //    CreateShape = new CreateShapeRequest()
            //    {
            //        ObjectId = textBoxId,
            //        ShapeType = "TEXT_BOX",
            //        ElementProperties = pageElementProperties
            //    }
            //});

            // Insert text into the box, using the object ID given to it.
            requests.Add(new Request()
            {
                CreateImage = new CreateImageRequest()
                {
                    ObjectId          = textBoxId,
                    Url               = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ4gPTyRGSqYQoObgXWS9JRdsqBI7sQfJfgaAwQiZR43GxrR2hjWJE-Hg",
                    ElementProperties = pageElementProperties
                }
            });

            // Execute the requests.
            BatchUpdatePresentationRequest body =
                new BatchUpdatePresentationRequest()
            {
                Requests = requests
            };
            BatchUpdatePresentationResponse response =
                slidesService.Presentations.BatchUpdate(body, presentationId).Execute();
            CreateImageResponse createShapeResponse = response.Replies.First().CreateImage;

            Console.WriteLine("Created textbox with ID: " + createShapeResponse.ObjectId);
        }