Ejemplo n.º 1
0
        public static SystemIntegration SaveCultivations(SystemIntegration schedule)
        {
            if (schedule == null)
            {
                return(null);
            }
            DeviceService.InitData();

            var tSchedule = schedule.CellCultivation;

            tSchedule.BatchNumber = CurrentContext.BatchNumber;
            tSchedule.CreatedAt   = Common.Utility.Common.ToUnixTime(DateTime.Now);

            using (var db = new IotContext())
            {
                db.CellCultivations.Add(tSchedule);
                db.SaveChanges();
            }

            using (var db = new IotContext())
            {
                schedule.Rocker.CultivationId = tSchedule.Id;
                db.Rockers.Add(schedule.Rocker);

                schedule.Gas.CultivationId = tSchedule.Id;
                db.Gases.Add(schedule.Gas);

                schedule.TemperatureGauge.DeviceId = tSchedule.Id;
                db.TemperatureGauges.Add(schedule.TemperatureGauge);

                var p = new List <Pump>()
                {
                    schedule.PumpIn, schedule.PumpOut
                };

                foreach (var each in p)
                {
                    each.CultivationId = tSchedule.Id;
                    db.Pumps.Add(each);
                }

                db.SaveChanges();
            }

            return(schedule);
        }
Ejemplo n.º 2
0
        private void OnReceiveHandler(SocketData data)
        {
            switch (data.Action)
            {
            case "requireSyncData":
            {
                LogFactory.Create().Info("requireSyncData");
                ControlCenter.Instance.SyncDeviceDataWithServer();
                break;
            }

            case "test":
            {
                LogFactory.Create().Info("test->" + data);
                break;
            }

            case "requireInit":
            {
                LogFactory.Create().Info("requireInit");
                _deviceInfo = new DeviceInfo()
                {
                    clientId    = Common.Utility.Common.GetMacAddress(),
                    description = Common.Utility.Common.GetLocalIpex(),
                    payload     = CurrentContext.SysCache?.SystemRealTimeStatus
                };
                Send(_deviceInfo, "first_conn");
                break;
            }

            case "command":
            {
                LogFactory.Create().Info("command->" + data.Data);
                var cmd = data.Data.ToString();

                OnControlHandler(cmd, "");
                break;
            }

            case "qr":
            {
                OnControlHandler("qr", data.Data);
                break;
            }

            //#TODO 远程编辑
            case "saveSchedule":
            {
                if (CurrentContext.Status == SysStatusEnum.Completed ||
                    CurrentContext.Status == SysStatusEnum.Unknown ||
                    CurrentContext.Status == SysStatusEnum.Ready ||
                    CurrentContext.Status == SysStatusEnum.Discarded)
                {
                    SystemIntegration systemIntegration;
                    try
                    {
                        systemIntegration = CultivationService.GetCultivations(JsonConvert.SerializeObject(data.Data));
                    }
                    catch (Exception e)
                    {
                        LogFactory.Create().Warnning(e.Message);
                        Send(new { code = e.Message }, "saveScheduleBack");
                        return;
                    }

                    var validErr = "";
                    var isValid  = systemIntegration.Check(out validErr);       //PumpValidation.CheckCultivation(cultivation.Pumps.ToList(), out validErr);

                    if (isValid)
                    {
                        ControlCenter.Instance.Dispose();
                        DeviceService.InitData();

                        Send(new { code = "success" }, "saveScheduleBack");
                        OnSaveScheduleHandler(systemIntegration);
                    }
                    else
                    {
                        Send(new { code = validErr }, "saveScheduleBack");
                    }
                }
                else
                {
                    Send(new { code = $"Current Status is {CurrentContext.Status}, can not set schedule" },
                         "saveScheduleBack");
                }

                break;
            }

            default:
                break;
            }
        }