コード例 #1
0
        private RideResponse recordRide(string rideId, string username, Unicorn unicorn)
        {
            //The client represents a connection to dynamo db's management plane
            using (var client = new Amazon.DynamoDBv2.AmazonDynamoDBClient()){
                //create a data context
                var context = new Amazon.DynamoDBv2.DataModel.DynamoDBContext(client);
                //populate the ride object
                Ride r = new Ride();
                r.Unicorn     = unicorn;
                r.RideId      = rideId;
                r.User        = username;
                r.RequestTime = DateTime.UtcNow;
                r.UnicornName = unicorn.Name;
                //Now persist it to DynamoDB, it is async but here we are waiting so that we know it has completed or failed
                context.SaveAsync(r).GetAwaiter().GetResult();
                //now build the response object
                var rr = new RideResponse();
                rr.ETA         = $"30 seconds";
                rr.Unicorn     = unicorn;
                rr.RideId      = rideId;
                rr.Rider       = username;
                rr.UnicornName = unicorn?.Name;

                return(rr);
            }
        }
コード例 #2
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        ///

        //Make a list of random unicorns
        private void LoadUnicorns()
        {
            Unicorn bucephalus = new Unicorn()
            {
                Name = "Bucephalus", Color = "Golden", Gender = "Male"
            };
            Unicorn shadowfax = new Unicorn()
            {
                Name = "Shadowfax", Color = "White", Gender = "Male"
            };
            Unicorn rocinante = new Unicorn()
            {
                Name = "Rocinante", Color = "Yellow", Gender = "Female"
            };
            Unicorn homer = new Unicorn()
            {
                Name = "Homer", Color = "Snow White", Gender = "Male"
            };

            fleet.Add(bucephalus);
            fleet.Add(homer);
            fleet.Add(shadowfax);
            fleet.Add(rocinante);
        }