public static async Task <IActionResult> VMStartedGet(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req,
            [OrchestrationClient] IDurableOrchestrationClient starter,
            ILogger log)
        {
            string  VMId            = req.Query["VMId"];
            string  requestVMIdBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic VMIdData        = JsonConvert.DeserializeObject(requestVMIdBody);

            VMId = VMId ?? VMIdData?.VMId;

            // Return bad request if VMId is null
            if (VMId == null)
            {
                return(new BadRequestObjectResult("Please pass VMId on the query string or in the request body"));
            }

            // Return value of VM entity
            EntityId id       = new EntityId("VM", VMId.Replace('/', '-').ToLower()); // Replace escape / character
            var      response = await starter.ReadEntityStateAsync <VM>(id);

            return(response.EntityExists
                        ? (ActionResult) new OkObjectResult(response)
                        : new BadRequestObjectResult(response));
        }
 public static async Task <Dictionary <string, int> > GetVotes(
     [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "votes")] HttpRequest req,
     [OrchestrationClient] IDurableOrchestrationClient client,
     ILogger log)
 {
     return((await client.ReadEntityStateAsync <Dictionary <string, int> >(DefaultEntityId)).EntityState);
 }
示例#3
0
 public async Task <EntityStateResponse <PullRequestStateContext> > GetPullRequestStateContext(
     [ActivityTrigger] string entityId,
     [OrchestrationClient] IDurableOrchestrationClient client,
     ILogger log
     )
 {
     return(await client.ReadEntityStateAsync <PullRequestStateContext>(new EntityId(nameof(PullRequestEntity), entityId)));
 }
        public static async Task <IActionResult> GetStatus(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "status/get/{status}")] HttpRequest req,
            string status,
            [OrchestrationClient] IDurableOrchestrationClient client)
        {
            var response = await client.ReadEntityStateAsync <string[]>(new EntityId(nameof(MailStatusEntity), status));

            return(new OkObjectResult(response.EntityState));
        }
        public static async Task <IActionResult> GetMail(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "mail/get/{id}")] HttpRequest req,
            string id,
            [OrchestrationClient] IDurableOrchestrationClient client)
        {
            var response = await client.ReadEntityStateAsync <MailEntity>(new EntityId(nameof(MailEntity), id));

            return(new OkObjectResult(response.EntityState));
        }
        public static async Task <IActionResult> GetStatus(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpTriggerArgs args,
            [OrchestrationClient] IDurableOrchestrationClient durableOrchestrationClient,
            ILogger log)
        {
            var entity = new EntityId(nameof(DeviceEntity), args.DeviceId);
            var device = await durableOrchestrationClient.ReadEntityStateAsync <Device>(entity);

            return(new OkObjectResult(device));
        }
示例#7
0
        public static async Task <EntityStateResponse <T> > ReadUserEntityAsync <T>(this IDurableOrchestrationClient client, string user)
        {
            var id     = user.AsEntityIdFor <T>();
            var result = await client.ReadEntityStateAsync <T>(id);

            if (result.EntityState is IHaveLists)
            {
                ((IHaveLists)result.EntityState).RestoreLists();
            }
            return(result);
        }
示例#8
0
        public static async Task <IActionResult> AcmeChallenge(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = ".well-known/acme-challenge/{token}")] HttpRequest req,
            [OrchestrationClient] IDurableOrchestrationClient starter, string token,
            ILogger log)
        {
            log.LogInformation("Acme-Challenge request for {Host}", req.Host.Host);

            var state = await starter.ReadEntityStateAsync <AuthorizationActorState>(new EntityId("Authorization", token));

            return(new ContentResult()
            {
                Content = state.EntityState.KeyAuthz, ContentType = "plain/text", StatusCode = 200
            });
            //   await ctx.Response.WriteAsync(keyAuthString);
        }
示例#9
0
        public static async Task <List <Inventory> > DeserializeListForUserWithClient(this InventoryList list, string user, IDurableOrchestrationClient client)
        {
            var result = new List <Inventory>();

            list.RestoreLists();
            foreach (var item in list.InventoryList)
            {
                var id        = user.AsEntityIdFor <Inventory>(item);
                var inventory = await client.ReadEntityStateAsync <Inventory>(id);

                if (inventory.EntityExists)
                {
                    result.Add(inventory.EntityState);
                }
            }
            return(result);
        }
