public async Task <PlanetResidents> Run(
            [OrchestrationTrigger] DurableOrchestrationContextBase context,
            ILogger log)
        {
            var planetName = context.GetInput <string>();

            var result = new PlanetResidents();

            var planetResult = await context.CallActivityAsync <Planet>(
                nameof(SearchPlanetActivity),
                planetName);

            if (planetResult != null)
            {
                result.PlanetName = planetResult.Name;

                var tasks = new List <Task <string> >();
                foreach (var residentUrl in planetResult.ResidentUrls)
                {
                    tasks.Add(
                        context.CallActivityAsync <string>(
                            nameof(GetCharacterActivity),
                            residentUrl)
                        );
                }

                await Task.WhenAll(tasks);

                result.Residents = tasks.Select(task => task.Result).ToArray();
            }

            return(result);
        }
Exemplo n.º 2
0
        public async Task <CharacterInfo> Run(
            [OrchestrationTrigger] DurableOrchestrationContextBase context,
            ILogger log)
        {
            var name   = context.GetInput <string>();
            var result = new CharacterInfo();

            var characterResult = await context.CallActivityAsync <Character>(
                nameof(SearchCharacterActivity),
                name);

            result.Name = characterResult.Name;

            var homeWorldResult = await context.CallActivityAsync <string>(
                nameof(GetPlanetActivity),
                characterResult.PlanetUrl);

            result.HomeWorld = homeWorldResult;

            var speciesResult = await context.CallActivityAsync <Species>(
                nameof(GetSpeciesActivity),
                characterResult.SpeciesUrl.FirstOrDefault());

            result.Species = speciesResult.Name;

            var speciesHomeWorldResult = await context.CallActivityAsync <string>(
                nameof(GetPlanetActivity),
                speciesResult.HomeWorld);

            result.SpeciesHomeWorld = speciesHomeWorldResult;

            return(result);
        }
        public static async Task CreateCustomerResourceGroup(
            [OrchestrationTrigger] DurableOrchestrationContextBase context,
            ILogger log)
        {
            CreationParameters creationParams = context.GetInput <CreationParameters>();

            if (!context.IsReplaying)
            {
                log.LogWarning("ORC - Creating Customer Resource Group: {resourceGroupName}", creationParams.ResourceGroupName);
            }

            await context.CallActivityAsync(nameof(ResourceCreationActivities.CreateResourceGroup), creationParams);

            if (!context.IsReplaying)
            {
                log.LogWarning("ORC - Registering Resource Providers in: {resourceGroupName}", creationParams.ResourceGroupName);
            }

            await context.CallActivityAsync(nameof(ResourceCreationActivities.RegisterResourceProviders), creationParams);

            if (!context.IsReplaying)
            {
                log.LogWarning($"ORC - Created Resource Group & Registered Providers in: {creationParams.ResourceGroupName}");
            }
        }
        public static async Task <string> ProcessOrderV2(
            [OrchestrationTrigger] DurableOrchestrationContextBase ctx,
            ILogger log)
        {
            var order = ctx.GetInput <Order>();

            if (!ctx.IsReplaying)
            {
                log.LogInformation($"Processing order {order.Id}");
            }

            await ctx.CallActivityAsync("A_SaveOrderToDatabase", order);

            // create files in parallel
            var pdfTask   = ctx.CallActivityAsync <string>("A_CreatePersonalizedPdf", order);
            var videoTask = ctx.CallActivityAsync <string>("A_CreateWatermarkedVideo", order);
            await Task.WhenAll(pdfTask, videoTask);

            var pdfLocation   = pdfTask.Result;
            var videoLocation = videoTask.Result;

            await ctx.CallActivityAsync("A_SendOrderConfirmationEmail", (order, pdfLocation, videoLocation));

            return("Order processed successfully");
        }
        private static Task <ConfirmParkingResponse> ConfirmParking(
            ConfirmParkingRequest request,
            LicensePlateRegistration licensePlateRegistration,
            DurableOrchestrationContextBase context)
        {
            Task <ConfirmParkingResponse> confirmTask;

            switch (licensePlateRegistration.Type)
            {
            case LicensePlateType.Appointment:
                confirmTask = context.CallActivityAsync <ConfirmParkingResponse>(
                    nameof(ConfirmParkingForAppointment),
                    request);
                break;

            case LicensePlateType.Employee:
                confirmTask = context.CallActivityAsync <ConfirmParkingResponse>(
                    nameof(ConfirmParkingForEmployee),
                    request);
                break;

            default:
                var unknownLicencePlateResponse = ConfirmParkingResponseBuilder.BuildWithFailedUnknownLicensePlate(request.ParkingGarageName);
                confirmTask = Task.FromResult(unknownLicencePlateResponse);
                break;
            }

            return(confirmTask);
        }
