/// <summary> /// Handle the receipt of this message /// </summary> /// <param name="context">The context of the receiver from which the message was sent</param> protected override bool UpdateTarget(ReceiveContext context) { QuickPollResultModel result = this.Target as QuickPollResultModel; if (result == null) { using (Synchronizer.Lock(this.m_Result.SyncRoot)) { this.Target = result = new QuickPollResultModel(this.m_Result.OwnerId, this.m_Result.ResultString); } } if (result != null) { PresentationModel presentation = (this.Parent != null && this.Parent.Parent != null) ? this.Parent.Parent.Target as PresentationModel : null; if (presentation == null) { return(false); } QuickPollModel poll = (this.Parent != null) ? this.Parent.Target as QuickPollModel : null; if (poll == null) { return(false); } using (Synchronizer.Lock(presentation.SyncRoot)) { poll.AddResult(result); } } // Don't want to store this as a target return(false); }
/// <summary> /// Release all resources /// </summary> /// <param name="disposing">True if truely disposing</param> protected override void Dispose(bool disposing) { if (this.m_Disposed) { return; } try { if (disposing) { // Unregister event listeners this.m_CurrentResult = null; this.m_Model.Changed["CurrentStudentQuickPollResult"].Remove(this.m_CurrentQuickPollResultChangedDispatcher.Dispatcher); ParticipantModel participant = null; using (Synchronizer.Lock(this.m_Model.Workspace.CurrentPresentation.SyncRoot)) { if (this.m_Model.Workspace.CurrentPresentation.Value != null) { using (Synchronizer.Lock(this.m_Model.Workspace.CurrentPresentation.Value.SyncRoot)) { participant = this.m_Model.Workspace.CurrentPresentation.Value.Owner; } } } if (participant != null) { using (Synchronizer.Lock(participant.SyncRoot)) { ((InstructorModel)(participant.Role)).Changed["AcceptingQuickPollSubmissions"].Remove(this.m_QuickPollChangedDispatcher.Dispatcher); } } this.Role = null; } } finally { base.Dispose(disposing); } this.m_Disposed = true; }
protected override object SetUpMember(int index, object member) { QuickPollResultModel result = ((QuickPollResultModel)member); Group receivers = Group.Submissions; this.SendPollResultInformation(result, receivers); return(new QuickPollResultNetworkService(this.m_Service.m_Sender, this.m_Service.m_Presentation, this.m_Service.m_QuickPoll, result)); }
/// <summary> /// Constructs a new QuickPollResultNetworkService /// </summary> /// <param name="sender">The message queue to use</param> /// <param name="presentation">The PresentationModel to associate this service with</param> /// <param name="poll">The QuickPollModel to associate this service with</param> /// <param name="result">The QuickPollResultModel to associate this service with</param> public QuickPollResultNetworkService(SendingQueue sender, PresentationModel presentation, QuickPollModel poll, QuickPollResultModel result) { this.m_Sender = sender; this.m_Presentation = presentation; this.m_QuickPoll = poll; this.m_Result = result; // Listen to changes tot he ResultString this.m_ResultChangedDispatcher = new EventQueue.PropertyEventDispatcher(this.m_Sender, new PropertyEventHandler(this.HandleResultChanged)); this.m_Result.Changed["ResultString"].Add(this.m_ResultChangedDispatcher.Dispatcher); }
protected override void TearDownMember(int index, object member, object tag) { QuickPollResultNetworkService service = ((QuickPollResultNetworkService)tag); if (service != null) { QuickPollResultModel result = service.Result; service.Dispose(); // Note: Do not need to send a removed message here since there should be no // case where a result is removed by a student (the student can abstain from // voting) } }
private void SendPollResultInformation(QuickPollResultModel result, Group receivers) { Message message, poll, res; message = new PresentationInformationMessage(this.m_Service.m_Presentation); message.Group = receivers; poll = new QuickPollInformationMessage(this.m_Service.m_QuickPoll); poll.Group = receivers; message.InsertChild(poll); res = new QuickPollResultInformationMessage(result); res.Group = receivers; poll.InsertChild(res); this.m_Service.m_Sender.Send(message); }
/// <summary> /// Accept a new result, aggreate it, and return the current array. /// </summary> /// <param name="result"></param> /// <param name="id"></param> /// <returns></returns> public int[] AcceptResult(QuickPollResultModel result, Guid id) { if (m_VoteCounts.ContainsKey(id)) { using (Synchronizer.Lock(result)) { m_VoteCounts[id].AddVote(result.ResultString, result.OwnerId); } return(m_VoteCounts[id].GetCurrentCount()); } else { Debug.WriteLine("***QuickPoll Result for non-existant Poll!"); return(new int[0]); } }
public PresenterModel() { this.m_Stylus = null; this.m_CurrentResult = null; this.m_Network = new NetworkModel(); this.m_VersionExchange = new VersionExchangeModel(); /// Note: We currently assume that the ParticipantModel Guid will be different for each application invocation. /// (In particular TCP reconnection relies on this assumption.) If we need an identifer that persists across /// sessions, we'd need to create a new identifier for this. ParticipantId = Guid.NewGuid(); this.m_Participant = new ParticipantModel(ParticipantId, System.Windows.Forms.SystemInformation.UserName); this.m_Workspace = new WorkspaceModel(); this.m_Undo = new UndoModel(); this.m_ViewerState = new ViewerStateModel(); this.m_PenState = new PenStateModel(); TheInstance = this; }
/// <summary> /// Handles when the value of the CurrentQuickPollResult changes /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void HandleQuickPollResultChanged(object sender, PropertyEventArgs args) { if (this.m_CurrentResult != null) { this.m_CurrentResult.Changed["ResultString"].Remove(this.m_CurrentQuickPollResultStringChangedDispatcher.Dispatcher); } using (Synchronizer.Lock(this.m_Model.SyncRoot)) { this.m_CurrentResult = this.m_Model.CurrentStudentQuickPollResult; if (m_CurrentResult != null) { this.m_CurrentResult.Changed["ResultString"].Add(this.m_CurrentQuickPollResultStringChangedDispatcher.Dispatcher); } } this.HandleQuickPollValueChanged(null, null); }
public void HandleQuickPollReceived(object server, Guid ownerId, string val) { QuickPollResultModel result = new QuickPollResultModel(ownerId, val); this.m_Presentation.QuickPoll.AddResult(result); }
public QuickPollResultRemovedMessage(QuickPollResultModel result) : base(result) { }
public QuickPollResultInformationMessage(QuickPollResultModel result) : base(result) { }
public QuickPollResultMessage(Message parent, SerializedPacket p) : base(parent, p) { this.m_Result = (!SerializedPacket.IsNullPacket(p.PeekNextPart())) ? new QuickPollResultModel(p.PeekNextPart()) : null; p.GetNextPart(); }
/// <summary> /// Constructor /// </summary> public QuickPollResultMessage(QuickPollResultModel result) : base(Guid.Empty) { // this.AddLocalRef( result ); this.m_Result = result; }
/// <summary> /// Constructor /// </summary> /// <param name="dispatcher">The event queue</param> /// <param name="model">The presenter model</param> public StudentQuickPollToolBarButton(ControlEventQueue dispatcher, PresenterModel model, string name, string value) : base(dispatcher, model) { this.m_Model = model; this.m_Value = value; this.Name = name; this.ToolTipText = name; this.Text = name; this.DisplayStyle = ToolStripItemDisplayStyle.Text; // Handle the changed result string this.m_CurrentQuickPollResultStringChangedDispatcher = new EventQueue.PropertyEventDispatcher(this.m_EventQueue, new PropertyEventHandler(this.HandleQuickPollResultChanged)); // This listener listens to changes in the CurrentStudentQuickPollResult field of the // PresenterModel, when this changes we need to update the UI and attach a new listener // to the ResultString of the model so that we can update the UI. this.m_CurrentQuickPollResultChangedDispatcher = new EventQueue.PropertyEventDispatcher(this.m_EventQueue, new PropertyEventHandler(this.HandleQuickPollResultChanged)); this.m_Model.Changed["CurrentStudentQuickPollResult"].Add(this.m_CurrentQuickPollResultChangedDispatcher.Dispatcher); using (Synchronizer.Lock(this.m_Model.SyncRoot)) { this.m_CurrentResult = this.m_Model.CurrentStudentQuickPollResult; } this.HandleQuickPollResultChanged(null, null); // This is the listener that we will attatch to the AcceptingStudentSubmissions field // once we've got the current presentation. We can't do this directly because // when this button is created there is no presentation yet. this.m_QuickPollChangedDispatcher = new EventQueue.PropertyEventDispatcher(this.m_EventQueue, new PropertyEventHandler(this.HandleQuickPollChanged)); // Listen for the Presentation. // Don't call the event handler immediately (use Listen instead of ListenAndInitialize) // because it needs to be delayed until Initialize() below. this.m_CurrentPresentationDispatcher = this.m_Model.Workspace.CurrentPresentation.Listen(dispatcher, delegate(Property <PresentationModel> .EventArgs args) { // Remove any previous listener if (args.Old != null) { if (args.Old.Owner != null) { using (Synchronizer.Lock(args.Old.Owner)) { ((InstructorModel)(((PresentationModel)(args.Old)).Owner.Role)).Changed["AcceptingQuickPollSubmissions"].Remove(this.m_QuickPollChangedDispatcher.Dispatcher); } } } // Get the new InstructorModel ParticipantModel participant = null; using (Synchronizer.Lock(this.m_Model.Workspace.CurrentPresentation.SyncRoot)) { if (this.m_Model.Workspace.CurrentPresentation.Value != null) { using (Synchronizer.Lock(this.m_Model.Workspace.CurrentPresentation.Value.SyncRoot)) { participant = this.m_Model.Workspace.CurrentPresentation.Value.Owner; } } } // Attach to the new AcceptingQuickPollSubmissions if (participant != null) { using (Synchronizer.Lock(participant.SyncRoot)) { ((InstructorModel)(participant.Role)).Changed["AcceptingQuickPollSubmissions"].Add(this.m_QuickPollChangedDispatcher.Dispatcher); } } // Update the UI this.HandleQuickPollChanged(null, null); }); base.InitializeRole(); }