public void TryCreateNetworkUnderOtherNetworkTest() { var environmentFactory = EnvironmentFactoryFactory.Create(); var authenticationContext = Substitute.For <IAuthenticationContext>(); var userOperations = environmentFactory.ManagementEnvironment.MgmtUserOperations; var companyOperations = environmentFactory.ManagementEnvironment.MgmtCompanyOperations; var settingProvider = new SettingProvider(environmentFactory.ManagementEnvironment.MgmtSettingOperations); var userService = new UserService(userOperations, authenticationContext, settingProvider, null); var userId1 = userService.Register(new RegisterDto() { Name = "user", Email = EmailHelper.Generate(), Password = "******" }, null); var companyService = new CompanyService(companyOperations, authenticationContext, null, new CapabilityProvider(settingProvider)); authenticationContext.GetContextUser().Returns(userId1); var companyId1 = companyService.Create("new company1"); var serviceOperations = environmentFactory.ManagementEnvironment.MgmtServiceOperations; var serviceService = new ServiceService(serviceOperations, companyOperations, authenticationContext, null, new CapabilityProvider(settingProvider)); var serviceId1 = serviceService.Create(new ServiceDto { CompanyId = companyId1, Name = "svc" }); var companyId2 = companyService.Create("new company2"); var serviceId2 = serviceService.Create(new ServiceDto() { CompanyId = companyId2, Name = "svc" }); var networkOperations = environmentFactory.ManagementEnvironment.MgmtNetworkOperations; var networkService = new NetworkService(networkOperations, serviceOperations, companyOperations, authenticationContext, null); var networkId2 = networkService.Create(new NetworkDto() { ServiceId = serviceId2, CompanyId = companyId2, Name = "svc" }); var network = new NetworkDto() { ParentNetworkId = networkId2, CompanyId = companyId1, ServiceId = serviceId1, Name = "test" }; networkService.Create(network); }
private void Initialize() { var environmentFactory = EnvironmentFactoryFactory.Create(); _authenticationContext = Substitute.For <IAuthenticationContext>(); _messagingServiceClient = Substitute.For <IMessagingServiceClient>(); var userOperations = environmentFactory.ManagementEnvironment.MgmtUserOperations; var companyOperations = environmentFactory.ManagementEnvironment.MgmtCompanyOperations; var settingProvider = new SettingProvider(environmentFactory.ManagementEnvironment.MgmtSettingOperations); var userService = new UserService(userOperations, _authenticationContext, settingProvider, null); _userId = userService.Register(new RegisterDto() { Name = "user", Email = EmailHelper.Generate(), Password = "******" }, null); _companyService = new CompanyService(companyOperations, _authenticationContext, null, new CapabilityProvider(settingProvider)); _authenticationContext.GetContextUser().Returns(_userId); _companyId = _companyService.Create("new company"); var serviceOperations = environmentFactory.ManagementEnvironment.MgmtServiceOperations; _serviceService = new ServiceService(serviceOperations, companyOperations, _authenticationContext, null, new CapabilityProvider(settingProvider)); _serviceId = _serviceService.Create(new ServiceDto() { CompanyId = _companyId, Name = "new service" }); var networkOperations = environmentFactory.ManagementEnvironment.MgmtNetworkOperations; _networkService = new NetworkService(networkOperations, serviceOperations, companyOperations, _authenticationContext, null); var network = new NetworkDto() { Name = "new network", ParentNetworkId = null, CompanyId = _companyId, ServiceId = _serviceId }; _networkId = _networkService.Create(network); _messagingServiceClient.Initialize("1234").ReturnsForAnyArgs(1); var deviceOperations = environmentFactory.ManagementEnvironment.MgmtDeviceOperations; _deviceService = new DeviceService(deviceOperations, networkOperations, serviceOperations, companyOperations, _authenticationContext, _messagingServiceClient); }
public void Update(NetworkDto network) { Authenticate(); Validator.ValidateId(network.Id); var current = _networkOperations.Get(network.Id); AuthorizeCompany(current.Company.Id); current.Name = Validator.TrimAndValidateAsName(network.Name); _networkOperations.Update(current); }
private NetworkDto AppendObjectToMessage() { var obj = new JGameObject() { Id = transform.name, Position = new JVector3(transform.localPosition.x, transform.localPosition.y, transform.localPosition.z), Scale = new JVector3(transform.localScale.x, transform.localScale.y, transform.localScale.z), EulerAngle = new JVector3(transform.localEulerAngles.x, transform.localEulerAngles.y, transform.localEulerAngles.z), Rotation = new JVector4(transform.localRotation.x, transform.localRotation.y, transform.localRotation.z, transform.localRotation.w), Type = JGameObjectType.Existed_Rotation }; var dto = new NetworkDto() { Msg = obj }; return(dto); }
public string Create(NetworkDto networkDto) { Authenticate(); Validator.ValidateId(networkDto.CompanyId); Validator.ValidateId(networkDto.ServiceId); if (networkDto.ParentNetworkId != null) { Validator.ValidateId(networkDto.ParentNetworkId); } networkDto.Name = Validator.TrimAndValidateAsName(networkDto.Name); var network = Mapper.Map <Network>(networkDto); AuthorizeCompany(network.Company.Id); var service = _serviceOperations.Get(network.Service.Id); AuthorizeCompany(service.Company.Id); if (service.Company.Id != network.Company.Id) { throw new ForbiddenException(); } if (network.ParentNetwork != null) { var parentNetwork = _networkOperations.Get(network.ParentNetwork.Id); if (parentNetwork.Company.Id != network.Company.Id) { throw new ForbiddenException(); } } network.NetworkKey = Crypto.GenerateSafeRandomToken(); return(_networkOperations.Create(network)); }
public void UpdateNetwork([FromBody] NetworkDto networkDto) // PUT: api/v1/networks { _networkService.Update(networkDto); }
public IActionResult CreateNetwork([FromBody] NetworkDto networkDto) // POST: api/v1/networks { return(Json(_networkService.Create(networkDto))); }
// Override this method in your own subclass to process the received event data protected override void OnReceivedTextData(string message) { NetworkDto g = JsonConvert.DeserializeObject <NetworkDto>(message); _statusQueue.Enqueue(g.Msg); }
public async Task <IActionResult> Create([FromBody] NetworkDto network) { var newNetwork = await _networkService.AddAsync(_mapper.Map <Network>(network)); return(Ok(_mapper.Map <NetworkDto>(newNetwork))); }