Exemplo n.º 6
0
        public static async Task <string> Run([OrchestrationTrigger] DurableOrchestrationContextBase context, ILogger log, [Inject] IGreeter greeter)
        {
            var name           = context.GetInput <string>();
            var greeting       = greeter.Greet(name);
            var primaryGoodbye = await context.CallActivityAsync <string>("PrimaryGoodbye2", name);

            var secondaryGoodbye = await context.CallActivityAsync <string>("SecondaryGoodbye2", name);

            return($"{greeting} {primaryGoodbye} or {secondaryGoodbye}");
        }
Exemplo n.º 7
0
        public static async Task CalendarUpdate(
            [OrchestrationTrigger] DurableOrchestrationContextBase context
            )
        {
            await context.CallActivityAsync(nameof(GoogleTokenServer.RefreshGoogleTokenActivity), string.Empty);

            await context.CallActivityAsync(nameof(MSATokenServer.RefreshMSATokenActivity), string.Empty);

            await context.CallActivityAsync(nameof(SignalRHandler.UpdateCalendarActivity), string.Empty);
        }
    public static async Task <List <string> > Run([OrchestrationTrigger] DurableOrchestrationContextBase context)
    {
        var outputs = new List <string>();

        outputs.Add(await context.CallActivityAsync <string>("E1_SayHello", "Seattle"));
        outputs.Add(await context.CallActivityAsync <string>("E1_SayHello", "Columbus"));
        outputs.Add(await context.CallActivityAsync <string>("E1_SayHello", "Marysville"));
        outputs.Add(await context.CallActivityAsync <string>("E1_SayHello", "London"));

        return(outputs);
    }
        public static async Task <List <string> > Run(
            [OrchestrationTrigger] DurableOrchestrationContextBase context)
        {
            var outputs = new List <string>();

            outputs.Add(await context.CallActivityAsync <string>("BackgroundVerification", "name"));
            outputs.Add(await context.CallActivityAsync <string>("RegisterDriver", "Seattle"));
            outputs.Add(await context.CallActivityAsync <string>("BookTraining", "London"));

            // returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
            return(outputs);
        }
        public static async Task <List <string> > Run(
            [OrchestrationTrigger] DurableOrchestrationContextBase context)
        {
            var outputs = new List <string>();

            outputs.Add(await context.CallActivityAsync <string>("E1_SayHello", "Tokyo"));
            outputs.Add(await context.CallActivityAsync <string>("E1_SayHello", "Seattle"));
            outputs.Add(await context.CallActivityAsync <string>("E1_SayHello", "London"));

            // returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
            return(outputs);
        }
Exemplo n.º 11
0
        public static async Task ImageUpdate(
            [OrchestrationTrigger] DurableOrchestrationContextBase context
            )
        {
            await context.CallActivityAsync(nameof(Storage.CheckConfigurationActivity), string.Empty);

            await context.CallActivityAsync(nameof(MSATokenServer.RefreshMSATokenActivity), string.Empty);

            string imageUpdateMessage = await context.CallActivityAsync <string>(nameof(ImageHandler.RollImageActivity), string.Empty);

            await context.CallActivityAsync(nameof(SignalRHandler.UpdateImageActivity), imageUpdateMessage);
        }
