AddApplication(IISHandler handler, string physPath, string siteName) { String[] paths = null; if (PathHelper.ContainsWildcard(physPath)) { paths = PathHelper.ExpandWildcardDirectories(physPath); foreach (var subPath in paths) { string virPath = ""; Site site = handler.GetSiteByName(siteName); if (site != null) { virPath = PathHelper.SuggestVirtualDirectory(site, subPath); } AddApplication(handler, virPath, subPath, siteName); } } else { string virPath = ""; Site site = handler.GetSiteByName(siteName); if (site != null) { virPath = PathHelper.SuggestVirtualDirectory(site, physPath); } AddApplication(handler, virPath, physPath, siteName); } }
private static void SetPool(IISHandler handler, string siteName, string poolName) { Site site = handler.GetSiteByName(siteName); ApplicationPool pool = handler.AddApplicationPool(poolName); handler.SetSiteApplicationPool(site, pool); }
RemoveApplication(IISHandler handler, string appName, string siteName) { if (appName.Equals("/")) { Console.WriteLine(appName + " cannot be removed safely. It is the site default. Removing would corrupt website."); return; } String[] paths = null; if (PathHelper.ContainsWildcard(appName)) { Site site = handler.GetSiteByName(siteName); if (site == null) { Console.WriteLine("Site " + siteName + " does not exist."); return; } paths = PathHelper.ExpandWildcardDirectories(appName); List <Application> apps = new List <Application>(site.Applications.Where(p => paths.Contains(p.VirtualDirectories["/"].PhysicalPath))); foreach (var app in apps) { Console.WriteLine("Removing app " + app); try { handler.RemoveApplicationNonCommit(site, app); } catch (Exception e) { Console.WriteLine(e.Message); } } handler.CommitChanges(); return; } try { handler.RemoveApplication(siteName, appName); } catch (Exception e) { Console.WriteLine(e.Message); } }
RemoveApplicationRecursively(IISHandler handler, string appPrefix, string siteName) { if (appPrefix.Equals("/")) { Console.WriteLine(appPrefix + " cannot be removed safely. It is the site default. Removing would corrupt website."); return; } try { Site site = handler.GetSiteByName(siteName); if (site == null) { Console.WriteLine("Site " + siteName + " does not exist."); return; } if (!appPrefix.StartsWith(site.Name)) { appPrefix = site.Name + appPrefix; } List <Application> apps = new List <Application>(site.Applications .Where(p => p.ToString().StartsWith(appPrefix))); foreach (var app in apps) { Console.WriteLine("Removing app: " + app); try { handler.RemoveApplicationNonCommit(site, app); } catch (Exception e) { Console.WriteLine(e.Message); } } handler.CommitChanges(); } catch (Exception e) { Console.WriteLine(e.Message); } }
AddApplication(IISHandler handler, string virPath, string physPath, string siteName) { string fullPath = Path.GetFullPath(physPath); Console.WriteLine("Adding app from dir: " + fullPath); Console.WriteLine("With virtual dir: " + virPath); Site site = handler.GetSiteByName(siteName); try { if (site != null) { site.Applications.Add(virPath, fullPath); } } catch (Exception e) { Console.WriteLine(e.Message); } handler.CommitChanges(); }