コード例 #1
0
 public static EuiList GetEUI(string eui)
 {
     using (var dbContext = new ManufacturingStoreEntities())
     {
         return(dbContext.EuiLists.Where(e => e.EUI == eui).Single());
     }
 }
コード例 #2
0
 public static string Generate(long startAddress, long endAddress)
 {
     using (var dbContext = new ManufacturingStoreEntities())
     {
         var mac = dbContext.GetNextMac(startAddress, endAddress);
         return(LongToStr(mac));
     }
 }
コード例 #3
0
        /// <summary>
        /// Gets the mac object from db with corresponding mac string
        /// </summary>
        /// <param name="mac"></param>
        /// <returns></returns>
        public static MacAddress GetMacAddress(string mac)
        {
            string macstr = mac.Replace(":", "").Replace("-", "").Replace("=", "").Trim();
            long   lmac   = long.Parse(macstr);

            using (var dbContext = new ManufacturingStoreEntities())
            {
                return(dbContext.MacAddresses.Where(m => m.MAC == lmac).Single());
            }
        }
コード例 #4
0
        /// <summary>
        /// Gets the last hub with corresponding EUI string
        /// </summary>
        /// <param name="EUI"></param>
        /// <returns></returns>
        public static JiliaHub GetHub(string EUI)
        {
            using (var dc = new ManufacturingStoreEntities())
            {
                // first get eui_id
                int eui_id = dc.EuiLists.Where(e => e.EUI == EUI).Single().Id;

                // Get hub for this eui
                return(dc.JiliaHubs.Where(h => h.EuiId == eui_id).OrderByDescending(h => h.Id).First());
            }
        }
コード例 #5
0
ファイル: ActivationTest.cs プロジェクト: vicmatmar/HubTester
        public override bool Run()
        {
            using (var ctx = new ManufacturingStoreEntities())
            {
                JiliaHub dbjhub = new JiliaHub();

                dbjhub.EuiId        = _dbeui.Id;
                dbjhub.MacAddressId = _dbmac.Id;

                dbjhub.Mac    = MacAddressGenerator.LongToStr(_dbmac.MAC);
                TestStatusTxt = $"Hub MAC {dbjhub.Mac}";
                dbjhub.Bid    = $"J{_dbeui.Id}";
                TestStatusTxt = $"Hub BId {dbjhub.Bid}";

                // Activation
                // /config/activation_key
                string line  = WriteCommand("cat /config/activation_key");
                Regex  regex = new Regex(@"([0-9,a-z,A-Z]{8})");
                Match  match = regex.Match(line);
                if (!match.Success || match.Groups.Count < 2)
                {
                    TestErrorTxt = $"Unable to parse hub activation.  Line was {line}";
                    return(false);
                }
                dbjhub.Activation = match.Groups[1].Value;
                TestStatusTxt     = $"Hub activation {dbjhub.Activation}";

                // Uid
                line  = WriteCommand("cat /data/run/.system");
                regex = new Regex(@"uuid: ([0-9,a-f]{8}-([0-9,a-f]{4}-){3}[0-9,a-f]{12})");
                match = regex.Match(line);
                if (!match.Success || match.Groups.Count < 2)
                {
                    TestErrorTxt = $"Unable to parse hub uuid.  Line was {line}";
                    return(false);
                }
                dbjhub.Uid    = match.Groups[1].Value;
                TestStatusTxt = $"Hub uuid {dbjhub.Uid}";

                // Insert
                ctx.JiliaHubs.Add(dbjhub);
                ctx.SaveChanges();
                TestStatusTxt = $"Hub dbrid {dbjhub.Id}";
            }
            return(true);
        }
コード例 #6
0
ファイル: DatabaseUtils.cs プロジェクト: vicmatmar/CodingUtil
        /// <summary>
        /// A total hack to get devices added in barscan
        ///
        /// We need to properlly add info about the test in db
        /// But I don't even know how to query for firmware version info
        ///
        /// </summary>
        /// <param name="euiId"></param>
        /// <returns></returns>
        public static int AddTargetDevice(int euiId)
        {
            using (ManufacturingStoreEntities cx = new ManufacturingStoreEntities())
            {
                if (!cx.TargetDevices.Where(td => td.EuiId == euiId).Any())
                {
                    TargetDevice td = new TargetDevice();
                    td.EuiId         = euiId;
                    td.IsaId         = 1;
                    td.ResultId      = 2;
                    td.TestSessionId = 4726869;
                    cx.TargetDevices.Add(td);
                    cx.SaveChanges();
                }

                return(cx.TargetDevices.Where(td => td.EuiId == euiId).Single().Id);
            }
        }
コード例 #7
0
 public ManufacturingStoreRepository(ManufacturingStoreEntities dbContext)
 {
     this.dbContext = dbContext;
 }
コード例 #8
0
ファイル: DatabaseUtils.cs プロジェクト: vicmatmar/CodingUtil
        /// <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;
                }
            }
        }