示例#10
0
        public static async Task <IActionResult> GameStatus(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "GameStatus/{username}")]
            HttpRequest req,
            [OrchestrationClient] IDurableOrchestrationClient client,
            string username,
            ILogger log)
        {
            if (string.IsNullOrWhiteSpace(username))
            {
                log.LogWarning("No username passed.");
                return(new BadRequestObjectResult("Username is required."));
            }

            var userCheck = await client.ReadUserEntityAsync <User>(username);

            if (!userCheck.EntityExists)
            {
                log.LogWarning("Username {0} not found", username);
                return(new BadRequestObjectResult($"Username '{username}' does not exist."));
            }
            var monsterCheck = await client.ReadUserEntityAsync <Monster>(username);

            var inventoryCheck = await client.ReadUserEntityAsync <InventoryList>(username);

            if (inventoryCheck.EntityExists)
            {
                inventoryCheck.EntityState.RestoreLists();
            }
            var roomCheck = await client.ReadUserEntityAsync <Room>(username);

            var userCount = await client.ReadEntityStateAsync <int>(
                UserCounter.Id);

            return(new OkObjectResult(new
            {
                user = userCheck.EntityState,
                activeUsers = userCount.EntityState,
                monster = monsterCheck.EntityState,
                inventory = inventoryCheck.EntityState?.InventoryList,
                room = roomCheck.EntityState
            }));
        }
示例#11
0
        public async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest request,
                                              [OrchestrationClient] IDurableOrchestrationClient entityClient,
                                              TraceWriter log)
        {
            var userId     = request.Query["userid"];
            var testEntity = new EntityId(nameof(User), userId);

            var current = await entityClient.ReadEntityStateAsync <UserData>(testEntity);

            if (current.EntityExists)
            {
                var share = new ShareRequest(current.EntityState.PersonId);
                share.Text = new Text {
                    Content = "Test share"
                };
                await _proxy.Share(current.EntityState.AccessToken, share);

                return(new OkObjectResult(current));
            }

            return(new UnauthorizedResult());
        }
        public static async Task VerifyOrderStatus([ActivityTrigger] IDurableActivityContext ctx, [OrchestrationClient] IDurableOrchestrationClient starter)
        {
            try
            {
                var input  = ctx.GetInput <WaitForNotPendingInput>();
                var entity = await starter.ReadEntityStateAsync <AcmeContextState>(input.EntityId);

                var context = new AcmeContext(entity.EntityState.LetsEncryptEndpoint, KeyFactory.FromPem(entity.EntityState.Pem));

                var orderCtx = context.Order(new Uri(input.OrderLocation));

                var order = await orderCtx.Resource();

                var tcs = new CancellationTokenSource(TimeSpan.FromMinutes(3));
                while (!tcs.IsCancellationRequested && order.Status == OrderStatus.Pending)
                {
                    await Task.Delay(5000);

                    order = await orderCtx.Resource();
                }
            }catch (Exception ex)
            {
            }
        }
        public static async Task <string[]> GetAuthorizationsActivity(
            [ActivityTrigger] IDurableActivityContext ctx,
            [OrchestrationClient] IDurableOrchestrationClient starter,
            ILogger log)
        {
            var input  = ctx.GetInput <CreateOrderOrchestratorInput>();
            var entity = await starter.ReadEntityStateAsync <AcmeContextState>(input.EntityId);

            var context = new AcmeContext(entity.EntityState.LetsEncryptEndpoint, KeyFactory.FromPem(entity.EntityState.Pem));

            var orderCtx = context.Order(new Uri(input.OrderLocation));

            var order = await orderCtx.Resource();


            if (order.Status == Certes.Acme.Resource.OrderStatus.Invalid || order.Status == Certes.Acme.Resource.OrderStatus.Valid)
            {
                //Valid means that its been finalized and we need a new one.
                throw new Exception("Bad order state");
            }


            var authorizations = await orderCtx.Authorizations();

            // var authorizationEntiy = new EntityId("Authorization",input.EntityId.EntityKey);


            var list = new List <string>();



            if (!input.UseDns01Authorization)
            {
                foreach (var authorizationCtx in authorizations)
                {
                    var challengeContext = await authorizationCtx.Http();

                    await starter.SignalEntityAsync(new EntityId("Authorization", challengeContext.Token), nameof(AuthorizationActor.AuthorizeHttp), new AuthorizeHttpInput
                    {
                        KeyAuthz = challengeContext.KeyAuthz,
                        // Token = challengeContext.Token,
                        OrchestratorId        = ctx.InstanceId,
                        AuthorizationLocation = authorizationCtx.Location,
                        EntityId = input.EntityId,
                    });

                    list.Add(challengeContext.Token);
                }
            }
            else
            {
                foreach (var authorizationCtx in authorizations)
                {
                    var challengeContext = await authorizationCtx.Dns();

                    var authorization = await authorizationCtx.Resource();

                    await starter.SignalEntityAsync(new EntityId("Authorization", challengeContext.Token), nameof(AuthorizationActor.AuthorizeDns), new AuthorizeDnsInput
                    {
                        Name = $"_acme-challenge.{authorization.Identifier.Value}",
                        //  Token = challengeContext.Token,
                        DnsTxt = context.AccountKey.DnsTxt(challengeContext.Token),
                        AuthorizationLocation = authorizationCtx.Location,
                        OrchestratorId        = ctx.InstanceId,
                        EntityId = input.EntityId
                    });

                    list.Add(challengeContext.Token);
                }
            }



            return(list.ToArray());


            //  return order;
        }