Database.cs 3.42 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* Copyright (C) 2004 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; version 2 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace NDB_CPC
{
	/// <summary>
	/// Summary description for Database.
	/// </summary>
	public class Database
	{
		public enum	Status {Disconnected=1,Connected=2, Unknown=3}
		private string m_name;
		private string m_owner;
		private int m_mgmtPort;
		private Status m_status;
		private ArrayList m_processes;
		public Database(string name)
		{	
			m_name=name;
			m_processes = new ArrayList();
		}
		public Database(string name, string owner)
		{	
			m_name=name;
			m_owner=owner;
			m_processes = new ArrayList();
		}
		public Database()
		{	
			m_processes = new ArrayList();
		}

		public string getName() 
		{
			return m_name;
		}
		
		public void setName(string name) 
		{
			m_name=name;
		}
		
		public void setMgmtPort(int port) 
		{
			m_mgmtPort=port;
		}

		public string getOwner() 
		{
			return m_owner;
		}
		
		public void setOwner(string name) 
		{
			m_owner=name;
		}


		public Status getStatus() 
		{
			return m_status;
		}

		public string getStatusString() 
		{
			if(m_status.Equals(Status.Connected))
				return "Connected";
			if(m_status.Equals(Status.Disconnected))
				return "Disconnected";
			if(m_status.Equals(Status.Unknown))
				return "Unknown";
			return "Unknown";
		}
		public void setStatus(Status status) 
		{
			m_status=status;
		}

		public void addProcess(Process process) 
		{
			/*if(check) 
			{
				if(m_processes==null)
					return;
				if(m_processes.Count>0) 
				{
					foreach (Process p in m_processes)
					{
						if(process.getId().Equals(p.getId()))
							return;
					}
				}
			}
			*/
			m_processes.Add(process);			
		}
		public void addProcessCheck(Process process) 
		{
	
			if(m_processes==null)
				return;
			if(m_processes.Count>0) 
			{
				foreach (Process p in m_processes)
				{
					if(process.getId().Equals(p.getId()))
						return;
				}
			}
			m_processes.Add(process);			
		}

		public Process getProcess(string id) 
		{
			foreach(Process process in m_processes)
			{
				if(process.getId().Equals(id))
					return process;
			}
			return null;
		}

		public Process getProcessByName(string name) 
		{
			foreach(Process process in m_processes)
			{
				if(process.getName().Equals(name))
					return process;
			}
			return null;
		}
		
		public void removeProcess( string processName)
		{
			Process p = this.getProcessByName(processName);
			m_processes.Remove(p);
		}

		public void removeAllProcesses() 
		{
			Computer c;
			foreach(Process p in m_processes)
			{
				c=p.getComputer();
				if(c.removeProcess(p.getName(),m_name).Equals(false)) 
				{
				
				}
			}
			m_processes.Clear();
		}

		public ArrayList getProcesses() 
		{
			return m_processes;
		}
	}
}