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.

1471 lines
47 KiB

  1. /// ************************************************************************
  2. /// Microsoft UDDI version 2.0
  3. /// Copyright (c) 2000-2001 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.Net;
  15. using System.Text;
  16. using System.Data;
  17. using Microsoft.Win32;
  18. using System.Diagnostics;
  19. using System.Reflection;
  20. using System.Collections;
  21. using System.Data.SqlClient;
  22. using System.ComponentModel;
  23. using System.ServiceProcess;
  24. using System.DirectoryServices;
  25. using System.Configuration.Install;
  26. using System.Runtime.InteropServices;
  27. using System.Xml.Serialization;
  28. using System.Resources;
  29. using System.Windows.Forms;
  30. using System.Security.Permissions;
  31. using System.Security.Principal;
  32. using System.Globalization;
  33. using UDDI;
  34. using UDDI.Diagnostics;
  35. using UDDI.API;
  36. using UDDI.API.Business;
  37. using UDDI.API.Service;
  38. using UDDI.API.Binding;
  39. using UDDI.API.ServiceType;
  40. using UDDI.ActiveDirectory;
  41. namespace UDDI.WebCA
  42. {
  43. /// <summary>
  44. /// Summary description for installer.
  45. /// </summary>
  46. [RunInstaller(true)]
  47. public class Installer : System.Configuration.Install.Installer
  48. {
  49. /// <summary>
  50. /// Required designer variable.
  51. /// </summary>
  52. private System.ComponentModel.Container components = null;
  53. private string serviceAccountPassword = null;
  54. private string targetDirectory = null;
  55. private string compileDirectory = null;
  56. private const int ERROR_USER_NOT_FOUND = -2147463164;
  57. private const int ERROR_USER_ALREADY_IN_GROUP = -2147023518;
  58. private const string busEntityKeyName = "Site.Key"; // we use this name to save the key in the Config
  59. private const string defaultHelpDir = "default";
  60. //
  61. // These values are set in the MSI
  62. //
  63. private const string addServicesKeyName = "UDDI_ADDSVC"; // "Add Services" context flag name
  64. private const string updateADKeyName = "UDDI_UPDATEAD"; // "Update Active Dir" context flag name
  65. private const string sslRequiredKey = "Security.HTTPS";
  66. private const string cultureID = "CultureID";
  67. private const string clustNodeTypeParam = "CNTYPE"; // cluster node type
  68. private const string clustNodeActive = "A"; // Denotes an "active" node
  69. private const string clustNodePassive = "P"; // Denotes a "passive" aka non-owning node
  70. private const string tmodelWinAuthMode = "uuid:0C61E2C3-73C5-4743-8163-6647AF5B4B9E";
  71. private const string tmodelUDDIAuthMode = "uuid:F358808C-E939-4813-A407-8873BFDC3D57";
  72. private const string tmodelAnonAuthMode = "uuid:E4A56494-4946-4805-ACA5-546B8D08EEFD";
  73. private const string tmodelUddiOrgPub = "uuid:64C756D1-3374-4E00-AE83-EE12E38FAE63";
  74. private const string tmodelUddiOrgPubV2 = "uuid:A2F36B65-2D66-4088-ABC7-914D0E05EB9E";
  75. private const string tmodelUddiOrgHttp = "uuid:68DE9E80-AD09-469D-8A37-088422BFBC36";
  76. private const string tmodelUddiOrgHomepage = "uuid:4CEC1CEF-1F68-4B23-8CB7-8BAA763AEB89";
  77. private const string tmodelUddiOrgInquiry = "uuid:4CD7E4BC-648B-426D-9936-443EAAC8AE23";
  78. private const string tmodelUddiOrgInquiryV2 = "uuid:AC104DCC-D623-452F-88A7-F8ACD94D9B2B";
  79. private const string tmodelMSComAddWebRef = "uuid:CE653789-F6D4-41B7-B7F4-31501831897D";
  80. private const string tmodelMSComUddiExtV2 = "uuid:B3C0835E-7206-41E0-9311-C8AD8FB19F73";
  81. //
  82. // ActiveDirectory Class Names and reserved Keywords
  83. //
  84. private const string pubInqClassName = "UddiInquireUrl";
  85. private const string pubPubClassName = "UddiPublishUrl";
  86. private const string pubWebClassName = "UddiWebSiteUrl";
  87. private const string pubDiscoClassName = "UddiDiscoveryUrl";
  88. private const string pubAddRefClassName = "UddiAddWebReferenceUrl";
  89. private const string kwdWinAuthMode = "WindowsAuthentication";
  90. private const string kwdUDDIAuthMode = "UDDIAuthentication";
  91. private const string kwdAnonAuthMode = "AnonymousAuthentication";
  92. private const string kwdWinAuthModeUuid = "0C61E2C3-73C5-4743-8163-6647AF5B4B9E";
  93. private const string kwdUDDIAuthModeUuid = "F358808C-E939-4813-A407-8873BFDC3D57";
  94. private const string kwdAnonAuthModeUuid = "E4A56494-4946-4805-ACA5-546B8D08EEFD";
  95. private const string kwdDiscoveryUrlID = "1276768A-1488-4C6F-A8D8-19556C6BE583";
  96. private const string kwdPublishServiceID = "64C756D1-3374-4E00-AE83-EE12E38FAE63";
  97. private const string kwdInquiryServiceID = "4CD7E4BC-648B-426D-9936-443EAAC8AE23";
  98. private const string kwdAddWebRefServiceID = "CE653789-F6D4-41B7-B7F4-31501831897D";
  99. private const string kwdWebSiteServiceID = "4CEC1CEF-1F68-4B23-8CB7-8BAA763AEB89";
  100. private const string kwdDiscoveryUrl = "Discovery Url";
  101. private const string kwdPublishService = "Publish API";
  102. private const string kwdInquiryService = "Inquire API";
  103. private const string kwdAddWebRefService= "Add Web Reference";
  104. private const string kwdWebSiteService = "Web Site";
  105. private const string addXPAccessSQL = @"
  106. USE master
  107. IF EXISTS ( SELECT * FROM sysusers where name = '{0}' )
  108. BEGIN
  109. EXEC sp_revokedbaccess '{0}'
  110. END
  111. EXEC sp_grantdbaccess '{0}'
  112. GRANT EXEC ON xp_recalculate_statistics TO public
  113. GRANT EXEC ON xp_reset_key TO public";
  114. public Installer()
  115. {
  116. Enter();
  117. //
  118. // This call is required by the Designer.
  119. //
  120. InitializeComponent();
  121. Leave();
  122. }
  123. public override void Install( System.Collections.IDictionary state )
  124. {
  125. Enter();
  126. try
  127. {
  128. base.Install( state );
  129. Log( String.Format( "Running under the '{0}' user credentials", WindowsIdentity.GetCurrent().Name ) );
  130. targetDirectory = (string) Registry.LocalMachine.OpenSubKey( @"SOFTWARE\Microsoft\UDDI" ).GetValue( "InstallRoot" );
  131. compileDirectory = targetDirectory + @"webroot\compile";
  132. //foreach( System.Reflection.Assembly a in System.AppDomain.CurrentDomain.GetAssemblies() )
  133. //{
  134. // Log( "Name: " + a.FullName + "\tLocation: " + a.Location );
  135. //}
  136. //
  137. // Generate a random password
  138. //
  139. serviceAccountPassword = GenerateRandomString();
  140. //System.Windows.Forms.MessageBox.Show( "UDDI Application Installer Stop", "UDDI.Debug" );
  141. //
  142. // obtain installation options
  143. //
  144. string szAddServiceFlag = Context.Parameters[ addServicesKeyName ];
  145. string szUpdateADFlag = Context.Parameters[ updateADKeyName ];
  146. if ( szAddServiceFlag == null )
  147. throw new InstallException( string.Format( "Required context value is not set: '{0}'", addServicesKeyName ) );
  148. if ( szUpdateADFlag == null )
  149. throw new InstallException( string.Format( "Required context value is not set: '{0}'", szUpdateADFlag ) );
  150. bool bAddServices = szAddServiceFlag.Equals( "1" );
  151. bool bUpdateActiveDir = szUpdateADFlag.Equals( "1" );
  152. //
  153. // First, are we on a cluster node ?
  154. //
  155. bool bActiveNode = false;
  156. string sClusterNodeType = Context.Parameters[ clustNodeTypeParam ];
  157. if ( sClusterNodeType == null || sClusterNodeType == "" )
  158. bActiveNode = true; // we are not on a node, assume "active" mode
  159. else if ( String.Compare( sClusterNodeType, clustNodeActive, true ) == 0 )
  160. bActiveNode = true;
  161. else
  162. bActiveNode = false;
  163. if ( bActiveNode )
  164. {
  165. CreateLogin();
  166. }
  167. RegisterWebServer();
  168. ImportCertificate();
  169. InitializeCounters();
  170. AddUserToIIS_WPG();
  171. RenameHelp( targetDirectory, true );
  172. if ( bActiveNode )
  173. {
  174. UpdateDiscoveryUrl( bAddServices );
  175. if ( bAddServices )
  176. {
  177. AddDefaultServices();
  178. }
  179. if ( bUpdateActiveDir )
  180. {
  181. PublishToActiveDirectory( true );
  182. }
  183. }
  184. try
  185. {
  186. StartService( "RemoteRegistry", 30 );
  187. }
  188. catch ( Exception e )
  189. {
  190. LogException( string.Format( "Exception occured during database install: '{0}'", "RemoteRegistry Start" ) , e );
  191. }
  192. }
  193. catch( Exception e )
  194. {
  195. LogException( "Exception thrown in Install()", e );
  196. throw e;
  197. }
  198. finally
  199. {
  200. Leave();
  201. }
  202. }
  203. public override void Uninstall( System.Collections.IDictionary state )
  204. {
  205. Enter();
  206. try
  207. {
  208. base.Uninstall( state );
  209. UnRegisterWebServer();
  210. DeleteCounters();
  211. //
  212. // Uninstall is called first during install; make sure our registry is laid down before
  213. // trying to move files.
  214. //
  215. RegistryKey uddiKey = Registry.LocalMachine.OpenSubKey( @"SOFTWARE\Microsoft\UDDI" );
  216. if( null != uddiKey )
  217. {
  218. RenameHelp( ( string ) uddiKey.GetValue( "InstallRoot" ), false );
  219. }
  220. }
  221. catch
  222. {
  223. // do nothing
  224. }
  225. finally
  226. {
  227. Leave();
  228. }
  229. }
  230. public override void Rollback( System.Collections.IDictionary state )
  231. {
  232. Enter();
  233. base.Rollback( state );
  234. Uninstall( state );
  235. Leave();
  236. }
  237. public void ImportData()
  238. {
  239. //
  240. // TODO: Import the initial data set
  241. // we need to get this from ckurt
  242. //
  243. }
  244. public void ImportCertificate()
  245. {
  246. //
  247. // TODO: Get the specified certificate name from the registry
  248. // and import it into the certificate store using certmgr.exe
  249. //
  250. }
  251. private void AddUserToIIS_WPG()
  252. {
  253. Enter();
  254. string userName = null;
  255. try
  256. {
  257. userName = Context.Parameters[ "WAM_USER_NAME" ];
  258. if( 0 == userName.Length )
  259. {
  260. throw new InstallException( "User name was not specified for the CreateLogin() function" );
  261. }
  262. //
  263. // replace any "\" with "/"
  264. //
  265. userName = userName.Replace( '\\', '/' );
  266. Log( "Attempting to add " + userName + " to the IIS_WPG group..." );
  267. string rootName = "WinNT://" + SystemInformation.ComputerName;
  268. DirectoryEntry computer = new DirectoryEntry( rootName );
  269. DirectoryEntry group = computer.Children.Find( "IIS_WPG", "group" );
  270. group.Invoke( "Add", new object[] { rootName + "/" + userName } );
  271. group.CommitChanges(); // actual store of entry
  272. }
  273. catch( Exception e )
  274. {
  275. //
  276. // check to see if the exception is because this user
  277. // is already in the group
  278. //
  279. COMException ce = ( COMException ) e.InnerException;
  280. if( ERROR_USER_ALREADY_IN_GROUP == ce.ErrorCode )
  281. {
  282. Log( "This user is already in the group" );
  283. }
  284. else
  285. {
  286. LogError( "Error adding " + userName + " to the IIS_WPG group: " + e.InnerException.Message );
  287. }
  288. }
  289. finally
  290. {
  291. Leave();
  292. }
  293. }
  294. private string GenerateRandomString()
  295. {
  296. byte[] begin = Guid.NewGuid().ToByteArray();
  297. byte[] end = Guid.NewGuid().ToByteArray();
  298. string str = Convert.ToBase64String( begin ) + "29.?" + Convert.ToBase64String( end );
  299. return str;
  300. }
  301. protected void AddDefaultServices()
  302. {
  303. Enter();
  304. try
  305. {
  306. //
  307. // set up the connection and other environment settings
  308. //
  309. ConnectionManager.Open( true, true );
  310. UDDI.Context.User.SetRole( new WindowsPrincipal( WindowsIdentity.GetCurrent() ) );
  311. UDDI.Context.User.ID = UDDI.Utility.GetDefaultPublisher();
  312. //
  313. // now retrieve the config options (site key etc.)
  314. //
  315. string key = UDDI.Config.GetString( busEntityKeyName, "*" );
  316. if ( key.Equals( "*" ) ) // there is no business entity key in the config
  317. throw new InstallException( string.Format( "Required configuration parameter is missing: '{0}'", busEntityKeyName ) );
  318. //
  319. // now as we know the site key, we can populate the Services data
  320. // First, generate the URL stubs
  321. //
  322. IPHostEntry hostInfo = Dns.GetHostByName( Dns.GetHostName() );
  323. string szUDDIPrivatePath = "http://" + hostInfo.HostName + "/uddi";
  324. string szUDDIPublicPath = "http://" + hostInfo.HostName + "/uddipublic";
  325. string szPublishPublicPath;
  326. string szPublishPrivatePath;
  327. string szRequireSSL = Config.GetString( sslRequiredKey, "0" );
  328. if ( szRequireSSL.Equals( "1" ) )
  329. {
  330. szPublishPrivatePath = "https://" + hostInfo.HostName + "/uddi";
  331. szPublishPublicPath = "https://" + hostInfo.HostName + "/uddipublic";
  332. }
  333. else
  334. {
  335. szPublishPrivatePath = "http://" + hostInfo.HostName + "/uddi";
  336. szPublishPublicPath = "http://" + hostInfo.HostName + "/uddipublic";
  337. }
  338. string szServiceName = Localization.GetString( "WEBCA_UDDI_SERVICE_NAME" );
  339. string szServiceDesc = Localization.GetString( "WEBCA_UDDI_DESC_SERVICE" );
  340. string szPublishAPIDesc = Localization.GetString( "WEBCA_UDDI_DESC_PUBGENERIC" );
  341. string szPublishAPIDesc_V1 = Localization.GetString( "WEBCA_UDDI_DESC_PUBVER1" );
  342. string szPublishAPIDesc_V2 = Localization.GetString( "WEBCA_UDDI_DESC_PUBVER2" );
  343. string szInquiryAPIDesc = Localization.GetString( "WEBCA_UDDI_DESC_INQUIRYGENERIC" );
  344. string szInquiryAPIDesc_V1 = Localization.GetString( "WEBCA_UDDI_DESC_INQUIRYV1" );
  345. string szInquiryAPIDesc_V2 = Localization.GetString( "WEBCA_UDDI_DESC_INQUIRYV2" );
  346. string szOrgHttpDesc = Localization.GetString( "WEBCA_UDDI_DESC_HTTP" );
  347. string szOrgHomepageDesc = Localization.GetString( "WEBCA_UDDI_DESC_HOMEPAGE" );
  348. string szWinAuthDesc = Localization.GetString( "WEBCA_UDDI_DESC_WINAUTH" );
  349. string szAnonAuthDesc = Localization.GetString( "WEBCA_UDDI_DESC_ANONAUTH" );
  350. string szUDDIAuthDesc = Localization.GetString( "WEBCA_UDDI_DESC_UDDIAUTH" );
  351. string szAddRefDesc = Localization.GetString( "WEBCA_UDDI_DESC_ADDREF" );
  352. string szExtensionsDesc = Localization.GetString( "WEBCA_UDDI_DESC_MSCOM_EXT" );
  353. string szExtensionsDesc_V2 = Localization.GetString( "WEBCA_UDDI_DESC_MSCOM_EXTV2" );
  354. //
  355. // Now let's update the services
  356. //
  357. int itemPos = 0;
  358. UDDI.API.Service.BusinessService defService = new UDDI.API.Service.BusinessService();
  359. defService.BusinessKey = key;
  360. defService.Names.Add( szServiceName );
  361. defService.Descriptions.Add( szServiceDesc );
  362. //
  363. // publish API, Windows authentication
  364. //
  365. BindingTemplate bindPublish = new BindingTemplate();
  366. bindPublish.AccessPoint.Value = szPublishPrivatePath + "/publish.asmx";
  367. bindPublish.Descriptions.Add( szPublishAPIDesc );
  368. itemPos = bindPublish.TModelInstanceInfos.Add( tmodelUddiOrgPub, "", "" );
  369. bindPublish.TModelInstanceInfos[ itemPos ].Descriptions.Add( szPublishAPIDesc_V1 );
  370. itemPos = bindPublish.TModelInstanceInfos.Add( tmodelUddiOrgPubV2, "", "" );
  371. bindPublish.TModelInstanceInfos[ itemPos ].Descriptions.Add( szPublishAPIDesc_V2 );
  372. itemPos = bindPublish.TModelInstanceInfos.Add( tmodelUddiOrgHttp, "", "" );
  373. bindPublish.TModelInstanceInfos[ itemPos ].Descriptions.Add( szOrgHttpDesc );
  374. itemPos = bindPublish.TModelInstanceInfos.Add( tmodelWinAuthMode, "", "" );
  375. bindPublish.TModelInstanceInfos[ itemPos ].Descriptions.Add( szWinAuthDesc );
  376. defService.BindingTemplates.Add( bindPublish );
  377. //
  378. // AddWebRef API, Windows authentication
  379. //
  380. BindingTemplate bindAddWebRef = new BindingTemplate();
  381. bindAddWebRef.Descriptions.Add( szAddRefDesc );
  382. bindAddWebRef.AccessPoint.Value = szUDDIPrivatePath + "/addwebreference";
  383. itemPos = bindAddWebRef.TModelInstanceInfos.Add( tmodelUddiOrgHttp, "", "" );
  384. bindAddWebRef.TModelInstanceInfos[ itemPos ].Descriptions.Add( szOrgHttpDesc );
  385. itemPos = bindAddWebRef.TModelInstanceInfos.Add( tmodelWinAuthMode, "", "" );
  386. bindAddWebRef.TModelInstanceInfos[ itemPos ].Descriptions.Add( szWinAuthDesc );
  387. itemPos = bindAddWebRef.TModelInstanceInfos.Add( tmodelMSComAddWebRef, "", "" );
  388. bindAddWebRef.TModelInstanceInfos[ itemPos ].Descriptions.Add( szAddRefDesc );
  389. defService.BindingTemplates.Add( bindAddWebRef );
  390. //
  391. // UI public (R/O) API, Anonymous authentication
  392. //
  393. BindingTemplate bindUIRO = new BindingTemplate();
  394. bindUIRO.AccessPoint.Value = szUDDIPublicPath;
  395. bindUIRO.Descriptions.Add( szOrgHomepageDesc );
  396. itemPos = bindUIRO.TModelInstanceInfos.Add( tmodelUddiOrgHttp, "", "" );
  397. bindUIRO.TModelInstanceInfos[ itemPos ].Descriptions.Add( szOrgHttpDesc );
  398. itemPos = bindUIRO.TModelInstanceInfos.Add( tmodelUddiOrgHomepage, "", "" );
  399. bindUIRO.TModelInstanceInfos[ itemPos ].Descriptions.Add( szOrgHomepageDesc );
  400. itemPos = bindUIRO.TModelInstanceInfos.Add( tmodelAnonAuthMode, "", "" );
  401. bindUIRO.TModelInstanceInfos[ itemPos ].Descriptions.Add( szAnonAuthDesc );
  402. defService.BindingTemplates.Add( bindUIRO );
  403. //
  404. // UI private API, Windows authentication
  405. //
  406. BindingTemplate bindUI = new BindingTemplate();
  407. bindUI.AccessPoint.Value = szUDDIPrivatePath;
  408. bindUI.Descriptions.Add( szOrgHomepageDesc );
  409. itemPos = bindUI.TModelInstanceInfos.Add( tmodelUddiOrgHttp, "", "" );
  410. bindUI.TModelInstanceInfos[ itemPos ].Descriptions.Add( szOrgHttpDesc );
  411. itemPos = bindUI.TModelInstanceInfos.Add( tmodelUddiOrgHomepage, "", "" );
  412. bindUI.TModelInstanceInfos[ itemPos ].Descriptions.Add( szOrgHomepageDesc );
  413. itemPos = bindUI.TModelInstanceInfos.Add( tmodelWinAuthMode, "", "" );
  414. bindUI.TModelInstanceInfos[ itemPos ].Descriptions.Add( szWinAuthDesc );
  415. defService.BindingTemplates.Add( bindUI );
  416. //
  417. // publish API, UDDI authentication
  418. //
  419. BindingTemplate bindPublishUDDI = new BindingTemplate();
  420. bindPublishUDDI.AccessPoint.Value = szPublishPublicPath + "/publish.asmx";
  421. bindPublishUDDI.Descriptions.Add( szPublishAPIDesc );
  422. itemPos = bindPublishUDDI.TModelInstanceInfos.Add( tmodelUddiOrgPub, "", "" );
  423. bindPublishUDDI.TModelInstanceInfos[ itemPos ].Descriptions.Add( szPublishAPIDesc_V1 );
  424. itemPos = bindPublishUDDI.TModelInstanceInfos.Add( tmodelUddiOrgPubV2, "", "" );
  425. bindPublishUDDI.TModelInstanceInfos[ itemPos ].Descriptions.Add( szPublishAPIDesc_V2 );
  426. itemPos = bindPublishUDDI.TModelInstanceInfos.Add( tmodelUddiOrgHttp, "", "" );
  427. bindPublishUDDI.TModelInstanceInfos[ itemPos ].Descriptions.Add( szOrgHttpDesc );
  428. itemPos = bindPublishUDDI.TModelInstanceInfos.Add( tmodelUDDIAuthMode, "", "" );
  429. bindPublishUDDI.TModelInstanceInfos[ itemPos ].Descriptions.Add( szUDDIAuthDesc );
  430. defService.BindingTemplates.Add( bindPublishUDDI );
  431. //
  432. // inquiry API, Windows authentication
  433. //
  434. BindingTemplate bindInq = new BindingTemplate();
  435. bindInq.AccessPoint.Value = szUDDIPrivatePath + "/inquire.asmx";
  436. bindInq.Descriptions.Add( szInquiryAPIDesc );
  437. itemPos = bindInq.TModelInstanceInfos.Add( tmodelWinAuthMode, "", "" );
  438. bindInq.TModelInstanceInfos[ itemPos ].Descriptions.Add( szWinAuthDesc );
  439. itemPos = bindInq.TModelInstanceInfos.Add( tmodelUddiOrgHttp, "", "" );
  440. bindInq.TModelInstanceInfos[ itemPos ].Descriptions.Add( szOrgHttpDesc );
  441. itemPos = bindInq.TModelInstanceInfos.Add( tmodelUddiOrgInquiry, "", "" );
  442. bindInq.TModelInstanceInfos[ itemPos ].Descriptions.Add( szInquiryAPIDesc_V1 );
  443. itemPos = bindInq.TModelInstanceInfos.Add( tmodelUddiOrgInquiryV2, "", "" );
  444. bindInq.TModelInstanceInfos[ itemPos ].Descriptions.Add( szInquiryAPIDesc_V2 );
  445. defService.BindingTemplates.Add( bindInq );
  446. //
  447. // inquiry API, Anonymous authentication
  448. //
  449. BindingTemplate bindInqPub = new BindingTemplate();
  450. bindInqPub.AccessPoint.Value = szUDDIPublicPath + "/inquire.asmx";
  451. bindInqPub.Descriptions.Add( szInquiryAPIDesc );
  452. itemPos = bindInqPub.TModelInstanceInfos.Add( tmodelAnonAuthMode, "", "" );
  453. bindInqPub.TModelInstanceInfos[ itemPos ].Descriptions.Add( szAnonAuthDesc );
  454. itemPos = bindInqPub.TModelInstanceInfos.Add( tmodelUddiOrgHttp, "", "" );
  455. bindInqPub.TModelInstanceInfos[ itemPos ].Descriptions.Add( szOrgHttpDesc );
  456. itemPos = bindInqPub.TModelInstanceInfos.Add( tmodelUddiOrgInquiry, "", "" );
  457. bindInqPub.TModelInstanceInfos[ itemPos ].Descriptions.Add( szInquiryAPIDesc_V1 );
  458. itemPos = bindInqPub.TModelInstanceInfos.Add( tmodelUddiOrgInquiryV2, "", "" );
  459. bindInqPub.TModelInstanceInfos[ itemPos ].Descriptions.Add( szInquiryAPIDesc_V2 );
  460. defService.BindingTemplates.Add( bindInqPub );
  461. //
  462. // categorization API (V2 Ext), UDDI authentication
  463. //
  464. BindingTemplate categoryPub = new BindingTemplate();
  465. categoryPub.AccessPoint.Value = szUDDIPublicPath + "/extension.asmx"; // #1509 - rename category.asmx to extension.asmx
  466. categoryPub.Descriptions.Add( szExtensionsDesc );
  467. itemPos = categoryPub.TModelInstanceInfos.Add( tmodelUddiOrgHttp, "", "" );
  468. categoryPub.TModelInstanceInfos[ itemPos ].Descriptions.Add( szOrgHttpDesc );
  469. itemPos = categoryPub.TModelInstanceInfos.Add( tmodelUDDIAuthMode, "", "" );
  470. categoryPub.TModelInstanceInfos[ itemPos ].Descriptions.Add( szUDDIAuthDesc );
  471. itemPos = categoryPub.TModelInstanceInfos.Add( tmodelMSComUddiExtV2, "", "" );
  472. categoryPub.TModelInstanceInfos[ itemPos ].Descriptions.Add( szUDDIAuthDesc );
  473. defService.BindingTemplates.Add( categoryPub );
  474. //
  475. // categorization API (V2 Ext), Windows authentication
  476. //
  477. BindingTemplate categoryWin = new BindingTemplate();
  478. categoryWin.AccessPoint.Value = szUDDIPrivatePath + "/extension.asmx"; // #1509 - rename category.asmx to extension.asmx
  479. categoryWin.Descriptions.Add( szExtensionsDesc );
  480. itemPos = categoryWin.TModelInstanceInfos.Add( tmodelUddiOrgHttp, "", "" );
  481. categoryWin.TModelInstanceInfos[ itemPos ].Descriptions.Add( szOrgHttpDesc );
  482. itemPos = categoryWin.TModelInstanceInfos.Add( tmodelWinAuthMode, "", "" );
  483. categoryWin.TModelInstanceInfos[ itemPos ].Descriptions.Add( szWinAuthDesc );
  484. itemPos = categoryWin.TModelInstanceInfos.Add( tmodelMSComUddiExtV2, "", "" );
  485. categoryWin.TModelInstanceInfos[ itemPos ].Descriptions.Add( szExtensionsDesc_V2 );
  486. defService.BindingTemplates.Add( categoryWin );
  487. //----------------------------------------
  488. // now save the service
  489. //
  490. defService.Save();
  491. //
  492. // Commit pending DB changes
  493. //
  494. ConnectionManager.Commit();
  495. }
  496. catch ( Exception e )
  497. {
  498. ConnectionManager.Abort();
  499. LogException( "AddDefaultServices", e );
  500. Log( string.Format( "Failed to create the default service bindings. Reason: {0}", e.Message ) );
  501. throw e;
  502. }
  503. finally
  504. {
  505. ConnectionManager.Close();
  506. Leave();
  507. }
  508. }
  509. protected void PublishToActiveDirectory( bool bOverwrite )
  510. {
  511. Enter();
  512. try
  513. {
  514. ConnectionManager.Open( false, false );
  515. UDDI.Context.User.SetRole( new WindowsPrincipal( WindowsIdentity.GetCurrent() ) );
  516. UDDI.Context.User.ID = UDDI.Utility.GetDefaultPublisher();
  517. //
  518. // now retrieve the config options (site key etc.)
  519. //
  520. string key = UDDI.Config.GetString( busEntityKeyName, "*" );
  521. if ( key.Equals( "*" ) ) // there is no business entity key in the config
  522. throw new Exception( "Missing value: " + busEntityKeyName );
  523. //
  524. // grab the business entity and all the related parts
  525. //
  526. BusinessEntity busEntity = new BusinessEntity( key );
  527. busEntity.Get();
  528. //
  529. // now get the entity name
  530. //
  531. string entityName = key; // in case we can't retrieve the name
  532. try
  533. {
  534. entityName = busEntity.Names[ 0 ].Value;
  535. }
  536. catch (Exception)
  537. {
  538. }
  539. //
  540. // now load the strings we need to have handy while creating the service
  541. // entries.
  542. // Note that we use the "main" resource from uddi.resources rather than
  543. // the "local" project-level one
  544. //
  545. string szInqClassDispName = Localization.GetString( "WEBCA_ADTAG_UDDI_INQUIRE" );
  546. string szPubClassDispName = Localization.GetString( "WEBCA_ADTAG_UDDI_PUBLISH" );
  547. string szWebClassDispName = Localization.GetString( "WEBCA_ADTAG_UDDI_WEBSITE" );
  548. string szDiscoClassDispName = Localization.GetString( "WEBCA_ADTAG_UDDI_DISCOVERY" );
  549. string szAddRefClassDispName= Localization.GetString( "WEBCA_ADTAG_UDDI_ADDWEBREF" );
  550. string szInqClassDesc = String.Format( Localization.GetString( "WEBCA_ADTAG_UDDI_INQUIREDESC" ), entityName );
  551. string szPubClassDesc = String.Format( Localization.GetString( "WEBCA_ADTAG_UDDI_PUBLISHDESC" ), entityName );
  552. string szWebClassDesc = String.Format( Localization.GetString( "WEBCA_ADTAG_UDDI_WEBSITEDESC" ), entityName );
  553. string szDiscoClassDesc = String.Format( Localization.GetString( "WEBCA_ADTAG_UDDI_DISCOVERYDESC" ), entityName );
  554. string szAddRefClassDesc= String.Format( Localization.GetString( "WEBCA_ADTAG_UDDI_ADDWEBREFDESC" ), entityName );
  555. string szWinAuthDescMask = Localization.GetString( "WEBCA_ADTAG_UDDI_AUTHWIN_DESC" );
  556. string szUDDIAuthDescMask = Localization.GetString( "WEBCA_ADTAG_UDDI_AUTHUDDI_DESC" );
  557. string szAnonAuthDescMask = Localization.GetString( "WEBCA_ADTAG_UDDI_AUTHANON_DESC" );
  558. //
  559. // wipe out the existing entry if needed
  560. //
  561. if ( bOverwrite )
  562. UDDIServiceConnPoint.ResetSiteEntry( key );
  563. else
  564. UDDIServiceConnPoint.CreateSiteEntry( key );
  565. //
  566. // then take care of the DiscoveryURL's
  567. //
  568. foreach ( DiscoveryUrl url in busEntity.DiscoveryUrls )
  569. {
  570. string tmpKey = Guid.NewGuid().ToString();
  571. string tmpUrl = url.Value;
  572. UDDIServiceConnPoint.CreateEntryPoint( key, tmpKey, tmpUrl,
  573. pubDiscoClassName, szDiscoClassDispName,
  574. szDiscoClassDesc,
  575. kwdDiscoveryUrl, kwdDiscoveryUrlID );
  576. }
  577. //
  578. // now we can iterate through the list of services
  579. // and publish them
  580. //
  581. BusinessService[] services = busEntity.BusinessServices.ToArray();
  582. foreach (BusinessService svc in services)
  583. {
  584. string svcKey = svc.ServiceKey;
  585. BindingTemplate[] templates = svc.BindingTemplates.ToArray();
  586. foreach (BindingTemplate busTemplate in templates)
  587. {
  588. string accPoint = busTemplate.AccessPoint.Value;
  589. string bindingKey = busTemplate.BindingKey;
  590. string svcClass = "";
  591. string svcDispName = "";
  592. string svcDesc = "";
  593. string svcDescMask = "";
  594. bool bWinAuth = false;
  595. bool bUDDIAuth = false;
  596. bool bAnonAuth = false;
  597. bool bInquiry = false;
  598. bool bPublish = false;
  599. bool bWebSite = false;
  600. bool bAddRef = false;
  601. ArrayList tmpKwds = new ArrayList();
  602. //
  603. // now let's go through the TModel list and figure out what
  604. // service is this
  605. //
  606. foreach (TModelInstanceInfo tmdInfo in busTemplate.TModelInstanceInfos)
  607. {
  608. string szTemp = tmdInfo.TModelKey;
  609. //
  610. // checking the authentication mode and service type
  611. //
  612. if ( String.Compare( szTemp, tmodelWinAuthMode, true ) == 0 )
  613. {
  614. bWinAuth = true;
  615. tmpKwds.Add( kwdWinAuthMode );
  616. tmpKwds.Add( kwdWinAuthModeUuid );
  617. svcDescMask = szWinAuthDescMask;
  618. }
  619. else if ( String.Compare( szTemp, tmodelUDDIAuthMode, true ) == 0 )
  620. {
  621. bUDDIAuth = true;
  622. tmpKwds.Add( kwdUDDIAuthMode );
  623. tmpKwds.Add( kwdUDDIAuthModeUuid );
  624. svcDescMask = szUDDIAuthDescMask;
  625. }
  626. else if ( String.Compare( szTemp, tmodelAnonAuthMode, true ) == 0 )
  627. {
  628. bAnonAuth = true;
  629. tmpKwds.Add( kwdAnonAuthMode );
  630. tmpKwds.Add( kwdAnonAuthModeUuid );
  631. svcDescMask = szAnonAuthDescMask;
  632. }
  633. else if ( String.Compare( szTemp, tmodelUddiOrgPub, true ) == 0 ||
  634. String.Compare( szTemp, tmodelUddiOrgPubV2, true ) == 0 )
  635. {
  636. if ( !bPublish )
  637. {
  638. bPublish = true;
  639. tmpKwds.Add( kwdPublishService );
  640. tmpKwds.Add( kwdPublishServiceID );
  641. svcClass = pubPubClassName;
  642. svcDispName = szPubClassDispName;
  643. svcDesc = szPubClassDesc;
  644. }
  645. }
  646. else if ( String.Compare( szTemp, tmodelUddiOrgInquiry, true ) == 0 ||
  647. String.Compare( szTemp, tmodelUddiOrgInquiryV2, true ) == 0 )
  648. {
  649. if ( !bInquiry )
  650. {
  651. bInquiry = true;
  652. tmpKwds.Add( kwdInquiryService );
  653. tmpKwds.Add( kwdInquiryServiceID );
  654. svcClass = pubInqClassName;
  655. svcDispName = szInqClassDispName;
  656. svcDesc = szInqClassDesc;
  657. }
  658. }
  659. else if ( String.Compare( szTemp, tmodelMSComAddWebRef, true ) == 0 )
  660. {
  661. bAddRef = true;
  662. tmpKwds.Add( kwdAddWebRefServiceID );
  663. tmpKwds.Add( kwdAddWebRefService );
  664. svcClass = pubAddRefClassName;
  665. svcDispName = szAddRefClassDispName;
  666. svcDesc = szAddRefClassDesc;
  667. }
  668. else if ( String.Compare( szTemp, tmodelUddiOrgHomepage, true ) == 0 )
  669. {
  670. bWebSite = true;
  671. tmpKwds.Add( kwdWebSiteService );
  672. tmpKwds.Add( kwdWebSiteServiceID );
  673. svcClass = pubWebClassName;
  674. svcDispName = szWebClassDispName;
  675. svcDesc = szWebClassDesc;
  676. }
  677. }
  678. //
  679. // first, a quick sanity check. If more than one authmode is set, or
  680. // if there is no authmode at all, then we should skip the entry as invalid
  681. //
  682. if ( !( bWinAuth | bUDDIAuth | bAnonAuth ) || !( bWinAuth ^ bUDDIAuth ^ bAnonAuth ) )
  683. continue;
  684. //
  685. // now same thing with the service types
  686. //
  687. if ( !( bPublish | bInquiry | bAddRef | bWebSite ) || !( bPublish ^ bInquiry ^ bAddRef ^ bWebSite ) )
  688. continue;
  689. //
  690. // now we are ready to create the AD entry
  691. //
  692. if ( svcDescMask.Length > 0 )
  693. svcDesc = String.Format( svcDescMask, svcDesc );
  694. UDDIServiceConnPoint.CreateEntryPoint( key, bindingKey, accPoint,
  695. svcClass, svcDispName,
  696. svcDesc, tmpKwds.ToArray() );
  697. }
  698. }
  699. }
  700. catch (Exception e)
  701. {
  702. LogException( string.Format( "Exception occured during web install: {0}", e.Message ), e );
  703. }
  704. finally
  705. {
  706. ConnectionManager.Close();
  707. Leave();
  708. }
  709. }
  710. //
  711. // Here we attempt to format the Discovery URL. If bForceUpdate is set to true
  712. // then the URL gets updated unconditionally.
  713. // Otherwise, we update the URL only and if only we are the first web site
  714. // installation that connectes to that database (in which case the DiscoveryURL
  715. // will point to localhost)
  716. //
  717. protected void UpdateDiscoveryUrl( bool bForceUpdate )
  718. {
  719. Enter();
  720. try
  721. {
  722. IPHostEntry hostInfo = Dns.GetHostByName( Dns.GetHostName() );
  723. string defaultDiscoveryUrl = "http://" + hostInfo.HostName + "/uddipublic/discovery.ashx?businessKey=";
  724. ConnectionManager.Open( true, true );
  725. UDDI.Context.User.SetRole( new WindowsPrincipal( WindowsIdentity.GetCurrent() ) );
  726. bool bUpdate = bForceUpdate;
  727. if ( !bUpdate )
  728. {
  729. //
  730. // now retrieve the Default URL from config options
  731. //
  732. string url = UDDI.Config.GetString( "DefaultDiscoveryURL", "*" );
  733. if ( url.Equals( "*" ) ) // there is no business entity key in the config
  734. bUpdate = true;
  735. else
  736. {
  737. if ( url.ToLower().IndexOf( "localhost" ) > 0 )
  738. bUpdate = true;
  739. }
  740. }
  741. //
  742. // Now we know whether the Discovery URL should be updated or not
  743. //
  744. if ( bUpdate )
  745. {
  746. UDDI.Config.SetString( "DefaultDiscoveryURL", defaultDiscoveryUrl );
  747. UDDI.Config.Refresh();
  748. ConnectionManager.Commit();
  749. }
  750. }
  751. catch( Exception e )
  752. {
  753. //
  754. // this method will throw if the database has not yet been created,
  755. // so do not rethrow this error!
  756. //
  757. ConnectionManager.Abort();
  758. LogException( "Error in DefaultDiscoveryURL() in web installer", e );
  759. }
  760. finally
  761. {
  762. ConnectionManager.Close();
  763. Leave();
  764. }
  765. }
  766. public void SetStartType( string svcName, ServiceStartMode startType )
  767. {
  768. Enter();
  769. try
  770. {
  771. //
  772. // open the registry entry for the service
  773. //
  774. RegistryKey HKLM = Registry.LocalMachine;
  775. RegistryKey svcKey = HKLM.OpenSubKey( "SYSTEM\\CurrentControlSet\\Services\\" + svcName, true );
  776. //
  777. // now set the start type
  778. //
  779. switch( startType )
  780. {
  781. case ServiceStartMode.Automatic:
  782. svcKey.SetValue ( "Start", 2 );
  783. break;
  784. case ServiceStartMode.Manual:
  785. svcKey.SetValue ( "Start", 3 );
  786. break;
  787. case ServiceStartMode.Disabled:
  788. svcKey.SetValue ( "Start", 4 );
  789. break;
  790. }
  791. svcKey.Close();
  792. HKLM.Close();
  793. }
  794. catch( Exception e )
  795. {
  796. throw new InstallException( LogException( string.Format( "Unable to set the start type for the service: {0}", svcName ), e ) );
  797. }
  798. finally
  799. {
  800. Leave();
  801. }
  802. }
  803. public void StartService ( string svcName, int timeoutSec )
  804. {
  805. Enter();
  806. try
  807. {
  808. ServiceController controller;
  809. ServiceControllerStatus srvStatus;
  810. TimeSpan timeout = new TimeSpan ( 0, 0, timeoutSec );
  811. //
  812. // first, connect to the SCM on the local box
  813. // and attach to the service, then get its status
  814. //
  815. controller = new ServiceController ( svcName );
  816. srvStatus = controller.Status;
  817. //
  818. // what is the service state?
  819. //
  820. switch ( srvStatus)
  821. {
  822. //
  823. // stopped ?
  824. //
  825. case ServiceControllerStatus.Stopped:
  826. controller.Start();
  827. break;
  828. //
  829. // are we trying to start?
  830. //
  831. case ServiceControllerStatus.StartPending:
  832. case ServiceControllerStatus.ContinuePending:
  833. break;
  834. //
  835. // are we trying to stop?
  836. //
  837. case ServiceControllerStatus.StopPending:
  838. controller.WaitForStatus( ServiceControllerStatus.Stopped, timeout );
  839. controller.Start();
  840. break;
  841. //
  842. // pausing ?
  843. //
  844. case ServiceControllerStatus.PausePending:
  845. controller.WaitForStatus ( ServiceControllerStatus.Paused, timeout );
  846. controller.Continue();
  847. break;
  848. default: // the service is already running. Just leave it alone
  849. break;
  850. }
  851. //
  852. // wait 'till the service wakes up
  853. //
  854. controller.WaitForStatus ( ServiceControllerStatus.Running, timeout );
  855. }
  856. catch( Exception e )
  857. {
  858. Log( e.Source );
  859. throw new InstallException( LogException( string.Format( "Unable to start the service: {0}", svcName ), e ) );
  860. }
  861. finally
  862. {
  863. Leave();
  864. }
  865. }
  866. protected void RegisterWebServer()
  867. {
  868. //
  869. // Get the value for Site.WebServers
  870. //
  871. string webServerList = Config.GetString( "Site.WebServers" );
  872. //
  873. // Add ourselves to it
  874. //
  875. if( webServerList.Length > 0)
  876. {
  877. webServerList += "%";
  878. }
  879. webServerList += System.Environment.MachineName;
  880. //
  881. // Store the setting
  882. //
  883. Config.SetString( "Site.WebServers", webServerList );
  884. }
  885. protected void UnRegisterWebServer()
  886. {
  887. //
  888. // Get the value for Site.WebServers
  889. //
  890. string webServerList = Config.GetString( "Site.WebServers" );
  891. //
  892. // Remove ourselves to it
  893. //
  894. string machineName = System.Environment.MachineName;
  895. StringBuilder newWebServerList = new StringBuilder();
  896. string[] webServers = webServerList.Split(new char[]{'%'});
  897. for( int i = 0; i < webServers.Length; i++ )
  898. {
  899. if( false == webServers[i].Equals( machineName ) )
  900. {
  901. if( i > 0 && i < webServers.Length - 1 )
  902. {
  903. newWebServerList.Append( '%' );
  904. }
  905. newWebServerList.Append( webServers[i] );
  906. }
  907. }
  908. //
  909. // Store the setting
  910. //
  911. Config.SetString( "Site.WebServers", newWebServerList.ToString() );
  912. }
  913. protected SqlDataReader ExecuteSql( SqlCommand cmd, bool nonQuery )
  914. {
  915. Enter();
  916. string connectionString = "";
  917. SqlDataReader reader = null;
  918. try
  919. {
  920. //
  921. // get the connection string and connect to the db
  922. //
  923. connectionString = ( string ) Registry.LocalMachine.OpenSubKey( "SOFTWARE\\Microsoft\\UDDI\\Database" ).GetValue( "WriterConnectionString" );
  924. SqlConnection conn = new SqlConnection( connectionString );
  925. try
  926. {
  927. conn.Open();
  928. }
  929. catch( Exception e )
  930. {
  931. Log( string.Format( "SQL Server raised an exception in {0}. Connection string used: '{1}'", "Createlogin()", connectionString ) );
  932. LogException( "conn.Open() failed", e );
  933. throw e;
  934. }
  935. try
  936. {
  937. if( true == nonQuery )
  938. {
  939. cmd.ExecuteNonQuery();
  940. }
  941. else
  942. {
  943. reader = cmd.ExecuteReader();
  944. }
  945. }
  946. catch( Exception e )
  947. {
  948. Log( string.Format( "SQL Server raised an exception in {0}. Connection string used: '{1}'", "Createlogin()", connectionString ) );
  949. LogException( cmd.CommandText, e );
  950. throw new InstallException( LogException( string.Format( "Error while executing the stored procedure '{0}': {1}", cmd.CommandText, e.Message ), e ) );
  951. }
  952. finally
  953. {
  954. conn.Close();
  955. }
  956. }
  957. catch( Exception e )
  958. {
  959. Log( string.Format( "SQL Server raised an exception in {0}. Connection string used: '{1}'", "Createlogin()", connectionString ) );
  960. throw new InstallException( LogException( string.Format( "Error while executing the stored procedure '{0}': {1}", cmd.CommandText, e.Message ), e ) );
  961. }
  962. finally
  963. {
  964. Leave();
  965. }
  966. return reader;
  967. }
  968. protected void CreateLogin()
  969. {
  970. Enter();
  971. //
  972. // Create the user login and add the login to the Admin role
  973. //
  974. string connectionString = "";
  975. try
  976. {
  977. //
  978. // get the user name from the properties passed to this Custom Action
  979. //
  980. string userName = Context.Parameters[ "LCL_USER_NAME" ];
  981. if( 0 == userName.Length )
  982. {
  983. throw new InstallException( "User name was not specified for the CreateLogin() function" ) ;
  984. }
  985. Log( "Windows Identity = " + WindowsIdentity.GetCurrent().Name );
  986. Log( "Thread Identity = " + System.Threading.Thread.CurrentPrincipal.Identity.Name );
  987. Log( "Creating db login for = " + userName );
  988. //
  989. // get the connection string and connect to the db
  990. //
  991. connectionString = ( string ) Registry.LocalMachine.OpenSubKey( "SOFTWARE\\Microsoft\\UDDI\\Database" ).GetValue( "WriterConnectionString" );
  992. SqlConnection conn = new SqlConnection( connectionString );
  993. SqlCommand cmd = new SqlCommand( "ADM_addServiceAccount", conn );
  994. try
  995. {
  996. conn.Open();
  997. }
  998. catch( Exception e )
  999. {
  1000. Log( string.Format( "SQL Server raised an exception in {0}. Connection string used: '{1}'", "Createlogin()", connectionString ) );
  1001. LogException( "conn.Open() failed", e );
  1002. throw e;
  1003. }
  1004. try
  1005. {
  1006. cmd.CommandType = CommandType.StoredProcedure;
  1007. cmd.Parameters.Add( new SqlParameter( "@accountName", SqlDbType.NVarChar, 128 ) ).Direction = ParameterDirection.Input;
  1008. Log( "Creating login for username=" + userName );
  1009. cmd.Parameters[ "@accountName" ].Value = userName;
  1010. cmd.ExecuteNonQuery();
  1011. //
  1012. // We need to also give ourselves permission to access the extended stored procedures on the DB. Do this
  1013. // in a separate try-catch so we can preserve the actual exception that is occuring.
  1014. //
  1015. try
  1016. {
  1017. cmd.CommandType = CommandType.Text;
  1018. cmd.CommandText = string.Format( addXPAccessSQL, userName );
  1019. cmd.ExecuteNonQuery();
  1020. }
  1021. catch( Exception innerException )
  1022. {
  1023. Log( string.Format( "SQL Server raised an exception in {0}. Connection string used: '{1}'", "Createlogin()", connectionString ) );
  1024. LogException( "ADM_addServiceAccount", innerException );
  1025. throw new InstallException( LogException( string.Format( "Error while requesting execute permissions on UDDI Services extended stored procedures: {0}", innerException.Message ), innerException ) );
  1026. }
  1027. }
  1028. catch (InstallException installException )
  1029. {
  1030. //
  1031. // If we got an inner exception, just re-throw it.
  1032. //
  1033. throw installException;
  1034. }
  1035. catch( Exception e )
  1036. {
  1037. Log( string.Format( "SQL Server raised an exception in {0}. Connection string used: '{1}'", "Createlogin()", connectionString ) );
  1038. LogException( "ADM_addServiceAccount", e );
  1039. throw new InstallException( LogException( string.Format( "Error while executing the stored procedure '{0}': {1}", "ADM_addServiceAccount", e.Message ), e ) );
  1040. }
  1041. finally
  1042. {
  1043. conn.Close();
  1044. }
  1045. }
  1046. catch( Exception e )
  1047. {
  1048. Log( string.Format( "SQL Server raised an exception in {0}. Connection string used: '{1}'", "Createlogin()", connectionString ) );
  1049. throw new InstallException( LogException( string.Format( "Error while executing the stored procedure '{0}': {1}", "ADM_addServiceAccount", e.Message ), e ) );
  1050. }
  1051. finally
  1052. {
  1053. Leave();
  1054. }
  1055. }
  1056. public void DeleteCounters()
  1057. {
  1058. Enter();
  1059. try
  1060. {
  1061. PerformanceCounterCategory.Delete( "UDDI.API.Times" );
  1062. PerformanceCounterCategory.Delete( "UDDI.API.Counts" );
  1063. }
  1064. catch
  1065. {
  1066. // don't care if it fails
  1067. }
  1068. finally
  1069. {
  1070. Leave();
  1071. }
  1072. }
  1073. public void InitializeCounters()
  1074. {
  1075. Enter();
  1076. try
  1077. {
  1078. Performance.InitializeCounters();
  1079. }
  1080. finally
  1081. {
  1082. Leave();
  1083. }
  1084. }
  1085. private void Enter()
  1086. {
  1087. System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace( 1, false );
  1088. System.Reflection.MethodBase method = trace.GetFrame( 0 ).GetMethod();
  1089. Log( "Entering " + method.ReflectedType.FullName + "." + method.Name + "..." );
  1090. }
  1091. private void Leave()
  1092. {
  1093. System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace( 1, false );
  1094. System.Reflection.MethodBase method = trace.GetFrame( 0 ).GetMethod();
  1095. Log( "Leaving " + method.ReflectedType.FullName + "." + method.Name );
  1096. }
  1097. protected string CheckForSlash( string str )
  1098. {
  1099. if( !str.EndsWith( @"\" ) )
  1100. {
  1101. return ( str + @"\" );
  1102. }
  1103. return str;
  1104. }
  1105. private string LogError( string errmsg )
  1106. {
  1107. System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace( 1, false );
  1108. System.Reflection.MethodBase method = trace.GetFrame( 0 ).GetMethod();
  1109. Log( "----------------------------------------------------------" );
  1110. Log( "An error occurred during installation. Details follow:" );
  1111. Log( "Method: " + method.ReflectedType.FullName + "." + method.Name );
  1112. Log( "Message: " + errmsg );
  1113. Log( "----------------------------------------------------------" );
  1114. return errmsg;
  1115. }
  1116. private string LogException( string context, Exception e )
  1117. {
  1118. System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace( 1, false );
  1119. System.Reflection.MethodBase method = trace.GetFrame( 0 ).GetMethod();
  1120. Log( "----------------------------------------------------------" );
  1121. Log( "An exception occurred during installation. Details follow:" );
  1122. Log( "Method: " + method.ReflectedType.FullName + "." + method.Name );
  1123. Log( "Context: " + context );
  1124. Log( "Stack Trace: " + e.StackTrace );
  1125. Log( "Source: " + e.Source );
  1126. Log( "Message: " + e.Message );
  1127. Log( "----------------------------------------------------------" );
  1128. return context + ": " + e.Message;
  1129. }
  1130. private void Log( string str )
  1131. {
  1132. try
  1133. {
  1134. System.Diagnostics.Debug.WriteLine( str );
  1135. FileStream f = new FileStream( System.Environment.ExpandEnvironmentVariables( "%systemroot%" ) + @"\uddisetup.log", FileMode.Append, FileAccess.Write );
  1136. StreamWriter s = new StreamWriter( f, System.Text.Encoding.Unicode );
  1137. s.WriteLine( "{0}: {1}", DateTime.Now.ToString(), str );
  1138. s.Close();
  1139. f.Close();
  1140. }
  1141. catch( Exception e )
  1142. {
  1143. System.Diagnostics.Debug.WriteLine( "Error in Log():" + e.Message );
  1144. }
  1145. }
  1146. private string GetPathToHelp( string installDir )
  1147. {
  1148. //
  1149. // The value 'default' must match the value in the MSI.
  1150. //
  1151. return string.Format( "{0}webroot/default", installDir );
  1152. }
  1153. private void RenameHelp( string installDir, bool install )
  1154. {
  1155. int lcid = 0;
  1156. string cultureIDValue = Context.Parameters[ cultureID ];
  1157. //
  1158. // 'cultureIDValue is expected to contain a neutral culture. ie,
  1159. // 'en', or 'ko', or 'de'. All but a few neutral cultures have
  1160. // a default specific culture. For example, the default specific
  1161. // culture of 'en' is 'en-US'.
  1162. //
  1163. // Traditional & simplified Chinese (zh-CHT and zh-CHS respectively)
  1164. // are examples of neutral cultures which have no default specific
  1165. // culture!
  1166. //
  1167. // So what happens below is this: First we try to lookup the default
  1168. // specific culture for the neutral culture that we were given. If that
  1169. // fails (ie, if CreateSpecificCulture throws), we just get the lcid
  1170. // of the neutral culture.
  1171. //
  1172. try
  1173. {
  1174. lcid = CultureInfo.CreateSpecificCulture( cultureIDValue ).LCID;
  1175. }
  1176. catch
  1177. {
  1178. CultureInfo ci = new CultureInfo( cultureIDValue );
  1179. lcid = ci.LCID;
  1180. }
  1181. //
  1182. // Build default paths to the main and add web reference help directories.
  1183. //
  1184. string defaultMainHelpPath = string.Format( @"{0}webroot\help\{1}", installDir, defaultHelpDir );
  1185. string defaultAWRHelpPath = string.Format( @"{0}webroot\addwebreference\{1}", installDir, defaultHelpDir );
  1186. //
  1187. // Build lang-specific paths to the main and add web reference help directories.
  1188. //
  1189. string langMainHelpPath = string.Format( @"{0}webroot\help\{1}", installDir, lcid );
  1190. string langAWRHelpPath = string.Format( @"{0}webroot\addwebreference\{1}", installDir, lcid );
  1191. if( true == install )
  1192. {
  1193. //
  1194. // If we are installing, then rename the default help directory to one that is language specific. Delete
  1195. // existing directories if we have to.
  1196. //
  1197. // FIX: UDDI#2443: catch any exceptions, don't pass error back if directories can't be deleted. added
  1198. // LogException call to watch when this ever happens.
  1199. //
  1200. try
  1201. {
  1202. if( true == Directory.Exists( langMainHelpPath ) )
  1203. {
  1204. Directory.Delete( langMainHelpPath, true );
  1205. }
  1206. if( true == Directory.Exists( langAWRHelpPath ) )
  1207. {
  1208. Directory.Delete( langAWRHelpPath, true );
  1209. }
  1210. }
  1211. catch( Exception e )
  1212. {
  1213. LogException( "Caught exception deleting lang-specific help directories.", e );
  1214. }
  1215. try
  1216. {
  1217. Directory.Move( defaultMainHelpPath, langMainHelpPath );
  1218. Directory.Move( defaultAWRHelpPath, langAWRHelpPath );
  1219. }
  1220. catch( Exception e )
  1221. {
  1222. LogException( "Caught exception moving default help directories to lang-specific directories.", e );
  1223. }
  1224. }
  1225. else
  1226. {
  1227. //
  1228. // If we are uninstalling, then rename the language specific help directory back to the default; this
  1229. // will let MSI clean up these files. Catch any exceptions, it's not a big deal if this directory can't
  1230. // be moved.
  1231. //
  1232. // FIX: UDDI#2443: added LogException call to watch when this ever happens.
  1233. //
  1234. try
  1235. {
  1236. Directory.Move( langMainHelpPath, defaultMainHelpPath );
  1237. Directory.Move( langAWRHelpPath, defaultAWRHelpPath );
  1238. }
  1239. catch( Exception e )
  1240. {
  1241. LogException( "Caught exception moving lang-specific help directories to default.", e );
  1242. }
  1243. }
  1244. }
  1245. #region Component Designer generated code
  1246. /// <summary>
  1247. /// Required method for Designer support - do not modify
  1248. /// the contents of this method with the code editor.
  1249. /// </summary>
  1250. private void InitializeComponent()
  1251. {
  1252. components = new System.ComponentModel.Container();
  1253. }
  1254. #endregion
  1255. }
  1256. }