private void AddFile() { this.LogTaskMessage(string.Format(CultureInfo.InvariantCulture, "Adding File: {0}", this.Path)); if (this.FileExists()) { if (this.Force) { this.DeleteFile(); } else { this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "The File already exists: {0}", this.Path)); return; } } using (DirectoryEntry web = new DirectoryEntry("IIS://" + this.MachineName + "/W3SVC")) { ComWrapper ws = new ComWrapper(web.NativeObject); try { ws.CallMethod("AddExtensionFile", new object[] { this.Path, this.permission == ExtensionPermission.Allowed, this.GroupId, this.Deletable, this.Description }); } catch (Exception ex) { throw new ApplicationException(string.Format(CultureInfo.InvariantCulture, "Unable to create the extension: {0}", this.Path), ex); } } }
public bool FileExists() { this.LogTaskMessage(MessageImportance.Low, string.Format(CultureInfo.InvariantCulture, "Checking whether File exists: {0}", this.Path)); bool result = false; using (DirectoryEntry web = new DirectoryEntry("IIS://" + this.MachineName + "/W3SVC")) { ComWrapper ws = new ComWrapper(web.NativeObject); Array extensionFiles = (Array)ws.CallMethod("ListExtensionFiles"); if (extensionFiles != null) { foreach (string extension in extensionFiles) { if (extension.Trim().ToUpperInvariant() == this.Path.Trim().ToUpperInvariant()) { result = true; break; } } } } return(result); }
public void DeleteFile() { this.LogTaskMessage(string.Format(CultureInfo.InvariantCulture, "Delete File: {0}", this.Path)); if (this.FileExists()) { using (DirectoryEntry web = new DirectoryEntry("IIS://" + this.MachineName + "/W3SVC")) { ComWrapper ws = new ComWrapper(web.NativeObject); try { ws.CallMethod("DeleteExtensionFileRecord", new object[] { this.Path }); } catch (COMException ex) { throw new ApplicationException(string.Format(CultureInfo.InvariantCulture, "Unable to delete web service extension of '{0}'", this.Path), ex); } } } }
public bool FileExists() { this.LogTaskMessage(MessageImportance.Low, string.Format(CultureInfo.InvariantCulture, "Checking whether File exists: {0}", this.Path)); bool result = false; using (DirectoryEntry web = new DirectoryEntry("IIS://" + this.MachineName + "/W3SVC")) { ComWrapper ws = new ComWrapper(web.NativeObject); Array extensionFiles = (Array)ws.CallMethod("ListExtensionFiles"); if (extensionFiles != null) { result = extensionFiles.Cast<string>().Any(extension => extension.Trim().ToUpperInvariant() == this.Path.Trim().ToUpperInvariant()); } } return result; }