Exemplo n.º 12
0
        public static async Task <List <string> > RunOrchestrator(
            [OrchestrationTrigger] DurableOrchestrationContextBase context)
        {
            var outputs = new List <string>();

            // Replace "hello" with the name of your Durable Activity Function.
            outputs.Add(await context.CallActivityAsync <string>("DurableFunctions_Hello", "Tokyo"));
            outputs.Add(await context.CallActivityAsync <string>("DurableFunctions_Hello", "Seattle"));
            outputs.Add(await context.CallActivityAsync <string>("DurableFunctions_Hello", "London"));

            return(outputs);
        }
        public static async Task Func([OrchestrationTrigger] DurableOrchestrationContextBase context)
        {
            var data = await context.CallActivityAsync <string[]>(GetDataActivity.Name, null);

            var tasks = data.Select(x => context.CallActivityAsync <bool>(ProcessActivity.Name, x));

            var results = await Task.WhenAll(tasks);

            if (results.Any(x => !x))
            {
                await context.CallActivityAsync(ErrorNotifyActivity.Name, null);
            }
        }
Exemplo n.º 14
0
        public static async Task <string[]> OrchestrationClientFunction(
            [OrchestrationTrigger] DurableOrchestrationContextBase context)
        {
            var outputs = new string[3];

            outputs[0] = await context.CallActivityAsync <string>(nameof(ActivityFunction), "Tokyo");

            outputs[1] = await context.CallActivityAsync <string>(nameof(ActivityFunction), "Seattle");

            outputs[2] = await context.CallActivityAsync <string>(nameof(ActivityFunction), "London");

            return(outputs);
        }
        public static async Task <ParkingOrchestrationResponse> Run(
            [OrchestrationTrigger] DurableOrchestrationContextBase context,
            ILogger logger)
        {
            if (!context.IsReplaying)
            {
                logger.LogInformation($"Started {nameof(ParkingGarageCarEntryOrchestration)} with InstanceId: {context.InstanceId}.");
            }

            var request = context.GetInput <ParkingOrchestrationRequest>();

            var licensePlateResult = await context.CallActivityAsync <LicensePlateRegistration>(
                nameof(GetLicensePlateRegistration),
                request.LicensePlateNumber);

            var confirmParkingRequest  = ConfirmParkingRequestBuilder.Build(request.ParkingGarageName, licensePlateResult);
            var confirmParkingResponse = await ConfirmParking(confirmParkingRequest, licensePlateResult, context);

            if (confirmParkingResponse.IsSuccess)
            {
                await context.CallActivityAsync(
                    nameof(OpenGate),
                    confirmParkingResponse.ParkingGarageName);
            }
            else
            {
                var displayMessageRequest = DisplayMessageRequestBuilder.Build(
                    confirmParkingResponse.ParkingGarageName,
                    confirmParkingResponse.Message);
                await context.CallActivityAsync(
                    nameof(DisplayMessage),
                    displayMessageRequest);
            }

            if (licensePlateResult.Type == LicensePlateType.Appointment)
            {
                var sendNotificationRequest = SendNotificationRequestBuilder.BuildWithAppointmentHasArrived(
                    licensePlateResult.ContactPerson,
                    licensePlateResult.Name);
                await context.CallActivityAsync(
                    nameof(SendNotification),
                    sendNotificationRequest);
            }


            var parkingOrchestrationResponse = ParkingOrchestrationResponseBuilder.Build(
                licensePlateResult,
                confirmParkingResponse.IsSuccess);

            return(parkingOrchestrationResponse);
        }
        public static async Task <List <string> > Run(
            [OrchestrationTrigger] DurableOrchestrationContextBase context)
        {
            var outputs = new List <string>();

            //context.GetInput();
            outputs.Add(await context.CallActivityAsync <string>("E1_SayHello", "Seattle"));
            outputs.Add(await context.CallActivityAsync <string>("E1_SayHello", "Utrecht"));
            outputs.Add(await context.CallActivityAsync <string>("E1_SayHello", "Future Tech"));

            await context.CallActivityAsync <string>("SendSignalRMessageActivity", new SignalRDto { id = context.InstanceId, message = $"Result: {String.Join(" ", outputs)}", progress = 100 });

            return(outputs);
        }
