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 );
}
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 )
{
lblAlert.Content = ex.Message;
lblAlert.Visibility = Visibility.Visible;
return;
}
rockConfig.RockBaseUrl = txtRockUrl.Text;
rockConfig.LogoFile = txtLogoFile.Text;
rockConfig.Save();
this.NavigationService.GoBack();
}