private void btnAddDevice_Click(object sender, EventArgs e) { try { if (DeviceManager.Devices.Count >= 8) { return; } string devName = txtDeviceName.Text; if (string.IsNullOrEmpty(devName)) { return; } if (!DeviceManager.CanAdd(devName)) { MessageBox.Show("Urządzenie o podanej nazwie już istnieje", "Niepoprawna nazwa", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } DeviceType type = (DeviceType)ddDeviceType.SelectedIndex; eCalendarColor color; int slot = Convert.ToInt32(ddDeviceSlot.Text); if (DeviceManager.HasColor(type)) { color = CalendarUtils.CalendarColorFromString(cddDeviceColor.SelectedItem.ToString()); } else { color = DeviceManager.GetDefaultColor(type); } DeviceManager.AddDevice(devName, type, slot, color); devName += getSlotFormat(slot); TimelineAddNewRow(devName, color); txtDeviceName.Text = ""; } catch (Exception ex) { Console.WriteLine(ex); } }
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); } }
private void btnRead_Click(object sender, EventArgs e) { try { string json = null; if (OFFLINE) { json = rx; } else { if (link.Connect()) { Console.WriteLine("Read config"); link.Send("TER_READ"); json = link.Receive(); link.Close(); } } Console.WriteLine("offline read"); var data = JObject.Parse(json); Console.WriteLine(data); var devices = data["Devices"].ToObject <Dictionary <string, JObject> >(); var config = data["Config"]; DeviceManager.Clear(); TimelineClear(); List <Event> temp = new List <Event>(); foreach (var entry in devices) { string devName = entry.Key; DeviceType devType = (DeviceType)Enum.Parse(typeof(DeviceType), (string)entry.Value["Type"]); RGB rgb = entry.Value["Color"].ToObject <RGB>(); eCalendarColor color = CalendarUtils.ConvertColor(rgb); int slot = (int)entry.Value["Slot"]; List <Event> events = new List <Event>(); foreach (var evData in entry.Value["Events"]) { Event ev = evData.ToObject <Event>(); events.Add(ev); } DeviceManager.AddDevice(devName, devType, slot, color); devName += getSlotFormat(slot); TimelineAddNewRow(devName, color); FillTimeline(events, devName); } /////////////////////////////////////////////////////// minTempLimit = (int)config["Limits"]["Min"]; maxTempLimit = (int)config["Limits"]["Max"]; List <LimitTempView> _views = new List <LimitTempView>(); foreach (var limit in config["Limits"]["Events"]) { LimitTempModel model = limit.ToObject <LimitTempModel>(); _views.Add(new LimitTempView(model)); } // Create views for Limit Temp window List <string> names = DeviceManager.GetNames(); List <LimitTempModel> models = (views == null) ? LimitTempModel.Create(names) : LimitTempModel.Create(names, views.ConvertAll(view => view.Model)); views = LimitTempView.Create(models); // Update those views with received data foreach (var _view in _views) { foreach (var view in views) { if (view.Model.Name == _view.Model.Name) { view.Model = _view.Model; } } } } catch (Exception ex) { Console.WriteLine(ex); } }