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.

219 lines
5.7 KiB

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Security.Principal;
  7. namespace UDDI.Tools
  8. {
  9. public interface IAdminObject
  10. {
  11. void Initialize( IAdminFrame parent );
  12. string GetNodeText();
  13. void Show( Control parentDisplay );
  14. }
  15. public interface IAdminFrame
  16. {
  17. void UpdateAllViews();
  18. }
  19. public class AdminFrame : Form, IAdminFrame
  20. {
  21. private TreeView nodesTreeView;
  22. private Splitter splitter;
  23. private Panel viewPanel;
  24. private MainMenu mainMenu;
  25. private MenuItem fileMenuItem;
  26. private MenuItem viewMenuItem;
  27. private MenuItem exitMenuItem;
  28. private MenuItem refreshMenuItem;
  29. public AdminFrame( ArrayList adminObjects )
  30. {
  31. InitializeComponent();
  32. foreach( IAdminObject adminObject in adminObjects )
  33. {
  34. TreeNode adminNode = new TreeNode( adminObject.GetNodeText() );
  35. adminNode.Tag = adminObject;
  36. try
  37. {
  38. adminObject.Initialize( this );
  39. nodesTreeView.Nodes.Add( adminNode );
  40. }
  41. catch( Exception e )
  42. {
  43. MessageBox.Show( string.Format( "There was an exception initializing: {0}\n\n{1}", adminObject.GetNodeText(), e.ToString() ) );
  44. }
  45. }
  46. }
  47. public void UpdateAllViews()
  48. {
  49. foreach( TreeNode treeNode in nodesTreeView.Nodes )
  50. {
  51. IAdminObject adminObject = ( IAdminObject )treeNode.Tag;
  52. try
  53. {
  54. adminObject.Show( viewPanel );
  55. }
  56. catch( Exception e )
  57. {
  58. MessageBox.Show( string.Format( "There was an exception updating: {0}\n\n{1}", adminObject.GetNodeText(), e.ToString() ) );
  59. }
  60. }
  61. }
  62. private void InitializeComponent()
  63. {
  64. nodesTreeView = new TreeView();
  65. splitter = new Splitter();
  66. viewPanel = new Panel();
  67. mainMenu = new MainMenu();
  68. fileMenuItem = new MenuItem();
  69. viewMenuItem = new MenuItem();
  70. exitMenuItem = new MenuItem();
  71. refreshMenuItem = new MenuItem();
  72. SuspendLayout();
  73. //
  74. // nodesTreeView
  75. //
  76. nodesTreeView.BorderStyle = BorderStyle.None;
  77. nodesTreeView.Dock = DockStyle.Left;
  78. nodesTreeView.ImageIndex = -1;
  79. nodesTreeView.Name = "nodesTreeView";
  80. nodesTreeView.SelectedImageIndex = -1;
  81. nodesTreeView.ShowLines = false;
  82. nodesTreeView.Size = new System.Drawing.Size(121, 549);
  83. nodesTreeView.TabIndex = 0;
  84. nodesTreeView.HotTracking = true;
  85. nodesTreeView.AfterSelect += new TreeViewEventHandler(NodesTreeView_AfterSelect);
  86. //
  87. // splitter
  88. //
  89. splitter.Location = new System.Drawing.Point(121, 0);
  90. splitter.Name = "splitter";
  91. splitter.Size = new System.Drawing.Size(3, 549);
  92. splitter.TabIndex = 1;
  93. splitter.TabStop = false;
  94. //
  95. // viewPanel
  96. //
  97. viewPanel.Dock = DockStyle.Fill;
  98. viewPanel.Location = new System.Drawing.Point(124, 0);
  99. viewPanel.Name = "viewPanel";
  100. viewPanel.Size = new System.Drawing.Size(676, 549);
  101. viewPanel.TabIndex = 2;
  102. //
  103. // mainMenu
  104. //
  105. mainMenu.MenuItems.AddRange( new MenuItem[] { fileMenuItem, viewMenuItem } );
  106. //
  107. // fileMenuItem
  108. //
  109. fileMenuItem.Index = 0;
  110. fileMenuItem.MenuItems.AddRange(new MenuItem[] { exitMenuItem } );
  111. fileMenuItem.Text = "File";
  112. // viewMenuItem
  113. viewMenuItem.Index = 1;
  114. viewMenuItem.MenuItems.AddRange(new MenuItem[] { refreshMenuItem } );
  115. viewMenuItem.Text = "View";
  116. //
  117. // exitMenuItem
  118. //
  119. exitMenuItem.Index = 0;
  120. exitMenuItem.Text = "E&xit";
  121. exitMenuItem.Click += new System.EventHandler( ExitMenuItem_Click );
  122. //
  123. // refreshMenuItem
  124. //
  125. refreshMenuItem.Index = 0;
  126. refreshMenuItem.Text = "Refresh";
  127. refreshMenuItem.Click += new EventHandler( RefreshMenuItem_Click );
  128. //
  129. // AdminFrame
  130. //
  131. AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  132. ClientSize = new System.Drawing.Size(705, 680);
  133. Controls.AddRange(new Control[] { viewPanel, splitter, nodesTreeView});
  134. Menu = mainMenu;
  135. Name = "AdminFrame";
  136. Text = "Replication Admin Tool";
  137. ResumeLayout(false);
  138. Resize += new EventHandler( AdminFrame_Resize );
  139. }
  140. private void AdminFrame_Resize( object sender, EventArgs eventArgs )
  141. {
  142. UpdateAllViews();
  143. }
  144. private void NodesTreeView_AfterSelect( object sender, TreeViewEventArgs treeViewArgs )
  145. {
  146. IAdminObject adminObject = treeViewArgs.Node.Tag as IAdminObject;
  147. if( null == adminObject )
  148. {
  149. MessageBox.Show( "Admin node was incorrectly initialized" );
  150. }
  151. else
  152. {
  153. viewPanel.Controls.Clear();
  154. adminObject.Show( viewPanel );
  155. }
  156. }
  157. private void RefreshMenuItem_Click( object sender, EventArgs eventArgs )
  158. {
  159. this.UpdateAllViews();
  160. }
  161. private void ExitMenuItem_Click( object sender, EventArgs eventArgs )
  162. {
  163. System.Windows.Forms.Application.Exit();
  164. }
  165. [STAThread]
  166. static void Main()
  167. {
  168. WindowsIdentity identity = WindowsIdentity.GetCurrent();
  169. WindowsPrincipal principal = new WindowsPrincipal( identity );
  170. Context.User.SetRole( principal );
  171. if( !Context.User.IsAdministrator )
  172. {
  173. MessageBox.Show( "Access denied.\r\n\r\nThis program must be executed by a member of the '"
  174. + Config.GetString( "GroupName.Administrators" ) + "'\r\ngroup. The current user '"
  175. + identity.Name + "' is not a member of this group." );
  176. return;
  177. }
  178. UDDI.ConnectionManager.Open( true, false );
  179. ArrayList adminObjects = new ArrayList();
  180. adminObjects.Add( new CorrectionAdmin() );
  181. AdminFrame adminFrame = new AdminFrame( adminObjects );
  182. System.Windows.Forms.Application.Run( adminFrame );
  183. }
  184. }
  185. }