Code Search for Developers
 
 
  

MaseListen.cs from MASE: Agile Software Engineering at Krugle


Show MaseListen.cs syntax highlighted

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Collections;
using System.Drawing;

using TableWhiteboard_HCI_Intergration;
using Whiteboard.MaseWS;
using New_Study_Project;
using System.Windows.Forms;

namespace Whiteboard
{
	/// <summary>
	/// Summary description for MaseListen.
	/// </summary>
	/// 
	public class MaseListenResult
	{
		public int updatedContentType;
		public bool originator;
		public TabletVO updatedTabletVOContent = null;

		public MaseListenResult(int updatedContentType, int updatedTabletVOId)
		{
			this.updatedContentType = updatedContentType;
			this.originator = false;
			try
			{
				this.updatedTabletVOContent = SingleWS.getInstance(null).getIndividualTabletVO((long)updatedTabletVOId);
			} 
			catch (Exception e)
			{
				MessageBox.Show(e.StackTrace);
			}
		}
	}

	public class MaseListen : System.Windows.Forms.Form
	{
		private static IPHostEntry ipHostEntry = Dns.GetHostByName("localhost");
		public static string hostname = ipHostEntry.HostName;
		public static string hostIP  = "";
		private static string port = ApplicationProperties.clientListeningPort;
		public static webServicesService ws = SingleWS.getInstance(null);
		public static long tabletClientId = -1;
		private static TcpListener tabletServer = null;
		private static TcpClient maseCallBack = null;
		public static bool stopListening = false;
		public static Dashboard dashboard = null;
		public static int StoryUpdated = 0;
		public static int StoryCreated = 1;
		public static int iterationUpdated = 0;
		public static int iterationCreated = 0;
		public static String data = null;
		public static bool testing = false;
		public static Queue recevivedUpdateQueue = new Queue();

		public MaseListen(Dashboard dashboard)
		{
			//
			// TODO: Add constructor logic here
			//
		}

		public static void registerCallback()
		{
			ipHostEntry = Dns.GetHostByName(hostname);
			hostIP = ipHostEntry.AddressList[0].ToString();
			bool portBindingSuccessful = false;
			
			while(!portBindingSuccessful)
			{
				portBindingSuccessful = true;
				try
				{
					tabletServer = new TcpListener(Convert.ToInt32(port));
					tabletServer.Start();
				} 
				catch(System.Net.Sockets.SocketException)
				{
					port = Convert.ToString(Convert.ToInt32(port) + 1);
					portBindingSuccessful = false;
				}
			}
			TabletVO[] selectedIterations = dashboard.getSelectedIterations();
			TabletVO backlog = dashboard.productBacklog;
			tabletClientId = ws.registerCallBack(hostIP, port, selectedIterations[0].iterationID, backlog.iterationID, MaseUpdate.appType);
		}

		private static void deregisterCallback()
		{
			if(tabletClientId != -1)
			{
				ws.deregisterCallBack(tabletClientId);
			}
		}

		public static void startListening()
		{
			int timerInterval = 100;
			Byte[] bytes = new Byte[256];

			while(true&&!stopListening)
			{
				if(tabletServer.Pending())
				{
					maseCallBack = tabletServer.AcceptTcpClient();
					NetworkStream stream = maseCallBack.GetStream();
					data = "";
					int i;
					while((i = stream.Read(bytes, 0, bytes.Length))!=0) 
					{   
						data = data + System.Text.Encoding.ASCII.GetString(bytes, 0, i);
					}
					
					String[] splitStrings = data.Split(new char[]{';'}, 3);
					if(splitStrings.Length!=3)
					{
						MessageBox.Show("Broadcast message is corrupted!! Please reinitialize your workspace to ensure you have got identical content as the MASE server.");
						continue;
					}
					int updatedTabletClientID = Convert.ToInt32(splitStrings[0]);
					int updatedContentType = Convert.ToInt32(splitStrings[1]);
					int updatesTabletVOId = Convert.ToInt32(splitStrings[2]);
						
					if(!testing)
					{
						MaseListenResult maseListenResult = new MaseListenResult(updatedContentType, updatesTabletVOId);
						if(updatedTabletClientID == MaseListen.tabletClientId)
							maseListenResult.originator = true;
						maseListenResult.updatedTabletVOContent.horizontalCenter.centerX = maseListenResult.updatedTabletVOContent.horizontalCenter.centerX * MaseUpdate.S_width;
						maseListenResult.updatedTabletVOContent.horizontalCenter.centerY = maseListenResult.updatedTabletVOContent.horizontalCenter.centerY * MaseUpdate.S_height;
						recevivedUpdateQueue.Enqueue(maseListenResult);
						/*
						 * the receivedUpdateQueue will be Dequeued at Workspace.DoingNothing_Tick()
						 * DoingNothing_Tick() will update all image objects' status and at the end it will repaint the planning area
						 * DoingNothing_Tick() will check if the receivedUpdatedQueue is empty. If not it will dequeue every one of them
						 * and display them according to their updatedContentType
						 */
					} 
				}	
				else 
				{
					try
					{
						Thread.Sleep(timerInterval);
					} 
					catch(Exception)
					{
						stopListening = true;
					}
				}
			}

			ws.deregisterCallBack(tabletClientId);
			if(maseCallBack!=null)
				maseCallBack.Close();
			tabletServer.Stop();
			stopListening = false;
		}
	}
}




See more files for this project here

MASE: Agile Software Engineering

The MASE project investigates methods to support the coordination and executable acceptance testing of software projects. Keywords: Agile methods, distributed teams, Extreme Programming. See http://ebe.cpsc.ucalgary.ca/ebe for more information.

Project homepage: http://sourceforge.net/projects/mase
Programming language(s): Java,XML
License: other

  ApplicationProperties.cs
  CardLocationWith4Corners.cs
  HandWrittenObj.cs
  HandwrittenStoryCard.cs
  Iteration.cs
  Iteration.resx
  MaseListen.cs
  MaseUpdate.cs
  ProcessNode.cs
  ProjectNode.cs
  RegisterObj.cs
  Serializer.cs
  SingleWS.cs
  StoryObj.cs
  TabletContentandUtil.cs
  Utility.cs
  VLabel.cs
  VLabel.resx