Skip to content

Commit 1410dc8

Browse files
author
Stephan
committed
Improve CustomTool config error messages
1 parent 317b2f3 commit 1410dc8

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

Umbraco.ModelsBuilder.CustomTool/Umbraco.ModelsBuilder.CustomTool.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
<Private>True</Private>
8585
</Reference>
8686
<Reference Include="System" />
87+
<Reference Include="System.Configuration" />
8788
<Reference Include="System.Core" />
8889
<Reference Include="System.Data" />
8990
<Reference Include="System.Design" />

Umbraco.ModelsBuilder.CustomTool/VisualStudio/VisualStudioHelper.cs

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
2-
using System.IO;
3-
using System.Linq;
4-
using System.Xml;
2+
using System.Collections.Generic;
3+
using System.Text;
54
using Microsoft.VisualStudio;
65
using Microsoft.VisualStudio.Shell;
76
using Microsoft.VisualStudio.Shell.Interop;
@@ -139,10 +138,10 @@ private static IVsHierarchy ToHierarchy(EnvDTE.Project project)
139138
140139
string projectGuid = null;
141140
142-
// DTE does not expose the project GUID that exists at in the msbuild project file.
143-
// Cannot use MSBuild object model because it uses a static instance of the Engine,
144-
// and using the Project will cause it to be unloaded from the engine when the
145-
// GC collects the variable that we declare.
141+
// DTE does not expose the project GUID that exists at in the msbuild project file.
142+
// Cannot use MSBuild object model because it uses a static instance of the Engine,
143+
// and using the Project will cause it to be unloaded from the engine when the
144+
// GC collects the variable that we declare.
146145
using (var projectReader = XmlReader.Create(project.FileName))
147146
{
148147
projectReader.MoveToContent();
@@ -155,7 +154,7 @@ private static IVsHierarchy ToHierarchy(EnvDTE.Project project)
155154
{
156155
if (!Equals(projectReader.LocalName, nodeName)) continue;
157156
158-
projectGuid = projectReader.ReadElementContentAsString();
157+
projectGuid = projectReader.ReadElementContentAsString();
159158
break;
160159
}
161160
}
@@ -294,16 +293,40 @@ public Options(EnvDTE.Properties properties)
294293

295294
public void Validate()
296295
{
297-
var valid = true;
298-
//valid &= !string.IsNullOrWhiteSpace(ConnectionString);
299-
//valid &= !string.IsNullOrWhiteSpace(DatabaseProvider);
300-
valid &= !string.IsNullOrWhiteSpace(UmbracoUrl);
301-
valid &= !string.IsNullOrWhiteSpace(UmbracoUser);
302-
valid &= !string.IsNullOrWhiteSpace(UmbracoPassword);
303-
// don't validate the binary directory
304-
305-
if (!valid)
306-
throw new Exception("Invalid configuration.");
296+
StringBuilder message = null;
297+
298+
var empty = new List<string>();
299+
if (string.IsNullOrWhiteSpace(UmbracoUrl))
300+
empty.Add("Site Url");
301+
if (string.IsNullOrWhiteSpace(UmbracoUser))
302+
empty.Add("User Name");
303+
if (string.IsNullOrWhiteSpace(UmbracoPassword))
304+
empty.Add("User Password");
305+
if (empty.Count > 0)
306+
{
307+
message = new StringBuilder("Invalid configuration. ");
308+
for (var i = 0; i < empty.Count; i++)
309+
{
310+
if (i > 0)
311+
message.Append(i < empty.Count - 1 ? ", " : "nor ");
312+
message.Append(empty[i]);
313+
}
314+
message.Append(" cannot be empty.");
315+
}
316+
317+
try
318+
{
319+
var uri = new Uri(UmbracoUrl);
320+
}
321+
catch
322+
{
323+
if (message == null) message = new StringBuilder("Invalid configuration. Site Url \"");
324+
message.Append(UmbracoUrl);
325+
message.Append("\" is not a valid Uri.");
326+
}
327+
328+
if (message != null)
329+
throw new Exception(message.ToString());
307330
}
308331
}
309332

0 commit comments

Comments
 (0)