Exemplo n.º 17
0
        public static async Task Run(
            [OrchestrationTrigger] DurableOrchestrationContextBase context,
            ILogger log)
        {
            var myGuid = System.Guid.NewGuid();

            log.LogWarning($"myGuid: {myGuid}");

            await context.CallActivityAsync(nameof(ActivityA), "1");

            await context.CallActivityAsync(nameof(ActivityA), "2");

            await context.CallActivityAsync(nameof(ActivityA), "3");
        }
Exemplo n.º 18
0
        public static async Task <bool> RunAsync(
            [OrchestrationTrigger] DurableOrchestrationContextBase context, ExecutionContext eContext)
        {
            _client = Client.InitializeClient(eContext.FunctionAppDirectory);

            var place = context.GetInput <Place>();

            try
            {
                log.Information("Calling CreatePlace function");
                place.Id = await context.CallActivityAsync <int>(PlacesConstants.CreatePlace, place);
            }
            catch (Exception ex)
            {
                log.Error(ex, $"Error occured in CreatePlace function {ex.Message} ");
            }

            try
            {
                log.Information($"Calling UpdatePlace function for Place with Id: {place.Id}");
                place = await context.CallActivityAsync <Place>(PlacesConstants.UpdatePlace, place.Id);
            }
            catch (Exception ex)
            {
                log.Error(ex, $"Error occured in UpdatePlace function {ex.Message}");
            }

            try
            {
                log.Information($"Calling DeletePlace function for Place with Id: {place.Id}");
                var deleted = await context.CallActivityAsync <bool>(PlacesConstants.DeletePlace, place.Id);
            }
            catch (Exception ex)
            {
                log.Error(ex, $"Error occured in DeletePlace function {ex.Message}");
            }

            try
            {
                log.Information($"Calling GetPlace function with palceId : {place.Id}");
                place = await context.CallActivityAsync <Place>(PlacesConstants.GetPlace, place.Id);
            }
            catch (Exception ex)
            {
                log.Error(ex, $"Error occured in GetPlace function {ex.Message}");
            }

            return(place != null);
        }
        public static async Task Func([OrchestrationTrigger] DurableOrchestrationContextBase context)
        {
            var data = await context.CallActivityAsync <string[]>(GetDataActivity.Name, null);

            await context.CreateTimer(context.CurrentUtcDateTime.AddSeconds(60), CancellationToken.None);

            var tasks = data.Select(x => context.CallActivityAsync <bool>(ProcessActivity.Name, x));

            var results = await Task.WhenAll(tasks);

            if (results.Any(x => !x))
            {
                await context.CallActivityAsync(ErrorNotifyActivity.Name, null);
            }
        }
