Skip to content

Commit

Permalink
Improve CustomTool config error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan committed Mar 2, 2016
1 parent 317b2f3 commit 1410dc8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Design" />
Expand Down
59 changes: 41 additions & 18 deletions Umbraco.ModelsBuilder.CustomTool/VisualStudio/VisualStudioHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Xml;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
Expand Down Expand Up @@ -139,10 +138,10 @@ private static IVsHierarchy ToHierarchy(EnvDTE.Project project)
string projectGuid = null;
// DTE does not expose the project GUID that exists at in the msbuild project file.
// Cannot use MSBuild object model because it uses a static instance of the Engine,
// and using the Project will cause it to be unloaded from the engine when the
// GC collects the variable that we declare.
// DTE does not expose the project GUID that exists at in the msbuild project file.
// Cannot use MSBuild object model because it uses a static instance of the Engine,
// and using the Project will cause it to be unloaded from the engine when the
// GC collects the variable that we declare.
using (var projectReader = XmlReader.Create(project.FileName))
{
projectReader.MoveToContent();
Expand All @@ -155,7 +154,7 @@ private static IVsHierarchy ToHierarchy(EnvDTE.Project project)
{
if (!Equals(projectReader.LocalName, nodeName)) continue;
projectGuid = projectReader.ReadElementContentAsString();
projectGuid = projectReader.ReadElementContentAsString();
break;
}
}
Expand Down Expand Up @@ -294,16 +293,40 @@ public Options(EnvDTE.Properties properties)

public void Validate()
{
var valid = true;
//valid &= !string.IsNullOrWhiteSpace(ConnectionString);
//valid &= !string.IsNullOrWhiteSpace(DatabaseProvider);
valid &= !string.IsNullOrWhiteSpace(UmbracoUrl);
valid &= !string.IsNullOrWhiteSpace(UmbracoUser);
valid &= !string.IsNullOrWhiteSpace(UmbracoPassword);
// don't validate the binary directory

if (!valid)
throw new Exception("Invalid configuration.");
StringBuilder message = null;

var empty = new List<string>();
if (string.IsNullOrWhiteSpace(UmbracoUrl))
empty.Add("Site Url");
if (string.IsNullOrWhiteSpace(UmbracoUser))
empty.Add("User Name");
if (string.IsNullOrWhiteSpace(UmbracoPassword))
empty.Add("User Password");
if (empty.Count > 0)
{
message = new StringBuilder("Invalid configuration. ");
for (var i = 0; i < empty.Count; i++)
{
if (i > 0)
message.Append(i < empty.Count - 1 ? ", " : "nor ");
message.Append(empty[i]);
}
message.Append(" cannot be empty.");
}

try
{
var uri = new Uri(UmbracoUrl);
}
catch
{
if (message == null) message = new StringBuilder("Invalid configuration. Site Url \"");
message.Append(UmbracoUrl);
message.Append("\" is not a valid Uri.");
}

if (message != null)
throw new Exception(message.ToString());
}
}

Expand Down

0 comments on commit 1410dc8

Please sign in to comment.