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.

2537 lines
72 KiB

  1. using System;
  2. using System.Diagnostics;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.IO;
  6. using System.Reflection;
  7. using System.Runtime.InteropServices;
  8. using System.Xml.Serialization;
  9. using Microsoft.Win32;
  10. using UDDI.API;
  11. using UDDI.API.ServiceType;
  12. using UDDI.API.Business;
  13. using UDDI.API.Service;
  14. using UDDI.API.Binding;
  15. using UDDI.API.Extensions;
  16. namespace UDDI.Tools
  17. {
  18. class Migrate
  19. {
  20. enum MigrationStage
  21. {
  22. DisplayUsage,
  23. SetReaderConnection,
  24. ResetWriter,
  25. MigratePublishers,
  26. MigrateBareTModels,
  27. BootstrapResources,
  28. MigrateCategorizationSchemes,
  29. MigrateFullTModels,
  30. MigrateHiddenTModels,
  31. MigrateBareBusinessEntities,
  32. MigrateBusinessEntities,
  33. MigratePublisherAssertions,
  34. RestoreReaderConnection
  35. }
  36. enum LogType
  37. {
  38. ConsoleAndLog,
  39. ConsoleOnly,
  40. LogOnly
  41. }
  42. //
  43. // Registry Constants
  44. //
  45. private const string DatabaseRoot = @"SOFTWARE\Microsoft\UDDI\Database";
  46. private const string DatabaseSetupRoot = @"SOFTWARE\Microsoft\UDDI\Setup\DBServer";
  47. private const string ReaderValueName = "ReaderConnectionString";
  48. private const string WriterValueName = "WriterConnectionString";
  49. private const string OldReaderValueName = "OldNewReaderConnectionString";
  50. //
  51. // Version Constants
  52. //
  53. private const string V2RC0SITESTR = "5.2.3626.0";
  54. private const string V2RC1SITESTR = "5.2.3663.0";
  55. private const string V2RC0STR = "2.0.1.0";
  56. private const string V2RC1STR = "2.0.1.1";
  57. private const string V2RC2STR = "2.0.1.2";
  58. private const string V2RTMSTR = "2.0.1.3";
  59. //
  60. // Upgrade contstants
  61. //
  62. private const string UpgradeRc0ToRc1Script = "uddi.v2.update_rc0_to_rc1.sql";
  63. private const string UpgradeRc1ToRc2Script = "uddi.v2.update_rc1_to_rc2.sql";
  64. //
  65. // Other Constants
  66. //
  67. private const string LogFileName = "migrate.log.txt";
  68. private const string ExceptionFileName = "migrate.exceptions.txt";
  69. private const string ExceptionDirName = "exceptions";
  70. private const string EmptyAccessPoint = "undefined"; // String to use when both accessPoint and hostingRedirector are null
  71. private const string EmptyPersonName = "unspecified"; // String to use when personName does not meet minumum length requriements
  72. //
  73. // Command Line Parameters
  74. //
  75. static MigrationStage Stage = MigrationStage.DisplayUsage;
  76. static string NewReaderConnectionString;
  77. static bool Verbose = false;
  78. //
  79. // Global Variables
  80. //
  81. static FileStream LogFile = new FileStream( LogFileName, FileMode.Append );
  82. static StreamWriter Stream = new StreamWriter( LogFile );
  83. static string ReaderConnectionString;
  84. static string WriterConnectionString;
  85. static string Separator="".PadLeft( 80, '-' );
  86. static int Exceptions = 0;
  87. static Version V2RC0SITE = new Version( V2RC0SITESTR );
  88. static Version V2RC1SITE = new Version( V2RC1SITESTR );
  89. static Version V2RC0 = new Version( V2RC0STR );
  90. static Version V2RC1 = new Version( V2RC1STR );
  91. static Version V2RC2 = new Version( V2RC2STR );
  92. static Version V2RTM = new Version( V2RTMSTR );
  93. [ StructLayout( LayoutKind.Sequential ) ]
  94. internal class SECURITY_ATTRIBUTES
  95. {
  96. public int nLength;
  97. public object lpSecurityDescriptor;
  98. public bool bInheritHandle;
  99. public SECURITY_ATTRIBUTES()
  100. {
  101. nLength = Marshal.SizeOf( typeof( SECURITY_ATTRIBUTES ) );
  102. lpSecurityDescriptor = null;
  103. bInheritHandle = false;
  104. }
  105. }
  106. internal enum SystemErrorCodes
  107. {
  108. ERROR_SUCCESS = 0,
  109. ERROR_ALREADY_EXISTS = 183
  110. }
  111. //
  112. // TODO add more values as we need them
  113. //
  114. internal enum FileHandleValues
  115. {
  116. INVALID_HANDLE_VALUE = -1
  117. }
  118. //
  119. // TODO add more values as we need them
  120. //
  121. internal enum SharedFileProtection : byte
  122. {
  123. PAGE_READONLY = 0x02
  124. }
  125. internal class SharedMemory
  126. {
  127. int hSharedMemory;
  128. const int INVALID_HANDLE_VALUE = -1;
  129. public bool Create( string name )
  130. {
  131. hSharedMemory = -1;
  132. bool success = false;
  133. try
  134. {
  135. SECURITY_ATTRIBUTES securityAttributes = new SECURITY_ATTRIBUTES();
  136. hSharedMemory = CreateFileMapping( ( int )FileHandleValues.INVALID_HANDLE_VALUE,
  137. securityAttributes,
  138. ( int )SharedFileProtection.PAGE_READONLY,
  139. 0,
  140. 1,
  141. name );
  142. if( ( int )SystemErrorCodes.ERROR_SUCCESS == GetLastError() )
  143. {
  144. success = true;
  145. }
  146. }
  147. catch
  148. {
  149. if( -1 != hSharedMemory )
  150. {
  151. CloseHandle( hSharedMemory );
  152. }
  153. }
  154. return success;
  155. }
  156. public void Release()
  157. {
  158. if( -1 != hSharedMemory )
  159. {
  160. CloseHandle( hSharedMemory );
  161. }
  162. }
  163. [DllImport( "user32.dll", CharSet=CharSet.Auto )]
  164. private static extern int MessageBox(int hWnd, String text, String caption, uint type);
  165. [DllImport( "kernel32.dll", SetLastError=true )]
  166. private static extern int CreateFileMapping( int hFile,
  167. SECURITY_ATTRIBUTES lpAttributes,
  168. int flProtect,
  169. int dwMaximumSizeHigh,
  170. int dwMaximumSizeLow,
  171. string lpName );
  172. [DllImport( "kernel32.dll" )]
  173. private static extern bool CloseHandle( int hObject );
  174. [DllImport( "kernel32.dll" )]
  175. private static extern int GetLastError();
  176. }
  177. static int Main( string[] args )
  178. {
  179. int retcode = 0;
  180. //
  181. // Use shared memory to make sure that only 1 instance of this process is running. sharedMemory.Release() MUST
  182. // be called when this process exits in order to free up the shared memory.
  183. //
  184. SharedMemory sharedMemory = new SharedMemory();
  185. try
  186. {
  187. Log( "Microsoft (R) UDDI Migrate Utility", LogType.ConsoleOnly );
  188. Log( "Copyright (C) Microsoft Corp. 2002. All rights reserved.\n", LogType.ConsoleOnly );
  189. if( false == sharedMemory.Create( "UDDI_migration_process" ) )
  190. {
  191. Console.WriteLine( "Only 1 instance of this process can be running." );
  192. System.Environment.Exit( 1 );
  193. }
  194. //
  195. // parse command line
  196. //
  197. retcode = ProcessCommandLine( args );
  198. if( Stage == MigrationStage.DisplayUsage )
  199. {
  200. DisplayUsage();
  201. }
  202. else
  203. {
  204. Log( "Starting execution of migrate.exe", LogType.ConsoleAndLog );
  205. //
  206. // Get connection strings from registry
  207. //
  208. GetSettings();
  209. //
  210. // Refresh the config settings
  211. //
  212. Config.Refresh();
  213. switch( Stage )
  214. {
  215. case MigrationStage.SetReaderConnection:
  216. SetReaderConnection();
  217. break;
  218. case MigrationStage.ResetWriter:
  219. CheckDatabaseVersions();
  220. ResetWriter();
  221. break;
  222. case MigrationStage.MigratePublishers:
  223. CheckDatabaseVersions();
  224. MigratePublishers();
  225. break;
  226. case MigrationStage.MigrateBareTModels:
  227. CheckDatabaseVersions();
  228. MigrateBareTModels();
  229. break;
  230. case MigrationStage.BootstrapResources:
  231. CheckDatabaseVersions();
  232. BootstrapResources();
  233. break;
  234. case MigrationStage.MigrateCategorizationSchemes:
  235. CheckDatabaseVersions();
  236. MigrateCategorizationSchemes();
  237. break;
  238. case MigrationStage.MigrateFullTModels:
  239. CheckDatabaseVersions();
  240. MigrateFullTModels();
  241. break;
  242. case MigrationStage.MigrateHiddenTModels:
  243. CheckDatabaseVersions();
  244. MigrateHiddenTModels();
  245. break;
  246. case MigrationStage.MigrateBareBusinessEntities:
  247. CheckDatabaseVersions();
  248. MigrateBareBusinessEntities();
  249. break;
  250. case MigrationStage.MigrateBusinessEntities:
  251. CheckDatabaseVersions();
  252. MigrateBusinessEntities();
  253. break;
  254. case MigrationStage.MigratePublisherAssertions:
  255. CheckDatabaseVersions();
  256. MigratePublisherAssertions();
  257. break;
  258. case MigrationStage.RestoreReaderConnection:
  259. RestoreReaderConnection();
  260. break;
  261. }
  262. }
  263. }
  264. catch ( Exception e )
  265. {
  266. retcode = 1;
  267. Log( "ERROR: " + e.ToString(), LogType.ConsoleAndLog );
  268. }
  269. finally
  270. {
  271. sharedMemory.Release();
  272. }
  273. if( retcode == 0 )
  274. Log( "Migrate.exe terminating normally", LogType.ConsoleAndLog );
  275. else
  276. Log( "Migrate.exe terminating abnormally", LogType.ConsoleAndLog );
  277. Stream.Close();
  278. LogFile.Close();
  279. return retcode;
  280. }
  281. private static int ProcessCommandLine( string [] args )
  282. {
  283. int retcode = 0;
  284. for( int i = 0; i < args.Length; i ++ )
  285. {
  286. if( '-' == args[i][0] || '/' == args[i][0] )
  287. {
  288. string option = args[i].Substring( 1 );
  289. if( "help" == option.ToLower() || "?" == option )
  290. {
  291. Stage = MigrationStage.DisplayUsage;
  292. return 0;
  293. }
  294. else if( "s" == option.ToLower() )
  295. {
  296. i++; // move to the next arg
  297. try
  298. {
  299. Stage = (MigrationStage)Enum.Parse( Stage.GetType(), args[i], true );
  300. }
  301. catch( Exception e )
  302. {
  303. Log ( "ERROR: Invalid migrationstage value: " + e.ToString(), LogType.ConsoleOnly );
  304. return 1;
  305. }
  306. }
  307. else if( "c" == option.ToLower() )
  308. {
  309. i++; // move to the next arg
  310. NewReaderConnectionString = args[i];
  311. }
  312. else if( "v" == option.ToLower() )
  313. {
  314. Verbose = true;
  315. }
  316. else if( "i" == option.ToLower() )
  317. {
  318. Stream.Close();
  319. LogFile.Close();
  320. LogFile = new FileStream( LogFileName, FileMode.Create );
  321. Stream = new StreamWriter( LogFile );
  322. }
  323. else
  324. {
  325. Stage = MigrationStage.DisplayUsage;
  326. return 1;
  327. }
  328. }
  329. }
  330. //
  331. // Check argument dependencies
  332. //
  333. switch( Stage )
  334. {
  335. case MigrationStage.SetReaderConnection:
  336. retcode = ( null == NewReaderConnectionString ? 1 : 0 );
  337. break;
  338. default:
  339. retcode = 0;
  340. break;
  341. }
  342. return retcode;
  343. }
  344. private static void CheckDatabaseVersions()
  345. {
  346. //
  347. // Process Reader Version
  348. //
  349. Version readerversion = GetDbVersion( ReaderConnectionString );
  350. Version writerversion = GetDbVersion( WriterConnectionString );
  351. if( !writerversion.Equals( readerversion ) )
  352. {
  353. Log( "Different database versions detected.", LogType.ConsoleAndLog );
  354. Log( "Writer Database Version: " + writerversion.ToString(), LogType.LogOnly );
  355. switch( writerversion.ToString() )
  356. {
  357. case V2RC1STR:
  358. if( readerversion.Equals( V2RC0 ) )
  359. {
  360. Log( "Upgrading reader to UDDI Database version " + V2RC1.ToString(), LogType.ConsoleAndLog );
  361. ExecuteScript( ReaderConnectionString, UpgradeRc0ToRc1Script );
  362. }
  363. else
  364. {
  365. throw new ApplicationException( "Migrations from a UDDI database version " + readerversion.ToString() + " to a UDDI database version " + writerversion.ToString() + " are not supported by this tool." );
  366. }
  367. break;
  368. case V2RC2STR:
  369. if( readerversion.Equals( V2RC1 ) )
  370. {
  371. Log( "Upgrading reader to UDDI Database version " + V2RC2.ToString(), LogType.ConsoleAndLog );
  372. ExecuteScript( ReaderConnectionString, UpgradeRc1ToRc2Script );
  373. }
  374. else
  375. {
  376. throw new ApplicationException( "Migrations from a UDDI database version " + readerversion.ToString() + " to a UDDI database version " + writerversion.ToString() + " are not supported by this tool." );
  377. }
  378. break;
  379. case V2RTMSTR:
  380. throw new ApplicationException( "Migrations from a UDDI database version " + readerversion.ToString() + " to a UDDI database version " + writerversion.ToString() + " are not yet supported by this tool." );
  381. default:
  382. throw new ApplicationException( "Unknown UDDI Database version encountered: " + writerversion.ToString() );
  383. }
  384. }
  385. }
  386. private static void SetReaderConnection()
  387. {
  388. Log( Separator, LogType.LogOnly );
  389. Log( "Executing Stage: SetReaderConnection", LogType.ConsoleAndLog );
  390. try
  391. {
  392. RegistryKey root = Registry.LocalMachine.OpenSubKey( DatabaseRoot, true );
  393. string oldconnectionstring = root.GetValue( ReaderValueName ).ToString();
  394. root.SetValue( ReaderValueName, NewReaderConnectionString );
  395. Log( "Registry setting changed: " + DatabaseRoot + "\\" + ReaderValueName + " = \"" + NewReaderConnectionString + "\"", LogType.LogOnly );
  396. root.SetValue( OldReaderValueName, oldconnectionstring );
  397. Log( "Registry setting changed: " + DatabaseRoot + "\\" + OldReaderValueName + " = \"" + oldconnectionstring + "\"", LogType.LogOnly );
  398. root.Close();
  399. }
  400. catch ( Exception e )
  401. {
  402. Log( "ERROR: unable to modify registry: " + e.ToString(), LogType.LogOnly );
  403. throw new ApplicationException( "SetReaderConnection failed." );
  404. }
  405. }
  406. private static void ResetWriter()
  407. {
  408. Log( Separator, LogType.LogOnly );
  409. Log( "Executing Stage: ResetWriter", LogType.ConsoleAndLog );
  410. //
  411. // Setup connection to writer
  412. //
  413. SqlConnection connection = new SqlConnection( WriterConnectionString );
  414. connection.Open();
  415. SqlTransaction transaction;
  416. transaction = connection.BeginTransaction();
  417. try
  418. {
  419. //
  420. // Setup command for delete operation
  421. //
  422. string cmdbatch = "";
  423. cmdbatch += "DELETE [UDC_categoryBag_TM] \n";
  424. cmdbatch += "DELETE [UDC_identifierBag_TM] \n";
  425. cmdbatch += "DELETE [UDC_tModelDesc] \n";
  426. cmdbatch += "DELETE [UDC_tModels] \n";
  427. cmdbatch += "DELETE [UDC_instanceDesc] \n";
  428. cmdbatch += "DELETE [UDC_tModelInstances] \n";
  429. cmdbatch += "DELETE [UDC_bindingDesc] \n";
  430. cmdbatch += "DELETE [UDC_bindingTemplates] \n";
  431. cmdbatch += "DELETE [UDC_names_BS] \n";
  432. cmdbatch += "DELETE [UDC_categoryBag_BS] \n";
  433. cmdbatch += "DELETE [UDC_serviceDesc] \n";
  434. cmdbatch += "DELETE [UDC_businessServices] \n";
  435. cmdbatch += "DELETE [UDC_addressLines] \n";
  436. cmdbatch += "DELETE [UDC_addresses] \n";
  437. cmdbatch += "DELETE [UDC_phones] \n";
  438. cmdbatch += "DELETE [UDC_emails] \n";
  439. cmdbatch += "DELETE [UDC_contactDesc] \n";
  440. cmdbatch += "DELETE [UDC_contacts] \n";
  441. cmdbatch += "DELETE [UDC_businessDesc] \n";
  442. cmdbatch += "DELETE [UDC_categoryBag_BE] \n";
  443. cmdbatch += "DELETE [UDC_identifierBag_BE] \n";
  444. cmdbatch += "DELETE [UDC_discoveryURLs] \n";
  445. cmdbatch += "DELETE [UDC_names_BE] \n";
  446. cmdbatch += "DELETE [UDC_assertions_BE] \n";
  447. cmdbatch += "DELETE [UDC_serviceProjections] \n";
  448. cmdbatch += "DELETE [UDT_taxonomyValues] \n";
  449. cmdbatch += "DELETE [UDT_taxonomies] \n";
  450. cmdbatch += "DELETE [UDO_changeLog] \n";
  451. cmdbatch += "DELETE [UDO_queryLog] \n";
  452. cmdbatch += "DELETE [UDO_operatorLog] \n";
  453. cmdbatch += "DELETE \n";
  454. cmdbatch += " [UDO_publishers] \n";
  455. cmdbatch += "WHERE \n";
  456. cmdbatch += " ([PUID] <> '"+ UDDI.Utility.GetDefaultPublisher() + "') \n";
  457. Log( cmdbatch, LogType.LogOnly );
  458. SqlCommand command = new SqlCommand( cmdbatch );
  459. command.Connection = connection;
  460. command.Transaction = transaction;
  461. //
  462. // Execute command
  463. //
  464. command.ExecuteNonQuery();
  465. transaction.Commit();
  466. Log( "Write database has been reset.", LogType.ConsoleAndLog );
  467. }
  468. catch( Exception e )
  469. {
  470. transaction.Rollback();
  471. Log( "ERROR: " + e.ToString(), LogType.ConsoleAndLog );
  472. throw new ApplicationException( "ResetWriter failed." );
  473. }
  474. finally
  475. {
  476. connection.Close();
  477. }
  478. }
  479. private static void MigratePublishers()
  480. {
  481. int count = 0;
  482. Log( Separator, LogType.LogOnly );
  483. Log( "Executing Stage: MigratePublishers", LogType.ConsoleAndLog );
  484. //
  485. // Get a list of publishers
  486. //
  487. SqlConnection readerconnection = new SqlConnection( ReaderConnectionString );
  488. readerconnection.Open();
  489. SqlConnection writerconnection = new SqlConnection( WriterConnectionString );
  490. writerconnection.Open();
  491. SqlTransaction transaction;
  492. transaction = writerconnection.BeginTransaction();
  493. try
  494. {
  495. //
  496. // Setup writer publisher insert statement
  497. //
  498. string writercommandbatch = "";
  499. writercommandbatch += "INSERT [UDO_publishers] ( \n";
  500. writercommandbatch += " [publisherStatusID], \n";
  501. writercommandbatch += " [PUID], \n";
  502. writercommandbatch += " [email], \n";
  503. writercommandbatch += " [name], \n";
  504. writercommandbatch += " [phone], \n";
  505. writercommandbatch += " [isoLangCode], \n";
  506. writercommandbatch += " [tModelLimit], \n";
  507. writercommandbatch += " [businessLimit], \n";
  508. writercommandbatch += " [serviceLimit], \n";
  509. writercommandbatch += " [bindingLimit], \n";
  510. writercommandbatch += " [assertionLimit], \n";
  511. writercommandbatch += " [companyName], \n";
  512. writercommandbatch += " [addressLine1], \n";
  513. writercommandbatch += " [addressLine2], \n";
  514. writercommandbatch += " [mailstop], \n";
  515. writercommandbatch += " [city], \n";
  516. writercommandbatch += " [stateProvince], \n";
  517. writercommandbatch += " [extraProvince], \n";
  518. writercommandbatch += " [country], \n";
  519. writercommandbatch += " [postalCode], \n";
  520. writercommandbatch += " [companyURL], \n";
  521. writercommandbatch += " [companyPhone], \n";
  522. writercommandbatch += " [altPhone], \n";
  523. writercommandbatch += " [backupContact], \n";
  524. writercommandbatch += " [backupEmail], \n";
  525. writercommandbatch += " [description], \n";
  526. writercommandbatch += " [securityToken], \n";
  527. writercommandbatch += " [flag] )\n";
  528. writercommandbatch += "VALUES ( \n";
  529. writercommandbatch += " @publisherStatusID, \n";
  530. writercommandbatch += " @PUID, \n";
  531. writercommandbatch += " @email, \n";
  532. writercommandbatch += " @name, \n";
  533. writercommandbatch += " @phone, \n";
  534. writercommandbatch += " @isoLangCode, \n";
  535. writercommandbatch += " @tModelLimit, \n";
  536. writercommandbatch += " @businessLimit, \n";
  537. writercommandbatch += " @serviceLimit, \n";
  538. writercommandbatch += " @bindingLimit, \n";
  539. writercommandbatch += " @assertionLimit, \n";
  540. writercommandbatch += " @companyName, \n";
  541. writercommandbatch += " @addressLine1, \n";
  542. writercommandbatch += " @addressLine2, \n";
  543. writercommandbatch += " @mailstop, \n";
  544. writercommandbatch += " @city, \n";
  545. writercommandbatch += " @stateProvince, \n";
  546. writercommandbatch += " @extraProvince, \n";
  547. writercommandbatch += " @country, \n";
  548. writercommandbatch += " @postalCode, \n";
  549. writercommandbatch += " @companyURL, \n";
  550. writercommandbatch += " @companyPhone, \n";
  551. writercommandbatch += " @altPhone, \n";
  552. writercommandbatch += " @backupContact, \n";
  553. writercommandbatch += " @backupEmail, \n";
  554. writercommandbatch += " @description, \n";
  555. writercommandbatch += " @securityToken, \n";
  556. writercommandbatch += " @flag )\n";
  557. SqlCommand writercommand = new SqlCommand( writercommandbatch );
  558. writercommand.Parameters.Add( "@publisherStatusID", SqlDbType.TinyInt );
  559. writercommand.Parameters.Add( "@PUID", SqlDbType.NVarChar, 450 );
  560. writercommand.Parameters.Add( "@email", SqlDbType.NVarChar, 450 );
  561. writercommand.Parameters.Add( "@name", SqlDbType.NVarChar, 100 );
  562. writercommand.Parameters.Add( "@phone", SqlDbType.VarChar, 20 );
  563. writercommand.Parameters.Add( "@isoLangCode", SqlDbType.VarChar, 17 );
  564. writercommand.Parameters.Add( "@tModelLimit", SqlDbType.Int );
  565. writercommand.Parameters.Add( "@businessLimit", SqlDbType.Int );
  566. writercommand.Parameters.Add( "@serviceLimit", SqlDbType.Int );
  567. writercommand.Parameters.Add( "@bindingLimit", SqlDbType.Int );
  568. writercommand.Parameters.Add( "@assertionLimit", SqlDbType.Int );
  569. writercommand.Parameters.Add( "@companyName", SqlDbType.NVarChar, 100 );
  570. writercommand.Parameters.Add( "@addressLine1", SqlDbType.NVarChar, 4000 );
  571. writercommand.Parameters.Add( "@addressLine2", SqlDbType.NVarChar, 4000 );
  572. writercommand.Parameters.Add( "@mailstop", SqlDbType.NVarChar, 20 );
  573. writercommand.Parameters.Add( "@city", SqlDbType.NVarChar, 100 );
  574. writercommand.Parameters.Add( "@stateProvince", SqlDbType.NVarChar, 100 );
  575. writercommand.Parameters.Add( "@extraProvince", SqlDbType.NVarChar, 100 );
  576. writercommand.Parameters.Add( "@country", SqlDbType.NVarChar, 100 );
  577. writercommand.Parameters.Add( "@postalCode", SqlDbType.VarChar, 100 );
  578. writercommand.Parameters.Add( "@companyURL", SqlDbType.NVarChar, 512 );
  579. writercommand.Parameters.Add( "@companyPhone", SqlDbType.VarChar, 20 );
  580. writercommand.Parameters.Add( "@altPhone", SqlDbType.VarChar, 20 );
  581. writercommand.Parameters.Add( "@backupContact", SqlDbType.NVarChar, 100 );
  582. writercommand.Parameters.Add( "@backupEmail", SqlDbType.NVarChar, 450 );
  583. writercommand.Parameters.Add( "@description", SqlDbType.NVarChar, 4000 );
  584. writercommand.Parameters.Add( "@securityToken", SqlDbType.UniqueIdentifier );
  585. writercommand.Parameters.Add( "@flag", SqlDbType.Int );
  586. writercommand.Connection = writerconnection;
  587. writercommand.Transaction = transaction;
  588. //
  589. // Execute query against reader and process results
  590. //
  591. SqlDataReader reader;
  592. reader = GetPublisherList( readerconnection );
  593. while( reader.Read() )
  594. {
  595. count++;
  596. //
  597. // Set writer insert parameters using reader result values.
  598. // Note: Assumes reader select and writer insert have identical column lists
  599. //
  600. for( int i = 0; i < writercommand.Parameters.Count; i++ )
  601. {
  602. writercommand.Parameters[ i ].Value = DBNull.Value;
  603. if( !reader.IsDBNull( i ) )
  604. writercommand.Parameters[ i ].Value = reader.GetSqlValue( i );
  605. }
  606. //
  607. // Execute writer insert
  608. //
  609. writercommand.ExecuteNonQuery();
  610. }
  611. reader.Close();
  612. transaction.Commit();
  613. }
  614. catch ( Exception e )
  615. {
  616. transaction.Rollback();
  617. count = 0;
  618. Log( "ERROR: database error: " + e.ToString(), LogType.ConsoleAndLog );
  619. throw new ApplicationException( "MigratePublishers failed." );
  620. }
  621. finally
  622. {
  623. readerconnection.Close();
  624. writerconnection.Close();
  625. Log( count.ToString() + " publishers migrated.", LogType.ConsoleAndLog );
  626. }
  627. }
  628. private static void MigrateBareTModels()
  629. {
  630. int count = 0;
  631. Log( Separator, LogType.LogOnly );
  632. Log( "Executing Stage: MigrateBareTModels", LogType.ConsoleAndLog );
  633. //
  634. // Open a separate connection to reader
  635. //
  636. SqlConnection connection = new SqlConnection( ReaderConnectionString );
  637. connection.Open();
  638. try
  639. {
  640. //
  641. // Get a list of tModels hosted by Microsoft on reader
  642. //
  643. SqlDataReader reader = GetCompleteTModelList( connection );
  644. //
  645. // Loop through each tModel in the result set
  646. //
  647. //string operatorkey = "";
  648. while( reader.Read() )
  649. {
  650. TModel tmodel = new TModel();
  651. //
  652. // Set identity
  653. //
  654. Context.User.ID = reader.IsDBNull( 1 ) ? null : reader.GetString( 1 );
  655. Context.User.SetPublisherRole( Context.User.ID );
  656. //
  657. // Get tModel from reader
  658. //
  659. tmodel.TModelKey = "uuid:" + ( reader.IsDBNull( 0 ) ? "" : reader.GetGuid( 0 ).ToString() );
  660. ConnectionManager.Open( false, false );
  661. tmodel.Get();
  662. ConnectionManager.Close();
  663. //
  664. // Remove identifier and categoryBags
  665. //
  666. if( tmodel.IdentifierBag.Count > 0 )
  667. {
  668. tmodel.IdentifierBag.Clear();
  669. Log( "Cleared identifierBag for tModelKey = " + tmodel.TModelKey, LogType.LogOnly );
  670. }
  671. if( tmodel.CategoryBag.Count > 0 )
  672. {
  673. tmodel.CategoryBag.Clear();
  674. Log( "Cleared categoryBag for tModelKey = " + tmodel.TModelKey, LogType.LogOnly );
  675. }
  676. //
  677. // Set authorizedName to null
  678. //
  679. tmodel.AuthorizedName = null;
  680. //
  681. // Open writer connection
  682. //
  683. ConnectionManager.Open( true, true );
  684. if( Context.User.ID != UDDI.Utility.GetDefaultPublisher() )
  685. Context.User.SetAllowPreassignedKeys( true );
  686. //
  687. // Save the bare tModel to the writer
  688. //
  689. Log( "save_tModel: tModelKey = " + tmodel.TModelKey + "; name = " + tmodel.Name + "; puid = " + Context.User.ID, LogType.LogOnly );
  690. tmodel.Save();
  691. count++;
  692. //
  693. // Note that transaction only spans single save_tModel and operator insert/delete due to connecton manager limitations
  694. //
  695. ConnectionManager.Commit();
  696. ConnectionManager.Close();
  697. }
  698. reader.Close();
  699. }
  700. catch ( Exception e )
  701. {
  702. Log( "ERROR: " + e.ToString(), LogType.ConsoleAndLog );
  703. throw new ApplicationException( "MigrateBareTModels failed." );
  704. }
  705. finally
  706. {
  707. connection.Close();
  708. ConnectionManager.Close();
  709. Log( count.ToString() + " bare tModels migrated.", LogType.ConsoleAndLog );
  710. }
  711. }
  712. private static void BootstrapResources()
  713. {
  714. int count=0;
  715. Log( Separator, LogType.LogOnly );
  716. Log( "Executing Stage: BootstrapResources", LogType.ConsoleAndLog );
  717. try
  718. {
  719. //
  720. // load all the bootstrap files found in the \uddi\bootstrap folder
  721. //
  722. string targetDir = Registry.LocalMachine.OpenSubKey( @"SOFTWARE\Microsoft\UDDI" ).GetValue( "InstallRoot" ).ToString();
  723. string bootstrapdir = CheckForSlash(targetDir) + "bootstrap";
  724. string bootstrapexe = CheckForSlash(targetDir) + @"bin\bootstrap.exe";
  725. Log( "Getting list of bootstrap files from directory '" + bootstrapdir + "'", LogType.LogOnly );
  726. string[] filepaths = Directory.GetFiles( bootstrapdir, "*.xml" );
  727. Log( "Writing " + filepaths.Length + " baseline resources to database.", LogType.ConsoleAndLog );
  728. foreach( string filepath in filepaths )
  729. {
  730. Log( "Importing bootstrap data from: " + filepath, LogType.ConsoleAndLog );
  731. ProcessStartInfo startInfo = new ProcessStartInfo( bootstrapexe, "/f \""+ filepath + "\"");
  732. startInfo.CreateNoWindow = true;
  733. startInfo.UseShellExecute = false;
  734. startInfo.RedirectStandardOutput = true;
  735. Process p = new Process();
  736. p = Process.Start( startInfo );
  737. //
  738. // grab the stdout string
  739. //
  740. string bootstrapOutput = p.StandardOutput.ReadToEnd();
  741. //
  742. // wait for bootstrap.exe to complete
  743. //
  744. p.WaitForExit();
  745. //
  746. // write the stdout string to the log
  747. //
  748. Log( bootstrapOutput, LogType.LogOnly );
  749. if( p.ExitCode != 0 )
  750. {
  751. throw new ApplicationException( "BootstrapResources failed." );
  752. }
  753. count++;
  754. }
  755. }
  756. catch( Exception e )
  757. {
  758. DispositionReport.Throw( e );
  759. Log( "ERROR: " + e.ToString(), LogType.ConsoleAndLog );
  760. throw new ApplicationException( "BootstrapResources failed." );
  761. }
  762. finally
  763. {
  764. Log( count.ToString() + " resource files bootstrapped.", LogType.ConsoleAndLog );
  765. }
  766. }
  767. private static void MigrateCategorizationSchemes()
  768. {
  769. int count = 0;
  770. Log( Separator, LogType.LogOnly );
  771. Log( "Executing Stage: MigrateCategorizationSchemes", LogType.ConsoleAndLog );
  772. //
  773. // Check database version compatibility
  774. //
  775. Version writerversion = GetDbVersion( WriterConnectionString );
  776. if ( writerversion.CompareTo( V2RC2 ) < 0 )
  777. {
  778. throw new ApplicationException( "The MigrateCategorizationSchemes migration stage is only supported for UDDI Services database versions " + V2RC2.ToString() + " or later. Your current database version is: " + writerversion.ToString() );
  779. }
  780. //
  781. // Open a separate connection to reader
  782. //
  783. SqlConnection connection = new SqlConnection( ReaderConnectionString );
  784. connection.Open();
  785. try
  786. {
  787. //
  788. // Get a list of taxonomies
  789. //
  790. SqlDataReader reader = GetTaxonomyList( connection );
  791. //
  792. // Loop through each taxonomy in the result set
  793. //
  794. while( reader.Read() )
  795. {
  796. //
  797. // Check to see if taxonomy is a user-defined taxonomy
  798. // Note: a user-defined taxonomy is any taxonomy that does not exist in a newly bootstrapped uddi database
  799. //
  800. if( !CategorizationSchemeExists( reader.IsDBNull( 0 ) ? null : reader.GetGuid( 0 ).ToString() ) )
  801. {
  802. CategorizationScheme scheme = new CategorizationScheme();
  803. //
  804. // Set identity to system since categorization schemes are not publications
  805. //
  806. Context.User.ID = UDDI.Utility.GetDefaultPublisher();
  807. Context.User.SetPublisherRole( Context.User.ID );
  808. //
  809. // Get categorization scheme from reader
  810. //
  811. scheme.TModelKey = "uuid:" + ( reader.IsDBNull( 0 ) ? "" : reader.GetGuid( 0 ).ToString() );
  812. ConnectionManager.Open( false, false );
  813. scheme.Get();
  814. ConnectionManager.Close();
  815. //
  816. // Save the categorization scheme to writer
  817. //
  818. ConnectionManager.Open( true, true );
  819. Log( "CategorizationScheme.Save(): tModelKey = " + scheme.TModelKey + "; puid = " + Context.User.ID + "; value count = " + scheme.CategoryValues.Count.ToString(), LogType.LogOnly );
  820. scheme.Save();
  821. count++;
  822. //
  823. // Note that transaction only spans single tmodel due to connecton manager limitations
  824. //
  825. ConnectionManager.Commit();
  826. ConnectionManager.Close();
  827. scheme = new CategorizationScheme();
  828. }
  829. }
  830. reader.Close();
  831. }
  832. catch ( Exception e )
  833. {
  834. Log( "ERROR: " + e.ToString(), LogType.ConsoleAndLog );
  835. throw new ApplicationException( "MigrateCategorizationSchemes failed." );
  836. }
  837. finally
  838. {
  839. connection.Close();
  840. ConnectionManager.Close();
  841. Log( count.ToString() + " categorization schemes migrated.", LogType.ConsoleAndLog );
  842. }
  843. }
  844. private static void MigrateFullTModels()
  845. {
  846. int count = 0;
  847. Log( Separator, LogType.LogOnly );
  848. Log( "Executing Stage: MigrateFullTModels", LogType.ConsoleAndLog );
  849. //
  850. // Open a separate connection to reader
  851. //
  852. SqlConnection connection = new SqlConnection( ReaderConnectionString );
  853. connection.Open();
  854. try
  855. {
  856. //
  857. // Get a list of tModels hosted by Micrsoft
  858. //
  859. SqlDataReader reader = GetCompleteTModelList( connection );
  860. //
  861. // Loop through each tModel in the result set
  862. //
  863. TModel tmodel = new TModel();
  864. while( reader.Read() )
  865. {
  866. count++;
  867. //
  868. // Set identity
  869. //
  870. Context.User.ID = reader.IsDBNull( 1 ) ? null : reader.GetString( 1 );
  871. Context.User.SetPublisherRole( Context.User.ID );
  872. string email = reader.IsDBNull( 2 ) ? null : reader.GetString( 2 );
  873. //
  874. // Get tModel from reader
  875. //
  876. string tmodelkey = reader.IsDBNull( 0 ) ? null : reader.GetGuid( 0 ).ToString();
  877. tmodel.TModelKey = "uuid:" + tmodelkey;
  878. ConnectionManager.Open( false, false );
  879. tmodel.Get();
  880. ConnectionManager.Close();
  881. //
  882. // Fix 1.0 bugs if any
  883. //
  884. FixTModel( tmodel, email );
  885. //
  886. // Set authorizedName to null
  887. //
  888. tmodel.AuthorizedName = null;
  889. //
  890. // Save tModel on writer
  891. //
  892. ConnectionManager.Open( true, true );
  893. Log( "save_tModel: tModelKey = " + tmodel.TModelKey + "; name = " + tmodel.Name + "; puid = " + Context.User.ID, LogType.LogOnly );
  894. tmodel.Save();
  895. //
  896. // Note that transaction only spans single tmodel due to connecton manager limitations
  897. //
  898. ConnectionManager.Commit();
  899. ConnectionManager.Close();
  900. tmodel = new TModel();
  901. }
  902. reader.Close();
  903. }
  904. catch ( Exception e )
  905. {
  906. Log( "ERROR: " + e.ToString(), LogType.ConsoleAndLog );
  907. throw new ApplicationException( "MigrateFullTModels failed." );
  908. }
  909. finally
  910. {
  911. connection.Close();
  912. ConnectionManager.Close();
  913. Log( count.ToString() + " full tModels migrated.", LogType.ConsoleAndLog );
  914. }
  915. }
  916. private static void MigrateHiddenTModels()
  917. {
  918. int count = 0;
  919. Log( Separator, LogType.LogOnly );
  920. Log( "Executing stage: MigrateHiddenTModels", LogType.ConsoleAndLog );
  921. //
  922. // Open a separate connection to reader
  923. //
  924. SqlConnection connection = new SqlConnection( ReaderConnectionString );
  925. connection.Open();
  926. //
  927. // Open writer connection
  928. //
  929. ConnectionManager.Open( true, true );
  930. try
  931. {
  932. //
  933. // Get a list of hidden tModels hosted by Microsoft from reader
  934. //
  935. SqlDataReader reader = GetHiddenTModelList( connection );
  936. //
  937. // Loop through each tModel in the result set
  938. //
  939. while( reader.Read() )
  940. {
  941. TModel tmodel = new TModel();
  942. count++;
  943. //
  944. // Set identity
  945. //
  946. Context.User.ID = reader.IsDBNull( 1 ) ? null : reader.GetString( 1 );
  947. Context.User.SetPublisherRole( Context.User.ID );
  948. //
  949. // Delete the tModel on the writer connection
  950. //
  951. tmodel.TModelKey = "uuid:" + ( reader.IsDBNull( 0 ) ? "" : reader.GetGuid( 0 ).ToString() );
  952. Log( "delete_tModel: tModelKey = " + tmodel.TModelKey + "; puid = " + Context.User.ID, LogType.LogOnly );
  953. tmodel.Delete();
  954. }
  955. reader.Close();
  956. ConnectionManager.Commit();
  957. }
  958. catch ( Exception e )
  959. {
  960. ConnectionManager.Abort();
  961. count = 0;
  962. Log( "ERROR: " + e.ToString(), LogType.ConsoleAndLog );
  963. throw new ApplicationException( "MigrateHiddenTModels failed." );
  964. }
  965. finally
  966. {
  967. connection.Close();
  968. ConnectionManager.Close();
  969. Log( count.ToString() + " hidden tModels migrated.", LogType.ConsoleAndLog );
  970. }
  971. }
  972. private static void MigrateBareBusinessEntities()
  973. {
  974. int count = 0;
  975. Log( Separator, LogType.LogOnly );
  976. Log( "Executing stage: MigrateBareBusinessEntities", LogType.ConsoleAndLog );
  977. //
  978. // Open a separate connection to reader
  979. //
  980. SqlConnection connection = new SqlConnection( ReaderConnectionString );
  981. connection.Open();
  982. try
  983. {
  984. //
  985. // Get a list of businessEntities hosted by Microsoft on reader
  986. //
  987. SqlDataReader reader = GetBusinessEntityList( connection );
  988. //
  989. // Loop through each businessEntity in the result set
  990. //
  991. while( reader.Read() )
  992. {
  993. BusinessEntity businessentity = new BusinessEntity();
  994. count++;
  995. //
  996. // Set identity
  997. //
  998. Context.User.ID = reader.IsDBNull( 1 ) ? null : reader.GetString( 1 );
  999. Context.User.SetPublisherRole( Context.User.ID );
  1000. string email = reader.IsDBNull( 2 ) ? null : reader.GetString( 2 );
  1001. //
  1002. // Get businessEntity from reader
  1003. //
  1004. businessentity.BusinessKey = reader.IsDBNull( 0 ) ? null : reader.GetGuid( 0 ).ToString();
  1005. ConnectionManager.Open( false, false );
  1006. businessentity.Get();
  1007. ConnectionManager.Close();
  1008. //
  1009. // Remove all keyedReferences from businessEntity
  1010. //
  1011. if( 0 < businessentity.CategoryBag.Count )
  1012. {
  1013. businessentity.CategoryBag.Clear();
  1014. Log( "Cleared categoryBag for businessEntity. businessKey = " + businessentity.BusinessKey, LogType.LogOnly );
  1015. }
  1016. if( 0 < businessentity.IdentifierBag.Count )
  1017. {
  1018. businessentity.IdentifierBag.Clear();
  1019. Log( "Cleared identifierBag for businessEntity. businessKey = " + businessentity.BusinessKey, LogType.LogOnly );
  1020. }
  1021. foreach( BusinessService bs in businessentity.BusinessServices )
  1022. {
  1023. //
  1024. // Remove all keyedReferences from businessService
  1025. //
  1026. if( 0 < bs.CategoryBag.Count )
  1027. {
  1028. bs.CategoryBag.Clear();
  1029. Log( "Cleared categoryBag for businessService. serviceKey = " + bs.ServiceKey, LogType.LogOnly );
  1030. }
  1031. foreach( BindingTemplate bt in bs.BindingTemplates )
  1032. {
  1033. //
  1034. // Clear hostingRedirector from bindingTemplate. Save key in accessPoint
  1035. //
  1036. if( null != bt.HostingRedirector.BindingKey )
  1037. {
  1038. bt.AccessPoint.Value = bt.HostingRedirector.BindingKey;
  1039. bt.HostingRedirector.BindingKey = null;
  1040. Log( "Cleared hostingRedirector for bindingTemplate. bindingKey = " + bt.BindingKey, LogType.LogOnly );
  1041. }
  1042. }
  1043. }
  1044. //
  1045. // Correct v1.0 bugs if any
  1046. //
  1047. FixBusiness( businessentity, email, false );
  1048. //
  1049. // Set authorizedName to null
  1050. //
  1051. businessentity.AuthorizedName = null;
  1052. //
  1053. // Open writer connection
  1054. //
  1055. ConnectionManager.Open( true, true );
  1056. if( Context.User.ID != UDDI.Utility.GetDefaultPublisher() )
  1057. Context.User.SetAllowPreassignedKeys( true );
  1058. //
  1059. // Save the businessEntity on the writer
  1060. //
  1061. Log( "save_business: businessKey = " + businessentity.BusinessKey + "; name = " + businessentity.Names[ 0 ].Value + "; puid = " + Context.User.ID, LogType.LogOnly );
  1062. businessentity.Save();
  1063. //
  1064. // Note that transaction only spans single save_tModel and operator insert/delete due to connecton manager limitations
  1065. //
  1066. ConnectionManager.Commit();
  1067. ConnectionManager.Close();
  1068. }
  1069. reader.Close();
  1070. }
  1071. catch ( Exception e )
  1072. {
  1073. Log( "ERROR: " + e.ToString(), LogType.ConsoleAndLog );
  1074. throw new ApplicationException( "MigrateBareBusinessEntities failed." );
  1075. }
  1076. finally
  1077. {
  1078. connection.Close();
  1079. ConnectionManager.Close();
  1080. Log( count.ToString() + " bare businessEntities migrated.", LogType.ConsoleAndLog );
  1081. }
  1082. }
  1083. private static void MigrateBusinessEntities()
  1084. {
  1085. int count = 0;
  1086. Log( Separator, LogType.LogOnly );
  1087. Log( "Executing stage: MigrateBusinessEntities", LogType.ConsoleAndLog );
  1088. //
  1089. // Open a separate connection to reader
  1090. //
  1091. SqlConnection connection = new SqlConnection( ReaderConnectionString );
  1092. connection.Open();
  1093. try
  1094. {
  1095. //
  1096. // Get a list of businessEntities hosted by Microsoft on reader
  1097. //
  1098. SqlDataReader reader = GetBusinessEntityList( connection );
  1099. //
  1100. // Loop through each businessEntity in the result set
  1101. //
  1102. while( reader.Read() )
  1103. {
  1104. BusinessEntity businessentity = new BusinessEntity();
  1105. count++;
  1106. //
  1107. // Set identity
  1108. //
  1109. Context.User.ID = reader.IsDBNull( 1 ) ? null : reader.GetString( 1 );
  1110. Context.User.SetPublisherRole( Context.User.ID );
  1111. string email = reader.IsDBNull( 2 ) ? null : reader.GetString( 2 );
  1112. //
  1113. // Get businessEntity from reader
  1114. //
  1115. businessentity.BusinessKey = reader.IsDBNull( 0 ) ? null : reader.GetGuid( 0 ).ToString();
  1116. ConnectionManager.Open( false, false );
  1117. businessentity.Get();
  1118. ConnectionManager.Close();
  1119. //
  1120. // Correct v1.0 bugs if any
  1121. //
  1122. FixBusiness( businessentity, email, true );
  1123. //
  1124. // Set authorizedName to null
  1125. //
  1126. businessentity.AuthorizedName = null;
  1127. //
  1128. // Open writer connection
  1129. //
  1130. ConnectionManager.Open( true, true );
  1131. if( Context.User.ID != UDDI.Utility.GetDefaultPublisher() )
  1132. Context.User.SetAllowPreassignedKeys( true );
  1133. //
  1134. // Save the businessEntity on the writer
  1135. //
  1136. Log( "save_business: businessKey = " + businessentity.BusinessKey + "; name = " + businessentity.Names[ 0 ].Value + "; puid = " + Context.User.ID, LogType.LogOnly );
  1137. businessentity.Save();
  1138. //
  1139. // Note that transaction only spans single save_tModel and operator insert/delete due to connecton manager limitations
  1140. //
  1141. ConnectionManager.Commit();
  1142. ConnectionManager.Close();
  1143. }
  1144. reader.Close();
  1145. }
  1146. catch ( Exception e )
  1147. {
  1148. Log( "ERROR: " + e.ToString(), LogType.ConsoleAndLog );
  1149. throw new ApplicationException( "MigrateBusinessEntities failed." );
  1150. }
  1151. finally
  1152. {
  1153. connection.Close();
  1154. ConnectionManager.Close();
  1155. Log( count.ToString() + " businessEntities migrated.", LogType.ConsoleAndLog );
  1156. }
  1157. }
  1158. private static void MigratePublisherAssertions()
  1159. {
  1160. int publishercount = 0;
  1161. int assertioncount = 0;
  1162. Log( Separator, LogType.LogOnly );
  1163. Log( "Executing stage: MigratePublisherAssertions", LogType.ConsoleAndLog );
  1164. //
  1165. // Open a separate connection to reader
  1166. //
  1167. SqlConnection connection = new SqlConnection( ReaderConnectionString );
  1168. connection.Open();
  1169. try
  1170. {
  1171. //
  1172. // Get a list of publishers on the reader
  1173. //
  1174. SqlDataReader reader = GetPublisherList( connection );
  1175. //
  1176. // Loop through each publisher in the result set
  1177. //
  1178. while( reader.Read() )
  1179. {
  1180. PublisherAssertionCollection assertions = new PublisherAssertionCollection();
  1181. //
  1182. // Set identity
  1183. //
  1184. Context.User.ID = reader.IsDBNull( 1 ) ? null : reader.GetString( 1 );
  1185. Context.User.SetPublisherRole( Context.User.ID );
  1186. //
  1187. // Get assertions
  1188. //
  1189. ConnectionManager.Open( false, false );
  1190. assertions.Get();
  1191. ConnectionManager.Close();
  1192. //
  1193. // Open writer connection
  1194. //
  1195. if( 0 < assertions.Count )
  1196. {
  1197. ConnectionManager.Open( true, true );
  1198. //
  1199. // Save the assertions on the writer
  1200. //
  1201. Log( "set_publisherAssertions: puid = " + Context.User.ID + "; count = " + assertions.Count.ToString(), LogType.LogOnly );
  1202. assertions.Save();
  1203. publishercount++;
  1204. assertioncount = assertioncount + assertions.Count;
  1205. //
  1206. // Note that transaction only spans single set_publisherAssertions due to connecton manager limitations
  1207. //
  1208. ConnectionManager.Commit();
  1209. ConnectionManager.Close();
  1210. }
  1211. }
  1212. reader.Close();
  1213. }
  1214. catch ( Exception e )
  1215. {
  1216. Log( "ERROR: " + e.ToString(), LogType.ConsoleAndLog );
  1217. throw new ApplicationException( "MigratePublisherAssertions failed." );
  1218. }
  1219. finally
  1220. {
  1221. connection.Close();
  1222. ConnectionManager.Close();
  1223. Log( assertioncount.ToString() + " assertions migrated for " + publishercount.ToString() + " publishers.", LogType.ConsoleAndLog );
  1224. }
  1225. }
  1226. private static void RestoreReaderConnection()
  1227. {
  1228. Log( Separator, LogType.LogOnly );
  1229. Log( "Executing stage: RestoreReaderConnection", LogType.ConsoleAndLog );
  1230. try
  1231. {
  1232. RegistryKey root = Registry.LocalMachine.OpenSubKey( DatabaseRoot, true );
  1233. if( null != root.GetValue( OldReaderValueName ) )
  1234. {
  1235. string oldreaderconnectionstring = root.GetValue( OldReaderValueName ).ToString();
  1236. root.SetValue( ReaderValueName, oldreaderconnectionstring );
  1237. Log( "Registry Setting Changed: " + DatabaseRoot + "\\" + ReaderValueName + " = \"" + oldreaderconnectionstring + "\"", LogType.LogOnly );
  1238. root.DeleteValue( OldReaderValueName, true );
  1239. Log( "Deleted Registry Value: " + DatabaseRoot + "\\" + OldReaderValueName, LogType.LogOnly );
  1240. root.Close();
  1241. }
  1242. }
  1243. catch ( Exception e )
  1244. {
  1245. Log( "ERROR:" + e.ToString(), LogType.ConsoleAndLog );
  1246. throw new ApplicationException( "RestoreReaderConnection failed." );
  1247. }
  1248. }
  1249. private static void GetSettings()
  1250. {
  1251. try
  1252. {
  1253. RegistryKey dbsetuproot = Registry.LocalMachine.OpenSubKey( DatabaseSetupRoot );
  1254. if( null == dbsetuproot )
  1255. {
  1256. throw new ApplicationException( "The UDDI Services Database Components are not installed on this machine." );
  1257. }
  1258. dbsetuproot.Close();
  1259. RegistryKey dbroot = Registry.LocalMachine.OpenSubKey( DatabaseRoot, true );
  1260. if( null == dbroot )
  1261. {
  1262. throw new ApplicationException( "Unable to open registry key: " + DatabaseRoot );
  1263. }
  1264. ReaderConnectionString = dbroot.GetValue( ReaderValueName ).ToString();
  1265. WriterConnectionString = dbroot.GetValue( WriterValueName ).ToString();
  1266. dbroot.Close();
  1267. }
  1268. catch ( Exception e )
  1269. {
  1270. Log( "ERROR:" + e.ToString(), LogType.ConsoleAndLog );
  1271. throw new ApplicationException( "GetSettings failed." );
  1272. }
  1273. }
  1274. private static SqlDataReader GetPublisherList( SqlConnection connection )
  1275. {
  1276. string cmdbatch = "";
  1277. cmdbatch += "SELECT \n";
  1278. cmdbatch += " [publisherStatusID], \n";
  1279. cmdbatch += " [PUID], \n";
  1280. cmdbatch += " [email], \n";
  1281. cmdbatch += " [name], \n";
  1282. cmdbatch += " [phone], \n";
  1283. cmdbatch += " [isoLangCode], \n";
  1284. cmdbatch += " [tModelLimit], \n";
  1285. cmdbatch += " [businessLimit], \n";
  1286. cmdbatch += " [serviceLimit], \n";
  1287. cmdbatch += " [bindingLimit], \n";
  1288. cmdbatch += " [assertionLimit], \n";
  1289. cmdbatch += " [companyName], \n";
  1290. cmdbatch += " [addressLine1], \n";
  1291. cmdbatch += " [addressLine2], \n";
  1292. cmdbatch += " [mailstop], \n";
  1293. cmdbatch += " [city], \n";
  1294. cmdbatch += " [stateProvince], \n";
  1295. cmdbatch += " [extraProvince], \n";
  1296. cmdbatch += " [country], \n";
  1297. cmdbatch += " [postalCode], \n";
  1298. cmdbatch += " [companyURL], \n";
  1299. cmdbatch += " [companyPhone], \n";
  1300. cmdbatch += " [altPhone], \n";
  1301. cmdbatch += " [backupContact], \n";
  1302. cmdbatch += " [backupEmail], \n";
  1303. cmdbatch += " [description], \n";
  1304. cmdbatch += " [securityToken], \n";
  1305. cmdbatch += " [flag] \n";
  1306. cmdbatch += "FROM \n";
  1307. cmdbatch += " [UDO_publishers] \n";
  1308. cmdbatch += "WHERE \n";
  1309. cmdbatch += " ([publisherID] NOT IN (SELECT [publisherID] FROM [UDO_operators])) \n";
  1310. cmdbatch += "ORDER BY \n";
  1311. cmdbatch += " [publisherID] ASC \n";
  1312. SqlCommand command = new SqlCommand( cmdbatch );
  1313. command.Connection = connection;
  1314. SqlDataReader reader;
  1315. try
  1316. {
  1317. reader = command.ExecuteReader();
  1318. }
  1319. catch ( Exception e )
  1320. {
  1321. Log( "ERROR: " + e.ToString(), LogType.ConsoleAndLog );
  1322. throw new ApplicationException( "GetPublisherList failed." );
  1323. }
  1324. return reader;
  1325. }
  1326. private static SqlDataReader GetCompleteTModelList( SqlConnection connection )
  1327. {
  1328. string cmdbatch = "";
  1329. cmdbatch += "SELECT \n";
  1330. cmdbatch += " TM.[tModelKey], \n";
  1331. cmdbatch += " PU.[PUID], \n";
  1332. cmdbatch += " PU.[email] \n";
  1333. cmdbatch += "FROM \n";
  1334. cmdbatch += " [UDC_tModels] TM \n";
  1335. cmdbatch += " JOIN [UDO_publishers] PU ON TM.[publisherID] = PU.[publisherID] \n";
  1336. cmdbatch += "ORDER BY \n";
  1337. cmdbatch += " [tModelID] ASC \n";
  1338. SqlCommand command = new SqlCommand( cmdbatch );
  1339. command.Connection = connection;
  1340. SqlDataReader reader;
  1341. try
  1342. {
  1343. reader = command.ExecuteReader();
  1344. }
  1345. catch( Exception e )
  1346. {
  1347. Log( "ERROR: " + e.ToString(), LogType.ConsoleAndLog );
  1348. throw new ApplicationException( "GetCompleteTModelList failed." );
  1349. }
  1350. return reader;
  1351. }
  1352. private static SqlDataReader GetHiddenTModelList( SqlConnection connection )
  1353. {
  1354. string cmdbatch = "";
  1355. cmdbatch += "SELECT \n";
  1356. cmdbatch += " TM.[tModelKey], \n";
  1357. cmdbatch += " PU.[PUID], \n";
  1358. cmdbatch += " PU.[email] \n";
  1359. cmdbatch += "FROM \n";
  1360. cmdbatch += " [UDC_tModels] TM \n";
  1361. cmdbatch += " JOIN [UDO_publishers] PU ON TM.[publisherID] = PU.[publisherID] \n";
  1362. cmdbatch += "WHERE \n";
  1363. cmdbatch += " ( TM.[flag] = 1 ) \n";
  1364. cmdbatch += "ORDER BY \n";
  1365. cmdbatch += " [tModelID] ASC \n";
  1366. SqlCommand command = new SqlCommand( cmdbatch );
  1367. command.Connection = connection;
  1368. SqlDataReader reader;
  1369. try
  1370. {
  1371. reader = command.ExecuteReader();
  1372. }
  1373. catch( Exception e )
  1374. {
  1375. Log( "ERROR: " + e.ToString(), LogType.ConsoleAndLog );
  1376. throw new ApplicationException( "GetCompleteTModelList failed." );
  1377. }
  1378. return reader;
  1379. }
  1380. private static SqlDataReader GetBusinessEntityList( SqlConnection connection )
  1381. {
  1382. string cmdbatch = "";
  1383. cmdbatch += "SELECT \n";
  1384. cmdbatch += " BE.[businessKey], \n";
  1385. cmdbatch += " PU.[PUID], \n";
  1386. cmdbatch += " PU.[email] \n";
  1387. cmdbatch += "FROM \n";
  1388. cmdbatch += " [UDC_businessEntities] BE \n";
  1389. cmdbatch += " JOIN [UDO_publishers] PU ON BE.[publisherID] = PU.[publisherID] \n";
  1390. cmdbatch += "ORDER BY \n";
  1391. cmdbatch += " [businessID] ASC \n";
  1392. SqlCommand command = new SqlCommand( cmdbatch );
  1393. command.Connection = connection;
  1394. SqlDataReader reader;
  1395. try
  1396. {
  1397. reader = command.ExecuteReader();
  1398. }
  1399. catch( Exception e )
  1400. {
  1401. Log( "ERROR: " + e.ToString(), LogType.ConsoleAndLog );
  1402. throw new ApplicationException( "GetBusinessEntityList failed." );
  1403. }
  1404. return reader;
  1405. }
  1406. private static SqlDataReader GetTaxonomyList( SqlConnection connection )
  1407. {
  1408. string cmdbatch = "";
  1409. cmdbatch += "SELECT \n";
  1410. cmdbatch += " [tModelKey], \n";
  1411. cmdbatch += " [flag] \n";
  1412. cmdbatch += "FROM \n";
  1413. cmdbatch += " [UDT_taxonomies] \n";
  1414. cmdbatch += "ORDER BY \n";
  1415. cmdbatch += " [taxonomyID] ASC \n";
  1416. SqlCommand command = new SqlCommand( cmdbatch );
  1417. command.Connection = connection;
  1418. SqlDataReader reader;
  1419. try
  1420. {
  1421. reader = command.ExecuteReader();
  1422. }
  1423. catch( Exception e )
  1424. {
  1425. Log( "ERROR: " + e.ToString(), LogType.ConsoleAndLog );
  1426. throw new ApplicationException( "GetCompleteTModelList failed." );
  1427. }
  1428. return reader;
  1429. }
  1430. private static bool CategorizationSchemeExists( string tmodelkey )
  1431. {
  1432. bool bExists = false;
  1433. ConnectionManager.Open( true, false );
  1434. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor( "net_taxonomy_get" );
  1435. sp.Parameters.Add( "@tModelKey", SqlDbType.UniqueIdentifier );
  1436. sp.Parameters.Add( "@flag", SqlDbType.Int, ParameterDirection.InputOutput );
  1437. sp.Parameters.SetGuidFromString( "@tModelKey", tmodelkey );
  1438. sp.Parameters.SetNull( "@flag" );
  1439. try
  1440. {
  1441. sp.ExecuteNonQuery();
  1442. bExists = true;
  1443. }
  1444. catch( System.Data.SqlClient.SqlException se )
  1445. {
  1446. switch ( se.Number - UDDI.Constants.ErrorTypeSQLOffset )
  1447. {
  1448. case (int) ErrorType.E_invalidKeyPassed :
  1449. // E_invalidKey: taxonomy does not exist on writer
  1450. bExists = false;
  1451. break;
  1452. default:
  1453. throw se;
  1454. }
  1455. }
  1456. catch( Exception e )
  1457. {
  1458. throw e;
  1459. }
  1460. finally
  1461. {
  1462. ConnectionManager.Close();
  1463. }
  1464. return bExists;
  1465. }
  1466. private static void FixTModel( TModel tmodel, string email )
  1467. {
  1468. bool changed = false;
  1469. string change = "";
  1470. string oldtmodel = Deserialize( UDDI.EntityType.TModel, tmodel );
  1471. //
  1472. // Fix null tModelKey in identifierBags
  1473. //
  1474. for( int i=0; i < tmodel.IdentifierBag.Count; i++ )
  1475. if( null == tmodel.IdentifierBag[ i ].TModelKey )
  1476. {
  1477. tmodel.IdentifierBag[ i ].TModelKey = Config.GetString( "TModelKey.GeneralKeywords" );
  1478. changed = true;
  1479. change += "tModel/identifierBag/keyedReference/@tModelKey {" + (i + 1).ToString() + "};";
  1480. }
  1481. //
  1482. // Delete invalid references to checked taxonomies in identifierBags
  1483. //
  1484. for( int i=0; i < tmodel.IdentifierBag.Count; i++ )
  1485. {
  1486. ConnectionManager.Open( true, false );
  1487. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();
  1488. sp.ProcedureName = "net_identifierBag_validate";
  1489. sp.Parameters.Add( "@keyValue", SqlDbType.NVarChar, UDDI.Constants.Lengths.KeyValue );
  1490. sp.Parameters.Add( "@tModelKey", SqlDbType.UniqueIdentifier );
  1491. sp.Parameters.SetString( "@keyValue", tmodel.IdentifierBag[ i ].KeyValue );
  1492. sp.Parameters.SetGuidFromKey( "@tModelKey", tmodel.IdentifierBag[ i ].TModelKey );
  1493. try
  1494. {
  1495. sp.ExecuteNonQuery();
  1496. }
  1497. catch( System.Data.SqlClient.SqlException se )
  1498. {
  1499. switch ( se.Number )
  1500. {
  1501. case 70200 :
  1502. // E_invalidValue: bad categorization detected, delete keyedReference
  1503. changed = true;
  1504. change += "tModel/identifierBag/keyedReference {" + (i + 1).ToString() + "}; ";
  1505. tmodel.IdentifierBag.Remove( tmodel.IdentifierBag[ i ] );
  1506. i--;
  1507. break;
  1508. case 50009 :
  1509. // E_subProcFailure
  1510. break;
  1511. default:
  1512. throw se;
  1513. }
  1514. }
  1515. catch( Exception e )
  1516. {
  1517. throw e;
  1518. }
  1519. finally
  1520. {
  1521. ConnectionManager.Close();
  1522. }
  1523. }
  1524. if( changed )
  1525. WriteException( email, UDDI.EntityType.TModel, tmodel.TModelKey, oldtmodel, Deserialize( UDDI.EntityType.TModel, tmodel ), change );
  1526. return;
  1527. }
  1528. private static void FixBusiness( BusinessEntity business, string email, bool logExceptions )
  1529. {
  1530. bool changed = false;
  1531. string change = "";
  1532. string oldbusiness = Deserialize( UDDI.EntityType.BusinessEntity, business );
  1533. //
  1534. // Fix businessEntities with no names
  1535. //
  1536. if( 0 == business.Names.Count )
  1537. {
  1538. string name = "unspecified";
  1539. business.Names.Add( "en", name );
  1540. changed = true;
  1541. change += "businessEntity/name {1); ";
  1542. }
  1543. //
  1544. // Fix null tModelKey and / or keyValue in identifierBags
  1545. //
  1546. for( int i=0; i < business.IdentifierBag.Count; i++ )
  1547. {
  1548. if( null == business.IdentifierBag[ i ].TModelKey )
  1549. {
  1550. business.IdentifierBag[ i ].TModelKey = Config.GetString( "TModelKey.GeneralKeywords" );
  1551. changed = true;
  1552. }
  1553. if( null == business.IdentifierBag[ i ].KeyValue )
  1554. {
  1555. business.IdentifierBag[ i ].KeyValue = "";
  1556. changed = true;
  1557. }
  1558. if( changed )
  1559. {
  1560. change += "businessEntity/identifierBag/keyedReference/@tModelKey {" + (i + 1).ToString() + "}; ";
  1561. }
  1562. }
  1563. //
  1564. // Fix personName elements that do not meet minumum length requirements
  1565. //
  1566. for( int i=0; i < business.Contacts.Count; i++ )
  1567. {
  1568. if( StringEmpty2( business.Contacts[ i ].PersonName ) )
  1569. {
  1570. business.Contacts[ i ].PersonName = EmptyPersonName;
  1571. changed = true;
  1572. change += "businessEntity/contact/personName {" + (i + 1).ToString() + "};";
  1573. }
  1574. }
  1575. //
  1576. // Fix bindingTemplates with null accessPoint and hostingRedirector
  1577. //
  1578. for( int i=0; i < business.BusinessServices.Count; i++ )
  1579. {
  1580. for( int j=0; j < business.BusinessServices[ i ].BindingTemplates.Count; j++ )
  1581. {
  1582. if( Utility.StringEmpty( business.BusinessServices[ i ].BindingTemplates[ j ].HostingRedirector.BindingKey ) && Utility.StringEmpty( business.BusinessServices[ i ].BindingTemplates[ j ].AccessPoint.Value ) )
  1583. {
  1584. business.BusinessServices[ i ].BindingTemplates[ j ].AccessPoint.Value = EmptyAccessPoint;
  1585. changed = true;
  1586. change += "businessEntity/businessServices/businessService/bindingTemplates/bindingTemplate/accessPoint {" + (j + 1).ToString() + "};";
  1587. }
  1588. }
  1589. }
  1590. //
  1591. // Delete invalid references to checked taxonomies in categoryBags
  1592. //
  1593. for( int i=0; i < business.CategoryBag.Count; i++ )
  1594. {
  1595. ConnectionManager.Open( true, false );
  1596. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();
  1597. sp.ProcedureName = "net_categoryBag_validate";
  1598. sp.Parameters.Add( "@keyValue", SqlDbType.NVarChar, UDDI.Constants.Lengths.KeyValue );
  1599. sp.Parameters.Add( "@tModelKey", SqlDbType.UniqueIdentifier );
  1600. sp.Parameters.SetString( "@keyValue", business.CategoryBag[ i ].KeyValue );
  1601. sp.Parameters.SetGuidFromKey( "@tModelKey", business.CategoryBag[ i ].TModelKey );
  1602. try
  1603. {
  1604. sp.ExecuteNonQuery();
  1605. }
  1606. catch( System.Data.SqlClient.SqlException se )
  1607. {
  1608. switch ( se.Number )
  1609. {
  1610. case 70200 :
  1611. // E_invalidValue: bad categorization detected, delete keyedReference
  1612. changed = true;
  1613. change += "businessEntity/categoryBag/keyedReference {" + (i + 1).ToString() + "}; ";
  1614. business.CategoryBag.Remove( business.CategoryBag[ i ] );
  1615. i--;
  1616. break;
  1617. case 50009 :
  1618. // E_subProcFailure
  1619. break;
  1620. default:
  1621. throw se;
  1622. }
  1623. }
  1624. catch( Exception e )
  1625. {
  1626. throw e;
  1627. }
  1628. finally
  1629. {
  1630. ConnectionManager.Close();
  1631. }
  1632. }
  1633. //
  1634. // Delete invalid references to checked taxonomies in identifierBags
  1635. //
  1636. for( int i=0; i < business.IdentifierBag.Count; i++ )
  1637. {
  1638. ConnectionManager.Open( true, false );
  1639. SqlStoredProcedureAccessor sp = new SqlStoredProcedureAccessor();
  1640. sp.ProcedureName = "net_identifierBag_validate";
  1641. sp.Parameters.Add( "@keyValue", SqlDbType.NVarChar, UDDI.Constants.Lengths.KeyValue );
  1642. sp.Parameters.Add( "@tModelKey", SqlDbType.UniqueIdentifier );
  1643. sp.Parameters.SetString( "@keyValue", business.IdentifierBag[ i ].KeyValue );
  1644. sp.Parameters.SetGuidFromKey( "@tModelKey", business.IdentifierBag[ i ].TModelKey );
  1645. try
  1646. {
  1647. sp.ExecuteNonQuery();
  1648. }
  1649. catch( System.Data.SqlClient.SqlException se )
  1650. {
  1651. switch ( se.Number )
  1652. {
  1653. case 70200 :
  1654. // E_invalidValue: bad categorization detected, delete keyedReference
  1655. changed = true;
  1656. change += "businessEntity/identifierBag/keyedReference {" + (i + 1).ToString() + "}; ";
  1657. business.IdentifierBag.Remove( business.IdentifierBag[ i ] );
  1658. i--;
  1659. break;
  1660. case 50009 :
  1661. // E_subProcFailure
  1662. break;
  1663. default:
  1664. throw se;
  1665. }
  1666. }
  1667. catch( Exception e )
  1668. {
  1669. throw e;
  1670. }
  1671. finally
  1672. {
  1673. ConnectionManager.Close();
  1674. }
  1675. }
  1676. //
  1677. // Fix dangling @hostingRedirectors
  1678. //
  1679. for( int i=0; i < business.BusinessServices.Count; i++ )
  1680. {
  1681. for( int j=0; j < business.BusinessServices[ i ].BindingTemplates.Count; j++ )
  1682. {
  1683. BindingTemplate binding = business.BusinessServices[ i ].BindingTemplates[ j ];
  1684. if( null != binding.HostingRedirector.BindingKey )
  1685. {
  1686. ConnectionManager.Open( true, false );
  1687. SqlStoredProcedureAccessor sp2 = new SqlStoredProcedureAccessor();
  1688. sp2.ProcedureName = "net_key_validate";
  1689. sp2.Parameters.Add( "@entityTypeID", SqlDbType.TinyInt );
  1690. sp2.Parameters.Add( "@entityKey", SqlDbType.UniqueIdentifier );
  1691. sp2.Parameters.SetShort( "@entityTypeID", (short)EntityType.BindingTemplate );
  1692. sp2.Parameters.SetGuidFromString( "@entityKey", binding.HostingRedirector.BindingKey );
  1693. try
  1694. {
  1695. sp2.ExecuteNonQuery();
  1696. }
  1697. catch( System.Data.SqlClient.SqlException se )
  1698. {
  1699. switch( se.Number - UDDI.Constants.ErrorTypeSQLOffset )
  1700. {
  1701. case (int) ErrorType.E_invalidKeyPassed:
  1702. //
  1703. // Bad hostingRedirector detected
  1704. //
  1705. changed = true;
  1706. change += "businessEntity/businessServices/bindingTemplates/bindingTemplate/hostingRedirector/@bindingKey {" + (i + 1).ToString() + "}; ";
  1707. binding.AccessPoint.Value = "unspecified (previously hostingRedirector/@bindingKey = " + binding.HostingRedirector.BindingKey.ToString() + ")";
  1708. binding.HostingRedirector.BindingKey = null;
  1709. break;
  1710. default:
  1711. throw se;
  1712. }
  1713. }
  1714. catch( Exception e )
  1715. {
  1716. throw e;
  1717. }
  1718. finally
  1719. {
  1720. ConnectionManager.Close();
  1721. }
  1722. }
  1723. }
  1724. }
  1725. if( changed && logExceptions )
  1726. WriteException( email, UDDI.EntityType.BusinessEntity, business.BusinessKey, oldbusiness, Deserialize( UDDI.EntityType.BusinessEntity, business ) , change );
  1727. return;
  1728. }
  1729. private static Version GetDbVersion( string connectionstring )
  1730. {
  1731. Version siteversion;
  1732. Version dbversion;
  1733. //
  1734. // Get Site.Version config item
  1735. //
  1736. if( connectionstring == WriterConnectionString )
  1737. {
  1738. // Use standard config against writer
  1739. UDDI.Diagnostics.Debug.VerifySetting( "Site.Version" );
  1740. siteversion = new Version( Config.GetString( "Site.Version" ) );
  1741. }
  1742. else // connectionstring == ReaderConnectionString
  1743. {
  1744. // Standard config routines only support writer
  1745. // We need to get the config setting from reader so use a different approach
  1746. siteversion = new Version( GetReaderConfigValue( "Site.Version" ) );
  1747. }
  1748. if( siteversion.CompareTo( V2RC0SITE ) < 0 )
  1749. {
  1750. throw new ApplicationException( "Unsupported UDDI Services Site Version detected: " + siteversion.ToString() );
  1751. }
  1752. //
  1753. // Get Database.Version config item
  1754. //
  1755. if( siteversion.CompareTo( V2RC0SITE ) == 0 )
  1756. {
  1757. //
  1758. // Indicates an RC0 (Qwest) build of UDDI Services for Windows Server 2003
  1759. // Note: The Database.Verison config item did not exist in RC0 so we use Site.Version instead
  1760. // Note: This is the earliest version of UDDI Services supported by the migration tool
  1761. //
  1762. dbversion = V2RC0;
  1763. }
  1764. else if( siteversion.CompareTo( V2RC1SITE ) == 0 )
  1765. {
  1766. //
  1767. // Indicates an RC1 build of UDDI Services for Windows Server 2003
  1768. // Note: The Database.Verison config item did not exist in RC1 so we use Site.Version instead
  1769. // Note: This is the earliest version of UDDI Services supported by the migration tool
  1770. //
  1771. dbversion = V2RC1;
  1772. }
  1773. else
  1774. {
  1775. //
  1776. // Indicates a post-RC1 build of UDDI Services for Windows Server 2003
  1777. //
  1778. if( connectionstring == WriterConnectionString )
  1779. {
  1780. // Use standard config against writer
  1781. UDDI.Diagnostics.Debug.VerifySetting( "Database.Version" );
  1782. dbversion = new Version( Config.GetString( "Database.Version" ) );
  1783. }
  1784. else // connectionstring == ReaderConnectionString
  1785. {
  1786. // Standard config routines only support writer
  1787. // We need to get the config setting from reader so use a different approach
  1788. dbversion = new Version( GetReaderConfigValue( "Database.Version" ) );
  1789. }
  1790. }
  1791. //
  1792. // Evalutate database version
  1793. //
  1794. switch( dbversion.ToString() )
  1795. {
  1796. case V2RC0STR:
  1797. case V2RC1STR:
  1798. case V2RC2STR:
  1799. break;
  1800. case V2RTMSTR:
  1801. //
  1802. // TODO: this will change when we ship RTM
  1803. //
  1804. throw new ApplicationException( "UDDI Services Database Version " + dbversion.ToString() + " is not currently supported by this tool." );
  1805. default:
  1806. throw new ApplicationException( "Unsupported UDDI Services Database Version detected: " + dbversion.ToString() );
  1807. }
  1808. Log( "UDDI Services Database Version detected: " + dbversion.ToString() + "; connection: " + connectionstring, LogType.LogOnly );
  1809. return dbversion;
  1810. }
  1811. private static string GetReaderConfigValue( string configname )
  1812. {
  1813. string configvalue = null;
  1814. SqlConnection connection = new SqlConnection( ReaderConnectionString );
  1815. connection.Open();
  1816. try
  1817. {
  1818. SqlCommand sp = new SqlCommand( "net_config_get", connection );
  1819. sp.CommandType = CommandType.StoredProcedure;
  1820. SqlDataReader reader = sp.ExecuteReader();
  1821. while( reader.Read() )
  1822. {
  1823. if( configname.ToUpper() == ( reader.IsDBNull( 0 ) ? null : reader.GetString( 0 ).ToUpper() ) )
  1824. {
  1825. configvalue = reader.IsDBNull( 1 ) ? null : reader.GetString( 1 );
  1826. break;
  1827. }
  1828. }
  1829. reader.Close();
  1830. }
  1831. catch( Exception e )
  1832. {
  1833. throw new ApplicationException( "Execute of net_config_get failed. Error: " + e.ToString() );
  1834. }
  1835. finally
  1836. {
  1837. connection.Close();
  1838. }
  1839. if( null == configvalue )
  1840. {
  1841. throw new ApplicationException( "Unknown configName requested: " + configname );
  1842. }
  1843. return configvalue;
  1844. }
  1845. private static string GetResource( string name )
  1846. {
  1847. try
  1848. {
  1849. Assembly assembly = Assembly.GetExecutingAssembly();
  1850. //
  1851. // Read the resource.
  1852. //
  1853. Log( "Reading resource: " + name, LogType.LogOnly );
  1854. Stream stream = assembly.GetManifestResourceStream( name );
  1855. StreamReader reader = new StreamReader( stream );
  1856. return reader.ReadToEnd();
  1857. }
  1858. catch ( Exception e )
  1859. {
  1860. throw new ApplicationException( "Unable to get resource for: " + name + "; error: " + e.ToString() );
  1861. }
  1862. }
  1863. private static void ExecuteScript( string connectionstring, string scriptname )
  1864. {
  1865. string script = GetResource( scriptname );
  1866. Log( "Executing script " + scriptname + " on connection: " + connectionstring, LogType.LogOnly );
  1867. //
  1868. // Scripts are comprised of multiple batches separated by "GO".
  1869. // The SQL managed provider does not recognize this convention,
  1870. // so this code must handle batching manually
  1871. //
  1872. string buffer = "";
  1873. for( int i=0; i <= ( script.Length - 1 ); i++ )
  1874. {
  1875. buffer = buffer + script[ i ].ToString();
  1876. //
  1877. // Detect 'G' + 'O' + whitespace at beginning of script
  1878. //
  1879. if( ( 2 == i ) && ( 'G' == Char.ToUpper( script[ i - 2 ] ) ) && ( 'O' == Char.ToUpper( script[ i - 1 ] ) ) && ( Char.IsWhiteSpace( script[ i ] ) ) )
  1880. {
  1881. //
  1882. // This case can be ignored since no commands exist in the batch
  1883. //
  1884. buffer = "";
  1885. continue;
  1886. }
  1887. //
  1888. // Detect whitespace + 'G' + 'O' + whitespace inside script
  1889. // Note: case whitespace + 'G' + 'O' at end of script is handled automatically
  1890. //
  1891. if( ( 2 < i ) && ( Char.IsWhiteSpace( script[ i - 3 ] ) ) && ( 'G' == Char.ToUpper( script[ i - 2 ] ) ) && ( 'O' == Char.ToUpper( script[ i - 1 ] ) ) && ( Char.IsWhiteSpace( script[ i ] ) ) )
  1892. {
  1893. RunBatch( connectionstring, buffer );
  1894. buffer = "";
  1895. }
  1896. }
  1897. if( buffer.Length > 0 )
  1898. {
  1899. RunBatch( connectionstring, buffer );
  1900. }
  1901. }
  1902. private static void RunBatch( string connectionstring, string batch )
  1903. {
  1904. batch = batch.Trim();
  1905. //
  1906. // Strip "GO" off end of batch if it exists
  1907. //
  1908. if( ( 3 < batch.Length ) && Char.IsWhiteSpace( batch[ batch.Length - 3 ] ) && ( batch.EndsWith( "GO" ) ) )
  1909. {
  1910. batch = batch.Substring( 0, batch.Length - 2 );
  1911. }
  1912. batch = batch.Trim();
  1913. if( batch.Length == 0 )
  1914. return;
  1915. SqlConnection connection = new SqlConnection( connectionstring );
  1916. connection.Open();
  1917. SqlCommand command = new SqlCommand( batch, connection );
  1918. try
  1919. {
  1920. command.ExecuteNonQuery();
  1921. }
  1922. catch( Exception e )
  1923. {
  1924. throw new ApplicationException( "Attempt to execute batch failed: " + e.ToString() );
  1925. }
  1926. finally
  1927. {
  1928. connection.Close();
  1929. }
  1930. }
  1931. private static void WriteException( string email, EntityType entitytype, string entitykey, string oldxml, string newxml, string change )
  1932. {
  1933. Exceptions++;
  1934. Log( "Logging exception number " + Exceptions.ToString( "0000" ) + " to exceptions file.", LogType.LogOnly );
  1935. if( !Directory.Exists( ExceptionDirName ) )
  1936. Directory.CreateDirectory( ExceptionDirName );
  1937. //
  1938. // Write a new record to exceptions file
  1939. //
  1940. string oldfilename = ExceptionDirName + "\\" + Exceptions.ToString( "0000" ) + "_old_" + entitykey + ".xml";
  1941. oldfilename = oldfilename.Replace( ':', '-' );
  1942. string newfilename = ExceptionDirName + "\\" + Exceptions.ToString( "0000" ) + "_new_" + entitykey + ".xml";
  1943. newfilename = newfilename.Replace( ':', '-' );
  1944. string exceptionRecord="";
  1945. exceptionRecord += Exceptions.ToString() + "\t";
  1946. exceptionRecord += email + "\t";
  1947. exceptionRecord += entitytype.ToString() + "\t";
  1948. exceptionRecord += entitykey + "\t";
  1949. exceptionRecord += oldfilename + "\t";
  1950. exceptionRecord += newfilename + "\t";
  1951. exceptionRecord += change;
  1952. FileStream exceptionfile = new FileStream( ExceptionFileName, FileMode.Append );
  1953. StreamWriter stream = new StreamWriter( exceptionfile );
  1954. stream.WriteLine( exceptionRecord );
  1955. stream.Close();
  1956. exceptionfile.Close();
  1957. //
  1958. // Write old and new entities out to exception directory
  1959. //
  1960. Log( "Creating exception file: " + oldfilename, LogType.LogOnly );
  1961. FileStream oldfile = new FileStream( oldfilename, FileMode.CreateNew );
  1962. stream = new StreamWriter( oldfile );
  1963. stream.Write( oldxml );
  1964. stream.Close();
  1965. oldfile.Close();
  1966. Log( "Creating exception file: " + newfilename, LogType.LogOnly );
  1967. FileStream newfile = new FileStream( newfilename, FileMode.CreateNew );
  1968. stream = new StreamWriter( newfile );
  1969. stream.Write( newxml );
  1970. stream.Close();
  1971. newfile.Close();
  1972. return;
  1973. }
  1974. private static string CheckForSlash( string str )
  1975. {
  1976. if( !str.EndsWith( @"\" ) )
  1977. {
  1978. return ( str + @"\" );
  1979. }
  1980. return str;
  1981. }
  1982. private static string Deserialize( EntityType entitytype, object entity )
  1983. {
  1984. XmlSerializer serializer;
  1985. string payload;
  1986. switch( entitytype )
  1987. {
  1988. case EntityType.BusinessEntity:
  1989. serializer = new XmlSerializer( typeof( BusinessEntity ) );
  1990. break;
  1991. case EntityType.TModel:
  1992. serializer = new XmlSerializer( typeof( TModel ) );
  1993. break;
  1994. default:
  1995. throw new ApplicationException( "Invalid entitytype in WriteException()." );
  1996. }
  1997. XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
  1998. UTF8EncodedStringWriter stringWriter = new UTF8EncodedStringWriter();
  1999. try
  2000. {
  2001. namespaces.Add( "", "urn:uddi-org:api_v2" );
  2002. serializer.Serialize( stringWriter, entity, namespaces );
  2003. payload = stringWriter.ToString();
  2004. }
  2005. finally
  2006. {
  2007. stringWriter.Close();
  2008. }
  2009. return payload;
  2010. }
  2011. private static void Log( string message, LogType logType )
  2012. {
  2013. switch ( logType )
  2014. {
  2015. case LogType.ConsoleAndLog:
  2016. Console.WriteLine( message );
  2017. Stream.WriteLine( "{0}: {1}", DateTime.Now.ToLongTimeString(), message );
  2018. break;
  2019. case LogType.ConsoleOnly:
  2020. Console.WriteLine( message );
  2021. break;
  2022. case LogType.LogOnly:
  2023. if( Verbose )
  2024. Console.WriteLine( message );
  2025. Stream.WriteLine( "{0}: {1}", DateTime.Now.ToLongTimeString(), message );
  2026. break;
  2027. }
  2028. }
  2029. private static void DisplayUsage()
  2030. {
  2031. Log( "Migrates data from UDDI V1.5 to UDDI V2.0", LogType.ConsoleOnly );
  2032. Log( "Output is logged to " + LogFileName + "\n", LogType.ConsoleOnly );
  2033. Log( "migrate [-?] [-s migrationstage] [-c readerconnectstring] [-v] [-i] \n", LogType.ConsoleOnly );
  2034. Log( " [?]: Display usage information ", LogType.ConsoleOnly );
  2035. Log( " [-s migrationstage]: Use one of the following values for migrationstage: ", LogType.ConsoleOnly );
  2036. Log( " SetReaderConnection: Sets ReaderConnectionString in registry", LogType.ConsoleOnly );
  2037. Log( " Note: Reference a V2.0 db loaded with V1.5 data", LogType.ConsoleOnly );
  2038. Log( " Note: Requires -c argument", LogType.ConsoleOnly );
  2039. Log( " ResetWriter: Resets publishers, tModels and businessEntities on write db", LogType.ConsoleOnly );
  2040. Log( " MigratePublishers: Migrates publisher accounts from read to write db", LogType.ConsoleOnly );
  2041. Log( " MigrateBareTModels: Migrates bare TModels from read to write db", LogType.ConsoleOnly );
  2042. Log( " BootstrapResources: Bootstraps all resources in \\uddi\\bootstrap", LogType.ConsoleOnly );
  2043. Log( " MigrateCategorizationSchemes: Migrates categorization schemes from read to write db", LogType.ConsoleOnly );
  2044. Log( " MigrateFullTModels: Migrates full TModels from read to write db", LogType.ConsoleOnly );
  2045. Log( " MigrateHiddenTModels: Migrates hidden TModels from read to write db", LogType.ConsoleOnly );
  2046. Log( " MigrateBusinessEntities: Migrates businessEntities from read to write db", LogType.ConsoleOnly );
  2047. Log( " MigratePublisherAssertions: Migrates publisher assertions from read to write db", LogType.ConsoleOnly );
  2048. Log( " RestoreReaderConnection: Restores original ReaderConnectionString", LogType.ConsoleOnly );
  2049. Log( " [-c readerconnectstring]: Used to specify a ReaderConnectionString", LogType.ConsoleOnly );
  2050. Log( " Note: use only with -s SetReaderConnection", LogType.ConsoleOnly );
  2051. Log( " Note: must use double-quotes around connection string", LogType.ConsoleOnly );
  2052. Log( " [-v]: Verbose output to console.", LogType.ConsoleOnly );
  2053. Log( " [-i]: Initialize log file.\n", LogType.ConsoleOnly );
  2054. Log( "Examples:", LogType.ConsoleOnly );
  2055. Log( " migrate -?", LogType.ConsoleOnly );
  2056. Log( " migrate -s SetReaderConnection ", LogType.ConsoleOnly );
  2057. Log( " -c \"Data Source=SRV;Initial Catalog=DB;Integrated Security=SSPI\" -i", LogType.ConsoleOnly );
  2058. Log( " migrate -s ResetWriter", LogType.ConsoleOnly );
  2059. Log( " migrate -s MigratePublishers", LogType.ConsoleOnly );
  2060. Log( " migrate -s MigrateBareTModels", LogType.ConsoleOnly );
  2061. Log( " migrate -s BootstrapResources", LogType.ConsoleOnly );
  2062. Log( " migrate -s MigrateCategorizationSchemes", LogType.ConsoleOnly );
  2063. Log( " migrate -s MigrateFullTModels", LogType.ConsoleOnly );
  2064. Log( " migrate -s MigrateHiddenTModels", LogType.ConsoleOnly );
  2065. Log( " migrate -s MigrateBareBusinessEntities", LogType.ConsoleOnly );
  2066. Log( " migrate -s MigrateBusinessEntities", LogType.ConsoleOnly );
  2067. Log( " migrate -s MigratePublisherAssertions", LogType.ConsoleOnly );
  2068. Log( " migrate -s RestoreReaderConnection", LogType.ConsoleOnly );
  2069. }
  2070. private static bool StringEmpty2( string str )
  2071. {
  2072. if( null == str )
  2073. return true;
  2074. #if never
  2075. if( 0 == str.Trim().Length )
  2076. return true;
  2077. #endif
  2078. return false;
  2079. }
  2080. }
  2081. }