public async Task GetDevices(int page)
        {
            var service = ServicesManager.SelfService;

            Filter.Page = page;

            try
            {
                GetDevicesResponse deviceResponse = await service.GetDevices(Token, Filter);

                if (deviceResponse == null || deviceResponse.Error != ErrorCode.OK)
                {
                    MainWindow.Instance.AddNotification(deviceResponse);
                }
                else
                {
                    Filter.AllPages = deviceResponse.Pages;
                    Devices         = new ObservableCollection <Models.Device.Device>();
                    foreach (var device in deviceResponse.Devices.OrderByDescending(x => x.LastUpdate))
                    {
                        Devices.Add(device);
                    }
                }
            }
            catch (ServiceException ex)
            {
                //TODO: HIGH Add logging
                MainWindow.Instance.AddNotification(ex);
            }
        }
示例#2
0
        public async Task <bool> AnyDevicesWithSerialNumber(string serialNumber)
        {
            var service = ServicesManager.SelfService;
            var Filter  = new DeviceFilter();

            Filter.SerialNumberFilter = serialNumber;

            try
            {
                GetDevicesResponse deviceResponse = await service.GetDevices(Token, Filter);

                if (deviceResponse == null || deviceResponse.Error != ErrorCode.OK)
                {
                    Notify(deviceResponse);
                    return(true);
                }
                else if (deviceResponse.Devices != null && deviceResponse.Devices.Any())
                {
                    return(true);
                }
            }
            catch (ServiceException ex)
            {
                //TODO: HIGH Add logging
                Notify(ex.Message);
            }

            return(false);
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetDevicesResponse response = new GetDevicesResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Devices", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <Device, DeviceUnmarshaller>(DeviceUnmarshaller.Instance);
                    response.Devices = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("NextToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextToken = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
示例#4
0
        public async Task GetDevicesTest()
        {
            using SimpleClicksSoapClient client = await new SimpleClicksSoapClient(
                      new Uri(ServiceUri), new NetworkCredential(Username, Password)).Configure();

            GetAgentsResponse getAgents = await client.Request <GetAgentsResponse>(new GetAgentsRequest());

            GetDevicesResponse getDevices = await client.Request <GetDevicesResponse>(new GetDevicesRequest(getAgents.Agents[0].AgentId));

            TestContext.WriteLine(JsonSerializer.Serialize(getDevices, new JsonSerializerOptions()
            {
                WriteIndented = true
            }));
            Assert.IsNotNull(getDevices);
        }
示例#5
0
        public async Task GetCountersTest()
        {
            using SimpleClicksSoapClient client = await new SimpleClicksSoapClient(
                      new Uri(ServiceUri), new NetworkCredential(Username, Password)).Configure();

            GetAgentsResponse getAgents = await client.Request <GetAgentsResponse>(new GetAgentsRequest());

            GetDevicesResponse getDevices = await client.Request <GetDevicesResponse>(new GetDevicesRequest(getAgents.Agents[0].AgentId));

            XDocument xml = await client.Request(new GetCountersRequest(getAgents.Agents[0].AgentId, getDevices.Devices[0].DeviceId));

            TestContext.WriteLine(xml);

            Assert.IsNotNull(getAgents);
        }
        public GetDevicesResponse Get(GetDevices request)
        {
            var result = new GetDevicesResponse()
            {
                Devices = new List <DeviceInfo>()
            };

            foreach (InsteonDevice device in manager.Network.Devices)
            {
                result.Devices.Add(new DeviceInfo()
                {
                    Address     = device.Address.ToString(),
                    Category    = device.Identity.GetDeviceCategoryName(),
                    SubCategory = device.Identity.GetSubCategoryName(),
                    Name        = device.DeviceName
                });
            }

            return(result);
        }