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. 44
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReference/AddServiceReferenceViewModel.cs

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

@ -58,34 +58,41 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -58,34 +58,41 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
this.assemblyReferences = serviceGenerator.GetCheckableAssemblyReferences().ToList();
HeadLine = header;
GoCommand = new RelayCommand(ExecuteGo, CanExecuteGo);
GoCommand = new RelayCommand(DiscoveryServices, CanExecuteGo);
AdvancedDialogCommand = new RelayCommand(ExecuteAdvancedDialogCommand, CanExecuteAdvancedDialogCommand);
TwoValues = new ObservableCollection<ImageAndDescription>();
}
#region Go Command
public ICommand GoCommand { get; private set; }
void ExecuteGo()
void DiscoveryServices()
{
if (String.IsNullOrEmpty(SelectedService)) {
MessageBox.Show(noUrl);
return;
}
Uri uri = TryGetUri(SelectedService);
if (uri != null) {
ServiceDescriptionMessage = waitMessage;
Uri uri = new Uri(SelectedService);
StartDiscovery(uri, new DiscoveryNetworkCredential(CredentialCache.DefaultNetworkCredentials, DiscoveryNetworkCredential.DefaultAuthenticationType));
}
}
bool CanExecuteGo()
Uri TryGetUri(string url)
{
return true;
if (String.IsNullOrEmpty(url)) {
ServiceDescriptionMessage = noUrl;
return null;
}
#endregion
try {
return new Uri(url);
} catch (Exception ex) {
ServiceDescriptionMessage = ex.Message;
}
return null;
}
#region AdvancedDialogCommand
bool CanExecuteGo()
{
return true;
}
public ICommand AdvancedDialogCommand { get; private set; }
@ -106,10 +113,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -106,10 +113,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
}
}
#endregion
#region discover service Code from Matt
void StartDiscovery(Uri uri, DiscoveryNetworkCredential credential)
{
// Abort previous discovery.
@ -233,8 +236,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -233,8 +236,6 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
return String.Empty;
}
#endregion
public string Title
{
get { return title; }
@ -348,10 +349,15 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference @@ -348,10 +349,15 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.ServiceReference
public void AddServiceReference()
{
CompilerMessageView.Instance.BringToFront();
try {
serviceGenerator.Options.Namespace = defaultNameSpace;
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