diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-09-01 17:34:59 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-09-01 17:34:59 -0700 |
commit | 6e8a6eb02294c28b13bacaa339e58a67fd766f99 (patch) | |
tree | a1bd58a2a51505ba71b697fb61378e7142df8ef3 /src/DotNetOpenAuth.BuildTasks/CreateWebApplication.cs | |
parent | e36299f39476c56977c39700067ed8f6ae0a4e49 (diff) | |
parent | 36b1ba3c75d060fa71f6f15582b90e7f70292ddc (diff) | |
download | DotNetOpenAuth-6e8a6eb02294c28b13bacaa339e58a67fd766f99.zip DotNetOpenAuth-6e8a6eb02294c28b13bacaa339e58a67fd766f99.tar.gz DotNetOpenAuth-6e8a6eb02294c28b13bacaa339e58a67fd766f99.tar.bz2 |
Merge branch 'master' into contracts
Conflicts:
src/DotNetOpenAuth.Test/Mocks/MockIdentifier.cs
src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs
src/DotNetOpenAuth.vsmdi
src/DotNetOpenAuth/DotNetOpenAuth.csproj
src/DotNetOpenAuth/Messaging/MessageReceivingEndpoint.cs
src/DotNetOpenAuth/OAuth/ChannelElements/OAuthServiceProviderMessageFactory.cs
src/DotNetOpenAuth/OAuth/Protocol.cs
src/DotNetOpenAuth/OAuth/ServiceProvider.cs
src/DotNetOpenAuth/OpenId/Association.cs
src/DotNetOpenAuth/OpenId/Behaviors/PpidGeneration.cs
src/DotNetOpenAuth/OpenId/NoDiscoveryIdentifier.cs
src/DotNetOpenAuth/OpenId/Provider/HostProcessedRequest.cs
src/DotNetOpenAuth/OpenId/Provider/IDirectedIdentityIdentifierProvider.cs
src/DotNetOpenAuth/OpenId/Provider/PrivatePersonalIdentifierProviderBase.cs
src/DotNetOpenAuth/OpenId/Realm.cs
src/DotNetOpenAuth/OpenId/RelyingParty/AuthenticationRequest.cs
src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.cs
src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdRelyingPartyAjaxControlBase.cs
src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs
src/DotNetOpenAuth/OpenId/RelyingParty/PositiveAuthenticationResponseSnapshot.cs
src/DotNetOpenAuth/OpenId/UriIdentifier.cs
src/DotNetOpenAuth/OpenId/XriIdentifier.cs
src/DotNetOpenAuth/Util.cs
Diffstat (limited to 'src/DotNetOpenAuth.BuildTasks/CreateWebApplication.cs')
-rw-r--r-- | src/DotNetOpenAuth.BuildTasks/CreateWebApplication.cs | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.BuildTasks/CreateWebApplication.cs b/src/DotNetOpenAuth.BuildTasks/CreateWebApplication.cs new file mode 100644 index 0000000..4980898 --- /dev/null +++ b/src/DotNetOpenAuth.BuildTasks/CreateWebApplication.cs @@ -0,0 +1,95 @@ +//----------------------------------------------------------------------- +// <copyright file="CreateWebApplication.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.BuildTasks { + using System; + using System.Linq; + using Microsoft.Build.Framework; + using Microsoft.Build.Utilities; + using Microsoft.Web.Administration; + + /// <summary> + /// Creates or updates web applications within an existing web site in IIS. + /// </summary> + public class CreateWebApplication : Task { + /// <summary> + /// Gets or sets the name of the application pool that should host the web application. + /// </summary> + /// <value>The name of an existing application pool.</value> + public string ApplicationPoolName { get; set; } + + /// <summary> + /// Gets or sets the name of the web site under which to create the web application. + /// </summary> + /// <value>The name of the existing web site.</value> + [Required] + public string WebSiteName { get; set; } + + /// <summary> + /// Gets or sets the virtual paths within the web site that will access these applications. + /// </summary> + /// <value>The virtual path, which must start with '/'.</value> + [Required] + public ITaskItem[] VirtualPaths { get; set; } + + /// <summary> + /// Gets or sets the full file system paths to the web applications. + /// </summary> + /// <value>The physical path.</value> + [Required] + public ITaskItem[] PhysicalPaths { get; set; } + + /// <summary> + /// Executes this instance. + /// </summary> + /// <returns>A value indicating whether the task completed successfully.</returns> + public override bool Execute() { + var serverManager = new ServerManager(); + + if (this.PhysicalPaths.Length != this.VirtualPaths.Length) { + Log.LogError(TaskStrings.MismatchingArrayLengths, "PhysicalPath", "VirtualPath"); + return false; + } + + if (this.VirtualPaths.Length == 0) { + // Nothing to do. + return true; + } + + // Find the root web site that this web application will be created under. + var site = serverManager.Sites.FirstOrDefault(s => string.Equals(s.Name, this.WebSiteName, StringComparison.OrdinalIgnoreCase)); + if (site == null) { + Log.LogError(TaskStrings.NoMatchingWebSiteFound, this.WebSiteName); + return false; + } + + Log.LogMessage(MessageImportance.Normal, "Creating web applications under web site: {0}", site.Name); + + for (int i = 0; i < this.PhysicalPaths.Length; i++) { + string physicalPath = this.PhysicalPaths[i].ItemSpec; + string virtualPath = this.VirtualPaths[i].ItemSpec; + + Log.LogMessage(MessageImportance.Normal, "\t{0} -> {1}", virtualPath, physicalPath); + + var app = site.Applications.FirstOrDefault(a => string.Equals(a.Path, virtualPath, StringComparison.OrdinalIgnoreCase)); + if (app == null) { + app = site.Applications.Add(virtualPath, physicalPath); + } else { + // Ensure physical path is set correctly. + var appRoot = app.VirtualDirectories.First(vd => vd.Path == "/"); + appRoot.PhysicalPath = physicalPath; + } + + if (!string.IsNullOrEmpty(this.ApplicationPoolName)) { + app.ApplicationPoolName = this.ApplicationPoolName; + } + } + + serverManager.CommitChanges(); + return true; + } + } +} |