コード例 #1
0
        public void GetOLStatus(int uID, string subcenterId)
        {
            try
            {
                Subcenter sub = new Subcenter {
                    SubcenterdId = subcenterId
                };

                DtuList list = grpcClient.GetDtuList(sub);

                dtuList = new CDictionary <int, DtuList>();

                if (list != null)
                {
                    if (dtuList.ContainsKey(uID))
                    {
                        dtuList[uID] = list;
                    }
                    else
                    {
                        dtuList.Add(uID, list);
                    }
                }
            }
            catch (Exception exp)
            {
                Debug.WriteLine("RPC failed" + exp);
                throw;
            }
        }
コード例 #2
0
        public ResultAndError <Subcenter> Add(Subcenter c)
        {
            ResultAndError <Subcenter> result = new ResultAndError <Subcenter>();

            try
            {
                db.Subcenters.Add(c);
                db.SaveChanges();
                return(result.AddResult(c));
            }
            catch (Exception e)
            {
                return(result.AddError(e, HttpStatusCode.InternalServerError));
            }
        }
コード例 #3
0
        public bool DeleteMulti(IEnumerable <string> Subcenters)
        {
            List <Subcenter> oSubcenters = new List <Subcenter>();

            foreach (string SubcenterNo in Subcenters)
            {
                Subcenter oSubcenter = Get(SubcenterNo);
                if (oSubcenter != null)
                {
                    oSubcenters.Add(oSubcenter);
                }
            }
            db.Subcenters.RemoveRange(oSubcenters);
            db.SaveChanges();
            return(true);
        }
コード例 #4
0
 public bool UpdateMulti(IEnumerable <Subcenter> oSubcenters, bool insertIfNoExists = false)
 {
     foreach (Subcenter Subcenter in oSubcenters)
     {
         Subcenter old = Get(Subcenter.Code);
         if (old == null && insertIfNoExists)
         {
             Add(Subcenter);
         }
         else
         {
             db.Entry(old).CurrentValues.SetValues(Subcenter);
         }
     }
     db.SaveChanges();
     return(true);
 }
コード例 #5
0
        public ResultAndError <Subcenter> Update(Subcenter cr, bool insertIfNoExists = false)
        {
            ResultAndError <Subcenter> result = new ResultAndError <Subcenter>();

            try
            {
                Subcenter old = Get(cr.Code);
                if (old == null && insertIfNoExists)
                {
                    return(Add(cr));
                }
                db.Entry(old).CurrentValues.SetValues(cr);
                db.SaveChanges();
                return(result.AddResult(cr));
            }
            catch (Exception e)
            {
                return(result.AddError(e, HttpStatusCode.InternalServerError));
            }
        }
コード例 #6
0
        public ResultAndError <bool> Delete(string id)
        {
            ResultAndError <bool> result = new ResultAndError <bool>();

            try
            {
                Subcenter Subcenter = Get(id);
                if (Subcenter == null)
                {
                    return(result.AddError("No se encontro el subcentro con el id " + id));
                }
                db.Subcenters.Remove(Subcenter);
                db.SaveChanges();
                return(result.AddResult(true));
            }
            catch (Exception e)
            {
                return(result.AddError(e, HttpStatusCode.InternalServerError));
            }
        }
