Exemple #1
0
        public static void Main(string[] args)
        {
            //_messagingService = new PureDatabaseCalls();
            _messagingServiceClient = new PureDatabaseCallsPgSqlClient();
            //_messagingService = new InprocMessagingService();

            //_messagingService = new WebApiMessagingService();
            //_messagingService.Setup("http://localhost/msvc/v1/messaging", "bb9lWD60BTCBWJO0FlOwtVZxLn0lrC3/");

            _deviceIds = new List <long>();

            for (int i = 0; i < QueueSize; i++)
            {
                _deviceIds.Add(_messagingServiceClient.Initialize(Identity.Next()));
                if (i % _stepSize == 0)
                {
                    Console.WriteLine("Idx: " + i);
                }
            }

            _enc     = 0;
            _dec     = 0;
            _decI    = 0;
            _decIAll = 0;

            for (int inst = 0; inst < 10; inst++)
            {
                Task.Factory.StartNew(Enqueue);

                //Task.Factory.StartNew(DequeueMany);
            }

            Console.WriteLine("Press enter to exit");
            Console.ReadLine();
        }
Exemple #2
0
        public string Create(DeviceDto deviceDto)
        {
            Authenticate();
            Validator.ValidateId(deviceDto.CompanyId);
            Validator.ValidateId(deviceDto.ServiceId);
            Validator.ValidateId(deviceDto.NetworkId);
            deviceDto.Name = Validator.TrimAndValidateAsName(deviceDto.Name);

            var device = Mapper.Map <Device>(deviceDto);

            AuthorizeCompany(device.Company.Id);

            var service = _serviceOperations.Get(device.Service.Id);

            AuthorizeCompany(service.Company.Id);

            if (service.Company.Id != device.Company.Id)
            {
                throw new ForbiddenException();
            }

            var parentNetwork = _networkOperations.Get(device.Network.Id);

            if (parentNetwork.Company.Id != device.Company.Id)
            {
                throw new ForbiddenException();
            }

            device.DeviceKey = Crypto.GenerateSafeRandomToken();

            var deviceId = _deviceOperations.Create(device);

            try
            {
                var deviceNumericId = _messagingServiceClient.Initialize(deviceId);

                var newDevice = _deviceOperations.Get(deviceId);
                newDevice.NumericId = deviceNumericId;
                _deviceOperations.Update(newDevice);
            }
            catch
            {
                try
                {
                    _deviceOperations.Delete(deviceId);
                }
                catch
                {
                    // best effort solution the remove not complete device
                }

                throw;
            }

            return(deviceId);
        }
Exemple #3
0
        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);
        }