예제 #1
0
        public CodeInfo(JsonDevice jsonDevice, JsonSubIr jsonSubIr, JsonButton jsonButton, JsonIrCode jsonIrCode)
        {
            if (!IsValid(jsonSubIr, jsonButton, jsonIrCode))
            {
                return;
            }

            Mac = jsonDevice.Mac;

            RemoteName = jsonSubIr.Name;
            RemoteType = jsonSubIr.Type;

            Id    = jsonButton.Id;
            Name  = jsonButton;
            Type  = jsonButton.Type;
            Index = jsonButton.Index;

            Delay = jsonIrCode.Delay;
            Order = jsonIrCode.Order;
            Code  = jsonIrCode.CodeHex;
        }
예제 #2
0
        public static CodeInfo[] GetSharedData(
            string fileJsonDevice = nameof(JsonDevice), string fileJsonButton = nameof(JsonButton),
            string fileJsonIrCode = nameof(JsonIrCode), string fileJsonSubIr  = nameof(JsonSubIr))
        {
            var jsonDevices = JsonDevice.Read();
            var jsonButtons = JsonButton.Read();
            var jsonIrCodes = JsonIrCode.Read();
            var jsonSubIrs  = JsonSubIr.Read();

            if (jsonDevices == null || jsonDevices.Length == 0 ||
                jsonButtons == null || jsonButtons.Length == 0 ||
                jsonIrCodes == null || jsonIrCodes.Length == 0 ||
                jsonSubIrs == null || jsonSubIrs.Length == 0)
            {
                return(null);
            }

            var model = new List <CodeInfo>();

            foreach (var subIr in jsonSubIrs)
            {
                if (jsonDevices.FirstOrDefault(item => item.Id == subIr.DeviceId) is JsonDevice device)
                {
                    foreach (var button in jsonButtons)
                    {
                        foreach (var irCode in jsonIrCodes)
                        {
                            if (IsValid(subIr, button, irCode) && !irCode.CodeHex.IsNullOrEmptyTrim() && irCode.CodeHex.Length > 0)
                            {
                                model.Add(new CodeInfo(device, subIr, button, irCode));
                            }
                        }
                    }
                }
            }
            return(model.OrderBy(item => item.ToString()).ToArray());
        }
예제 #3
0
 public static bool IsValid(JsonSubIr jsonSubIr, JsonButton jsonButton, JsonIrCode jsonIrCode) => jsonSubIr.Id != 0 && jsonButton.Id != 0 && jsonIrCode.ButtonId != 0 && jsonSubIr.Id == jsonButton.SubIrId && jsonIrCode.ButtonId == jsonButton.Id && jsonIrCode.CodeHex != null && jsonIrCode.CodeHex.Length > 0;