Browse Source

Fix null reference when using Show Service in Browser when service address not found in app.config.

4.2
Matt Ward 14 years ago
parent
commit
e98d78f6df
  1. 87
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/ReferenceFolderNodeCommands.cs

87
src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/ReferenceFolderNodeCommands.cs

@ -3,6 +3,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Net; using System.Net;
using System.Web.Services.Discovery; using System.Web.Services.Discovery;
using System.Windows.Forms; using System.Windows.Forms;
@ -178,54 +179,70 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
} }
return webReferencesNode; return webReferencesNode;
} }
} }
public class ShowServiceInBrowser: AbstractMenuCommand public class ShowServiceInBrowser : AbstractMenuCommand
{ {
private static string NodePath = "//system.serviceModel//client//endpoint"; static string NodePath = "//system.serviceModel//client//endpoint";
public override void Run() public override void Run()
{ {
// hack try url fvoid = LoadConfigDocument(f); XmlDocument appConfig = LoadAppConfig();
if (appConfig != null) {
string endpointAddress = FindEndPointAddress(appConfig);
if (endpointAddress != null) {
StartInternetExplorer(endpointAddress);
} else {
MessageService.ShowError("No service found.");
}
} else {
MessageService.ShowError("No app.config file found.");
}
}
XmlDocument LoadAppConfig()
{
AbstractProjectBrowserTreeNode node = ProjectBrowserPad.Instance.SelectedNode; AbstractProjectBrowserTreeNode node = ProjectBrowserPad.Instance.SelectedNode;
var f = CompilableProject.GetAppConfigFile(node.Project,false); FileName appConfigFileName = CompilableProject.GetAppConfigFile(node.Project, false);
if (!String.IsNullOrEmpty(f)) if (!String.IsNullOrEmpty(appConfigFileName)) {
{ return LoadAppConfig(appConfigFileName);
var configFile = LoadConfigDocument(f);
var endPoint = configFile.SelectSingleNode(NodePath).Attributes["address"].Value;
ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
startInfo.WindowStyle = ProcessWindowStyle.Normal;
startInfo.Arguments = endPoint;
Process.Start(startInfo);
} else
{
MessageService.ShowError("No app.config File found");
} }
return null;
} }
static XmlDocument LoadConfigDocument(string fileName) static XmlDocument LoadAppConfig(string fileName)
{ {
XmlDocument doc = null; try {
try var doc = new XmlDocument();
{
doc = new XmlDocument();
doc.Load(fileName); doc.Load(fileName);
return doc; return doc;
} catch (FileNotFoundException ex) {
LoggingService.Debug("LoadConfigDocument: " + fileName + ": " + ex.Message);
} }
catch (System.IO.FileNotFoundException e) return null;
{ }
throw new Exception("No configuration file found.", e);
string FindEndPointAddress(XmlDocument appConfig)
{
XmlNode endPoint = appConfig.SelectSingleNode(NodePath);
if (endPoint != null) {
XmlAttribute addressAttribute = endPoint.Attributes["address"];
if (addressAttribute != null) {
return addressAttribute.Value;
}
} }
return null;
}
void StartInternetExplorer(string arguments)
{
var startInfo = new ProcessStartInfo("IExplore.exe") {
WindowStyle = ProcessWindowStyle.Normal,
Arguments = arguments
};
Process.Start(startInfo);
} }
} }
public class AddServiceReferenceToProject : AbstractMenuCommand public class AddServiceReferenceToProject : AbstractMenuCommand
{ {
@ -247,14 +264,12 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
} }
} }
public class RefreshReference : AbstractMenuCommand public class RefreshReference : AbstractMenuCommand
{ {
public override void Run() public override void Run()
{ {
ReferenceNode node = Owner as ReferenceNode; var node = Owner as ReferenceNode;
if (node != null) if (node != null) {
{
ReferenceProjectItem item = node.ReferenceProjectItem; ReferenceProjectItem item = node.ReferenceProjectItem;
if (item != null) { if (item != null) {
AssemblyParserService.RefreshProjectContentForReference(item); AssemblyParserService.RefreshProjectContentForReference(item);

Loading…
Cancel
Save