private void TryConnectAction(ActionEntry entry) { entry.LogLine( "Trying to connect using connection string: " + ConnectionStringHelper.GetConnectionStringWithoutPassword(PasswordHideString), 50 ); using( var connection = new SqlConnection(ConnectionString) ) { connection.Open(); entry.LogLine( "Executing command 'SELECT 1'", ((AdditionalTest == null) ? 90 : 70) ); using( var command = connection.CreateCommand() ) { command.CommandText = "SELECT 1"; command.ExecuteNonQuery(); } if( AdditionalTest != null ) AdditionalTest( entry, connection ); } }
private void LoadWebsites(ActionEntry entry) { ddWebSites.Items.Clear(); entry.LogLine( "Accessing active directory entry 'IIS://localhost/W3svc'" ); var iis = new DirectoryEntry( "IIS://localhost/W3svc" ); entry.LogLine( "Looking for entries of type 'IIsWebServer'" ); var websites = iis.Children .Cast<DirectoryEntry>() .Where( v=>v.SchemaClassName == "IIsWebServer" ); var items = new List<ComboBoxItem>(); foreach( var website in websites ) { entry.LogLine( "Found '" + website.Path + "'" ); var description = (string)website.Properties[ "ServerComment" ].Value; string rootPath = website.Path + "/ROOT"; entry.LogLine( "Getting '" + rootPath + "'" ); (new DirectoryEntry(rootPath)).Children.Cast<object>().ToArray(); // Check the directory is valid items.Add( new ComboBoxItem { Content = string.Format( "{0}: {1}", website.Name, description ), Tag = rootPath } ); } foreach( var item in items ) ddWebSites.Items.Add( item ); if( ddWebSites.Items.Count > 0 ) ddWebSites.SelectedIndex = 0; }
private void RemoveVirtualDirectory(ActionEntry entry) { string fullPath, parentDir, dirName; GetSelectedDirectoryPath( out fullPath, out parentDir, out dirName ); entry.LogLine( "Removing directory entry '" + fullPath + "'" ); using( var directoryEntry = new DirectoryEntry(fullPath) ) { directoryEntry.DeleteTree(); } }
private void LoadVirtualDirectories(ActionEntry entry) { ddVirtualDirs.Items.Clear(); var webSiteItem = ddWebSites.SelectedItem as ComboBoxItem; if( webSiteItem == null ) { entry.LogLine( "No website selected" ); return; } var webSiteDirectoryEntryPath = (string)webSiteItem.Tag; entry.LogLine( "Using website at '" + webSiteDirectoryEntryPath + "'" ); var webSiteDirectoryEntry = new DirectoryEntry( webSiteDirectoryEntryPath ); entry.LogLine( "Searching recursively for virtual dirs" ); var dirList = new List<DirectoryEntry>(); dirList.Add( webSiteDirectoryEntry ); BrowseDirectoriesRecursive( entry, webSiteDirectoryEntry, dirList ); ComboBoxItem selectedItem = null; var physicalPath = PhysicalPath; foreach( var dirEntry in dirList ) { string rootRelativePath = dirEntry.Path.Substring( webSiteDirectoryEntry.Path.Length ); if( rootRelativePath.Length == 0 ) rootRelativePath = "/"; var item = new ComboBoxItem { Content = rootRelativePath, Tag = dirEntry.Path }; ddVirtualDirs.Items.Add( item ); if( (physicalPath != null) && (physicalPath.ToLower() == ((string)dirEntry.Properties["Path"].Value ?? "").ToLower()) ) { entry.LogLine( "Using virtual dir at '" + dirEntry.Path + "'" ); selectedItem = item; } } if( selectedItem != null ) ddVirtualDirs.SelectedItem = selectedItem; CheckStatus(); }
private void CreateVirtualDirectory(ActionEntry entry) { // TODO: Alain: Test on XP ; seems it needs a boolean here : // Acces en lecture // Choix du framework (v2 / v4) // ASP doit être installé/activé: aspnet_regiis.exe -i -enable // a executer dans le répertoire "WINDOWS/Microsoft.NET/Framework/v4.0.30319" ou/et "v2.0.50727" // (désinstall: aspnet_regiis.exe -ua) // sinon, manque les directoryEntry.Properties["ScriptMap"] ==> *.aspx : machin_aspnet.dll // c.f. http://serverfault.com/questions/1649/why-does-iis-refuse-to-serve-asp-net-content // => Détection de l'installation/activation string fullPath, parentDir, dirName; GetSelectedDirectoryPath( out fullPath, out parentDir, out dirName ); string physicalPath = PhysicalPath; System.Diagnostics.Debug.Assert( physicalPath != null, "'PhysicalPath' should be available here" ); entry.LogLine( "Getting directory entry '" + parentDir + "'" ); using( var parentDirectoryEntry = new DirectoryEntry(parentDir) ) { parentDirectoryEntry.Children.Cast<object>().ToArray(); // Check that the entry is valid entry.LogLine( "Creating entry '" + dirName + "'" ); // c.f. http://michaelsync.net/2005/12/01/iis-6-virtual-directories-management-with-c using( var directoryEntry = parentDirectoryEntry.Children.Add( dirName,"IIsWebVirtualDir") ) { directoryEntry.Properties["Path"][0] = physicalPath; directoryEntry.Properties["EnableDirBrowsing"][0] = IISEnableDirBrowsing; directoryEntry.Properties["AccessRead"][0] = IISAccessRead; directoryEntry.Properties["AccessExecute"][0] = IISAccessExecute; directoryEntry.Properties["AccessWrite"][0] = IISAccessWrite; directoryEntry.Properties["AccessScript"][0] = IISAccessScript; //directoryEntry.Properties["AuthNTLM"][0] = true; //directoryEntry.Properties["EnableDefaultDoc"][0] = true; directoryEntry.Properties["DefaultDoc"][0] = IISDefaultDoc; //directoryEntry.Properties["AspEnableParentPaths"][0] = true; directoryEntry.Properties["AppFriendlyName"][0] = WebAppFriendlyName; directoryEntry.CommitChanges(); //'the following are acceptable params //'INPROC = 0 //'OUTPROC = 1 //'POOLED = 2 // TODO: Alain: What's this? directoryEntry.Invoke("AppCreate", 1); directoryEntry.CommitChanges(); } } }
/// <summary> /// Check the content of 'txtPhysicalPath' and update 'PhysicalPath'. /// </summary> private void CheckPhysicalPath(ActionEntry entry) { string realPath = null; try { var proposition = PhysicalPathProposition; if( string.IsNullOrEmpty(proposition) ) { entry.AddError( "No physical path specified" ); goto ExitProc; } entry.LogLine( "Checking directory '" + proposition ); var dirInfo = new DirectoryInfo( proposition ); if(! dirInfo.Exists ) { entry.AddError( "Directory '" + proposition + "' does not exists" ); goto ExitProc; } var fileInfo = new FileInfo( System.IO.Path.Combine(proposition, "Web.config") ); if(! fileInfo.Exists ) { entry.AddError( "Directory '" + proposition + "' does not contain a file 'Web.config'" ); goto ExitProc; } // Directory OK => We can use it realPath = proposition;; } catch( System.Exception ex ) { entry.AddException( ex ); } ExitProc: PhysicalPath = realPath; CheckStatus(); }
private void btnReplace_Click(ActionEntry entry) { entry.LogLine( "Removing old virtual directory" ); entry.LaunchSubAction( RemoveVirtualDirectory ); if( (!entry.HasErrors) && (!entry.HasExceptions) ) { entry.LogLine( "Recreate virtual directory" ); entry.LaunchSubAction( CreateVirtualDirectory ); } entry.LogLine( "Reload IIS virtual directories list" ); ddVirtualDirs.SelectedIndex = -1; entry.LaunchSubAction( LoadVirtualDirectories ); if( (!entry.HasErrors) && (!entry.HasExceptions) ) { MessageBox.Show( "Virtual directory replaced" ); } else { System.Diagnostics.Debug.Fail( "HERE: DialogBox de l'ActionEntry qui a foiré" ); } CheckStatus(); }
private void BrowseDirectoriesRecursive(ActionEntry entry, DirectoryEntry dirEntry, List<DirectoryEntry> dirList) { foreach( var child in dirEntry.Children.Cast<DirectoryEntry>() ) { switch( child.SchemaClassName ) { case "IIsWebVirtualDir": entry.LogLine( "Found virtual directory at '" + child.Path + "'" ); dirList.Add( child ); goto case "IIsWebDirectory"; case "IIsWebDirectory": entry.LaunchSubAction( (e)=>{ BrowseDirectoriesRecursive( e, child, dirList ); } ); break; default: System.Diagnostics.Debug.Fail( "Unknown child type '" + child.SchemaClassName + "'" ); break; } } }