public HttpResponseMessage Put(String beaconID, [FromBody] BEACON BEACON) { try { using (knowhauEntities entities = new knowhauEntities()) { BEACON entity = new BEACON(); entity = entities.BEACONs.FirstOrDefault(e => e.beaconID == beaconID); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Beacon with id " + beaconID.ToString() + " not found to update")); } else { entity.beaconID = BEACON.beaconID; entity.majorvalue = BEACON.majorvalue; entity.minorvalue = BEACON.minorvalue; entity.model = BEACON.model; entity.name = BEACON.name; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, entity)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public UpstreamPointConfig(BEACON beacon, string dir, int len, SyDB sydb) { this.Beacon = beacon; this.Dir = dir; //BMGR-0037 MAX_TRAIN_LENGTH + beacon.BeaconTolID this.Length = len + this.GetBeaconPTDistance(beacon.m_layoutInfo.BeaconTolID); this.Sydb = sydb; }
/// <summary> /// get the distance of beacon and nearest sddb in beacon direction /// unit: cm( sydb kp data is cm) /// </summary> /// <param name="beacon"></param> /// <returns></returns> private int CalBeacon2SDDB(BEACON beacon) { GENERIC_SYSTEM_PARAMETERS.BLOCKS.BLOCK beaconBlk = SyDB.GetLocatedBlock(beacon.m_layoutInfo.kp, beacon.m_layoutInfo.TrackID); if (null == beaconBlk) { TraceMethod.Record(TraceMethod.TraceKind.ERROR, $"Beacon {beacon.Info} type={beacon.m_ibbmInfo.GetBeaconType()} find beacon located block get null, can't get BMB_SDDB_distance"); return(0); } //calculate length from beacon to beacon located Blk end string dir = beacon.m_ibbmInfo.Direction; int length = Sys.GetSDDBLenOfLocatedBlock(beacon.m_layoutInfo.kp, beaconBlk, dir); if (Sys.GetSDDBPosInLocatedBlock(beaconBlk, dir) == Sys.SddbInBlock.end) { return(length); } //calculate length from beaconBlk end to SDDB //only sddb and beacon in different blk will do this int nextBlkID = -1; GENERIC_SYSTEM_PARAMETERS.BLOCKS.BLOCK curBlk = beaconBlk; while (true) { if (curBlk.Is_Direction_Opposite.Equals(true)) { dir = SyDB.GetReverseDir(dir); } nextBlkID = SyDB.GetNextBlkID(curBlk, dir); if (nextBlkID == -1) { TraceMethod.RecordInfo($"{curBlk.Info} search next block in {dir} occer convergent point,Error:Beacon {beacon.Info} type={beacon.m_ibbmInfo.GetBeaconType()} can't get BMB_SDDB_distance."); return(0); } var nextBlk = (GENERIC_SYSTEM_PARAMETERS.BLOCKS.BLOCK)Sys.GetNode(nextBlkID, sydb.blockInfoList.Cast <Node>().ToList()); if (null == nextBlk) { TraceMethod.RecordInfo($"{curBlk.Info} search next block in {dir} get null,Error:Beacon {beacon.Info} type={beacon.m_ibbmInfo.GetBeaconType()} can't get BMB_SDDB_distance"); return(0); } Sys.SddbInBlock sddbInWalk = Sys.SddbWalkThroughBlock(nextBlk, dir); if (Sys.SddbInBlock.none != sddbInWalk) { if (Sys.SddbInBlock.end == sddbInWalk) { length += nextBlk.GetBlockLen(); } break; } length += nextBlk.GetBlockLen(); curBlk = nextBlk; } return(length); }
//BMGR-0027 private XmlVisitor CalBMVariantNode(BEACON beacon) { XmlVisitor bmNode = XmlVisitor.Create("BM_variants", null); foreach (Variant var in beacon.m_variantLst) { bmNode.AppendChild(var.GetVariantXmlNode()); } return(bmNode); }
//BMGR-0046 private bool GenerateBeaconInfoNode(BEACON beacon, ref XmlVisitor node, int outnum) { if (false == beacon.SetBeaconInfoNode_LEURF(ref node, outnum)) { TraceMethod.RecordInfo($"Write SetBeaconInfoNode_LEURF for {beacon.Info} error!"); return(false); } //BMGR-0047 node.AppendChild("Variants_inputs", beacon.GetVariantsInputs()); return(true); }
//BMGR-0027 private bool GenerateVariantList(BEACON beacon) { beacon.m_variantLst = new List <Variant>(); foreach (OriginSignal sig in beacon.GetOrgSignalList()) { sig.CalVariants(beacon.m_variantLst); } foreach (Variant var in beacon.m_variantLst) { if (var.GetVarSrc() == VAR_TYPE.E_POINT) { VariantPoint pvar = (VariantPoint)var; //BMGR-0031 set inputRank from IBBM var.InputRank = beacon.m_ibbmInfo.getInputRank(var.GetName(), pvar.PointVariantPos); pvar.check(beacon.Name); } } //del repeat by object_name beacon.m_variantLst = beacon.m_variantLst.Distinct().ToList(); //set idx int idx = 1; foreach (Variant var in beacon.m_variantLst) { var.SetIdx(idx); ++idx; } if (beacon.m_variantLst.Count() > BEACON.MAXVARNUM) { TraceMethod.Record(TraceMethod.TraceKind.ERROR, $"{beacon.Info} has {beacon.m_variantLst.Count()} variants more than {BEACON.MAXVARNUM}!"); foreach (Variant var in beacon.m_variantLst) { TraceMethod.RecordInfo($"{var.Info}"); } } return(true); }
//BMGR-0050 //BMGR-0049 /// <summary> /// generate all message of section info for one beacon, not consider upstream /// </summary> /// <param name="beacon"></param> /// <returns></returns> private List <Message> GenerateMessage(BEACON beacon) { //the order in msgLst should not be changed List <Message> msgLst = new List <Message>(); int msgRankIdx = 0; {//BMGR-0050 generate leu default message rank = 0 Message msg_leudefault = new Message(msgRankIdx++); msgLst.Add(msg_leudefault); } {//rank = 1 Message msgRed = new Message(msgRankIdx++); msgLst.Add(msgRed); } Message msgBase = new Message(); if (BeaconType.Approach == beacon.m_ibbmInfo.GetBeaconType()) { #region [only approach] //BMGR-0078 only app foreach (OriginSignal appOrg in beacon.m_AppOrgSigLst) { foreach (RouteSegment appRS in appOrg.RsList) { Message msgApp = new Message(msgRankIdx++, msgBase); msgApp.apRs = appRS;//BMGR-0079 has app then no overlap msgLst.Add(msgApp); } } #endregion } else if (BeaconType.Reopening == beacon.m_ibbmInfo.GetBeaconType()) { #region [only reopen] if (null != beacon.m_ReopenOrgSig) { //BMGR-0079 foreach (RouteSegment rs in beacon.m_ReopenOrgSig.RsList) { msgBase.rpRs = rs;//msg add reopen rs //BMGR-0077 if RSroute has overlap, then generate rs + ol if (null != rs.m_overlap) { if (null != rs.m_overlap.m_pathLst && 0 < rs.m_overlap.m_pathLst.Count()) {//reopen rs + overlap path foreach (PathInfo path in rs.m_overlap.m_pathLst) { Message msgolp = new Message(msgRankIdx++, msgBase); msgolp.olPath = path; msgolp.overlap = rs.m_overlap; msgLst.Add(msgolp); } } else {//reopen rs + overlap with no path Message msgol = new Message(msgRankIdx++, msgBase); msgol.overlap = rs.m_overlap; msgLst.Add(msgol); } } else//BMGR-0077 if RSroute has no overlap and no appRoute, then generate rs { Message msgrs = new Message(msgRankIdx++, msgBase); msgLst.Add(msgrs); } } } #endregion } else { #region [reopen and approach] if (null != beacon.m_ReopenOrgSig) { foreach (RouteSegment rs in beacon.m_ReopenOrgSig.RsList) { msgBase.rpRs = rs;//msg add reopen rs //BMGR-0077 if RSroute has overlap, then generate rs + ol if (null != rs.m_overlap) { if (null != rs.m_overlap.m_pathLst && 0 < rs.m_overlap.m_pathLst.Count()) {//reopen rs + overlap path foreach (PathInfo path in rs.m_overlap.m_pathLst) { Message msgolp = new Message(msgRankIdx++, msgBase); msgolp.olPath = path; msgolp.overlap = rs.m_overlap; msgLst.Add(msgolp); } } else {//reopen rs + overlap with no path Message msgol = new Message(msgRankIdx++, msgBase); msgol.overlap = rs.m_overlap; msgLst.Add(msgol); } } else//BMGR-0077 if RSroute has no overlap, then generate rs { Message msgrs = new Message(msgRankIdx++, msgBase); msgLst.Add(msgrs); } //BMGR-0078 rs+ol first now rs+app rs.dest sig == app.org sig OriginSignal appOrg = beacon.GetOriginSignalBySignalName(rs.GetDstSignalName()); if (null != appOrg && null != appOrg.RsList) { foreach (RouteSegment appRS in appOrg.RsList) { Message msgApp = new Message(msgRankIdx++, msgBase); msgApp.apRs = appRS; msgLst.Add(msgApp); } } } } #endregion } if (msgRankIdx != msgLst.Count()) { TraceMethod.RecordInfo(string.Format("Beacon[{0}] GenerateMessage run error msgRankIdx[{1}] != msgLst.Count[{2}]", beacon.Name, msgRankIdx, msgLst.Count())); return(null); } return(msgLst); }
//BMGR-0051. the if should obey the order from 0051 //msg has but open =1 //msg has but close =0 //msg not has but linked signal =0 //msg not has but input rank = S P //msg not has and not input rank = 0 private string GetMsgVar(Message msg, BEACON beacon) { int rank = msg.GetRank(); if (-1 == rank) { TraceMethod.RecordInfo(string.Format("Beacon[{0}] GetMsgVar run error msg rank is -1", beacon.Name)); return(""); } if (0 == rank) { return("".PadLeft(BEACON.MAXVARNUM, '0')); } //string[] strVar = new string[BEACON.MAXVARNUM] { "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" }; string[] strVar = new string[BEACON.MAXVARNUM]; for (int i = 0; i < strVar.Count(); i++) { strVar[i] = "0"; } foreach (Variant var in beacon.m_variantLst) { if (var.m_Idx > BEACON.MAXVARNUM) { continue; } strVar[var.m_Idx - 1] = msg.GetVariantState(var).ToString(); if ("-1" == strVar[var.m_Idx - 1]) { if (beacon.GetLindedSignalName() == var.GetName()) { strVar[var.m_Idx - 1] = "0"; } else if (-1 != var.InputRank) {//signal or point has input rank and not exist in message combine section if (VAR_TYPE.E_SIGNAL == var.GetVarSrc()) { strVar[var.m_Idx - 1] = "S"; } else { strVar[var.m_Idx - 1] = "P"; } } else//else is set 0 { strVar[var.m_Idx - 1] = "0"; } } } string varState = ""; for (int i = 0; i < strVar.Count(); i++) { varState += strVar[i]; } return(varState); }
public HttpResponseMessage Post([FromBody] BEACON beacon, String admin, String mensagem, int super) { try { HttpConfiguration config = GlobalConfiguration.Configuration; config.Formatters.JsonFormatter .SerializerSettings .ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; using (knowhauEntities entities = new knowhauEntities()) { LOGWEBAPP web = new LOGWEBAPP(); web.date = DateTime.Now; web.eventtype = "I"; web.username = admin; if (super == 0) { BA id = new BA(); id.beaconID = beacon.beaconID; id.adminemail = admin; entities.BAs.Add(id); } CONTENT cont = new CONTENT(); cont.beaconID = beacon.beaconID; cont.contentmsg = mensagem; entities.BEACONs.Add(beacon); entities.CONTENTs.Add(cont); entities.LOGWEBAPPs.Add(web); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, beacon); message.Headers.Location = new Uri(Request.RequestUri + beacon.name.ToString()); return(message); } } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); // Throw a new DbEntityValidationException with the improved exception message. throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
/// <summary> /// in this function will check and load beacon info from sydb.IBBM /// all LEU and Beacon from sydb.IBBM will be generate in this function /// </summary> /// <returns></returns> private bool GenrateDeviceByIBBM() { bool rt = true; //BMGR-0016 LEUID start from 1 int LEUID = 1; //clear leu and beacon before add new data to them LEUList.Clear(); beaconList.Clear(); int IsAddBeacon; List <IBeaconInfo> list1 = sydb.GetBeacons(); // newly added to avoid outputting the same ID and name repeatedly //List<string> ibbmBeaconList = (from ibbmBeacon in sydb.ibbmInfoList select ibbmBeacon.Name); foreach (GENERIC_SYSTEM_PARAMETERS.IMPLEMENTATION_BEACON_BLOCK_MODE.BM_BEACON ibbm in sydb.ibbmInfoList)//search sydb.ibbm, LEUID should be same with this order { //IBeaconInfo layout = sydb.GetBeacons().Find(x => x.Name == ibbm.Name); // This line will repeat the output ID and Name IBeaconInfo layout = list1.Find(x => x.Name == ibbm.Name); //judge the beacon first, if this beacon is not exist in Beacons, then ignore this beacon and LEU if (null == layout) { TraceMethod.Record(TraceMethod.TraceKind.WARNING, $"Beacon[{ibbm.Name}] exist in Implementation_Beacon_Block_Mode but not exist in Beacons."); continue; } if (false == layout.IsVariantBeacon()) { TraceMethod.Record(TraceMethod.TraceKind.WARNING, $"Beacon[{ibbm.Name}] exist in Implementation_Beacon_Block_Mode but is Fixed Beacon."); continue; } BEACON newbeacon = new BEACON(layout, ibbm); beaconList.Add(newbeacon); if (newbeacon.m_Type == "Invalid") { continue; } int LEUidx = LEUList.FindIndex(x => x.Name == ibbm.LEU.LEU_Name); if (-1 == LEUidx)//if the LEU not exist, then create a new one { //BMGR-0016 set LEUID for each new LEU in IBBM order LEU newLEU = new LEU(ibbm.LEU.LEU_Name, LEUID, ibbm.CI_Name); ++LEUID;//LEU ID start from 1, add 1 for each diff one LEUList.Add(newLEU); LEUidx = LEUList.Count() - 1; } { //check LEU.BeaconOutNum IsAddBeacon = LEUList[LEUidx].AddBeacon(ibbm.LEU.Beacon_Output_number, ibbm.Name); //if (false == LEUList[LEUidx].AddBeacon(ibbm.LEU.Beacon_Output_number, ibbm.Name)) if (-1 == IsAddBeacon) { LEUList.RemoveAt(LEUidx); // new add to remove error LEU --LEUID; continue; } else if (-2 == IsAddBeacon) { //LEUList.RemoveAt(LEUidx); // new add to remove error LEU //--LEUID; TraceMethod.Record(TraceMethod.TraceKind.WARNING, $"Beacon {ibbm.Info} will link to LEU {ibbm.LEU.Info} faild."); } } //BEACON newbeacon = new BEACON(layout, ibbm); //beaconList.Add(newbeacon); //if (newbeacon.m_Type == "Invalid") //{ // continue; //} } if (null == beaconList || beaconList.Count() <= 0) { TraceMethod.Record(TraceMethod.TraceKind.ERROR, "GenrateDeviceByIBBM, after check IBBM and Beacons, no valid beacon can used to generate data"); return(false); } //check if exist variant beacon which in beacons but not in Implementation_Beacon_Block_Mode //foreach (IBeaconInfo beacon in sydb.GetBeacons()) foreach (IBeaconInfo beacon in list1) { if (true == beacon.IsVariantBeacon()) { int Bidx = beaconList.FindIndex(x => x.Name == beacon.Name); if (-1 == Bidx) { TraceMethod.Record(TraceMethod.TraceKind.WARNING, $"{beacon.Info} can't get vaild info from sydb.IBBM. BMVF file will generate no info for this beacon"); continue; } } } LEUList.ForEach(delegate(LEU name) // print LEU { Console.WriteLine(name.Name); }); return(rt); }
//BMGR-0021 private bool GenerateBMBSDDBDisInfoNode(BEACON beacon, ref XmlVisitor node) { if (null == beacon) { return(false); } try { //boundary beacon then get the value and return. node.AppendChild("BMB_SDDB_distance", Sys.Cm2Meter(beacon.m_layoutInfo.BMB_Distance_cm, 3).ToString("0.000")); //node.AppendChild("BMB_SDDB_distance", beacon.m_layoutInfo.BMB_Distance_cm); beacon.BMB_Distance_cm = beacon.m_layoutInfo.BMB_Distance_cm; return(true); } catch (Exception ex) { //if not boundary beacon then do next } BEACON reopeningBeacon = null; if (beacon.m_ibbmInfo.GetBeaconType() == BeaconType.Approach) { //find the reopen beacon string sigName = beacon.m_ibbmInfo.getLinkedSigName(); if (BEACON.SignamReBeaconDic.ContainsKey(sigName)) { string reopenBeaconName = BEACON.SignamReBeaconDic[sigName]; reopeningBeacon = beaconList.Find(x => x.Name == reopenBeaconName); } } else { reopeningBeacon = beacon; } if (null == reopeningBeacon) { TraceMethod.Record(TraceMethod.TraceKind.ERROR, $"Beacon {beacon.Info} type={beacon.m_ibbmInfo.GetBeaconType()} find reopen Beacon ERROR, can't get BMB_SDDB_distance"); return(false); } if (reopeningBeacon.BMB_Distance_cm <= 0) { int length = CalBeacon2SDDB(reopeningBeacon); if (length <= 0) { TraceMethod.Record(TraceMethod.TraceKind.ERROR, $"Beacon {beacon.Info} type={beacon.m_ibbmInfo.GetBeaconType()} can't get BMB_SDDB_distance"); return(false); } beacon.BMB_Distance_cm = length; } else { beacon.BMB_Distance_cm = reopeningBeacon.BMB_Distance_cm; } try { node.AppendChild("BMB_SDDB_distance", Sys.Cm2Meter(beacon.BMB_Distance_cm, 3).ToString("0.000")); //node.AppendChild("BMB_SDDB_distance", beacon.BMB_Distance_cm); } catch (Exception ex) { TraceMethod.Record(TraceMethod.TraceKind.ERROR, $"Beacon {beacon.Info} type={beacon.m_ibbmInfo.GetBeaconType()} calculate BMB_SDDB_distance {ex.Message}."); return(false); } return(true); }