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.

198 lines
4.3 KiB

  1. using System;
  2. using System.Globalization;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using Microsoft.Win32;
  6. using System.Resources;
  7. namespace UDDI.Tools
  8. {
  9. class Recalcstats
  10. {
  11. static SqlConnection connection;
  12. static SqlTransaction transaction;
  13. static int Main( string[] args )
  14. {
  15. int rc = 0; // assume success
  16. try
  17. {
  18. //
  19. // Check if CurrentUICulture needs to be overridden
  20. //
  21. UDDI.Localization.SetConsoleUICulture();
  22. DisplayBanner();
  23. //
  24. // Parse the command line
  25. //
  26. if( !ProcessCommandLine( args ) )
  27. {
  28. return 1;
  29. }
  30. //
  31. // Recalculate statistics
  32. //
  33. RecalcStats();
  34. }
  35. catch( Exception e )
  36. {
  37. Console.WriteLine( FormatFromResource( "RECALCSTATS_FAILED" , e.Message ) );
  38. rc = 1;
  39. }
  40. return rc;
  41. }
  42. private static bool ProcessCommandLine( string [] args )
  43. {
  44. bool bOK = false;
  45. if ( args.Length > 0 )
  46. {
  47. for( int i = 0; i < args.Length; i ++ )
  48. {
  49. if( '-' == args[i][0] || '/' == args[i][0] )
  50. {
  51. string option = args[i].Substring( 1 );
  52. if( "help" == option.ToLower() || "?" == option )
  53. {
  54. DisplayUsage();
  55. return false;
  56. }
  57. }
  58. }
  59. }
  60. else
  61. bOK = true;
  62. if( !bOK )
  63. {
  64. DisplayUsage();
  65. return false;
  66. }
  67. return true;
  68. }
  69. static void DisplayBanner()
  70. {
  71. Console.WriteLine( FormatFromResource( "RECALCSTATS_COPYRIGHT_1" ) );
  72. Console.WriteLine( FormatFromResource( "RECALCSTATS_COPYRIGHT_2" ) );
  73. Console.WriteLine();
  74. }
  75. static void DisplayUsage()
  76. {
  77. Console.WriteLine( FormatFromResource( "RECALCSTATS_USAGE_1" ) );
  78. Console.WriteLine( FormatFromResource( "RECALCSTATS_USAGE_2" ) );
  79. Console.WriteLine();
  80. }
  81. static void RecalcStats()
  82. {
  83. OpenConnection();
  84. try
  85. {
  86. //
  87. // Get entity counts
  88. //
  89. Console.Write( FormatFromResource( "RECALCSTATS_GETTINGENTITYCOUNTS" ) );
  90. SqlCommand cmd = new SqlCommand( "UI_getEntityCounts", connection, transaction );
  91. cmd.CommandType = CommandType.StoredProcedure;
  92. cmd.ExecuteNonQuery();
  93. Console.WriteLine( FormatFromResource( "RECALCSTATS_DONE" ) );
  94. //
  95. // Get publisher stats
  96. //
  97. Console.Write( FormatFromResource( "RECALCSTATS_GETTINGPUBLISHERSTATS" ) );
  98. cmd.CommandText = "UI_getPublisherStats";
  99. cmd.ExecuteNonQuery();
  100. Console.WriteLine( FormatFromResource( "RECALCSTATS_DONE" ) );
  101. //
  102. // Get top publishers
  103. //
  104. Console.Write( FormatFromResource( "RECALCSTATS_GETTINGTOPPUBLISHERS" ) );
  105. cmd.CommandText = "UI_getTopPublishers";
  106. cmd.ExecuteNonQuery();
  107. Console.WriteLine( FormatFromResource( "RECALCSTATS_DONE" ) );
  108. //
  109. // Get taxonomy stats
  110. //
  111. Console.Write( FormatFromResource( "RECALCSTATS_GETTINGTAXONOMYSTATS" ) );
  112. cmd.CommandText = "UI_getTaxonomyStats";
  113. cmd.ExecuteNonQuery();
  114. Console.WriteLine( FormatFromResource( "RECALCSTATS_DONE" ) );
  115. //
  116. // All sprocs succeeded
  117. //
  118. Console.WriteLine( FormatFromResource( "RECALCSTATS_SUCCEEDED" ) );
  119. }
  120. finally
  121. {
  122. CloseConnection();
  123. }
  124. return;
  125. }
  126. static void OpenConnection()
  127. {
  128. try
  129. {
  130. string connectionString = (string) Registry.LocalMachine.OpenSubKey( @"SOFTWARE\Microsoft\UDDI\Database" ).GetValue( "WriterConnectionString" );
  131. connection = new SqlConnection( connectionString );
  132. connection.Open();
  133. transaction = connection.BeginTransaction( IsolationLevel.ReadCommitted, "recalcstats" );
  134. }
  135. catch
  136. {
  137. throw new Exception( "Unable to connect to the database" );
  138. }
  139. }
  140. static void CloseConnection()
  141. {
  142. transaction.Commit();
  143. connection.Close();
  144. }
  145. static string FormatFromResource( string resID, params object[] inserts )
  146. {
  147. try
  148. {
  149. string resourceStr = UDDI.Localization.GetString( resID );
  150. if( null != resourceStr )
  151. {
  152. string resultStr = string.Format( resourceStr, inserts );
  153. return resultStr;
  154. }
  155. return "String not specified in the resources: " + resID;
  156. }
  157. catch( Exception e )
  158. {
  159. return "FormatFromResource failed to load the resource string for ID: " + resID + " Reason: " + e.Message;
  160. }
  161. }
  162. }
  163. }