11using System ;
2- using System . IO ;
3- using System . Linq ;
4- using System . Xml ;
2+ using System . Collections . Generic ;
3+ using System . Text ;
54using Microsoft . VisualStudio ;
65using Microsoft . VisualStudio . Shell ;
76using 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