コード例 #1
0
        public async Task <InvokeResult> AddInstanceAsync(DeploymentInstance instance, EntityHeader org, EntityHeader user)
        {
            var host = CreateHost(instance);

            instance.PrimaryHost = new EntityHeader <DeploymentHost>()
            {
                Id = host.Id, Text = host.Name
            };

            ValidationCheck(host, Actions.Create);
            ValidationCheck(instance, Actions.Create);

            await AuthorizeAsync(instance, AuthorizeResult.AuthorizeActions.Create, user, org);

            if (!EntityHeader.IsNullOrEmpty(instance.DeviceRepository))
            {
                var repo = await _deviceManagerRepo.GetDeviceRepositoryAsync(instance.DeviceRepository.Id, org, user);

                if (EntityHeader.IsNullOrEmpty(repo.Instance))
                {
                    repo.Instance = EntityHeader.Create(instance.Id, instance.Name);
                    await _deviceManagerRepo.UpdateDeviceRepositoryAsync(repo, org, user);
                }
                else
                {
                    throw new ValidationException("Can not reassign repo", new ErrorMessage($"Repository is already assigned to the instance {repo.Instance.Text}.  A Device Repository can only be assigned to one Instance at a time."));
                }
            }

            await _instanceRepo.AddInstanceAsync(instance);

            await _deploymentHostManager.AddDeploymentHostAsync(host, org, user);

            return(InvokeResult.Success);
        }
コード例 #2
0
 public Task <InvokeResult> AddHostAsync([FromBody] DeploymentHost host)
 {
     return(_hostManager.AddDeploymentHostAsync(host, OrgEntityHeader, UserEntityHeader));
 }