Exemplo n.º 1
0
        /// <summary>
        /// Gets the machine id from database
        /// It creates an entry if not found
        /// </summary>
        /// <returns></returns>
        public static int insertMachine()
        {
            var    mac_ip      = GetMacAndIpAddress();
            string macaddr_str = mac_ip.Item1;
            string ip_str      = mac_ip.Item2;

            string description = null;

            try { description = GetComputerDescription(); }
            catch (Exception) { };
            // Set a computer description based on domain and nic if one was not found
            if (description == null || description == "")
            {
                string production_site_name = null;
                try
                {
                    var ss = _dc.StationSites.Where(d => d.StationMac == macaddr_str).Single();
                    production_site_name = ss.ProductionSite.Name;
                }
                catch (Exception) { };

                NetworkInterface nic = GetFirstNic();
                if (production_site_name != null)
                {
                    description = string.Format("{0}, {1}", production_site_name, nic.Description);
                }
                else
                {
                    description = string.Format("{0}, {1}", Environment.UserDomainName, nic.Description);
                }
            }


            TestStationMachine machine = new TestStationMachine();

            machine.Name        = Environment.MachineName;
            machine.IpAddress   = ip_str;
            machine.MacAddress  = macaddr_str;
            machine.Description = description;
            try
            {
                string machineguid = GetMachineGuid();
                // Database should default to "00000000-0000-0000-0000-000000000000"
                // Just check to make sure we got the same length
                if (machineguid.Length <= 36)
                {
                    machine.MachineGuid = machineguid;
                }
            }
            catch { };

            _dc.TestStationMachines.InsertOnSubmit(machine);
            _dc.SubmitChanges();

            return(machine.Id);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the machine id from database
        /// It creates an entry if not found
        /// </summary>
        /// <returns></returns>
        public static int insertMachine()
        {
            var mac_ip = GetMacAndIpAddress();
            string macaddr_str = mac_ip.Item1;
            string ip_str = mac_ip.Item2;

            ManufacturingStore_DataContext dc = new ManufacturingStore_DataContext(ConnectionSB.ConnectionString);

            string description = null;
            try { description = GetComputerDescription(); }
            catch (Exception) { };
            // Set a computer description based on domain and nic if one was not found
            if (description == null || description == "")
            {
                string production_site_name = null;
                try
                {
                    var ss = dc.StationSites.Where(d => d.StationMac == macaddr_str).Single();
                    production_site_name = ss.ProductionSite.Name;
                }
                catch (Exception) { };

                NetworkInterface nic = GetFirstNic();
                if (production_site_name != null)
                    description = string.Format("{0}, {1}", production_site_name, nic.Description);
                else
                    description = string.Format("{0}, {1}", Environment.UserDomainName, nic.Description);
            }

            TestStationMachine machine = new TestStationMachine();
            machine.Name = Environment.MachineName;
            machine.IpAddress = ip_str;
            machine.MacAddress = macaddr_str;
            machine.Description = description;
            try
            {
                string machineguid = GetMachineGuid();
                // Database should default to "00000000-0000-0000-0000-000000000000"
                // Just check to make sure we got the same length
                if (machineguid.Length <= 36)
                    machine.MachineGuid = machineguid;
            }
            catch { };

            dc.TestStationMachines.InsertOnSubmit(machine);
            dc.SubmitChanges();

            return machine.Id;
        }