Exemple #1
0
        public override bool?IsActivated(string deviceId)
        {
            Toolbox.Log.Trace("check activated...");
            Toolbox.Log.LogDebug(nameof(IsActivated), $"deviceId: {deviceId}");
            if (new Guid(deviceId) != Constants.Output1)
            {
                throw new MIPDriverException("E4.1 - Device does not support Output commands");
            }

            // TODO: If supported make request to device
            try
            {
                string      url            = this.Container.ConnectionManager.Uri.AbsoluteUri; // ex http://localhost:5000
                string      switchId       = this.Container.SettingsManager.GetSetting(new DeviceSetting(Constants.Switch1, deviceId, null)).Value;
                string      activatedState = this.Container.SettingsManager.GetSetting(new DeviceSetting(Constants.Switch1Activated, deviceId, null)).Value;
                DeviceProxy proxy          = new DeviceProxy();

                Console.WriteLine("getting current state...");
                string currentState = proxy.Get(url, switchId);
                Console.WriteLine($"Got current state: {currentState}.");
                Toolbox.Log.LogError(nameof(IsActivated), $"Just INFO! Got current state: {currentState}");
                return(currentState == activatedState);
            }
            catch (ApplicationException ex)
            {
                Toolbox.Log.LogError(nameof(IsActivated), $"Most INFO! Coulden't get current state: {ex}");
                return(null);
            }
        }
        static void Main(string[] args)
        {
            string stateInput = "off";
            string content    = "{'state'  : '" + stateInput + "  '}";

            content = content.Replace('\'', '"');
            Console.WriteLine(content);

            var    kvs   = content.Split(new char[] { '{', '\'', '"', ' ', ':', '}' }, StringSplitOptions.RemoveEmptyEntries);
            string state = kvs[1];

            Console.WriteLine(state);


            DeviceProxy proxy = new DeviceProxy();

            Console.WriteLine("sending...");
            proxy.Send("http://localhost:5000/", "Door2", "blue");
            Console.WriteLine("sent.");

            string got = proxy.Get("http://localhost:5000/", "Door2");

            Console.WriteLine(got);
        }