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

📄 eventbase.cs

📁 用C#实现的取得CellID和LAC的程序源代码!
💻 CS
字号:
using System;
using System.Collections;

namespace NiceTracker.Events
{
	/// <summary>
	/// Summary description for EventBase.
	/// </summary>
	public abstract class EventBase
	{
		protected GSMCell currentCell = null;
		private string friendlyName = "<No name>";
		private string description = "<No name>";		

		private bool inEventCatchment = false;

		private ArrayList cellList = new ArrayList();
		private ArrayList areaList = new ArrayList();

		public enum TriggerType { EnterCell, ExitCell, CellChanged };
		public enum TriggerModeType { OneCell, EachCell };

		public TriggerType Trigger = TriggerType.EnterCell;
		public TriggerModeType TriggerMode = TriggerModeType.OneCell;

		public EventBase()
		{
		}

		public void AddCell( GSMCell cell )
		{
			cellList.Add( cell );
		}

		public void RemoveCell( GSMCell cell )
		{
			cellList.Remove( cell );
		}

		public void ClearCells( )
		{
			cellList.Clear();
		}

		public ICollection ListCells()
		{
			return cellList;
		}

		public void AddArea( GSMCell cell )
		{
			areaList.Add( cell );
		}

		public void RemoveArea( GSMCell cell )
		{
			areaList.Remove( cell );
		}

		public void ClearAreas( )
		{
			areaList.Clear();
		}

		public ICollection ListAreas()
		{
			return areaList;
		}

		public bool CheckEventCatchment( GSMCell newCell )
		{
			int count = 0;
			bool inCatchment = false;

			// Process area based events
			while ( count < areaList.Count && !inCatchment )
			{
				GSMCell thisCell = areaList[ count ] as GSMCell;

				if ( thisCell.LAC == newCell.LAC )
				{		
					inCatchment = true;
				}

				count++;
			}


			// Reset counter
			count = 0;

			// Process cell based events
			while ( count < cellList.Count && !inCatchment )
			{
				GSMCell thisCell = cellList[ count ] as GSMCell;

				if ( thisCell.LAC == newCell.LAC && thisCell.CI == newCell.CI )
				{
					inCatchment = true;
				}
				count++;
			}

			return inCatchment;
		}


		public void Perform( GSMCell newCell )
		{
			currentCell = newCell;

			bool proceedAfterEvent = true;						
			bool enteredEventCatchment = false;
			int count = 0;

			// Process area based events
			while ( count < areaList.Count && proceedAfterEvent )
			{
				GSMCell thisCell = areaList[ count ] as GSMCell;

				if ( thisCell.LAC == newCell.LAC )
				{					
					if ( !inEventCatchment )
						Action();

					enteredEventCatchment = true;					

					if ( TriggerMode == TriggerModeType.OneCell )
						proceedAfterEvent = false;
				}

				count++;
			}


			// Reset counter
			count = 0;

			// Process cell based events
			while ( count < cellList.Count && proceedAfterEvent )
			{
				GSMCell thisCell = cellList[ count ] as GSMCell;

				if ( thisCell.LAC == newCell.LAC && thisCell.CI == newCell.CI )
				{
					if ( !inEventCatchment )
						Action();

					enteredEventCatchment = true;

					if ( TriggerMode == TriggerModeType.OneCell )
						proceedAfterEvent = false;
				}

				count++;
			}

			inEventCatchment = enteredEventCatchment;
		}

		public abstract void Action();

		#region Configuration
		public string GetConfigurationString( )
		{
			EventParameters ep = new EventParameters();
			
			ep.Set( "FriendlyName", FriendlyName );
			ep.Set( "Description", Description );
			
			if ( Trigger == TriggerType.EnterCell )
				ep.Set( "Trigger", "Enter" );
			else if ( Trigger == TriggerType.ExitCell )
				ep.Set( "Trigger", "Exit" );

			if ( TriggerMode == TriggerModeType.OneCell )
				ep.Set( "TriggerMode", "One" );
			else if ( TriggerMode == TriggerModeType.EachCell )
				ep.Set( "TriggerMode", "Each" );

			// prepare cell string
			string cells = "";

			foreach ( GSMCell thisCell in cellList )
			{
				cells += thisCell.ToString();
			}

			ep.Set( "Cells", cells );

			// prepare area string
			string areas = "";

			foreach ( GSMCell thisCell in areaList )
			{
				areas += thisCell.ToString();
			}

			ep.Set( "Areas", areas );

			SaveParameters( ep );

			return ep.ToString();
		}

		public void SetConfigurationByString( string configString )
		{
			EventParameters ep = new EventParameters( configString );

			FriendlyName = ep.Get( "FriendlyName" );
			Description = ep.Get( "Description" );
			
			string tType = ep.Get( "Trigger" );
			if ( tType == "Enter" )
				Trigger = TriggerType.EnterCell;
			else if ( tType == "Exit" )
				Trigger = TriggerType.ExitCell;

			string tMode = ep.Get( "TriggerMode" );
			if ( tMode == "One" )
				TriggerMode = TriggerModeType.OneCell;
			else if ( tMode == "Each" )
				TriggerMode = TriggerModeType.EachCell;

			// Parse and set cells
			string gsmString = ep.Get( "Cells" );
			gsmString = gsmString.Replace( "{", "" );
			string[] gsmList = gsmString.Split( '}' );
			foreach ( string gsmCellString in gsmList )
			{
				if ( gsmCellString != "" )
				{
					GSMCell newCell = new GSMCell();
					newCell.ConfigureByString( gsmCellString );
				
					AddCell( newCell );
				}
			}

			// Parse and set areas
			gsmString = ep.Get( "Areas" );
			gsmString = gsmString.Replace( "{", "" );
			gsmList = gsmString.Split( '}' );
			foreach ( string gsmCellString in gsmList )
			{
				if ( gsmCellString != "" )
				{
					GSMCell newCell = new GSMCell();
					newCell.ConfigureByString( gsmCellString );
				
					AddArea( newCell );
				}
			}

			LoadParameters( ep );			
		}
		#endregion

		public abstract void SaveParameters( EventParameters eventParameters );
		public abstract void LoadParameters( EventParameters eventParameters );

		public string FriendlyName 
		{
			get
			{
				return friendlyName;
			}
			set
			{
				friendlyName = value;
			}
		}

		public string Description 
		{
			get
			{
				return description;
			}
			set
			{
				description = value;
			}
		}

		public EventBase EventObject
		{
			get
			{
				return this;
			}
		}

		public bool InEventCatchment
		{
			get
			{
				return inEventCatchment;
			}
			set
			{
				inEventCatchment = value;
			}
		}

	}
}

⌨️ 快捷键说明

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