diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2010-10-24 15:56:48 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2010-10-24 15:56:48 -0700 |
commit | 9dbb9aab73812202648c4e68d60261dd84d6c8e2 (patch) | |
tree | 5de139019a7b2f870f84c57cac36c0e489bd1e41 /src/DotNetOpenAuth.BuildTasks/DeleteWebApplication.cs | |
parent | 4b27c330fbfb3a260aa3bd6a9b1232ee3b53deb0 (diff) | |
parent | e7ce41355c38b3125729a62920231f274b7a2100 (diff) | |
download | DotNetOpenAuth-origin/mono2.zip DotNetOpenAuth-origin/mono2.tar.gz DotNetOpenAuth-origin/mono2.tar.bz2 |
Merge branch 'v3.2' into mono2origin/mono2
Conflicts:
src/DotNetOpenAuth/Messaging/HttpRequestInfo.cs
Diffstat (limited to 'src/DotNetOpenAuth.BuildTasks/DeleteWebApplication.cs')
-rw-r--r-- | src/DotNetOpenAuth.BuildTasks/DeleteWebApplication.cs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.BuildTasks/DeleteWebApplication.cs b/src/DotNetOpenAuth.BuildTasks/DeleteWebApplication.cs new file mode 100644 index 0000000..930a8c4 --- /dev/null +++ b/src/DotNetOpenAuth.BuildTasks/DeleteWebApplication.cs @@ -0,0 +1,66 @@ +//----------------------------------------------------------------------- +// <copyright file="DeleteWebApplication.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> + /// Deletes a web application from IIS. + /// </summary> + public class DeleteWebApplication : Task { + /// <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> + /// Executes this instance. + /// </summary> + /// <returns>A value indicating whether the task completed successfully.</returns> + public override bool Execute() { + var serverManager = new ServerManager(); + + // 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.LogMessage(MessageImportance.Low, TaskStrings.NoMatchingWebSiteFound, this.WebSiteName); + return true; + } + + if (this.VirtualPaths.Length == 0) { + // Nothing to do. + return true; + } + + foreach (ITaskItem path in this.VirtualPaths) { + var app = site.Applications.FirstOrDefault(a => string.Equals(a.Path, path.ItemSpec, StringComparison.OrdinalIgnoreCase)); + if (app != null) { + site.Applications.Remove(app); + Log.LogMessage(MessageImportance.Normal, TaskStrings.DeletedWebApplication, app.Path); + } else { + Log.LogMessage(MessageImportance.Low, TaskStrings.WebApplicationNotFoundSoNotDeleted, path.ItemSpec); + } + } + + serverManager.CommitChanges(); + + return true; + } + } +} |