Пример #1
0
        private void btnLimits_Click(object sender, EventArgs e)
        {
            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);

            LimitWindow window = new LimitWindow(views, minTempLimit, maxTempLimit);

            window.FormClosing += window_FormClosing;
            window.ShowDialog();
        }
Пример #2
0
        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);
            }
        }