Exemplo n.º 1
0
 public async Task UpdateApplicationHost(RomiApplicationHost host)
 {
     using (var uow = new UnitOfWork <RomiApplicationHost, RomiDbContext>())
     {
         await Task.Run(() => uow.Repository().Update(host));
     }
 }
 public async Task DeleteHost([FromBody] RomiApplicationHost host)
 {
     using (var uow = new UnitOfWork <RomiApplicationHost>(new RomiDbContext()))
     {
         await Task.Run(() => uow.Repository().Delete(host));
     }
 }
Exemplo n.º 3
0
        public async Task <RomiApplicationHost> RegisterApplicationHost(string name, HostSettings settings)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                name = name ?? "[null]";
                throw new DataException($"ApplicationHost name '{name}' is invalid");
            }

            var host = await GetHost(name);

            if (host != null)
            {
                throw new DataException($"ApplicationHost '{name}' already registered");
            }

            host = new RomiApplicationHost()
            {
                Name = name, Settings = this._mapper.Map <RomiSettings>(settings), Devices = null
            };
            using (var uow = new UnitOfWork <RomiApplicationHost, RomiDbContext>())
            {
                await Task.Run(() => uow.Repository().Add(host));

                host = await uow.Repository().Query(x => x.Name == name).Include(t => t.Settings)
                       .SingleOrDefaultAsync();
            }

            return(host);
        }
Exemplo n.º 4
0
        public async Task <TDevice> GetDevice <TDevice>(RomiApplicationHost host = null)
            where TDevice : RegisteredDevice, new()
        {
            Type deviceType = typeof(TDevice);
            var  deviceList = await this.GetDevices();

            return(deviceList.FirstOrDefault(t => t.Name == deviceType.FullName) as TDevice);
        }
        public async Task <IActionResult> RegisterHost(string name, [FromBody] HostSettings settings = null)
        {
            if (settings == null)
            {
                settings = HostSettings.Default;
            }

            RomiApplicationHost result = await this._config.RegisterApplicationHost(name, settings);

            return(new JsonResult(result));
        }
Exemplo n.º 6
0
        public async Task <RomiApplicationHost> GetHost(string name)
        {
            RomiApplicationHost result = null;

            using (var uow = new UnitOfWork <RomiApplicationHost, RomiDbContext>())
            {
                result = await uow.Repository().Query(x => x.Name == name).Include(t => t.Settings)
                         .SingleOrDefaultAsync();
            }

            return(result);
        }
        public async Task <IActionResult> GetHost(string name)
        {
            RomiApplicationHost result = null;

            if (name == "local")
            {
                name = ".";
            }

            using (var uow = new UnitOfWork <RomiApplicationHost>(new RomiDbContext()))
            {
                result = await uow.Repository().SingleOrDefaultAsync(t => t.Name == name);
            }

            return(new JsonResult(result));
        }
Exemplo n.º 8
0
        public async Task <List <RegisteredDevice> > GetDevices(
            RomiApplicationHost host            = null,
            RegisteredInterface deviceInterface = null)
        {
            if (host == null)
            {
                host = await this.GetLocalHost();
            }

            List <RegisteredDevice> result = new List <RegisteredDevice>();

            using (var uow = new UnitOfWork <RegisteredDevice, RomiDbContext>())
            {
                var items = await uow.Repository().FindAsync(
                    t => t.ApplicationHost == host &&
                    (deviceInterface == null || t.Interface == deviceInterface));

                result.AddRange(items);
            }

            return(result);
        }