private void btnSave_Click( object sender, RoutedEventArgs e )
{
RockConfig rockConfig = RockConfig.Load();
try
{
txtRockUrl.Text = txtRockUrl.Text.Trim();
Uri rockUrl = new Uri( txtRockUrl.Text );
var validSchemes = new string[] { Uri.UriSchemeHttp, Uri.UriSchemeHttps };
if ( !validSchemes.Contains( rockUrl.Scheme ) )
{
txtRockUrl.Text = "http://" + rockUrl.AbsoluteUri;
}
RockRestClient client = new RockRestClient( txtRockUrl.Text );
client.Login( rockConfig.Username, rockConfig.Password );
BatchPage.LoggedInPerson = client.GetData<Person>( string.Format( "api/People/GetByUserName/{0}", rockConfig.Username ) );
}
catch ( WebException wex )
{
HttpWebResponse response = wex.Response as HttpWebResponse;
if ( response != null )
{
if ( response.StatusCode == HttpStatusCode.Unauthorized )
{
// valid URL but invalid login, so navigate back to the LoginPage
rockConfig.RockBaseUrl = txtRockUrl.Text;
rockConfig.Save();
LoginPage loginPage = new LoginPage( true );
this.NavigationService.Navigate( loginPage );
return;
}
}
lblAlert.Content = wex.Message;
lblAlert.Visibility = Visibility.Visible;
return;
}
catch ( Exception ex )
{
App.LogException( ex );
lblAlert.Content = ex.Message;
lblAlert.Visibility = Visibility.Visible;
return;
}
rockConfig.RockBaseUrl = txtRockUrl.Text;
if ( cboScannerInterfaceType.SelectedItem.Equals( "MagTek" ) )
{
rockConfig.ScannerInterfaceType = RockConfig.InterfaceType.MICRImageRS232;
}
else
{
rockConfig.ScannerInterfaceType = RockConfig.InterfaceType.RangerApi;
}
string imageOption = cboImageOption.SelectedValue as string;
rockConfig.Sensitivity = txtSensitivity.Text.Trim().AsInteger().ToString();
rockConfig.Plurality = txtPlurality.Text.Trim().AsInteger().ToString();
switch ( imageOption )
{
case "Grayscale":
rockConfig.ImageColorType = RangerImageColorTypes.ImageColorTypeGrayscale;
break;
case "Color":
rockConfig.ImageColorType = RangerImageColorTypes.ImageColorTypeColor;
break;
default:
rockConfig.ImageColorType = RangerImageColorTypes.ImageColorTypeBitonal;
break;
}
string comPortName = cboMagTekCommPort.SelectedItem as string;
if ( !string.IsNullOrWhiteSpace( comPortName ) )
{
rockConfig.MICRImageComPort = short.Parse( comPortName.Replace( "COM", string.Empty ) );
}
rockConfig.Save();
// shutdown the scanner so that options will be reloaded when the batch page loads
if ( BatchPage.rangerScanner != null )
{
BatchPage.rangerScanner.ShutDown();
}
BatchPage.ConnectToScanner();
this.NavigationService.GoBack();
}