Esempio n. 1
0
        public static async Task <TravelPlan> TravelBooking(
            [ActivityTrigger] TravelPlan upComingTrip,
            [Queue("YourTrips", Connection = "AzureWebJobsStorage")] IAsyncCollector <TravelPlan> trips,
            ILogger log)
        {
            log.LogInformation($"{TRAVELBOOKING}:{upComingTrip.TripName}");
            log.LogInformation($"{TRAVELBOOKING}:add booking fee 5%");
            // function custom binding for storage access - queue
            upComingTrip = WFBusinessData.AdminProcess(upComingTrip, 0.05m);
            await trips.AddAsync(upComingTrip);

            await Task.Delay(5000);

            return(upComingTrip);
        }
Esempio n. 2
0
        public static async Task TravelConfirmation(
            [ActivityTrigger] TravelPlan upComingTrip,
            [Blob("tripsconfirmation", Connection = "AzureWebJobsStorage")] CloudBlobContainer container,
            ILogger log)
        {
            await container.CreateIfNotExistsAsync();

            var blobRef = container.GetBlockBlobReference($"{upComingTrip.TripName}{Guid.NewGuid().ToString()}.txt");

            // function custom binding for storage access - blob
            upComingTrip = WFBusinessData.AdminProcess(upComingTrip, 0.05m);

            await blobRef.UploadTextAsync($"Confirmation of travel trip: {upComingTrip.TripName} | {upComingTrip.TravelBy} | {upComingTrip.TravelDistance} miles | ${upComingTrip.TravelCost} Have a nice trip!");

            log.LogInformation($"{TRAVELCONFIRMATION}:{upComingTrip.TripName}");
            log.LogInformation($"{TRAVELCONFIRMATION}:add closing fee 5%");
        }
Esempio n. 3
0
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]
            HttpRequestMessage req,
            [OrchestrationClient] DurableOrchestrationClient starter,             // manually added runtime components
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            // parse query parameter
            string name = req.GetQueryNameValuePairs()
                          .FirstOrDefault(q => string.Compare(q.Key, "TripName", true) == 0)
                          .Value;

            if (name == null)
            {
                // Get request body
                dynamic data = await req.Content.ReadAsAsync <object>();

                name = data?.name;
            }

            if (name == null)
            {
                log.LogInformation($"missing the trip name key on the query string or in the request body");
                return(req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a trip name on the query string or in the request body"));
            }
            else
            {
                name = $"(Trip to: {name})";
            }

            log.LogInformation($"About to start orchestration for {name}");

            var pickTrip = WFBusinessData.DrawTravelPlan(name);

            var orchestrationId = await starter.StartNewAsync("Traveler", pickTrip);    // creating an instance of orchestration

            return(starter.CreateCheckStatusResponse(req, orchestrationId));            // http status 202
        }
Esempio n. 4
0
        public static async Task <TravelPlan> TravelRegistration(
            [ActivityTrigger] TravelPlan upComingTrip,
            [Table("TripOutings", Connection = "AzureWebJobsStorage")] IAsyncCollector <TravelPlan> trips,
            ILogger log)
        {
            // RowKey | PartitionKey | ETag {null}
            log.LogInformation($"{TRAVELREGISTRATION}:{upComingTrip.TripName}");
            log.LogInformation($"{TRAVELREGISTRATION}:add registration fee 10%");

            // function custom binding for storage access - table

            // table storage entity mapping (from|to runtime context business object)
            // before inserting a table entity record
            upComingTrip = WFBusinessData.AdminProcess(upComingTrip, 0.10m);
            upComingTrip.PartitionKey = "YourTrips";
            upComingTrip.RowKey       = Guid.NewGuid().ToString();
            // upComingTrip.ETag = "*";

            await trips.AddAsync(upComingTrip);

            await Task.Delay(5000);

            return(upComingTrip);
        }