Exemplo n.º 20
0
        public async Task <IActionResult> LoadWaterAllocationDataOrchestration([OrchestrationTrigger] DurableOrchestrationContextBase context, ILogger log)
        {
            var runId = context.GetInput <string>();

            log.LogInformation($"Load Water Allocation Data Orchestration [{runId}]");

            var parallelTasks = new List <Task <StatusHelper> >
            {
                context.CallActivityAsync <StatusHelper>(FunctionNames.LoadOrganizations, runId)
                , context.CallActivityAsync <StatusHelper>(FunctionNames.LoadSites, runId)
                , context.CallActivityAsync <StatusHelper>(FunctionNames.LoadWaterSources, runId)
                , context.CallActivityAsync <StatusHelper>(FunctionNames.LoadMethods, runId)
                , context.CallActivityAsync <StatusHelper>(FunctionNames.LoadRegulatoryOverlays, runId)
                , context.CallActivityAsync <StatusHelper>(FunctionNames.LoadReportingUnits, runId)
                , context.CallActivityAsync <StatusHelper>(FunctionNames.LoadVariables, runId)
            };

            var parallelResults = await Task.WhenAll(parallelTasks);

            foreach (var result in parallelResults)
            {
                log.LogInformation(JsonConvert.SerializeObject(result));
            }

            if (parallelResults.Any(a => !a.Status))
            {
                throw new Exception("Failure Loading Initial Data");
            }

            var results = new List <StatusHelper>
            {
                await context.CallActivityAsync <StatusHelper>(FunctionNames.LoadAggregatedAmounts, runId)
                , await context.CallActivityAsync <StatusHelper>(FunctionNames.LoadWaterAllocation, runId)
                , await context.CallActivityAsync <StatusHelper>(FunctionNames.LoadSiteSpecificAmounts, runId)
            };

            foreach (var result in results)
            {
                log.LogInformation(JsonConvert.SerializeObject(result));
            }

            if (results.Any(a => !a.Status))
            {
                throw new Exception("Failure Loading Fact Data");
            }

            return(new OkObjectResult(new { status = "success" }));
        }
        public static async Task <string> ProcessOrderV3(
            [OrchestrationTrigger] DurableOrchestrationContextBase ctx,
            ILogger log)
        {
            var order = ctx.GetInput <Order>();

            if (!ctx.IsReplaying)
            {
                log.LogInformation($"Processing order {order.Id}");
            }

            await ctx.CallActivityAsync("A_SaveOrderToDatabase", order);

            string pdfLocation   = null;
            string videoLocation = null;

            try
            {
                // create files in parallel
                var pdfTask   = ctx.CallActivityAsync <string>("A_CreatePersonalizedPdf", order);
                var videoTask = ctx.CallActivityAsync <string>("A_CreateWatermarkedVideo", order);
                await Task.WhenAll(pdfTask, videoTask);

                pdfLocation   = pdfTask.Result;
                videoLocation = videoTask.Result;
            }
            catch (Exception ex)
            {
                if (!ctx.IsReplaying)
                {
                    log.LogError($"Failed to create files", ex);
                }
            }

            if (pdfLocation != null && videoLocation != null)
            {
                await ctx.CallActivityWithRetryAsync("A_SendOrderConfirmationEmail",
                                                     new RetryOptions(TimeSpan.FromSeconds(30), 3),
                                                     (order, pdfLocation, videoLocation));

                return("Order processed successfully");
            }
            await ctx.CallActivityWithRetryAsync("A_SendProblemEmail",
                                                 new RetryOptions(TimeSpan.FromSeconds(30), 3),
                                                 order);

            return("There was a problem processing this order");
        }
        public static async Task <SubOrchestratorExampleOutput> Run(
            [OrchestrationTrigger] DurableOrchestrationContextBase context)
        {
            var input     = context.GetInput <SubOrchestratorExampleModel>();
            var activity1 = await context.CallActivityAsync <string>("E1_SayHello", input.Input);

            var activity2 = await context.CallActivityAsync <string>(
                "SendSignalRMessageActivity",
                new SignalRDto { id = context.ParentInstanceId, message = input.Input, progress = input.Progress });

            return(new SubOrchestratorExampleOutput
            {
                Message = activity1,
                Canceled = false
            });
        }
