Пример #1
0
		public override void CreateVirtualDirectory(WebProject project)
		{
			string error = null;
			var virtualRoot = new IISVirtualRoot();
			virtualRoot.Create(IIS_WEB_LOCATION,
				project.Directory,
				project.Name,
				out error);
			if (!String.IsNullOrEmpty(error)) {
				throw new ApplicationException(error);
			}
		}
Пример #2
0
		/// <summary>
		/// Creates a virtual directory in local IIS or IIS Express.
		/// </summary>
		/// <param name="virtualDirectoryName">Virtual directory name.</param>
		/// <param name="virtualDirectoryPath">Physical path.</param>
		/// <returns>Error string or string null = no errors.</returns>
		public static string CreateVirtualDirectory(WebServer webServer, string virtualDirectoryName, string physicalDirectoryPath)
		{
			try {
				string iisNotFoundError = ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.IISNotFound");
				if (!IsIISOrIISExpressInstalled)
					return iisNotFoundError;
				
				string error;
				
				switch(IISVersion)
				{
					case IISVersion.IIS5:
					case IISVersion.IIS6:
						var vr = new IISVirtualRoot();
						vr.Create(IIS_WEB_LOCATION,
						          physicalDirectoryPath,
						          virtualDirectoryName,
						          out error);
						break;
					default:
						if (!IsIISExpressInstalled && (IISVersion == IISVersion.None))
							return iisNotFoundError;

						// TODO: find a better way to create IIS applications without Microsoft.Web.Administration.ServerManager
						string name = "/" + virtualDirectoryName;
						// load from GAC
						Assembly webAdministrationAssembly = null;
						try {
							// iis installed
							foreach(DomAssemblyName assembly in GacInterop.GetAssemblyList()) {
								if (assembly.FullName.Contains("Microsoft.Web.Administration")) {
									if (IsAssemblyForWebServer(webServer, assembly)) {
										webAdministrationAssembly = Assembly.Load(assembly.FullName);
										break;
									}
								}
							}
						} catch {
							return iisNotFoundError;
						}
						if (webAdministrationAssembly == null)
							return iisNotFoundError;
						
						// use dynamic because classic reflection is way TOO ugly
						dynamic manager = webAdministrationAssembly.CreateInstance("Microsoft.Web.Administration.ServerManager");
						
						if (manager.Sites[DEFAULT_WEB_SITE] != null) {
							if (manager.Sites[DEFAULT_WEB_SITE].Applications[name] == null) {
								manager.Sites[DEFAULT_WEB_SITE].Applications.Add(name, physicalDirectoryPath);
								manager.CommitChanges();
								error = string.Empty;
							} else {
								error = ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.ApplicationExists");
							}
						} else {
							if (manager.Sites[0].Applications[name] == null) {
								manager.Sites[0].Applications.Add(name, physicalDirectoryPath);
								manager.CommitChanges();
								error = string.Empty;
							} else {
								error = ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.ApplicationExists");
							}
						}
						manager.Dispose();
						break;
				}
				
				return error;
			}
			catch (Exception ex) {
				return ex.Message;
			}
		}
Пример #3
0
		/// <summary>
		/// Creates a virtual directory in local IIS or IIS Express.
		/// </summary>
		/// <param name="virtualDirectoryName">Virtual directory name.</param>
		/// <param name="virtualDirectoryPath">Physical path.</param>
		/// <returns></returns>
		public static string CreateVirtualDirectory(string virtualDirectoryName, string physicalDirectoryPath)
		{
			try {
				if (!IsIISInstalled)
					return ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.IISNotFound");
				
				string error;
				
				switch(IISVersion)
				{
					case IISVersion.IIS5:
					case IISVersion.IIS6:
						var vr = new IISVirtualRoot();
						vr.Create(IIS_WEB_LOCATION,
						          physicalDirectoryPath,
						          virtualDirectoryName,
						          out error);
						break;
						
					default:
						// TODO: find a better way to create IIS 7 applications without Microsoft.Web.Administration.ServerManager
						string name = "/" + virtualDirectoryName;
						// load from GAC - IIS7 is installed
						Assembly webAdministrationAssembly;
						try {
							// iis 7
							webAdministrationAssembly = Assembly.Load("Microsoft.Web.Administration, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
						}
						catch {
							// iis express
							webAdministrationAssembly = Assembly.Load("Microsoft.Web.Administration, Version=7.9.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
						}
						
						// use dynamic because classic reflection is way TOO ugly
						dynamic manager = webAdministrationAssembly.CreateInstance("Microsoft.Web.Administration.ServerManager");
						
						if (manager.Sites[DEFAULT_WEB_SITE] != null) {
							if (manager.Sites[DEFAULT_WEB_SITE].Applications[name] == null) {
								manager.Sites[DEFAULT_WEB_SITE].Applications.Add(name, physicalDirectoryPath);
								manager.CommitChanges();
								error = string.Empty;
							} else {
								error = ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.ApplicationExists");
							}
						} else {
							if (manager.Sites[0].Applications[name] == null) {
								manager.Sites[0].Applications.Add(name, physicalDirectoryPath);
								manager.CommitChanges();
								error = string.Empty;
							} else {
								error = ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.ApplicationExists");
							}
						}
						manager.Dispose();
						break;
				}
				
				return error;
			}
			catch (Exception ex) {
				return ex.Message;
			}
		}