private void loadForm()
        {
            try
            {
                clearErrors();

                if (IsFirstLaunch)
                {
                    trySaveDbKeysFromInstallDrive();
                }

                AvailablePorts.Clear();
                AvailableStatuses.Clear();
                AvailableStatuses.Add("AT GIN");
                AvailableStatuses.Add("ON FEEDER");

                this.TargetStatus = "AT GIN";

                AvailablePorts.Add("NONE");
                foreach (var p in SerialPort.GetPortNames().OrderBy(s => s))
                {
                    AvailablePorts.Add(p);
                }

                using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
                {
                    var repo = dp.SettingsRepository;

                    var portSetting = repo.FindSingle(x => x.Key == BridgeSettingKeys.SCALE_COM_PORT);
                    if (portSetting != null && !string.IsNullOrWhiteSpace(portSetting.Value))
                    {
                        PortName = portSetting.Value;
                    }
                    else
                    {
                        if (AvailablePorts.Count > 0)
                        {
                            PortName = AvailablePorts.First();
                        }
                        else
                        {
                            PortName = "";
                        }
                    }

                    portSetting = repo.FindSingle(x => x.Key == BridgeSettingKeys.BARCODE_COM_PORT);
                    if (portSetting != null && !string.IsNullOrWhiteSpace(portSetting.Value))
                    {
                        BarcodePortName = portSetting.Value;
                    }
                    else
                    {
                        if (AvailablePorts.Count > 0)
                        {
                            BarcodePortName = AvailablePorts.First();
                        }
                        else
                        {
                            BarcodePortName = "";
                        }
                    }

                    ReaderHostname = repo.GetSettingWithDefault(BridgeSettingKeys.READER_HOST_NAME, "169.254.1.1");
                    _originalHost  = ReaderHostname;

                    ScreenTitle          = repo.GetSettingWithDefault(BridgeSettingKeys.GIN_NAME, "");
                    BridgeID             = repo.GetSettingWithDefault(BridgeSettingKeys.BRIDGE_ID, "");
                    Latitude             = repo.GetSettingWithDefault(BridgeSettingKeys.LATITUDE, "");
                    Longitude            = repo.GetSettingWithDefault(BridgeSettingKeys.LONGITUDE, "");
                    TargetStatus         = repo.GetSettingWithDefault(BridgeSettingKeys.TARGET_STATUS, "AT GIN");
                    DocumentDbConnection = repo.GetSettingWithDefault(BridgeSettingKeys.DOCUMENT_DB_KEY, "");
                    DocumentDbEndpoint   = repo.GetSettingWithDefault(BridgeSettingKeys.DOCUMENTDB_ENDPOINT, "");
                    DataSyncInterval     = int.Parse(repo.GetSettingWithDefault(BridgeSettingKeys.DATA_SYNC_INTERVAL, "1"));
                    WeighInTimeout       = int.Parse(repo.GetSettingWithDefault(BridgeSettingKeys.WEIGH_IN_TIMEOUT, "30"));
                    StableWeightSeconds  = int.Parse(repo.GetSettingWithDefault(BridgeSettingKeys.STABLE_WEIGHT_SECONDS, "10"));

                    WeightAutoSaveTimeout = int.Parse(repo.GetSettingWithDefault(BridgeSettingKeys.WEIGHT_AUTO_SAVE_TIMEOUT, "10"));
                    UnattendedMode        = bool.Parse(repo.GetSettingWithDefault(BridgeSettingKeys.UNATTENDED_MODE, "FALSE"));
                }
            }
            catch (Exception exc)
            {
                Logging.Logger.Log(exc);
            }
        }
        private void loadForm()
        {
            clearErrors();

            AvailablePorts.Clear();
            AvailableStatuses.Clear();
            AvailableStatuses.Add("AT GIN");
            AvailableStatuses.Add("GINNED");

            this.TargetStatus = "AT GIN";

            AvailablePorts.Add("NONE");
            foreach (var p in System.IO.Ports.SerialPort.GetPortNames().OrderBy(s => s))
            {
                AvailablePorts.Add(p);
            }

            using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork())
            {
                var repo = dp.SettingsRepository;

                var portSetting = repo.FindSingle(x => x.Key == BridgeSettingKeys.SCALE_COM_PORT);
                if (portSetting != null && !string.IsNullOrWhiteSpace(portSetting.Value))
                {
                    PortName = portSetting.Value;
                }
                else
                {
                    if (AvailablePorts.Count > 0)
                    {
                        PortName = AvailablePorts.First();
                    }
                    else
                    {
                        PortName = "";
                    }
                }

                portSetting = repo.FindSingle(x => x.Key == BridgeSettingKeys.BARCODE_COM_PORT);
                if (portSetting != null && !string.IsNullOrWhiteSpace(portSetting.Value))
                {
                    BarcodePortName = portSetting.Value;
                }
                else
                {
                    if (AvailablePorts.Count > 0)
                    {
                        BarcodePortName = AvailablePorts.First();
                    }
                    else
                    {
                        BarcodePortName = "";
                    }
                }

                ScreenTitle          = repo.GetSettingWithDefault(BridgeSettingKeys.GIN_NAME, "");
                BridgeID             = repo.GetSettingWithDefault(BridgeSettingKeys.BRIDGE_ID, "");
                Latitude             = repo.GetSettingWithDefault(BridgeSettingKeys.LATITUDE, "");
                Longitude            = repo.GetSettingWithDefault(BridgeSettingKeys.LONGITUDE, "");
                TargetStatus         = repo.GetSettingWithDefault(BridgeSettingKeys.TARGET_STATUS, "AT GIN");
                DocumentDbConnection = repo.GetSettingWithDefault(BridgeSettingKeys.DOCUMENT_DB_KEY, "");
                DocumentDbEndpoint   = repo.GetSettingWithDefault(BridgeSettingKeys.DOCUMENTDB_ENDPOINT, "");
                DataSyncInterval     = int.Parse(repo.GetSettingWithDefault(BridgeSettingKeys.DATA_SYNC_INTERVAL, "1"));
            }
        }