Exemplo n.º 23
0
        public static async Task <LSAMessage> ActionA2(
            [OrchestrationTrigger] DurableOrchestrationContextBase context)
        {
            var message = context.GetInput <LSAMessage>();


            message = await context.CallActivityAsync <LSAMessage>("StepA", message);

            context.SetCustomStatus(message);
            message = await context.CallActivityAsync <LSAMessage>("StepC", message);

            context.SetCustomStatus(message);


            return(message);
        }
        public static async Task CreateSiteResources(
            [OrchestrationTrigger] DurableOrchestrationContextBase context,
            ILogger log)
        {
            CreationParameters creationParams = context.GetInput <CreationParameters>();

            if (!context.IsReplaying)
            {
                log.LogWarning("ORC - Creating Site Resources in: {resourceGroup}", creationParams.ResourceGroupName);
            }

            // site resources (sql server, sql db, redis cache, storageAccount (record attachments), ???)
            var storageRequest = CreateStorageAccountRequest.FromCreationParams(creationParams);

            storageRequest.StorageAccountName = ResourceCreationActivities.GenerateStorageAccountName(creationParams, string.Empty);

            var t1 = context.CallSubOrchestratorAsync(nameof(CreateSiteSqlServerAndDatabase), creationParams);
            var t2 = context.CallActivityAsync <CreateStorageAccountResult>(nameof(ResourceCreationActivities.CreateStorageAccount), storageRequest);
            await Task.WhenAll(t1, t2);

            if (!context.IsReplaying)
            {
                log.LogWarning($"ORC - Created Storage Account Name: {t2.Result.StorageAccountName} - Primary Key: {t2.Result.PrimaryKey.KeyName}, {t2.Result.PrimaryKey.Value}");
                log.LogWarning($"ORC - Created Site Resources in Resource Group: {creationParams.ResourceGroupName}");
            }
        }
Exemplo n.º 25
0
    public static async Task Run(
        [OrchestrationTrigger] DurableOrchestrationContextBase context,
        ILogger log)
    {
        var input = context.GetInput <MessageInput>();

        var smsKey = await context.CallActivityAsync <string>("A_SaveTwilioMapping", context.InstanceId);

        input.SmsKey = smsKey;

        await context.CallActivityAsync <string>("A_SendTwilioText", input);

        var status = await context.WaitForExternalEvent <string>("TwilioCallback");

        log.LogWarning("Got a status from Twilio! " + status);
    }
Exemplo n.º 26
0
 public static Task DurableFunctionWithSeparateActivityInput(
     [OrchestrationTrigger] DurableOrchestrationContextBase context)
 {
     return(context.CallActivityAsync(nameof(ActivityVerifyingInput), new TestFunctionInput()
     {
         Token = "activity"
     }));
 }
        public async Task <string> Run(
            [OrchestrationTrigger] DurableOrchestrationContextBase context,
            ILogger log)
        {
            var result = await context.CallActivityAsync <string>(
                nameof(HelloWorldActivity),
                null);

            return(result);
        }
        public static async Task CreateSiteSqlServerAndDatabase(
            [OrchestrationTrigger] DurableOrchestrationContextBase context,
            ILogger log)
        {
            CreationParameters creationParams = context.GetInput <CreationParameters>();

            if (!context.IsReplaying)
            {
                log.LogWarning("ORC - Creating Sql Server and Database Resources in: {resourceGroupName}", creationParams.ResourceGroupName);
            }

            await context.CallActivityAsync(nameof(ResourceCreationActivities.CreateSqlServer), creationParams);

            await context.CallActivityAsync(nameof(ResourceCreationActivities.CreateSqlDatabase), creationParams);

            if (!context.IsReplaying)
            {
                log.LogWarning($"ORC - Created Sql Server and Database Resources in: {creationParams.ResourceGroupName}");
            }
        }
        public static async Task RunAsync(
            [OrchestrationTrigger] DurableOrchestrationContextBase context)
        {
            var place = new Place()
            {
                Name           = "Public room",
                Description    = "Place...",
                Capacity       = 35,
                Location       = "Skopje",
                DateRegistered = DateTime.Now,
                City           = "Skopje"
            };

            var placeId = await context.CallActivityAsync <int>("CreatePlace", place);

            var updatePlace = await context.CallActivityAsync <Place>("UpdatePlace", placeId);

            var isDeletedPlace = await context.CallActivityAsync <HttpStatusCode>("DeletePlace", updatePlace.Id);

            var getPlace = await context.CallActivityAsync <Place>("GetPlace", placeId);
        }
        public static async Task <string> RunOrchestrator(
            [OrchestrationTrigger] DurableOrchestrationContextBase context,
            ILogger log)
        {
            var score = context.GetInput <HighScore>();

            var blobUri = await context.CallActivityAsync <string>(
                nameof(QRCodeGeneratorActivity),
                score);

            return(blobUri);
        }