public override bool Setup() { // Make sure everything we need is set // EUI if (string.IsNullOrEmpty(TestSequence.HUB_EUI)) { TestErrorTxt = $"Hub EUI needs to be set before this test"; return(false); } Regex regex = new Regex(@"[0-9a-fA-F]{16}"); if (regex.Matches(TestSequence.HUB_EUI).Count != 1) { TestErrorTxt = $"Bad Hub EUI {TestSequence.HUB_EUI} provided"; return(false); } _dbeui = DataUtils.GetEUI(TestSequence.HUB_EUI); // MAC if (string.IsNullOrEmpty(TestSequence.HUB_MAC_ADDR)) { TestErrorTxt = $"Hub MAC address needs to be set before this test"; return(false); } regex = new Regex(@"([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}"); if (regex.Matches(TestSequence.HUB_MAC_ADDR).Count != 1) { TestErrorTxt = $"Bad Hub MAc address {TestSequence.HUB_MAC_ADDR} provided"; return(false); } _dbmac = DataUtils.GetMacAddress(TestSequence.HUB_MAC_ADDR); return(base.Setup()); }
private bool VerifyEui(EmberEui64 eui) { bool result = false; using (var manufacturingStoreRepository = dataContextFactory.CreateManufacturingStoreRepository()) { var euiString = eui.ToString(); var dbEui = manufacturingStoreRepository.EuiLists.AsNoTracking().FirstOrDefault(e => e.EUI == euiString); string dbEuiSKU = null; if (dbEui != null) { dbEuiSKU = dbEui.TargetDevices.OrderByDescending(x => x.Id).FirstOrDefault()?.TestSession?.Product?.SKU; if (dbEuiSKU == ValidProduct?.SKU) { result = true; } else { errorProducerService.AddMessage(new ErrorMessage(string.Format("SKU: {0} is invalid for the selected product", dbEuiSKU), ErrorType.Error)); } } else { if (ValidProduct?.Board.ChipType.Name == EM250_CHIP) { // EM250 Chips do not have EUIs in DB since they are not coded in EBL dbEui = new EuiList() { EUI = euiString, ProductionSiteId = CurrentStationSite.ProductionSite.Id }; manufacturingStoreRepository.EuiLists.Add(dbEui); manufacturingStoreRepository.SaveChanges(); result = true; } else { errorProducerService.AddMessage(new ErrorMessage(string.Format("EUI: {0} could not be found in database", euiString), ErrorType.Error)); } } return(result); } }
/// <summary> /// Inserts the EUI if not in table /// </summary> /// <param name="eui">EUI</param> /// <returns>ID</returns> public static int InsertEUI(long eui) { try { using (ManufacturingStoreEntities cx = new ManufacturingStoreEntities()) { // Get production site string mac = StationSetupUtility.GetMacAddress(); var production_stie_id = cx.StationSites.Where(s => s.StationMac == mac).Single().ProductionSiteId; if (production_stie_id == 0) { _logger.Warn($"Invalid production site id: {production_stie_id} for MAC: {mac}"); } // db eui is a string string euistr = eui.ToString("X16"); // Form query for the eui var q = cx.EuiLists.Where(e => e.EUI == euistr); if (q.Any()) { return(q.Single().Id); // I'm not sure we care what site previously coded the device // So I'm removing this for now... // Checking for a valid site id maybe better... // Check is the same site id //int db_site_id = q.Single().ProductionSiteId; //if (db_site_id != production_stie_id) //{ // string msg = $"EUI {euistr} already in db with site id = {db_site_id}, this machine is assigned site id {production_stie_id}"; // _logger.Error(msg); // throw new Exception(msg); //} //else //{ // return q.Single().Id; //} } EuiList euiList = new EuiList(); euiList.EUI = eui.ToString("X16"); euiList.ProductionSiteId = production_stie_id; cx.EuiLists.Add(euiList); cx.SaveChanges(); return(q.Single().Id); } } catch (Exception ex) { _logger.Error($"Exception in InsertEUI: {ex.Message}\r\n{ex.StackTrace}"); if (ex.GetBaseException().GetType() == typeof(SqlException)) { // I think I originally added this to skip errors when trying to insert already existing EUI // This should no longer happen as we now check for if already exists...So re-throw it SqlException sx = (SqlException)ex.GetBaseException(); if (sx.Number == 2627) { //Violation of primary key/Unique constraint throw; } else { throw; } } else { throw; } } }