Browse Source

Fix unhandled exception when using invalid url in Add Service Reference dialog.

pull/6/merge
Matt Ward 13 years ago
parent
commit
419ad6f456
  1. 54
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AddServiceReferenceViewModel.cs

54
src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AddServiceReferenceViewModel.cs

@ -58,24 +58,35 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
this.assemblyReferences = serviceGenerator.GetCheckableAssemblyReferences().ToList(); this.assemblyReferences = serviceGenerator.GetCheckableAssemblyReferences().ToList();
HeadLine = header; HeadLine = header;
GoCommand = new RelayCommand(ExecuteGo, CanExecuteGo); GoCommand = new RelayCommand(DiscoveryServices, CanExecuteGo);
AdvancedDialogCommand = new RelayCommand(ExecuteAdvancedDialogCommand, CanExecuteAdvancedDialogCommand); AdvancedDialogCommand = new RelayCommand(ExecuteAdvancedDialogCommand, CanExecuteAdvancedDialogCommand);
TwoValues = new ObservableCollection<ImageAndDescription>(); TwoValues = new ObservableCollection<ImageAndDescription>();
} }
#region Go Command
public ICommand GoCommand { get; private set; } public ICommand GoCommand { get; private set; }
void ExecuteGo() void DiscoveryServices()
{
Uri uri = TryGetUri(SelectedService);
if (uri != null) {
ServiceDescriptionMessage = waitMessage;
StartDiscovery(uri, new DiscoveryNetworkCredential(CredentialCache.DefaultNetworkCredentials, DiscoveryNetworkCredential.DefaultAuthenticationType));
}
}
Uri TryGetUri(string url)
{ {
if (String.IsNullOrEmpty(SelectedService)) { if (String.IsNullOrEmpty(url)) {
MessageBox.Show(noUrl); ServiceDescriptionMessage = noUrl;
return; return null;
}
try {
return new Uri(url);
} catch (Exception ex) {
ServiceDescriptionMessage = ex.Message;
} }
ServiceDescriptionMessage = waitMessage; return null;
Uri uri = new Uri(SelectedService);
StartDiscovery(uri, new DiscoveryNetworkCredential(CredentialCache.DefaultNetworkCredentials, DiscoveryNetworkCredential.DefaultAuthenticationType));
} }
bool CanExecuteGo() bool CanExecuteGo()
@ -83,10 +94,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
return true; return true;
} }
#endregion
#region AdvancedDialogCommand
public ICommand AdvancedDialogCommand { get; private set; } public ICommand AdvancedDialogCommand { get; private set; }
bool CanExecuteAdvancedDialogCommand() bool CanExecuteAdvancedDialogCommand()
@ -105,11 +112,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
serviceGenerator.UpdateAssemblyReferences(assemblyReferences); serviceGenerator.UpdateAssemblyReferences(assemblyReferences);
} }
} }
#endregion
#region discover service Code from Matt
void StartDiscovery(Uri uri, DiscoveryNetworkCredential credential) void StartDiscovery(Uri uri, DiscoveryNetworkCredential credential)
{ {
// Abort previous discovery. // Abort previous discovery.
@ -233,8 +236,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
return String.Empty; return String.Empty;
} }
#endregion
public string Title public string Title
{ {
get { return title; } get { return title; }
@ -348,10 +349,15 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
public void AddServiceReference() public void AddServiceReference()
{ {
CompilerMessageView.Instance.BringToFront(); CompilerMessageView.Instance.BringToFront();
serviceGenerator.Options.Namespace = defaultNameSpace;
serviceGenerator.Options.Url = discoveryUri.ToString(); try {
serviceGenerator.AddServiceReference(); serviceGenerator.Options.Namespace = defaultNameSpace;
new RefreshProjectBrowser().Run(); serviceGenerator.Options.Url = discoveryUri.ToString();
serviceGenerator.AddServiceReference();
new RefreshProjectBrowser().Run();
} catch (Exception ex) {
ICSharpCode.Core.LoggingService.Error("Failed to add service reference.", ex);
}
} }
} }

Loading…
Cancel
Save