Exemple #1
0
        private static JObject GetConfigJsonObj(int min, int max, List <LimitTempModel> limitTempModels)
        {
            JObject config = new JObject();
            JObject limits = new JObject();

            // filter models - remove not selected one
            limitTempModels.RemoveAll(model => !model.Selected);

            limits.Add(JsonCreator.PropertyFromList("Events", limitTempModels));
            limits.Add(new JProperty("Min", min));
            limits.Add(new JProperty("Max", max));

            config.Add("Limits", limits);

            return(config);
        }
Exemple #2
0
        public static string GetJson(List <DeviceConfig> devConfs, int min, int max, List <LimitTempModel> limitTempModels)
        {
            JObject data    = new JObject();
            JObject devices = new JObject();
            JObject config  = GetConfigJsonObj(min, max, limitTempModels);

            for (int i = 0; i < devConfs.Count; i++)
            {
                JObject content = new JObject();
                content.Add(JsonCreator.PropertyFromList("Events", devConfs[i].Events));
                content.Add("Slot", devConfs[i].Slot);
                content.Add("Color", JObject.FromObject(devConfs[i].Color));
                content.Add("Type", devConfs[i].Type);
                devices.Add(new JProperty(devConfs[i].Name, content));
            }

            data.Add("Devices", devices);
            data.Add("Config", config);

            Console.WriteLine(data);
            return(JsonConvert.SerializeObject(data));
        }
Exemple #3
0
        private void SendJsonData()
        {
            try
            {
                ConcatAppointments();
                List <DeviceConfig> devConfs = new List <DeviceConfig>();
                List <DeviceModel>  devices  = DeviceManager.Devices;

                for (int i = 0; i < devices.Count; i++)
                {
                    DeviceConfig config = new DeviceConfig(devices[i].Name);
                    Color        color  = CalendarUtils.ConvertColor(devices[i].Color);
                    config.Color  = new RGB(color.R, color.G, color.B);
                    config.Events = GetEventsFromTimeline(i);
                    config.Slot   = devices[i].Slot;
                    config.Type   = devices[i].Type.ToString();
                    devConfs.Add(config);
                }

                string output = JsonCreator.GetJson(
                    devConfs,
                    minTempLimit,
                    maxTempLimit,
                    views.ConvertAll(view => view.Model));
                if (OFFLINE)
                {
                    sentData = output;
                }
                else
                {
                    link.Send(output);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Exemple #4
0
        public static JProperty PropertyFromList <T>(string propName, List <T> items)
        {
            JArray array = JsonCreator.ArrayFromList(items);

            return(new JProperty(propName, array));
        }