⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialogobserver.cs

📁 Oracle Service Manager
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Net;
using System.Resources;
using System.ServiceProcess;
using System.Windows.Forms;
using kae.ServiceStatePublisher;

namespace kae.OracleServiceManager
{
	/// <summary>
	/// DialogObserver is a concrete observer listening to the current subject for changes
	/// DialogObserver manages the dialog interface of OSM
	/// </summary>
	public class DialogObserver : Form
	{
		protected delegate void UpdateFunction( ServiceSubject subject);
		protected delegate void ServiceAction();

		private readonly string START;
		private readonly string PAUSE;
		private readonly string STOP;

		private OsmResources _resources;
		private IContainer components;
		private Label serverLabel;
		private ComboBox serverCombo;
		private Label serviceLabel;
		private ComboBox serviceCombo;
		private Button refreshButton;
		private PictureBox statePicture;
		private Label startServiceLabel;
		private Button startServiceButton;
		private Label pauseServiceLabel;
		private Button pauseServiceButton;
		private Label stopServiceLabel;
		private Button stopServiceButton;
		private StatusBar statusBar;
		private bool _updating;
		private UpdateFunction serverChanged;
		private UpdateFunction serviceChanged;
		private UpdateFunction serviceStateChanged;
		private ServiceAction startService;
		private ServiceAction pauseService;
		private ServiceAction stopService;

		public DialogObserver( ServiceSubject subject)
		{
			if (subject != null)
			{
				subject.ServerChanged += new EventHandler( this.OnServerChanged);
				subject.ServiceChanged += new EventHandler( this.OnServiceChanged);
				subject.StateChanged += new EventHandler( this.OnStateChanged);
			}

			serverChanged = new UpdateFunction( this.ServerChanged);
			serviceChanged = new UpdateFunction( this.ServiceChanged);
			serviceStateChanged = new UpdateFunction( this.ServiceStateChanged);

			startService = new ServiceAction( App.Subject.Start);
			pauseService = new ServiceAction( App.Subject.Pause);
			stopService = new ServiceAction( App.Subject.Stop);

			_resources = App.Resources;
			START = GetAppString( "Start");
			PAUSE = GetAppString( "Pause");
			STOP = GetAppString( "Stop");

			InitializeComponent();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing)
		{
			if (disposing)
			{
				if (components != null)
					components.Dispose();
			}
			base.Dispose( disposing);
		}

		protected OracleServiceManager App
		{
			get { return OracleServiceManager.Instance; }
		}

		protected bool Updating
		{
			get { return _updating; }
			set { _updating = value; }
		}

		internal ISynchronizeInvoke SynchronizingObject
		{
			get { return serviceCombo; }
		}

