Exemple #1
0
        private async Task <DaemonHostViewModel> GetDaemons(DaemonHost daemonHost)
        {
            try
            {
                var api = _restApiProvider.Get <IDaemonApi>(daemonHost.Url);

                var daemons = await api.GetDaemons(daemonHost.SubscribedDaemons.ToArray());

                // we pass this url to the Lightbringer.Service.
                // when one of its daemons changes, it will notify us by calling this url.
                var url = $"{Request.Scheme}://{Request.Host}{Request.PathBase}/api/notify/changed?id={daemonHost.Id}&type={NotifyParameter.DaemonType}&daemon={NotifyParameter.DaemonName}&state={NotifyParameter.State}";
                await api.Notify(url);

                var daemonVms = daemons
                                .Select(d => _daemonDtoConverter.ToDaemonVm(d, daemonHost))
                                .ToArray();

                return(new DaemonHostViewModel {
                    DaemonHost = daemonHost, Daemons = daemonVms
                });
            }
            catch (Exception ex)
            {
                return(new DaemonHostViewModel {
                    DaemonHost = daemonHost, Error = ex.Message
                });
            }
        }
        private async Task <IEnumerable <DaemonVm> > GetDaemonDtos(DaemonHost daemonHost, string filter)
        {
            var url = daemonHost.Url;

            var daemonApi = _restApiProvider.Get <IDaemonApi>(url);

            var daemons = (await daemonApi.FindDaemons(filter))
                          .Select(d => _daemonDtoConverter.ToDaemonVm(d, daemonHost));

            return(daemons);
        }