public async Task <IActionResult> Edit(DeviceFunctionEntity deviceFunctionEntity)
        {
            if (!await IsMyDevice(deviceFunctionEntity.PartitionKey))
            {
                return(NotFound());
            }
            if (String.IsNullOrEmpty(deviceFunctionEntity.RowKey))
            {
                deviceFunctionEntity.RowKey = Guid.NewGuid().ToString();
            }

            if (deviceFunctionEntity.TriggerType == FunctionTriggerType.CronSchedule.ToString())
            {
                if (!new CronSchedule().IsValid(deviceFunctionEntity.CronSchedule))
                {
                    ModelState.AddModelError("CronSchedule", "Invalid cron schedule");
                }
            }

            await _deviceFunctionService.SaveFunctionAsync(deviceFunctionEntity.PartitionKey,
                                                           deviceFunctionEntity.RowKey, deviceFunctionEntity.Name, deviceFunctionEntity.TriggerType, deviceFunctionEntity.Interval,
                                                           deviceFunctionEntity.CronSchedule, deviceFunctionEntity.QueueName, deviceFunctionEntity.Enabled, deviceFunctionEntity.Script);

            await _deviceManagementService.UpdateFunctionsAndVersionsTwinPropertyAsync(deviceFunctionEntity.PartitionKey);

            return(await Edit(deviceFunctionEntity.PartitionKey, deviceFunctionEntity.RowKey));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> CreateNew(string deviceId, string functionId, [FromBody] DeviceFunctionModel functionModel)
        {
            await _deviceFunctionService.SaveFunctionAsync(deviceId, functionId, functionModel.Name,
                                                           functionModel.TriggerType.ToString(), functionModel.Interval, functionModel.CronSchedule,
                                                           functionModel.QueueName, functionModel.Enabled, functionModel.Script);

            await _deviceManagementService.UpdateFunctionsAndVersionsTwinPropertyAsync(deviceId);

            return(Ok());
        }