Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1810 lines
46 KiB

  1. /// ************************************************************************
  2. /// Microsoft UDDI version 2.0
  3. /// Copyright (c) 2000-2002 Microsoft Corporation
  4. /// All rights reserved
  5. ///
  6. /// ** Microsoft Confidential **
  7. /// ------------------------------------------------------------------------
  8. /// <summary>
  9. /// </summary>
  10. /// ************************************************************************
  11. ///
  12. using System;
  13. using System.IO;
  14. using System.Data;
  15. using Microsoft.Win32;
  16. using System.DirectoryServices;
  17. using System.Diagnostics;
  18. using System.Reflection;
  19. using System.Globalization;
  20. using System.Collections;
  21. using System.Collections.Specialized;
  22. using System.Data.SqlClient;
  23. using System.ComponentModel;
  24. using System.Configuration.Install;
  25. using System.ServiceProcess;
  26. using System.Security.Cryptography;
  27. using System.Runtime.InteropServices;
  28. using System.Windows.Forms;
  29. using System.Security.Principal;
  30. using UDDI;
  31. using UDDI.API;
  32. using UDDI.API.Business;
  33. using UDDI.ActiveDirectory;
  34. namespace UDDI.DBCA
  35. {
  36. [ RunInstaller( true ) ]
  37. public class Installer : System.Configuration.Install.Installer
  38. {
  39. private SQLDMO.SQLServer2 server = null;
  40. private SQLDMO.Database2 database = null;
  41. private SQLDMO.Database2 masterdb = null;
  42. private const string dbName = "uddi"; //name of the uddi database
  43. private const string dataFolderName = "data"; //name of the uddi data folder
  44. private const string resetkeyfile = @"bin\resetkey.exe";
  45. private const string uddiXPFile = @"bin\uddi.xp.dll";
  46. private const int SQL_ALREADY_STARTED = -2147023840;
  47. private StringCollection uninstDataFiles = null;
  48. private const string busEntityParamName = "UPRV"; // context value expected
  49. private const string clustNodeTypeParam = "CNTYPE"; // cluster node type
  50. private const string busEntityKeyName = "Site.Key"; // we use this name to save the key in the Config
  51. private const string siteVerKeyName = "Site.Version"; // we use this name to save the product vesrion in the Config
  52. private const string siteLangKeyName = "Site.Language"; // we use this name to save the default product language in the Config
  53. private const string defaultOperatorkey = "Operator";
  54. private const string clustNodeActive = "A"; // Denotes an "active" node
  55. private const string clustNodePassive = "P"; // Denotes a "passive" aka non-owning node
  56. private const string regDBServerKeyName = "SOFTWARE\\Microsoft\\UDDI\\Setup\\DBServer";
  57. private const string regVersionKeyName = "ProductVersion";
  58. private const string tmodelUddiOrgOpers = "uuid:327a56f0-3299-4461-bc23-5cd513e95c55";
  59. private const string tokenOBEKeyValue = "operationalBusinessEntity";
  60. //
  61. // Database path and file name variables
  62. //
  63. private const string propSysFilePath = "SFP";
  64. private const string propCoreFilePath_1 = "C1P";
  65. private const string propCoreFilePath_2 = "C2P";
  66. private const string propJournalFilePath = "JRNLP";
  67. private const string propStagingFilePath = "STGP";
  68. private const string propXactLogFilePath = "XLP";
  69. private string SystemFilePath;
  70. private string SystemFileSpec;
  71. private string Core1FilePath;
  72. private string Core1FileSpec;
  73. private string Core2FilePath;
  74. private string Core2FileSpec;
  75. private string JournalFilePath;
  76. private string JournalFileSpec;
  77. private string StagingFilePath;
  78. private string StagingFileSpec;
  79. private string LogFilePath;
  80. private string LogFileSpec;
  81. const string RegisterXpSqlFormat = @"
  82. IF EXISTS (SELECT * FROM sysobjects where name = 'xp_reset_key' and type = 'X')
  83. EXEC sp_dropextendedproc 'xp_reset_key'
  84. GO
  85. EXEC sp_addextendedproc 'xp_reset_key', '{0}'
  86. GO
  87. IF EXISTS (SELECT * FROM sysobjects where name= 'xp_recalculate_statistics' and type = 'X')
  88. EXEC sp_dropextendedproc 'xp_recalculate_statistics'
  89. GO
  90. EXEC sp_addextendedproc 'xp_recalculate_statistics', '{0}'
  91. GO";
  92. //
  93. // These sql scripts will get executed in the master database after the
  94. // database is created.
  95. //
  96. string[] masterInstallScripts = { "uddi.v2.messages.sql" };
  97. //
  98. // These sql scripts will get executed in the master database when the
  99. // database is being uninstalled.
  100. //
  101. string[] masterUninstallScripts = { "uddi.v2.xp.uninstall.sql" };
  102. //
  103. // These sql scripts will get executed in the uddi database
  104. // after the master database scripts are run
  105. //
  106. string[] uddiScripts =
  107. {
  108. "uddi.v2.ddl.sql",
  109. "uddi.v2.tableopts.sql",
  110. "uddi.v2.ri.sql",
  111. "uddi.v2.dml.sql",
  112. "uddi.v2.func.sql",
  113. "uddi.v2.sp.sql",
  114. "uddi.v2.admin.sql",
  115. "uddi.v2.repl.sql",
  116. "uddi.v2.trig.sql",
  117. "uddi.v2.uisp.sql",
  118. "uddi.v2.tModel.sql",
  119. "uddi.v2.businessEntity.sql",
  120. "uddi.v2.businessService.sql",
  121. "uddi.v2.bindingTemplate.sql",
  122. "uddi.v2.publisher.sql",
  123. "uddi.v2.sec.sql" };
  124. private System.ComponentModel.Container components = null;
  125. public Installer()
  126. {
  127. Enter();
  128. try
  129. {
  130. //
  131. // This call is required by the Designer.
  132. //
  133. InitializeComponent();
  134. uninstDataFiles = new StringCollection();
  135. }
  136. catch ( Exception e )
  137. {
  138. LogException( "Installer()", e );
  139. throw e;
  140. }
  141. finally
  142. {
  143. Leave();
  144. }
  145. }
  146. #region Component Designer generated code
  147. /// <summary>
  148. /// Required method for Designer support - do not modify
  149. /// the contents of this method with the code editor.
  150. /// </summary>
  151. private void InitializeComponent()
  152. {
  153. Enter();
  154. try
  155. {
  156. components = new System.ComponentModel.Container();
  157. }
  158. catch ( Exception e )
  159. {
  160. Debug.WriteLine( "Exception in 'InitializeComponent()': " + e.Message );
  161. }
  162. finally
  163. {
  164. Leave();
  165. }
  166. }
  167. #endregion
  168. private void InitializeSQLDMO()
  169. {
  170. Enter();
  171. try
  172. {
  173. server = new SQLDMO.SQLServer2Class();
  174. }
  175. catch( Exception e )
  176. {
  177. Log( "The database installer failed to construct an instance of the SQLDMO.SQLServer2 class. SQL Server may not be installed." );
  178. throw new InstallException( string.Format( "Exception occured during database install: '{0}'", "InitializeSQLDMO" ) , e );
  179. }
  180. finally
  181. {
  182. Leave();
  183. }
  184. }
  185. public override void Install( System.Collections.IDictionary state )
  186. {
  187. Enter();
  188. try
  189. {
  190. // System.Windows.Forms.MessageBox.Show( "UDDI Application Installer Stop", "UDDI.Debug" );
  191. InitializeSQLDMO();
  192. InitializeDataFiles();
  193. //
  194. // Set up the cleanup data
  195. //
  196. uninstDataFiles.Clear();
  197. uninstDataFiles.Add( SystemFileSpec );
  198. uninstDataFiles.Add( Core1FileSpec );
  199. uninstDataFiles.Add( Core2FileSpec );
  200. uninstDataFiles.Add( JournalFileSpec );
  201. uninstDataFiles.Add( StagingFileSpec );
  202. uninstDataFiles.Add( LogFileSpec );
  203. //
  204. // Proceed with the base installer routine
  205. //
  206. base.Install( state );
  207. //
  208. // First, are we on a cluster node ?
  209. //
  210. bool bActiveNode = false;
  211. bool bStandalone = true;
  212. string sClusterNodeType = Context.Parameters[ clustNodeTypeParam ];
  213. if ( sClusterNodeType == null || sClusterNodeType == "" )
  214. {
  215. bActiveNode = false;
  216. bStandalone = true;
  217. }
  218. else if ( String.Compare( sClusterNodeType, clustNodeActive, true ) == 0 )
  219. {
  220. bActiveNode = true;
  221. bStandalone = false;
  222. }
  223. else
  224. {
  225. bActiveNode = false;
  226. bStandalone = false;
  227. }
  228. //
  229. // On a "passive" node we do not do most of the CA operations
  230. //
  231. if ( bActiveNode || bStandalone )
  232. {
  233. bool bDatabaseFound = false;
  234. //
  235. // Do the custom action here. Start with cleaning the stage
  236. //
  237. if ( bStandalone )
  238. CleanupDataFiles();
  239. //
  240. // Now proceed with the installation itself
  241. //
  242. StartSQLService();
  243. ConnectToDatabase();
  244. CheckDatabaseConfiguration();
  245. //
  246. // If we are on an active cluster node, we should not attempt
  247. // to overwrite the database
  248. //
  249. if ( bActiveNode )
  250. {
  251. bDatabaseFound = FindUDDIDatabase();
  252. }
  253. if ( !bDatabaseFound )
  254. {
  255. WriteDatabase();
  256. LocateDatabase();
  257. //
  258. // Register our extended stored procedures. Need to do this first since our scripts refer to these.
  259. //
  260. RegisterExtendedStoredProcedures();
  261. //
  262. // Run the scripts.
  263. //
  264. foreach( string scriptName in masterInstallScripts )
  265. {
  266. string script = GetResource( scriptName );
  267. Log( string.Format( "Executing {0} SQL script.", scriptName ) ) ;
  268. masterdb.ExecuteImmediate( script, SQLDMO.SQLDMO_EXEC_TYPE.SQLDMOExec_Default, script.Length );
  269. }
  270. foreach( string scriptName in uddiScripts )
  271. {
  272. string script = GetResource( scriptName );
  273. Log( string.Format( "Executing {0} SQL script.", scriptName ) ) ;
  274. database.ExecuteImmediate( script, SQLDMO.SQLDMO_EXEC_TYPE.SQLDMOExec_Default, script.Length );
  275. }
  276. //
  277. // Configure the database
  278. //
  279. SQLDMO.DBOption2 dboption2 = ( SQLDMO.DBOption2 ) database.DBOption;
  280. dboption2.RecoveryModel = SQLDMO.SQLDMO_RECOVERY_TYPE.SQLDMORECOVERY_Simple;
  281. SetSSLRequired();
  282. ImportBootstrapData();
  283. GenerateCryptoKey();
  284. string szSiteDesc = Localization.GetString( "DBCA_UDDI_DESC_SITE" );
  285. AssignOperator( Context.Parameters[ busEntityParamName ] );
  286. CreateBusinessEntity( Context.Parameters[ busEntityParamName ], szSiteDesc );
  287. // RegisterWithActiveDirectory();
  288. RecalculateStatistics();
  289. UpdateVersionFromRegistry();
  290. UpdateSiteLanguage( 0 );
  291. }
  292. } // active Node
  293. try
  294. {
  295. StartService( "RemoteRegistry", 30 );
  296. }
  297. catch ( Exception e )
  298. {
  299. LogException( string.Format( "Exception occured during database install: '{0}'", "RemoteRegistry Start" ) , e );
  300. }
  301. }
  302. catch( Exception e )
  303. {
  304. throw new InstallException( LogException( string.Format( "Exception occured during database install: '{0}'", "Installer.Install" ) , e ) );
  305. }
  306. finally
  307. {
  308. Leave();
  309. }
  310. }
  311. public override void Uninstall( System.Collections.IDictionary state )
  312. {
  313. Enter();
  314. // System.Windows.Forms.MessageBox.Show( "UDDI Application Installer Stop Uninstall", "UDDI.Debug" );
  315. try
  316. {
  317. try
  318. {
  319. string userName = WindowsIdentity.GetCurrent().Name;
  320. Log( "Execuring uninstall as " + userName );
  321. }
  322. catch (Exception)
  323. {
  324. }
  325. //
  326. // try to shut down the database
  327. //
  328. try
  329. {
  330. InitializeSQLDMO();
  331. uninstDataFiles.Clear();
  332. base.Uninstall( state );
  333. //
  334. // First, are we on a cluster node ?
  335. //
  336. bool bActiveNode = false;
  337. string sClusterNodeType = Context.Parameters[ clustNodeTypeParam ];
  338. if ( sClusterNodeType == null || sClusterNodeType == "" )
  339. bActiveNode = true; // we are not on a node, assume "active" mode
  340. else if ( String.Compare( sClusterNodeType, clustNodeActive, true ) == 0 )
  341. bActiveNode = true;
  342. else
  343. bActiveNode = false;
  344. if ( bActiveNode )
  345. {
  346. StartSQLService();
  347. ConnectToDatabase();
  348. }
  349. //
  350. // Attempt to remove the AD entry
  351. //
  352. try
  353. {
  354. RemoveADSiteEntry();
  355. }
  356. catch ( Exception )
  357. {
  358. }
  359. if ( bActiveNode )
  360. {
  361. LocateDatabase();
  362. //
  363. // Run the uninstall SQL scripts
  364. //
  365. foreach( string scriptName in masterUninstallScripts )
  366. {
  367. string script = GetResource( scriptName );
  368. Log( string.Format( "Executing {0} SQL script.", scriptName ) ) ;
  369. masterdb.ExecuteImmediate( script, SQLDMO.SQLDMO_EXEC_TYPE.SQLDMOExec_Default, script.Length );
  370. }
  371. CollectDatafilePaths();
  372. TakeDatabaseOffline();
  373. DetachDatabase();
  374. CleanupDataFiles();
  375. }
  376. }
  377. catch
  378. {
  379. // do not throw exceptions on uninstall
  380. }
  381. }
  382. finally
  383. {
  384. Leave();
  385. }
  386. }
  387. public override void Rollback( System.Collections.IDictionary state )
  388. {
  389. Enter();
  390. base.Rollback( state );
  391. Uninstall( state );
  392. Leave();
  393. }
  394. protected void StartSQLService()
  395. {
  396. Enter();
  397. string instanceName = "";
  398. try
  399. {
  400. // get the instance name from the registry
  401. instanceName = ( string ) Registry.LocalMachine.OpenSubKey( @"SOFTWARE\Microsoft\UDDI" ).GetValue( "InstanceName" );
  402. server.Name = instanceName;
  403. Log( string.Format( "Attempting to start database {0}.", instanceName ) );
  404. server.Start( false, instanceName, null, null );
  405. WaitForSQLServiceStartup();
  406. Log( string.Format( "Database server {0} successfully started.", instanceName ) );
  407. }
  408. catch( COMException e )
  409. {
  410. if( SQL_ALREADY_STARTED != e.ErrorCode )
  411. {
  412. string excepstr = string.Format( "Unable to start the UDDI database server {0}.", ((""!=instanceName)?instanceName:"(UNKNOWN)" ));
  413. throw new InstallException( LogException( excepstr , e ) );
  414. }
  415. else
  416. {
  417. Log( string.Format( "Database {0} already started.", instanceName ) );
  418. }
  419. }
  420. catch( Exception e )
  421. {
  422. string excepstr = string.Format( "Unable to start the UDDI database server {0}.", ((null!=instanceName)?instanceName:"(UNKNOWN)" ));
  423. throw new InstallException( LogException( excepstr , e ) );
  424. }
  425. finally
  426. {
  427. Leave();
  428. }
  429. }
  430. protected void WaitForSQLServiceStartup()
  431. {
  432. Enter();
  433. try
  434. {
  435. //
  436. // wait for a while for the serice to start
  437. //
  438. Log( "Waiting for SQL Service to start..." );
  439. for( int i=0; i<15; i++ )
  440. {
  441. try
  442. {
  443. if( server.Status == SQLDMO.SQLDMO_SVCSTATUS_TYPE.SQLDMOSvc_Running )
  444. break;
  445. }
  446. catch( Exception e )
  447. {
  448. Log( string.Format( "Error testing the DB server status: {0}", e.Message ) );
  449. }
  450. System.Threading.Thread.Sleep( 3000 );
  451. }
  452. if( server.Status != SQLDMO.SQLDMO_SVCSTATUS_TYPE.SQLDMOSvc_Running )
  453. {
  454. throw new InstallException( "Unable to start the SQL database." );
  455. }
  456. Log( "SQL Service Started!" );
  457. }
  458. finally
  459. {
  460. Leave();
  461. }
  462. }
  463. protected void ConnectToDatabase()
  464. {
  465. Enter();
  466. server.LoginSecure = true;
  467. string instanceName = null;
  468. try
  469. {
  470. server.LoginTimeout = ( int ) Registry.LocalMachine.OpenSubKey( @"SOFTWARE\Microsoft\UDDI\Database" ).GetValue( "Timeout", 90 );
  471. instanceName = ( string ) Registry.LocalMachine.OpenSubKey( @"SOFTWARE\Microsoft\UDDI" ).GetValue( "InstanceName" );
  472. Log( string.Format( "Attempting to connect to database server: {0}", instanceName ) );
  473. server.Connect( instanceName, null, null );
  474. }
  475. catch( Exception e )
  476. {
  477. string excepstr = string.Format( "Unable to connect to database server {0}.", ( (null!=instanceName)?instanceName:"(UNKNOWN)" ) );
  478. throw new InstallException( LogException( excepstr, e ) );
  479. }
  480. finally
  481. {
  482. Leave();
  483. }
  484. }
  485. protected void CheckDatabaseConfiguration()
  486. {
  487. Enter();
  488. try
  489. {
  490. string errStr = "";
  491. if( !server.Issysadmin )
  492. {
  493. errStr = "The current user does not have administrative privileges.";
  494. LogError( errStr );
  495. throw new InstallException( errStr );
  496. }
  497. if( server.VersionMajor < 8 )
  498. {
  499. errStr = "Unsupported release of SQL Server.";
  500. throw new InstallException( LogError( errStr ) );
  501. }
  502. }
  503. finally
  504. {
  505. Leave();
  506. }
  507. }
  508. protected bool FindUDDIDatabase()
  509. {
  510. Enter();
  511. bool found = false;
  512. try
  513. {
  514. for( int k=1; k <= server.Databases.Count; k++ )
  515. {
  516. string tempName = server.Databases.Item( k, null ).Name;
  517. if( tempName.Equals( dbName ) )
  518. {
  519. found = true;
  520. break;
  521. }
  522. }
  523. }
  524. catch( Exception e )
  525. {
  526. LogException( "FindUDDIDatabase", e );
  527. }
  528. finally
  529. {
  530. Leave();
  531. }
  532. return found;
  533. }
  534. protected void LocateDatabase()
  535. {
  536. Enter();
  537. try
  538. {
  539. for( int k=1; k <= server.Databases.Count; k++ )
  540. {
  541. string tempName = server.Databases.Item( k, null ).Name;
  542. if( tempName.Equals( dbName ) )
  543. {
  544. database = ( SQLDMO.Database2 ) server.Databases.Item( k, null );
  545. }
  546. else if( tempName.Equals( "master" ) )
  547. {
  548. masterdb = ( SQLDMO.Database2 ) server.Databases.Item( k, null );
  549. }
  550. }
  551. if( null == ( object ) database )
  552. {
  553. string errstr = string.Format( "Couldn't find the database: {0}", dbName );
  554. throw new InstallException( LogError( errstr ) );
  555. }
  556. if( null == ( object ) masterdb )
  557. {
  558. string errstr = string.Format( "Couldn't find the database: {0}", "master" );
  559. throw new InstallException( LogError( errstr ) );
  560. }
  561. }
  562. finally
  563. {
  564. Leave();
  565. }
  566. }
  567. protected string CheckForSlash( string str )
  568. {
  569. if( !str.EndsWith( @"\" ) )
  570. {
  571. return ( str + @"\" );
  572. }
  573. return str;
  574. }
  575. protected void WriteDatabase()
  576. {
  577. Enter();
  578. try
  579. {
  580. //
  581. // Create directories, clean up old files if they exist
  582. //
  583. Log( "SystemFilePath=" + SystemFilePath );
  584. if( !Directory.Exists( SystemFilePath ) )
  585. Directory.CreateDirectory( SystemFilePath );
  586. Log( "Core1FilePath=" + Core1FilePath );
  587. if( !Directory.Exists( Core1FilePath ) )
  588. Directory.CreateDirectory( Core1FilePath );
  589. Log( "Core2FilePath=" + Core2FilePath );
  590. if( !Directory.Exists( Core2FilePath ) )
  591. Directory.CreateDirectory( Core2FilePath );
  592. Log( "JournalFilePath=" + JournalFilePath );
  593. if( !Directory.Exists( JournalFilePath ) )
  594. Directory.CreateDirectory( JournalFilePath );
  595. Log( "StagingFilePath=" + StagingFilePath );
  596. if( !Directory.Exists( StagingFilePath ) )
  597. Directory.CreateDirectory( StagingFilePath );
  598. Log( "LogFilePath=" + LogFilePath );
  599. if( !Directory.Exists( LogFilePath ) )
  600. Directory.CreateDirectory( LogFilePath );
  601. //
  602. // Create database
  603. //
  604. try
  605. {
  606. database = new SQLDMO.Database2Class();
  607. database.Name = dbName;
  608. //
  609. // Create the system file in the primary filegroup
  610. //
  611. Log( "System database file = " + SystemFileSpec );
  612. SQLDMO.DBFile dbFile = new SQLDMO.DBFileClass();
  613. dbFile.Name = "UDDI_SYS";
  614. dbFile.PhysicalName = SystemFileSpec;
  615. database.FileGroups.Item( "PRIMARY" ).DBFiles.Add( dbFile );
  616. //
  617. // Create the database log file
  618. //
  619. Log( "Setting UDDI log file = " + LogFileSpec );
  620. SQLDMO.LogFile logFile = new SQLDMO.LogFileClass();
  621. logFile.Name = "UDDI_LOG";
  622. logFile.PhysicalName = LogFileSpec;
  623. database.TransactionLog.LogFiles.Add( logFile );
  624. server.Databases.Add( database );
  625. LocateDatabase();
  626. //
  627. // Create the core filegroup
  628. //
  629. SQLDMO.FileGroup2 corefilegroup = new SQLDMO.FileGroup2Class();
  630. corefilegroup.Name = "UDDI_CORE";
  631. database.FileGroups.Add( corefilegroup );
  632. //
  633. // Create the Core 1 file
  634. //
  635. Log( "Core 1 database file = " + Core1FileSpec );
  636. SQLDMO.DBFile core1file = new SQLDMO.DBFileClass();
  637. core1file.Name = "UDDI_CORE_1";
  638. core1file.PhysicalName = Core1FileSpec;
  639. database.FileGroups.Item( "UDDI_CORE" ).DBFiles.Add( core1file );
  640. //
  641. // Create the Core 2 file
  642. //
  643. Log( "Core 2 database file = " + Core2FileSpec );
  644. SQLDMO.DBFile core2file = new SQLDMO.DBFileClass();
  645. core2file.Name = "UDDI_CORE_2";
  646. core2file.PhysicalName = Core2FileSpec;
  647. database.FileGroups.Item( "UDDI_CORE" ).DBFiles.Add( core2file );
  648. //
  649. // Create the journal filegroup
  650. //
  651. SQLDMO.FileGroup2 journalfilegroup = new SQLDMO.FileGroup2Class();
  652. journalfilegroup.Name = "UDDI_JOURNAL";
  653. database.FileGroups.Add( journalfilegroup );
  654. //
  655. // Create the journal file
  656. //
  657. Log( "Journal database file = " + JournalFileSpec );
  658. SQLDMO.DBFile journalfile = new SQLDMO.DBFileClass();
  659. journalfile.Name = "UDDI_JOURNAL_1";
  660. journalfile.PhysicalName = JournalFileSpec;
  661. database.FileGroups.Item( "UDDI_JOURNAL" ).DBFiles.Add( journalfile );
  662. //
  663. // Create the staging filegroup
  664. //
  665. SQLDMO.FileGroup2 stagingfilegroup = new SQLDMO.FileGroup2Class();
  666. stagingfilegroup.Name = "UDDI_STAGING";
  667. database.FileGroups.Add( stagingfilegroup );
  668. //
  669. // Create the staging file
  670. //
  671. Log( "Staging database file = " + StagingFileSpec );
  672. SQLDMO.DBFile stagingfile = new SQLDMO.DBFileClass();
  673. stagingfile.Name = "UDDI_STAGING_1";
  674. stagingfile.PhysicalName = StagingFileSpec;
  675. database.FileGroups.Item( "UDDI_STAGING" ).DBFiles.Add( stagingfile );
  676. }
  677. catch ( Exception e )
  678. {
  679. string errstr = string.Format( "Unable to add the database: {0}", database );
  680. throw new InstallException( LogException( errstr, e ) );
  681. }
  682. }
  683. finally
  684. {
  685. Leave();
  686. }
  687. }
  688. protected void TakeDatabaseOffline()
  689. {
  690. Enter();
  691. Debug.Assert( null != masterdb, "masterdb is null" );
  692. Debug.Assert( null != dbName, "dbName is null" );
  693. string commandBatch = "ALTER DATABASE " + dbName + " SET OFFLINE WITH ROLLBACK IMMEDIATE";
  694. try
  695. {
  696. masterdb.ExecuteImmediate( commandBatch, SQLDMO.SQLDMO_EXEC_TYPE.SQLDMOExec_Default, commandBatch.Length );
  697. }
  698. catch ( Exception e )
  699. {
  700. string errstr = string.Format( "Couldn't take the following database offline: {0}",dbName );
  701. throw new InstallException( LogException( errstr, e ) );
  702. }
  703. finally
  704. {
  705. Leave();
  706. }
  707. }
  708. protected void DetachDatabase()
  709. {
  710. Enter();
  711. Debug.Assert( null != server, "server is null" );
  712. Debug.Assert( null != dbName, "dbName is null" );
  713. try
  714. {
  715. string status = server.DetachDB( dbName, false );
  716. Log( "DetachDatabase() returned: " + status );
  717. }
  718. catch ( Exception e )
  719. {
  720. string errstr = string.Format( "Couldn't detach the following database: {0}", dbName );
  721. throw new InstallException( LogException( errstr, e ) );
  722. }
  723. finally
  724. {
  725. Leave();
  726. }
  727. }
  728. protected void CleanupDataFiles()
  729. {
  730. Enter();
  731. foreach ( string fileName in uninstDataFiles )
  732. {
  733. try
  734. {
  735. CleanupDatabaseFile( fileName );
  736. }
  737. catch (Exception)
  738. {
  739. }
  740. }
  741. Leave();
  742. }
  743. protected void CleanupDatabaseFile( string filespec )
  744. {
  745. Enter();
  746. try
  747. {
  748. Log( "Cleaning up: " + filespec );
  749. MoveDatabaseFile( filespec );
  750. DeleteDatabaseFile( filespec );
  751. }
  752. catch
  753. {
  754. string errstr = string.Format( "These file must be renamed or moved: '{0}'", filespec );
  755. throw new InstallException( LogError( errstr ) );
  756. }
  757. finally
  758. {
  759. Leave();
  760. }
  761. return;
  762. }
  763. protected void MoveDatabaseFile( string filespec )
  764. {
  765. Enter();
  766. //
  767. // rename data file
  768. //
  769. try
  770. {
  771. string fname = filespec.Trim();
  772. if ( !File.Exists( fname ) )
  773. {
  774. Log( "File not found: " + fname );
  775. return;
  776. }
  777. Log( "Renaming..." );
  778. for ( int i = 0; i < 10000; i++ )
  779. {
  780. string fileRename = fname;
  781. if ( i < 10 )
  782. fileRename += ".0" + i.ToString();
  783. else
  784. fileRename += "." + i.ToString();
  785. if( !File.Exists( fileRename ) )
  786. {
  787. File.Copy( fname, fileRename, /* overwrite= */ true );
  788. break;
  789. }
  790. }
  791. }
  792. catch( Exception e )
  793. {
  794. string errstr = string.Format( "Error renaming data file: '{0}'",filespec );
  795. throw new InstallException( LogException( errstr, e ) );
  796. }
  797. finally
  798. {
  799. Leave();
  800. }
  801. }
  802. protected void DeleteDatabaseFile( string filespec )
  803. {
  804. Enter();
  805. try
  806. {
  807. string fname = filespec.Trim();
  808. //
  809. // delete data file
  810. //
  811. if( File.Exists( fname ) )
  812. {
  813. Log( "Deleting..." );
  814. File.Delete( fname );
  815. }
  816. }
  817. catch( Exception e )
  818. {
  819. throw new InstallException( LogException( "Error deleting database files.", e ) );
  820. }
  821. finally
  822. {
  823. Leave();
  824. }
  825. }
  826. protected void SetSSLRequired()
  827. {
  828. Enter();
  829. string connectionString = "";
  830. try
  831. {
  832. //
  833. // The SSL setting (0 or 1) is passed to this custom action on the command line
  834. //
  835. string sslrequired = Context.Parameters[ "SSL" ];
  836. //
  837. // get the connection string and connect to the db
  838. //
  839. connectionString = ( string ) Registry.LocalMachine.OpenSubKey( @"SOFTWARE\Microsoft\UDDI\Database" ).GetValue( "WriterConnectionString" );
  840. SqlConnection conn = new SqlConnection( connectionString );
  841. SqlCommand cmd = new SqlCommand( "net_config_save", conn );
  842. conn.Open();
  843. try
  844. {
  845. cmd.CommandType = CommandType.StoredProcedure;
  846. cmd.Parameters.Add( new SqlParameter( "@configName", SqlDbType.NVarChar, UDDI.Constants.Lengths.ConfigName ) ).Direction = ParameterDirection.Input;
  847. cmd.Parameters.Add( new SqlParameter( "@configValue", SqlDbType.NVarChar, UDDI.Constants.Lengths.ConfigValue ) ).Direction = ParameterDirection.Input;
  848. cmd.Parameters[ "@configName" ].Value = "Security.HTTPS";
  849. cmd.Parameters[ "@configValue" ].Value = sslrequired;
  850. cmd.ExecuteNonQuery();
  851. }
  852. finally
  853. {
  854. conn.Close();
  855. }
  856. }
  857. catch( Exception e )
  858. {
  859. string logstr = string.Format( "Exception occured during database install: '{0}'", "SetSSLRequired()", connectionString );
  860. Log( logstr );
  861. Log( string.Format( "SQL Server raised an exception in {0}. Connection string used: '{1}'", "SetSSLRequired()", connectionString ) );
  862. string errstr = string.Format( "Error setting value for: {0}", "Security.HTTPS" );
  863. throw new InstallException( LogException( errstr, e ) );
  864. }
  865. finally
  866. {
  867. Leave();
  868. }
  869. }
  870. public void SetStartType( string svcName, ServiceStartMode startType )
  871. {
  872. Enter();
  873. try
  874. {
  875. //
  876. // open the registry entry for the service
  877. //
  878. RegistryKey HKLM = Registry.LocalMachine;
  879. RegistryKey svcKey = HKLM.OpenSubKey( "SYSTEM\\CurrentControlSet\\Services\\" + svcName, true );
  880. //
  881. // now set the start type
  882. //
  883. switch( startType )
  884. {
  885. case ServiceStartMode.Automatic:
  886. svcKey.SetValue ( "Start", 2 );
  887. break;
  888. case ServiceStartMode.Manual:
  889. svcKey.SetValue ( "Start", 3 );
  890. break;
  891. case ServiceStartMode.Disabled:
  892. svcKey.SetValue ( "Start", 4 );
  893. break;
  894. }
  895. svcKey.Close();
  896. HKLM.Close();
  897. }
  898. catch( Exception e )
  899. {
  900. throw new InstallException( LogException( string.Format( "Error setting value for: {0}", svcName ), e ) );
  901. }
  902. finally
  903. {
  904. Leave();
  905. }
  906. }
  907. public void StartService ( string svcName, int timeoutSec )
  908. {
  909. Enter();
  910. try
  911. {
  912. ServiceController controller;
  913. ServiceControllerStatus srvStatus;
  914. TimeSpan timeout = new TimeSpan ( 0, 0, timeoutSec );
  915. //
  916. // first, connect to the SCM on the local box
  917. // and attach to the service, then get its status
  918. //
  919. controller = new ServiceController ( svcName );
  920. srvStatus = controller.Status;
  921. //
  922. // what is the service state?
  923. //
  924. switch ( srvStatus)
  925. {
  926. //
  927. // stopped ?
  928. //
  929. case ServiceControllerStatus.Stopped:
  930. controller.Start();
  931. break;
  932. //
  933. // are we trying to start?
  934. //
  935. case ServiceControllerStatus.StartPending:
  936. case ServiceControllerStatus.ContinuePending:
  937. break;
  938. //
  939. // are we trying to stop?
  940. //
  941. case ServiceControllerStatus.StopPending:
  942. controller.WaitForStatus( ServiceControllerStatus.Stopped, timeout );
  943. controller.Start();
  944. break;
  945. //
  946. // pausing ?
  947. //
  948. case ServiceControllerStatus.PausePending:
  949. controller.WaitForStatus ( ServiceControllerStatus.Paused, timeout );
  950. controller.Continue();
  951. break;
  952. default: // the service is already running. Just leave it alone
  953. break;
  954. }
  955. //
  956. // wait 'till the service wakes up
  957. //
  958. controller.WaitForStatus ( ServiceControllerStatus.Running, timeout );
  959. }
  960. catch( Exception e )
  961. {
  962. throw new InstallException( LogException( string.Format( "Unable to start the service: {0}", svcName ), e ) );
  963. }
  964. finally
  965. {
  966. Leave();
  967. }
  968. }
  969. public void RegisterWithActiveDirectory()
  970. {
  971. try
  972. {
  973. }
  974. catch( Exception e )
  975. {
  976. LogException( "RegisterWithActiveDirectory", e );
  977. throw e;
  978. }
  979. }
  980. public void ImportBootstrapData()
  981. {
  982. Enter();
  983. try
  984. {
  985. //
  986. // load all the bootstrap files found in the \uddi\bootstrap folder
  987. //
  988. string targetDir = Registry.LocalMachine.OpenSubKey( @"SOFTWARE\Microsoft\UDDI" ).GetValue( "InstallRoot" ).ToString();
  989. string bootstrapdir = CheckForSlash(targetDir) + "bootstrap";
  990. string bootstrapexe = CheckForSlash(targetDir) + @"bin\bootstrap.exe";
  991. Log( "Getting list of bootstrap files from directory '" + bootstrapdir + "'" );
  992. //
  993. // 751411 - Explicitly sort the files we receive in alphabetical order.
  994. //
  995. BootStrapFileOrder fileOrder = new BootStrapFileOrder();
  996. string[] filepaths = Directory.GetFiles( bootstrapdir, "*.xml" );
  997. //
  998. // Log if we could not obtain an expected order. We can continue since BootStrapFileOrder
  999. // will use a default order.
  1000. //
  1001. if( false == fileOrder.UsingExpectedOrder )
  1002. {
  1003. Log( "Warning, bootstrap files were not sorted with the expected culture information (en-US). This may cause incomplete data to be stored in the UDDI Services database, or cause the installation to fail." );
  1004. }
  1005. Array.Sort( filepaths, fileOrder );
  1006. Log( "Writing " + filepaths.Length + " baseline resources to database." );
  1007. foreach( string filepath in filepaths )
  1008. {
  1009. Log( "Importing bootstrap data from: " + filepath );
  1010. ProcessStartInfo startInfo = new ProcessStartInfo( bootstrapexe, "/f \""+ filepath + "\"");
  1011. startInfo.CreateNoWindow = true;
  1012. startInfo.UseShellExecute = false;
  1013. startInfo.RedirectStandardOutput = true;
  1014. Process p = new Process();
  1015. p = Process.Start( startInfo );
  1016. //
  1017. // grab the stdout string
  1018. //
  1019. string bootstrapOutput = p.StandardOutput.ReadToEnd();
  1020. //
  1021. // wait for bootstrap.exe to complete
  1022. //
  1023. p.WaitForExit();
  1024. //
  1025. // write the stdout string to the log
  1026. //
  1027. Log( bootstrapOutput );
  1028. if( p.ExitCode != 0 )
  1029. {
  1030. LogError( "ImportBootstrapData failed!" );
  1031. }
  1032. }
  1033. }
  1034. catch( Exception e )
  1035. {
  1036. throw new InstallException( LogException( "Error importing the Bootstrap data.", e ) );
  1037. }
  1038. finally
  1039. {
  1040. Leave();
  1041. }
  1042. }
  1043. protected void GenerateCryptoKey()
  1044. {
  1045. Enter();
  1046. try
  1047. {
  1048. Log( "Generating cryptography key" );
  1049. //
  1050. // get the path to the exe we run
  1051. //
  1052. string targetDir = Registry.LocalMachine.OpenSubKey( @"SOFTWARE\Microsoft\UDDI" ).GetValue( "InstallRoot" ).ToString();
  1053. string resetkeypath = targetDir + resetkeyfile;
  1054. //
  1055. // make sure that the resetkey.exe was installed ok
  1056. //
  1057. if( !File.Exists( resetkeypath ) )
  1058. {
  1059. throw new InstallException( LogError( string.Format( "Unable to find the following file: '{0}'", resetkeypath ) ) );
  1060. }
  1061. ProcessStartInfo startInfo = new ProcessStartInfo( resetkeypath );
  1062. startInfo.Arguments = "/now";
  1063. startInfo.CreateNoWindow = true;
  1064. startInfo.UseShellExecute = false;
  1065. startInfo.RedirectStandardOutput = true;
  1066. Process p = new Process();
  1067. p = Process.Start( startInfo );
  1068. //
  1069. // grab the stdout string
  1070. //
  1071. string output = p.StandardOutput.ReadToEnd();
  1072. //
  1073. // wait for exe to complete
  1074. //
  1075. p.WaitForExit();
  1076. //
  1077. // write the stdout string to the log
  1078. //
  1079. // don't put this data into the log!
  1080. // Log( output );
  1081. if( p.ExitCode != 0 )
  1082. {
  1083. throw new InstallException( LogError( string.Format( "Exception occured during database install: '{0}'", "resetkey.exe" ) ) );
  1084. }
  1085. }
  1086. catch( Exception e )
  1087. {
  1088. throw new InstallException( LogException( "Unable to generate a crypto key.", e) );
  1089. }
  1090. finally
  1091. {
  1092. Leave();
  1093. }
  1094. }
  1095. protected void RecalculateStatistics ()
  1096. {
  1097. Enter();
  1098. string connectionString = "";
  1099. try
  1100. {
  1101. // System.Windows.Forms.MessageBox.Show( "RecalculateStatistics" );
  1102. //
  1103. // get the connection string and connect to the db
  1104. //
  1105. connectionString = ( string ) Registry.LocalMachine.OpenSubKey( @"SOFTWARE\Microsoft\UDDI\Database" ).GetValue( "WriterConnectionString" );
  1106. SqlConnection conn = new SqlConnection( connectionString );
  1107. SqlCommand cmd = new SqlCommand( "net_statistics_recalculate", conn );
  1108. cmd.CommandType = CommandType.StoredProcedure;
  1109. conn.Open();
  1110. try
  1111. {
  1112. cmd.ExecuteNonQuery();
  1113. }
  1114. finally
  1115. {
  1116. conn.Close();
  1117. }
  1118. }
  1119. catch( Exception e )
  1120. {
  1121. Log( string.Format( "SQL Server raised an exception in {0}. Connection string used: '{1}'", "RecalculateStatistics()", connectionString ) );
  1122. throw new InstallException( LogException( "Unable to recalculate statistics.", e ) );
  1123. }
  1124. finally
  1125. {
  1126. Leave();
  1127. }
  1128. }
  1129. protected void AssignOperator( string name )
  1130. {
  1131. Enter();
  1132. try
  1133. {
  1134. //
  1135. // set up the connection and other environment settings
  1136. //
  1137. ConnectionManager.Open( true, true );
  1138. UDDI.Context.User.SetRole( new WindowsPrincipal( WindowsIdentity.GetCurrent() ) );
  1139. UDDI.Context.User.ID = UDDI.Utility.GetDefaultPublisher();
  1140. UDDI.Config.SetString( defaultOperatorkey, name );
  1141. ConnectionManager.Commit();
  1142. }
  1143. catch ( Exception e )
  1144. {
  1145. ConnectionManager.Abort();
  1146. LogException( "AssignOperator", e );
  1147. Log( string.Format( "Unable to change the Operator Name to '{0}'. Reason: {1}", name, e.Message ) );
  1148. throw e;
  1149. }
  1150. finally
  1151. {
  1152. ConnectionManager.Close();
  1153. Leave();
  1154. }
  1155. }
  1156. protected void CreateBusinessEntity( string name, string description )
  1157. {
  1158. Enter();
  1159. try
  1160. {
  1161. //
  1162. // set up the connection and other environment settings
  1163. //
  1164. ConnectionManager.Open( true, true );
  1165. UDDI.Context.User.SetRole( new WindowsPrincipal( WindowsIdentity.GetCurrent() ) );
  1166. UDDI.Context.User.ID = UDDI.Utility.GetDefaultPublisher();
  1167. //
  1168. // set up the new entity attributes
  1169. //
  1170. BusinessEntity busEntity = new BusinessEntity();
  1171. busEntity.Names.Add( name );
  1172. busEntity.Descriptions.Add( description );
  1173. busEntity.AuthorizedName = UDDI.Context.User.ID;
  1174. busEntity.Operator = ""; // let it be default
  1175. // now add the uddi-org:operators keyed reference
  1176. busEntity.IdentifierBag.Add( "", tokenOBEKeyValue, tmodelUddiOrgOpers );
  1177. //
  1178. // Persist the business entity
  1179. //
  1180. busEntity.Save();
  1181. //
  1182. // now store the key value for future use
  1183. //
  1184. string key = busEntity.EntityKey;
  1185. UDDI.Config.SetString( busEntityKeyName, key );
  1186. ConnectionManager.Commit();
  1187. }
  1188. catch ( Exception e )
  1189. {
  1190. ConnectionManager.Abort();
  1191. LogException( "CreateBusinessEntity", e );
  1192. Log( string.Format( "Unable to create a new Business Entity '{0}'. Reason: {1}", name, e.Message ) );
  1193. throw e;
  1194. }
  1195. finally
  1196. {
  1197. ConnectionManager.Close();
  1198. Leave();
  1199. }
  1200. }
  1201. //
  1202. // Sets the Site.Language key to the ISO standard language code
  1203. // corresponding to the localeID
  1204. // If localeID = 0, then the system default language will be used
  1205. //
  1206. protected void UpdateSiteLanguage( int localeID )
  1207. {
  1208. Enter();
  1209. try
  1210. {
  1211. //
  1212. // set up the connection and other environment settings
  1213. //
  1214. ConnectionManager.Open( true, true );
  1215. UDDI.Context.User.SetRole( new WindowsPrincipal( WindowsIdentity.GetCurrent() ) );
  1216. UDDI.Context.User.ID = UDDI.Utility.GetDefaultPublisher();
  1217. CultureInfo culture;
  1218. if ( localeID == 0 )
  1219. culture = CultureInfo.CurrentCulture;
  1220. else
  1221. culture = new CultureInfo( localeID );
  1222. string languageCode = culture.TwoLetterISOLanguageName;
  1223. UDDI.Config.SetString( siteLangKeyName, languageCode );
  1224. ConnectionManager.Commit();
  1225. }
  1226. catch ( Exception e )
  1227. {
  1228. ConnectionManager.Abort();
  1229. LogException( "UpdateSiteLanguage", e );
  1230. }
  1231. finally
  1232. {
  1233. ConnectionManager.Close();
  1234. Leave();
  1235. }
  1236. }
  1237. protected void UpdateVersionFromRegistry()
  1238. {
  1239. Enter();
  1240. try
  1241. {
  1242. //
  1243. // set up the connection and other environment settings
  1244. //
  1245. ConnectionManager.Open( true, true );
  1246. UDDI.Context.User.SetRole( new WindowsPrincipal( WindowsIdentity.GetCurrent() ) );
  1247. UDDI.Context.User.ID = UDDI.Utility.GetDefaultPublisher();
  1248. string version = ( string ) Registry.LocalMachine.OpenSubKey( regDBServerKeyName ).GetValue( regVersionKeyName );
  1249. UDDI.Config.SetString( siteVerKeyName, version );
  1250. ConnectionManager.Commit();
  1251. }
  1252. catch ( Exception e )
  1253. {
  1254. ConnectionManager.Abort();
  1255. LogException( "UpdateVersionFromRegistry", e );
  1256. }
  1257. finally
  1258. {
  1259. ConnectionManager.Close();
  1260. Leave();
  1261. }
  1262. }
  1263. protected string GetResource( string name )
  1264. {
  1265. string fullname = "";
  1266. try
  1267. {
  1268. //
  1269. // Prefix the resource name with the assembly name
  1270. //
  1271. Assembly assembly = Assembly.GetExecutingAssembly();
  1272. //fullname = assembly.GetName().Name + "." + name;
  1273. fullname = name;
  1274. //
  1275. // Read the resource.
  1276. //
  1277. Log( "Reading resource: " + fullname );
  1278. Stream stream = assembly.GetManifestResourceStream( fullname );
  1279. StreamReader reader = new StreamReader( stream );
  1280. return reader.ReadToEnd();
  1281. }
  1282. catch ( Exception e )
  1283. {
  1284. throw new InstallException( LogException( string.Format( "Unable to get resource for: {0}", fullname ), e ) );
  1285. }
  1286. }
  1287. public void Enter()
  1288. {
  1289. System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace( 1, false );
  1290. System.Reflection.MethodBase method = trace.GetFrame( 0 ).GetMethod();
  1291. Log( "Entering " + method.ReflectedType.FullName + "." + method.Name + "..." );
  1292. }
  1293. public void Leave()
  1294. {
  1295. System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace( 1, false );
  1296. System.Reflection.MethodBase method = trace.GetFrame( 0 ).GetMethod();
  1297. Log( "Leaving " + method.ReflectedType.FullName + "." + method.Name );
  1298. }
  1299. private string LogError( string errmsg )
  1300. {
  1301. System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace( 1, false );
  1302. System.Reflection.MethodBase method = trace.GetFrame( 0 ).GetMethod();
  1303. Log( "----------------------------------------------------------" );
  1304. Log( "An error occurred during installation. Details follow:" );
  1305. Log( "Method: " + method.ReflectedType.FullName + "." + method.Name );
  1306. Log( "Message: " + errmsg );
  1307. Log( "----------------------------------------------------------" );
  1308. return errmsg;
  1309. }
  1310. private string LogException( string context, Exception e )
  1311. {
  1312. System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace( 1, false );
  1313. System.Reflection.MethodBase method = trace.GetFrame( 0 ).GetMethod();
  1314. Log( "----------------------------------------------------------" );
  1315. Log( "An exception occurred during installation. Details follow:" );
  1316. Log( "Method: " + method.ReflectedType.FullName + "." + method.Name );
  1317. Log( "Context: " + context );
  1318. Log( "Stack Trace: " + e.StackTrace );
  1319. Log( "Source: " + e.Source );
  1320. Log( "Message: " + e.Message );
  1321. Log( "----------------------------------------------------------" );
  1322. return context + ": " + e.Message;
  1323. }
  1324. private void Log( string str )
  1325. {
  1326. try
  1327. {
  1328. Debug.WriteLine( str );
  1329. FileStream f = new FileStream( System.Environment.ExpandEnvironmentVariables( "%systemroot%" ) + @"\uddisetup.log", FileMode.Append, FileAccess.Write );
  1330. StreamWriter s = new StreamWriter( f, System.Text.Encoding.Unicode );
  1331. s.WriteLine( "{0}: {1}", DateTime.Now.ToString(), str );
  1332. s.Close();
  1333. f.Close();
  1334. }
  1335. catch( Exception e )
  1336. {
  1337. Debug.WriteLine( "Error in Log():" + e.Message );
  1338. }
  1339. }
  1340. private void InitializeDataFiles()
  1341. {
  1342. //
  1343. // Initialize default data directory
  1344. //
  1345. string installroot = ( string ) Registry.LocalMachine.OpenSubKey( @"SOFTWARE\Microsoft\UDDI" ).GetValue( "InstallRoot" );
  1346. Log( "InstallRoot=" + installroot );
  1347. string defaultdatapath = CheckForSlash( installroot ) + dataFolderName; //dir local to db server for data files
  1348. Log( "DefaultDataPath=" + defaultdatapath );
  1349. //
  1350. // Get paths from properties passed from OCM dll, or set to default
  1351. //
  1352. SystemFilePath = Context.Parameters[ propSysFilePath ];
  1353. if ( null == SystemFilePath )
  1354. SystemFilePath = defaultdatapath;
  1355. SystemFileSpec = CheckForSlash( SystemFilePath ) + dbName + ".sys.mdf";
  1356. Core1FilePath = Context.Parameters[ propCoreFilePath_1 ];
  1357. if ( null == Core1FilePath )
  1358. Core1FilePath = defaultdatapath;
  1359. Core1FileSpec = CheckForSlash( Core1FilePath ) + dbName + ".data.1.ndf";
  1360. Core2FilePath = Context.Parameters[ propCoreFilePath_1 ];
  1361. if ( null == Core2FilePath )
  1362. Core2FilePath = defaultdatapath;
  1363. Core2FileSpec = CheckForSlash( Core2FilePath ) + dbName + ".data.2.ndf";
  1364. JournalFilePath = Context.Parameters[ propJournalFilePath ];
  1365. if ( null == JournalFilePath )
  1366. JournalFilePath = defaultdatapath;
  1367. JournalFileSpec = CheckForSlash( JournalFilePath ) + dbName + ".journal.1.ndf";
  1368. StagingFilePath = Context.Parameters[ propStagingFilePath ];
  1369. if ( null == StagingFilePath )
  1370. StagingFilePath = defaultdatapath;
  1371. StagingFileSpec = CheckForSlash( StagingFilePath ) + dbName + ".staging.1.ndf";
  1372. LogFilePath = Context.Parameters[ propXactLogFilePath ];
  1373. if ( null == LogFilePath )
  1374. LogFilePath = defaultdatapath;
  1375. LogFileSpec = CheckForSlash( LogFilePath ) + dbName + ".log.ldf";
  1376. return;
  1377. }
  1378. private void CollectDatafilePaths()
  1379. {
  1380. Enter();
  1381. try
  1382. {
  1383. if ( database == null ) // we probably failed to locate the database
  1384. return;
  1385. //
  1386. // first get the log
  1387. //
  1388. foreach ( SQLDMO._LogFile log in database.TransactionLog.LogFiles )
  1389. {
  1390. uninstDataFiles.Add( log.PhysicalName );
  1391. }
  1392. //
  1393. // now take care of the data files
  1394. //
  1395. foreach ( SQLDMO._FileGroup fgrp in database.FileGroups )
  1396. {
  1397. foreach ( SQLDMO.DBFile dbfile in fgrp.DBFiles )
  1398. {
  1399. uninstDataFiles.Add( dbfile.PhysicalName );
  1400. }
  1401. }
  1402. }
  1403. catch (Exception e)
  1404. {
  1405. LogException( "CollectDatafilePaths()", e );
  1406. }
  1407. finally
  1408. {
  1409. Leave();
  1410. }
  1411. }
  1412. //
  1413. // Drops the Active Directory site entry. The site comes from the
  1414. // Config table
  1415. //
  1416. protected void RemoveADSiteEntry()
  1417. {
  1418. Enter();
  1419. try
  1420. {
  1421. //
  1422. // set up the connection and other environment settings
  1423. //
  1424. ConnectionManager.Open( false, false );
  1425. UDDI.Context.User.SetRole( new WindowsPrincipal( WindowsIdentity.GetCurrent() ) );
  1426. UDDI.Context.User.ID = UDDI.Utility.GetDefaultPublisher();
  1427. //
  1428. // Try loading the site key
  1429. //
  1430. string defSiteKey = UDDI.Config.GetString( busEntityKeyName, "*" );
  1431. if ( defSiteKey.Equals( "*" ) )
  1432. Log( "Unable to get a site key" );
  1433. else
  1434. {
  1435. UDDIServiceConnPoint.DeleteSiteEntry( defSiteKey );
  1436. }
  1437. }
  1438. catch ( Exception e )
  1439. {
  1440. LogException( "RemoveADSiteEntry", e );
  1441. }
  1442. finally
  1443. {
  1444. ConnectionManager.Close();
  1445. Leave();
  1446. }
  1447. }
  1448. //
  1449. // Registering the extended stored procedure is a bit tricky because you need the absolute path to the DLL.
  1450. //
  1451. private void RegisterExtendedStoredProcedures()
  1452. {
  1453. //
  1454. // Build path to where the uddi.xp.dll file is going to be.
  1455. //
  1456. string targetDir = Registry.LocalMachine.OpenSubKey( @"SOFTWARE\Microsoft\UDDI" ).GetValue( "InstallRoot" ).ToString();
  1457. string fullPath = CheckForSlash( targetDir ) + uddiXPFile;
  1458. //
  1459. // Create the script that we need to register the extended stored proc.
  1460. //
  1461. string sqlScript = string.Format( RegisterXpSqlFormat, fullPath );
  1462. //
  1463. // Run this as a script using the master database DMO
  1464. //
  1465. masterdb.ExecuteImmediate( sqlScript, SQLDMO.SQLDMO_EXEC_TYPE.SQLDMOExec_Default, sqlScript.Length );
  1466. }
  1467. }
  1468. //
  1469. // 751411 - Explicitly sort the files we receive in alphabetical order.
  1470. //
  1471. internal class BootStrapFileOrder : IComparer
  1472. {
  1473. private CultureInfo usCultureInfo;
  1474. public BootStrapFileOrder()
  1475. {
  1476. //
  1477. // Try to create a US English culture info. This should always work no matter
  1478. // what the locale of the system, but do a catch just in case.
  1479. //
  1480. try
  1481. {
  1482. usCultureInfo = CultureInfo.CreateSpecificCulture( "en-US" );
  1483. }
  1484. catch
  1485. {
  1486. usCultureInfo = null;
  1487. }
  1488. }
  1489. public bool UsingExpectedOrder
  1490. {
  1491. get
  1492. {
  1493. return null != usCultureInfo;
  1494. }
  1495. }
  1496. public int Compare( object x, object y )
  1497. {
  1498. //
  1499. // Use the US English culture info if we have one, otherwise
  1500. // take our chances with the system one. Always ignore the case
  1501. // of the file.
  1502. //
  1503. if( null != usCultureInfo )
  1504. {
  1505. return String.Compare( x as string , y as string, true, usCultureInfo );
  1506. }
  1507. else
  1508. {
  1509. return String.Compare( x as string , y as string, true );
  1510. }
  1511. }
  1512. }
  1513. }