		#region Manually generated Form code
		private void InitializeComponent()
		{
			const int _leftBorder = 5;
			const int _rightBorder = 5;
			const int _topBorder = 5;
			const int BUTTON_WIDTH = 25;
			const int BUTTON_HEIGHT = 25;
			int oneThirdWidth, top = _topBorder;
			int labelTop;

			components = new System.ComponentModel.Container();
			serverLabel = new Label();
			serverCombo = new ComboBox();
			serviceLabel = new Label();
			serviceCombo = new ComboBox();
			refreshButton = new Button();
			startServiceButton = new Button();
			startServiceLabel = new Label();
			pauseServiceButton = new Button();
			pauseServiceLabel = new Label();
			stopServiceButton = new Button();
			stopServiceLabel = new Label();
			statePicture = new PictureBox();
			statusBar = new StatusBar();
			SuspendLayout();
			// 
			// DialogObserver
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(286, 230);
			this.Controls.AddRange( new Control[] 
				{
					serverLabel, serverCombo, serviceLabel, serviceCombo, refreshButton,
					startServiceButton, startServiceLabel, pauseServiceButton,
					pauseServiceLabel, stopServiceButton, stopServiceLabel,
					statePicture, statusBar
				});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.MaximizeBox = false;
			this.Name = "DialogObserver";
			this.Text = _resources.ApplicationName;
			this.Icon = GetSmallStateImage( ServiceStateUnknown.Instance);
			this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
			this.Closing += new System.ComponentModel.CancelEventHandler( this.ClosingDialog);
			oneThirdWidth = ClientSize.Width - _leftBorder - _rightBorder;
			oneThirdWidth /= 3;
			//
			// serverCombo
			//
			serverCombo.Name = "serverCombo";
			serverCombo.TabIndex = 2;
			serverCombo.Location = new System.Drawing.Point( oneThirdWidth + _leftBorder, top);
			serverCombo.Width = oneThirdWidth * 2;
			serverCombo.CausesValidation = true;
			serverCombo.Validating += new CancelEventHandler( this.ServerComboValidating);
			//
			// serverLabel
			//
			serverLabel.Name = "serverLabel";
			serverLabel.AutoSize = true;
			serverLabel.UseMnemonic = true;
			serverLabel.TabIndex = 1;
			serverLabel.Text = GetStringFromResources( "Server");
			labelTop = top + ((serverCombo.Height / 2) - (serverLabel.Height / 2));
			serverLabel.Location = new System.Drawing.Point( _leftBorder, labelTop);
			top += serverCombo.Height + _topBorder;
			//
			// serviceCombo
			//
			serviceCombo.Name = "serviceCombo";
			serviceCombo.TabIndex = 4;
			serviceCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			serviceCombo.Location = new System.Drawing.Point( oneThirdWidth + _leftBorder, top);
			serviceCombo.Width = oneThirdWidth * 2;
			serviceCombo.SelectedIndexChanged += new EventHandler( this.ServiceComboChangedIndex);
			//
			// serviceLabel
			//
			serviceLabel.Name = "serviceLabel";
			serviceLabel.AutoSize = true;
			serviceLabel.UseMnemonic = true;
			serviceLabel.TabIndex = 3;
			serviceLabel.Text = GetStringFromResources( "Service");
			labelTop = top + ((serviceCombo.Height / 2) - (serviceLabel.Height / 2));
			serviceLabel.Location = new System.Drawing.Point( _leftBorder, labelTop);
			top += serviceCombo.Height + _topBorder;
			//
			// refreshButton
			//
			refreshButton.Name = "refreshButton";
			refreshButton.TabIndex = 5;
			refreshButton.Text = GetStringFromResources( "RefreshServices");
			refreshButton.Location = new System.Drawing.Point( oneThirdWidth + _leftBorder, top);
			refreshButton.Width = serviceCombo.Width;
			refreshButton.Click += new EventHandler( this.RefreshClick);
			top += refreshButton.Height + (3 * _topBorder);
			//
			// startServiceButton
			//
			startServiceButton.Name = "startServiceButton";
			startServiceButton.TabIndex = 7;
			startServiceButton.Image = Image.FromStream( GetActionImage( "Start", false));
			startServiceButton.Size = new System.Drawing.Size( BUTTON_WIDTH, BUTTON_HEIGHT);
			startServiceButton.Location = new System.Drawing.Point( oneThirdWidth + _leftBorder, top);
			startServiceButton.Click += new EventHandler( this.StartClick);
			top += startServiceButton.Height + (2 * _topBorder);
			//
			// startServiceLabel
			//
			startServiceLabel.Name = "startServiceLabel";
			startServiceLabel.AutoSize = true;
			startServiceLabel.UseMnemonic = true;
			startServiceLabel.TabIndex = 6;
			startServiceLabel.Text = GetStringFromResources( "StartContinue");
			labelTop = startServiceButton.Top + ((startServiceButton.Height / 2) - (startServiceLabel.Height / 2));
			startServiceLabel.Location = new System.Drawing.Point( 
				startServiceButton.Right + (2 * _leftBorder),
				labelTop);
			//
			// pauseServiceButton
			//
			pauseServiceButton.Name = "pauseServiceButton";
			pauseServiceButton.TabIndex = 9;
			pauseServiceButton.Image = Image.FromStream( GetActionImage( "Pause", false));
			pauseServiceButton.Size = new System.Drawing.Size( BUTTON_WIDTH, BUTTON_HEIGHT);
			pauseServiceButton.Location = new System.Drawing.Point( oneThirdWidth + _leftBorder, top);
			pauseServiceButton.Click += new EventHandler( this.PauseClick);
			top += pauseServiceButton.Height + (2 * _topBorder);
			//
			// pauseServiceLabel
			//
			pauseServiceLabel.Name = "pauseServiceLabel";
			pauseServiceLabel.AutoSize = true;
			pauseServiceLabel.UseMnemonic = true;
			pauseServiceLabel.TabIndex = 8;
			pauseServiceLabel.Text = GetStringFromResources( "Pause");
			labelTop = pauseServiceButton.Top + ((pauseServiceButton.Height / 2) - (pauseServiceLabel.Height / 2));
			pauseServiceLabel.Location = new System.Drawing.Point( 
				pauseServiceButton.Right + (2 * _leftBorder), 
				labelTop);
			//
			// stopServiceButton
			//
			stopServiceButton.Name = "stopServiceButton";
			stopServiceButton.TabIndex = 11;
			stopServiceButton.Image = Image.FromStream( GetActionImage( "Stop", false));
			stopServiceButton.Size = new System.Drawing.Size( BUTTON_WIDTH, BUTTON_HEIGHT);
			stopServiceButton.Location = new System.Drawing.Point( oneThirdWidth + _leftBorder, top);
			stopServiceButton.Click += new EventHandler( this.StopClick);
			top += stopServiceButton.Height + _topBorder;
			//
			// stopServiceLabel
			//
			stopServiceLabel.Name = "stopServiceLabel";
			stopServiceLabel.AutoSize = true;
			stopServiceLabel.UseMnemonic = true;
			stopServiceLabel.TabIndex = 10;
			stopServiceLabel.Text = GetStringFromResources( "Stop");
			labelTop = stopServiceButton.Top + ((stopServiceButton.Height / 2) - (stopServiceLabel.Height / 2));
			stopServiceLabel.Location = new System.Drawing.Point( 
				stopServiceButton.Right + (2 * _leftBorder), 
				labelTop);
			//
			// statePicture
			//
			System.Drawing.Size pictureSize = new System.Drawing.Size( 48, 48);
			int leftCenter = (serviceCombo.Left / 2) - (pictureSize.Width / 2);
			int topCenter = ((startServiceButton.Top + stopServiceButton.Bottom) / 2) - (pictureSize.Height / 2);
			statePicture.Name = "statePicture"; 
			statePicture.Location = new System.Drawing.Point( leftCenter, topCenter);
			statePicture.SizeMode = PictureBoxSizeMode.StretchImage;
			statePicture.Size = pictureSize;
			statePicture.Image = Image.FromStream( GetLargeStateImage( ServiceStateUnknown.Instance));
			//
			// statusBar
			//
			statusBar.Name = "statusBar";
			statusBar.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
			statusBar.Dock = System.Windows.Forms.DockStyle.Bottom;
			statusBar.SizingGrip = false;
			statusBar.ShowPanels = true;
			statusBar.Panels.Add( new StatusBarPanel());
			statusBar.Panels[0].Text = GetStringFromResources( "Ready");
			statusBar.Panels[0].BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.Sunken;
			statusBar.Panels[0].AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;

			// The form should now process the layout directions
			ResumeLayout( false);
		}
		#endregion
		
		#region Implementation of Listener/Observer
		protected void OnServerChanged( object sender, System.EventArgs e)
		{
			ServiceSubject subject = (ServiceSubject) sender;
			Update( serverChanged, subject);
		}

		protected void OnServiceChanged( object sender, System.EventArgs e)
		{
			ServiceSubject subject = (ServiceSubject) sender;
			Update( serviceChanged, subject);
		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -