public BroadcastManager(PresenterModel model, TCPConnectionManager tcpMgr) { IPv6LinkLocalMulticast = IPAddress.Parse("ff02::1"); UseIPv6 = false; //Use IPv6 only if IPv4 is unavailable if ((!Socket.OSSupportsIPv4) && (Socket.OSSupportsIPv6)) { UseIPv6 = true; } this.m_Model = model; this.m_TCPConnectionMgr = tcpMgr; this.m_TCPClassroomMgr = tcpMgr.ClassroomManager; this.m_TCPClientClassrooms = new Hashtable(); this.m_RTPAdvertisedClassrooms = new Hashtable(); m_EventQueue = new ThreadEventQueue(); // this.m_RTPConnectionMgr = rtpMgr; StartListener(); //Subscribe to the instructor advertisements that the BroadcastListener provides m_InstructorAdvertisementCollectionHelper = new InstructorAdvertisementCollectionHelper(this, this.m_Listener); //Subscribe to all the RTP Classrooms to learn when they connect/disconnect. //Notice that we assume there will be no new RTP classrooms created (other than the ones we create in response to advertisements). /*this.m_RtpClassroomConnected = false; * using (Synchronizer.Lock(m_RTPConnectionMgr.Protocol.SyncRoot)) { * foreach (ClassroomModel cm in m_RTPConnectionMgr.Protocol.Classrooms) { * cm.Changed["Connected"].Add(new PropertyEventHandler(OnRtpClassroomConnectedChanged)); * } * }*/ m_IsInstructor = false; using (Synchronizer.Lock(this.m_Model.Participant.SyncRoot)) { //This is the server's identifier which remains constant for the app instance m_SenderID = this.m_Model.Participant.Guid; //Subscribe to the local presenter's role to track when we are instructor this.m_Model.Participant.Changed["Role"].Add(new PropertyEventHandler(OnRoleChanged)); if (this.m_Model.Participant.Role is InstructorModel) { m_IsInstructor = true; } } //Subscribe to the TCP Server to find out when it starts and stops this.m_TCPClassroomMgr.Changed["ServerStarted"].Add(new PropertyEventHandler(ServerStartedChangedHandler)); m_TcpServerStarted = false; using (Synchronizer.Lock(m_TCPClassroomMgr.SyncRoot)) { if (m_TCPClassroomMgr.ServerStarted) { m_TcpServerStarted = true; } } UpdateSenderStatus(); }
public ConnectTCPRadioButton(ControlEventQueue dispatcher, PresenterModel model, ManualConnectionPanel manual, Point location, int width) { this.m_EventQueue = dispatcher; this.m_Model = model; this.m_Manual = manual; this.m_Connected = false; this.FlatStyle = FlatStyle.System; this.Font = Model.Viewer.ViewerStateModel.StringFont1; this.Text = Strings.ConnectToTCPServer; this.Location = location; this.Size = new Size(width, this.Font.Height + 5); this.m_ClassroomManager = null; //Watch for Role changes and disable if role is Instructor. this.m_RoleChangedDispatcher = new EventQueue.PropertyEventDispatcher(this.m_EventQueue, new PropertyEventHandler(this.HandleRoleChanged)); this.m_Model.Participant.Changed["Role"].Add(this.m_RoleChangedDispatcher.Dispatcher); using (Synchronizer.Lock(this.m_Model.Participant.SyncRoot)) { if (this.m_Model.Participant.Role is InstructorModel) { this.Enabled = false; } else { this.Enabled = true; } } //should probably make this a listener //Do persistence in a more intelligent way - this doesn't make the popup pop up. /*using (Synchronizer.Lock(this.m_Model.ViewerState.SyncRoot)) { * if (this.Text == this.m_Model.ViewerState.ManualConnectionButtonName) { * this.Checked = true; * } * }*/ this.CheckedChanged += new EventHandler(OnClick); this.m_ProtocolCollectionHelper = new ProtocolCollectionHelper(this, this.m_Model.Network); }
private void AddClassroom(TCPClassroomManager classroom) { this.m_ClassroomManager = classroom; this.Enabled = true; }
private void RemoveClassroom() { this.m_ClassroomManager = null; this.Enabled = false; }
protected override void OnClick(EventArgs click) { base.OnClick(click); if (this.m_Classrooms.Count <= 0) { return; } TCPClassroomManager manager = this.m_Classrooms[0]; if (!m_Connected) { Form form = new Form(); form.Text = "Connect to TCP Server..."; form.ClientSize = new Size(350, form.ClientSize.Height); form.FormBorderStyle = FormBorderStyle.FixedDialog; Label label = new Label(); label.Text = "Server:"; using (Graphics graphics = label.CreateGraphics()) label.ClientSize = Size.Add(new Size(10, 0), graphics.MeasureString(label.Text, label.Font).ToSize()); label.Location = new Point(5, 5); TextBox host = new TextBox(); host.Location = new Point(label.Right + 10, label.Top); host.Width = form.ClientSize.Width - host.Left - 5; Button okay = new Button(); okay.Text = Strings.OK; okay.Width = (host.Right - label.Left) / 2 - 5; okay.Location = new Point(label.Left, Math.Max(host.Bottom, label.Bottom) + 10); Button cancel = new Button(); cancel.Text = Strings.Cancel; cancel.Width = okay.Width; cancel.Location = new Point(okay.Right + 10, okay.Top); EventHandler connect = delegate(object source, EventArgs args) { try { //manager.ClientConnect(host.Text); //obsolete this.m_Connected = true; this.Text = "Disconnect from &TCP Server..."; form.Dispose(); } catch (Exception e) { MessageBox.Show( string.Format("Classroom Presenter 3 was unable to connect to\n\n" + "\t\"{0}\"\n\nfor the following reason:\n\n{1}", host.Text, e.Message), "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); this.m_Connected = false; } }; host.KeyPress += delegate(object source, KeyPressEventArgs args) { if (args.KeyChar == '\r') { connect(source, EventArgs.Empty); } }; okay.Click += connect; cancel.Click += delegate(object source, EventArgs args) { this.m_Connected = false; form.Dispose(); }; form.ClientSize = new Size(form.ClientSize.Width, Math.Max(okay.Bottom, cancel.Bottom) + 5); form.Controls.Add(label); form.Controls.Add(host); form.Controls.Add(okay); form.Controls.Add(cancel); DialogResult dr = form.ShowDialog(this.GetMainMenu() != null ? this.GetMainMenu().GetForm() : null); } else { //manager.ClientDisconnect(); this.Text = "Connect to &TCP Server..."; m_Connected = false; } }
private void RemoveClassroom(TCPClassroomManager classroom) { this.m_Classrooms.Remove(classroom); this.Enabled = (this.m_Classrooms.Count > 0); }