コード例 #7
0
        private DtuList FindDtuList(Subcenter subcenter)
        {
            DtuList dtuList = new DtuList();

            List <ModemInfoStruct>               stateList    = new List <ModemInfoStruct>();
            List <CEntityStation>                stations     = new List <CEntityStation>();
            List <CEntitySoilStation>            soilStations = new List <CEntitySoilStation>();
            List <CEntitySubCenter>              subCenters   = new List <CEntitySubCenter>();
            Dictionary <string, ModemInfoStruct> gprsDic      = new Dictionary <string, ModemInfoStruct>();

            stateList    = Clone <ModemInfoStruct>(CProtocolEventManager.Instance.GetOnlineStatusList());
            stations     = CDBDataMgr.Instance.GetAllStation();
            soilStations = CDBSoilDataMgr.Instance.GetAllSoilStation();
            subCenters   = CDBDataMgr.Instance.GetAllSubCenter();

            if (stateList.Count() != 0)
            {
                for (int i = 0; i < stateList.Count(); i++)
                {
                    string uid = ((uint)stateList[i].m_modemId).ToString("X").PadLeft(8, '0');
                    gprsDic.Add(uid, stateList[i]);
                }
            }

            foreach (var s in stations)
            {
                if (subcenter.SubcenterdId == s.SubCenterID.ToString() || subcenter.SubcenterdId == "0")
                {
                    if (gprsDic.Count() != 0)
                    {
                        if (gprsDic.ContainsKey(s.GPRS))
                        {
                            Dtu dtu = new Dtu();

                            ModemInfoStruct state       = gprsDic[s.GPRS];
                            string          phoneno     = CGprsUtil.Byte11ToPhoneNO(state.m_phoneno, 0);
                            string          dynIP       = CGprsUtil.Byte4ToIP(state.m_dynip, 0);
                            string          connectTime = CGprsUtil.ULongToDatetime(state.m_conn_time).ToString();
                            string          refreshTime = CGprsUtil.ULongToDatetime(state.m_refresh_time).ToString();

                            dtu.SubcenterId = s.SubCenterID.ToString();
                            string subName = CDBDataMgr.Instance.GetSubCenterName(s.SubCenterID.ToString());
                            dtu.SubcenterName = subName;
                            dtu.StationId     = s.StationID;
                            dtu.StationName   = s.StationName;
                            dtu.GprsId        = s.GPRS;
                            dtu.GsmNum        = phoneno;
                            dtu.IpAddr        = dynIP;
                            dtu.ConnTime      = connectTime;
                            dtu.RefreshTime   = refreshTime;
                            dtu.State         = "1";
                            dtu.StationType   = CEnumHelper.StationTypeToDBStr(s.StationType);
                            dtuList.Dtu.Add(dtu);
                        }
                    }
                    else
                    {
                        Dtu dtu = new Dtu();
                        dtu.SubcenterId = s.SubCenterID.ToString();
                        string subName = CDBDataMgr.Instance.GetSubCenterName(s.SubCenterID.ToString());
                        dtu.SubcenterName = subName;
                        dtu.StationId     = s.StationID;
                        dtu.StationName   = s.StationName;
                        dtu.GprsId        = s.GPRS;
                        dtu.State         = "2";
                        dtu.StationType   = CEnumHelper.StationTypeToDBStr(s.StationType);
                        dtuList.Dtu.Add(dtu);
                    }
                }
            }

            foreach (var s in stations)
            {
                if (subcenter.SubcenterdId == s.SubCenterID.ToString() || subcenter.SubcenterdId == "0")
                {
                    if (gprsDic.Count() != 0)
                    {
                        if (!gprsDic.ContainsKey(s.GPRS))
                        {
                            Dtu dtu = new Dtu();
                            dtu.SubcenterId = s.SubCenterID.ToString();
                            string subName = CDBDataMgr.Instance.GetSubCenterName(s.SubCenterID.ToString());
                            dtu.SubcenterName = subName;
                            dtu.StationId     = s.StationID;
                            dtu.StationName   = s.StationName;
                            dtu.GprsId        = s.GPRS;
                            dtu.State         = "2";
                            dtu.StationType   = CEnumHelper.StationTypeToDBStr(s.StationType);
                            dtuList.Dtu.Add(dtu);
                        }
                    }
                }
            }

            foreach (var s in soilStations)
            {
                if (subcenter.SubcenterdId == s.SubCenterID.ToString() || subcenter.SubcenterdId == "0")
                {
                    if (gprsDic.Count() != 0)
                    {
                        if (gprsDic.ContainsKey(s.GPRS))
                        {
                            Dtu dtu = new Dtu();

                            ModemInfoStruct state       = gprsDic[s.GPRS];
                            string          phoneno     = CGprsUtil.Byte11ToPhoneNO(state.m_phoneno, 0);
                            string          dynIP       = CGprsUtil.Byte4ToIP(state.m_dynip, 0);
                            string          connectTime = CGprsUtil.ULongToDatetime(state.m_conn_time).ToString();
                            string          refreshTime = CGprsUtil.ULongToDatetime(state.m_refresh_time).ToString();

                            if (subcenter.SubcenterdId == s.SubCenterID.ToString() || subcenter.SubcenterdId == "0")
                            {
                                dtu.SubcenterId = s.SubCenterID.ToString();
                                string subName = CDBDataMgr.Instance.GetSubCenterName(s.SubCenterID.ToString());
                                dtu.SubcenterName = subName;
                                dtu.StationId     = s.StationID;
                                dtu.StationName   = s.StationName;
                                dtu.GprsId        = s.GPRS;
                                dtu.GsmNum        = phoneno;
                                dtu.IpAddr        = dynIP;
                                dtu.ConnTime      = connectTime;
                                dtu.RefreshTime   = refreshTime;
                                dtu.State         = "1";
                                dtu.StationType   = CEnumHelper.StationTypeToDBStr(s.StationType);
                                dtuList.Dtu.Add(dtu);
                            }
                        }
                    }
                    else
                    {
                        Dtu dtu = new Dtu();
                        dtu.SubcenterId = s.SubCenterID.ToString();
                        string subName = CDBDataMgr.Instance.GetSubCenterName(s.SubCenterID.ToString());
                        dtu.SubcenterName = subName;
                        dtu.StationId     = s.StationID;
                        dtu.StationName   = s.StationName;
                        dtu.GprsId        = s.GPRS;
                        dtu.State         = "2";
                        dtu.StationType   = CEnumHelper.StationTypeToDBStr(s.StationType);
                        dtuList.Dtu.Add(dtu);
                    }
                }
            }

            foreach (var s in soilStations)
            {
                if (subcenter.SubcenterdId == s.SubCenterID.ToString() || subcenter.SubcenterdId == "0")
                {
                    if (gprsDic.Count() != 0)
                    {
                        if (!gprsDic.ContainsKey(s.GPRS))
                        {
                            Dtu dtu = new Dtu();
                            dtu.SubcenterId = s.SubCenterID.ToString();
                            string subName = CDBDataMgr.Instance.GetSubCenterName(s.SubCenterID.ToString());
                            dtu.SubcenterName = subName;
                            dtu.StationId     = s.StationID;
                            dtu.StationName   = s.StationName;
                            dtu.GprsId        = s.GPRS;
                            dtu.State         = "2";
                            dtu.StationType   = CEnumHelper.StationTypeToDBStr(s.StationType);
                            dtuList.Dtu.Add(dtu);
                        }
                    }
                }
            }

            return(dtuList);
        }
コード例 #8
0
 public override Task <DtuList> GetDtuList(Subcenter subcenter, ServerCallContext context)
 {
     return(Task.FromResult(FindDtuList(subcenter)));
 }
コード例 #9
0
 public IActionResult UpdSubCenter([FromBody] Subcenter subCenter, bool insertIfNoExists = false)
 {
     return(Ok(sBS.Update(subCenter, insertIfNoExists)));
 }