public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Admin, "post", Route = "unsubscribe/{teamId}")] HttpRequest req,
            [DurableClient] IDurableOrchestrationClient starter,
            string teamId,
            ILogger log)
        {
            try
            {
                var connection = await _scheduleConnectorService.GetConnectionAsync(teamId).ConfigureAwait(false);
            }
            catch (KeyNotFoundException)
            {
                return(new NotFoundResult());
            }

            // ensure that in the very brief period of time before the connection is deleted that
            // the orchestrators are not started
            await _scheduleConnectorService.UpdateEnabledAsync(teamId, false).ConfigureAwait(false);

            // and that any running instances are terminated
            await StopTrigger.StopRunningOrchestratorsAsync(teamId, starter).ConfigureAwait(false);

            // finally, delete the connection
            await _scheduleConnectorService.DeleteConnectionAsync(teamId).ConfigureAwait(false);

            log.LogUnsubscribeTeam(teamId);

            return(new OkResult());
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Admin, "post", Route = "clearschedule")] ClearScheduleModel clearScheduleModel,
            [DurableClient] IDurableOrchestrationClient starter,
            ILogger log)
        {
            if (!clearScheduleModel.IsValid())
            {
                return(new BadRequestResult());
            }

            // ensure that the team's orchestrators will not execute by disabling them
            await _scheduleConnectorService.UpdateEnabledAsync(clearScheduleModel.TeamId, false).ConfigureAwait(false);

            // get the connection model as we need the time zone information for the team
            var connectionModel = await _scheduleConnectorService.GetConnectionAsync(clearScheduleModel.TeamId).ConfigureAwait(false);

            try
            {
                SetStartAndEndDates(clearScheduleModel, connectionModel.TimeZoneInfoId);
            }
            catch (ArgumentException ex)
            {
                return(new BadRequestObjectResult(ex.Message));
            }

            if (await starter.TryStartSingletonAsync(nameof(ClearScheduleOrchestrator), ClearScheduleOrchestrator.InstanceId(clearScheduleModel.TeamId), clearScheduleModel).ConfigureAwait(false))
            {
                return(new OkResult());
            }
            else
            {
                return(new ConflictResult());
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Admin, "post", Route = "start/{teamId}")] HttpRequest req,
            string teamId,
            ILogger log)
        {
            await _scheduleConnectorService.UpdateEnabledAsync(teamId, true).ConfigureAwait(false);

            log.LogEnableOrchestrators(teamId);

            return(new OkResult());
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Admin, "post", Route = "stop/{teamId}")] HttpRequest req,
            [DurableClient] IDurableOrchestrationClient starter,
            string teamId,
            ILogger log)
        {
            await _scheduleConnectorService.UpdateEnabledAsync(teamId, false).ConfigureAwait(false);

            await StopRunningOrchestratorsAsync(teamId, starter).ConfigureAwait(false);

            log.LogDisableOrchestrators(teamId);

            return(new OkResult());
        }