예제 #1
0
        public void Put(RelayCollection collection)
        {
            if (collection == null)
            {
                throw new ArgumentNullException(nameof(RelayCollection), "RelayCollection was nullable");
            }

            var request = new RestRequest(_requestUrl, Method.PUT)
            {
                Timeout = 2500
            };

            var jsonRelayCollection = JsonConvert.SerializeObject(collection);

            var jsonParts = this.ConstructJsonBodyParts(jsonRelayCollection);

            request.AddJsonBody(jsonParts);

            _mxioContext.MandatoryHeaders.Select(t => new { t.Key, t.Value }).ToList().ForEach(t => request.AddHeader(t.Key, t.Value));

            IRestResponse response = _mxioContext.Client.Execute(request);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new Exception($"Put query was failder with {response.StatusCode}");
            }
        }
예제 #2
0
        public void RelayCollection_SingleItem()
        {
            // Arrange
            var list = new List <RelayOnChain>()
            {
                new RelayOnChain
                {
                    Url = "http://test.url"
                }
            };

            _client.Setup(x => x.GetAddrAsync(It.IsAny <Uri>()))
            .ReturnsAsync(new GetAddrResponse()
            {
                Ready = true
            });

            // Act
            var collection = new RelayCollection(_client.Object, list);

            // Assert
            Assert.Single(collection);
            var relay = collection.First().Value;

            Assert.True(relay.IsLoaded);
            Assert.True(relay.Ready);
        }
예제 #3
0
        public void RelayCollection_EmptyCollection()
        {
            // Act
            var collection = new RelayCollection(_client.Object, new List <RelayOnChain>());

            // Assert
            Assert.Empty(collection);
        }
예제 #4
0
        public void RelayCollection_SingleItemWithInvalidUrl()
        {
            // Arrange
            var list = new List <RelayOnChain>()
            {
                new RelayOnChain()
            };

            // Act
            var collection = new RelayCollection(_client.Object, list);

            // Assert
            Assert.Single(collection);
            var relay = collection.First().Value;

            Assert.False(relay.IsLoaded);
            Assert.False(relay.Ready);
        }
예제 #5
0
        private async Task ObservableStateAsync(object state)
        {
            await Task.Run(async() =>
            {
                Ping ping       = new Ping();
                PingReply reply = await ping.SendPingAsync(IPAddress.Parse(_mxioContext.Client.BaseUrl.Host));

                if (reply.Status != IPStatus.Success)
                {
                    return;
                }

                RelayCollection relayInputs = default;

                //TODO:Include
                try
                {
                    relayInputs = await this.GetAsync();
                }
                finally { }

                if (_lastRelays == null)
                {
                    _lastRelays = relayInputs;
                    return;
                }

                var differentDigitalInputs = relayInputs.Where(t => _lastRelays.FirstOrDefault(k => k.Index == t.Index).Status != t.Status);

                if (differentDigitalInputs.Count() != 0)
                {
                    OnChanged?.Invoke(this, relayInputs);
                }


                _lastRelays = relayInputs;
            });
        }
예제 #6
0
 private void SetRlsStatus(RelayCollection e)
 {
     RelayContacts = new ObservableCollection <RelayModel>(e.Select(t => new RelayModel {
         Relay = t
     }));
 }