/// <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> /// Constructor /// </summary> public QuickPollMessage(QuickPollModel poll) : base((poll != null) ? poll.Id : Guid.Empty) { if (poll != null) { this.AddLocalRef(poll); } this.m_Model = poll; }
private QuickPollModel m_CurrentQuickPoll; // TODO: Can get this from the PresentationModel public InstructorModel(Guid id) : base(id) { this.m_CurrentPresentation = null; this.m_CurrentDeckTraversal = null; this.m_CurrentQuickPoll = null; this.m_AcceptingStudentSubmissions = true; this.m_AcceptingQuickPollSubmissions = false; this.m_ForcingStudentNavigationLock = false; this.m_StudentNavigationType = LinkedDeckTraversalModel.NavigationSelector.Full; }
/// <summary> /// Add a new QuickPoll. /// </summary> /// <param name="id"></param> public void AddQuickPoll(QuickPollModel model) { if (m_VoteCounts.ContainsKey(model.Id)) { m_VoteCounts.Remove(model.Id); } VoteCounter vc = new VoteCounter(model.PollStyle); m_VoteCounts.Add(model.Id, vc); }
/// <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); }
public int AddQuickPoll(QuickPollModel model, int userId) { using (var scope = new TransactionScope()) { try { var poll = new PollModel() { IsActive = true, IsVotingCompleted = false, UserId = userId, OptionTypeId = (int)Lookups.PollOptionTypes.Text, SelectionTypeId = (int)Lookups.PollSelectionTypes.Single, Text = model.Text }; int pollId = _poll.Add(poll); foreach (var optionText in model.Options) { var option = new OptionModel() { Text = optionText, PollId = pollId, }; _option.Add(option); } // Add entity type poll Here _entityPoll.Add(new EntityPollModel() { EntityId = model.EntityId, PollId = pollId, EntityTypeId = model.EntityTypeId }); scope.Complete(); return(pollId); } catch (Exception ex) { scope.Dispose(); JavaScriptSerializer js = new JavaScriptSerializer(); string json = js.Serialize(model); Log.Error("BL-Poll - AddQuickPoll" + json, ex); throw new ReturnExceptionModel(new CustomExceptionModel() { StatusCode = HttpStatusCode.BadRequest, Message = ex.Message }); } } }
/// <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) { QuickPollModel poll = this.Target as QuickPollModel; // Update Target and poll if (poll == null) { if (this.m_Model == null) { this.Target = poll = null; return(false); } else { // Create a new model using (Synchronizer.Lock(this.m_Model.SyncRoot)) { this.Target = poll = new QuickPollModel(((Guid)this.TargetId), this.m_Model); } // Find a parent PresentationModel message PresentationModel presentation = null; Message parent = this.Parent; while (parent != null && presentation == null) { if (parent.Target is PresentationModel) { presentation = parent.Target as PresentationModel; } else { parent = parent.Parent; } } if (presentation == null) { return(false); } using (Synchronizer.Lock(presentation.SyncRoot)) { if (presentation.QuickPoll == null || !presentation.QuickPoll.Equals(poll)) { presentation.QuickPoll = poll; } } } } else { // No properties can get updated } return(true); }
public QuickPollNetworkService(SendingQueue sender, PresentationModel presentation) { this.m_Sender = sender; this.m_Presentation = presentation; using (Synchronizer.Lock(this.m_Presentation.SyncRoot)) { this.m_QuickPoll = this.m_Presentation.QuickPoll; } if (this.m_QuickPoll != null) { this.m_QuickPollResultCollectionHelper = new QuickPollResultCollectionHelper(this); } }
/// <summary> /// Handle displaying the PropertiesForm when the menu item is clicked on /// </summary> /// <param name="e">The event arguments </param> protected override void OnClick(EventArgs e) { string result = ""; using (this.localModel.Workspace.Lock()) { if ((~this.localModel.Workspace.CurrentPresentation) != null) { using (Synchronizer.Lock((~this.localModel.Workspace.CurrentPresentation).SyncRoot)) { if ((~this.localModel.Workspace.CurrentPresentation).QuickPoll != null) { using (Synchronizer.Lock((~this.localModel.Workspace.CurrentPresentation).QuickPoll.SyncRoot)) { System.Collections.Hashtable table = (~this.localModel.Workspace.CurrentPresentation).QuickPoll.GetVoteCount(); foreach (string s in table.Keys) { result += QuickPollModel.GetLocalizedQuickPollString(s) + " - " + table[s].ToString() + System.Environment.NewLine; } } } } } } MessageBox.Show(result); }
/// <summary> /// Creates a new QuickPoll and the associated slide (and deck) /// </summary> /// <param name="model">The PresenterModel</param> /// <param name="role">The RoleModel</param> public static void CreateNewQuickPoll(PresenterModel model, RoleModel role) { // Create the quickpoll QuickPollModel newQuickPoll = null; using (Synchronizer.Lock(model.ViewerState.SyncRoot)) { newQuickPoll = new QuickPollModel(Guid.NewGuid(), Guid.NewGuid(), model.ViewerState.PollStyle); } // Get the Current Slide SlideModel oldSlide; using (Synchronizer.Lock(role.SyncRoot)) { using (Synchronizer.Lock(((InstructorModel)role).CurrentDeckTraversal.SyncRoot)) { using (Synchronizer.Lock(((InstructorModel)role).CurrentDeckTraversal.Current.SyncRoot)) { oldSlide = ((InstructorModel)role).CurrentDeckTraversal.Current.Slide; } } } // Add a new QuickPoll to the model // NOTE: This should trigger a network message about the new QuickPoll // NOTE: Need to do this first before adding the sheet otherwise the // public display will not be able to associate the sheet with // this quick poll. using (model.Workspace.Lock()) { using (Synchronizer.Lock((~model.Workspace.CurrentPresentation).SyncRoot)) { (~model.Workspace.CurrentPresentation).QuickPoll = newQuickPoll; } } // Add the quickpoll slide to the quickpoll using (model.Workspace.Lock()) { using (Synchronizer.Lock(model.Participant.SyncRoot)) { DeckTraversalModel qpTraversal = null; DeckModel qpDeck = null; // Find the first quickpoll slidedeck. foreach (DeckTraversalModel candidate in model.Workspace.DeckTraversals) { if ((candidate.Deck.Disposition & DeckDisposition.QuickPoll) != 0) { qpTraversal = candidate; using (Synchronizer.Lock(qpTraversal.SyncRoot)) { qpDeck = qpTraversal.Deck; } break; } } // If there is no existing quickpoll deck, create one. if (qpTraversal == null) { // Change the name of quickpoll according to the number of it string qpName = "QuickPoll"; // NOTE: This code is duplicated in DecksMenu.CreateBlankWhiteboardDeckMenuItem. qpDeck = new DeckModel(Guid.NewGuid(), DeckDisposition.QuickPoll, qpName); qpDeck.Group = Network.Groups.Group.Submissions; qpTraversal = new SlideDeckTraversalModel(Guid.NewGuid(), qpDeck); if (model.Workspace.CurrentPresentation.Value != null) { using (Synchronizer.Lock((~model.Workspace.CurrentPresentation).SyncRoot)) { (~model.Workspace.CurrentPresentation).DeckTraversals.Add(qpTraversal); } } else { model.Workspace.DeckTraversals.Add(qpTraversal); } } // Add the slide // TODO CMPRINCE: Associate the quickpoll with this slide using (Synchronizer.Lock(qpDeck.SyncRoot)) { // Copy the values and sheets from the old slide to the new slide // Get oldSlide's Guid Guid oldId = Guid.Empty; using (Synchronizer.Lock(oldSlide.SyncRoot)) { oldId = oldSlide.Id; } // Create the new slide to add SlideModel newSlide = new SlideModel(Guid.NewGuid(), new LocalId(), SlideDisposition.Remote | SlideDisposition.StudentSubmission, DEFAULT_SLIDE_BOUNDS, oldId); // Make a list of image content sheets that need to be added to the deck. List <ImageSheetModel> images = new List <ImageSheetModel>(); // Update the fields of the slide using (Synchronizer.Lock(oldSlide.SyncRoot)) { using (Synchronizer.Lock(newSlide.SyncRoot)) { newSlide.Title = oldSlide.Title; newSlide.Bounds = oldSlide.Bounds; newSlide.Zoom = oldSlide.Zoom; newSlide.BackgroundColor = oldSlide.BackgroundColor; newSlide.SubmissionSlideGuid = oldSlide.SubmissionSlideGuid; newSlide.SubmissionStyle = oldSlide.SubmissionStyle; // Copy all of the content sheets. // Because ContentSheets do not change, there is no // need to do a deep copy (special case for ImageSheetModels). foreach (SheetModel s in oldSlide.ContentSheets) { newSlide.ContentSheets.Add(s); // Queue up any image content to be added the deck below. ImageSheetModel ism = s as ImageSheetModel; if (ism != null) { images.Add(ism); } } // Add the QuickPollSheet newSlide.ContentSheets.Add(new QuickPollSheetModel(Guid.NewGuid(), newQuickPoll)); // Make a deep copy of all the ink sheets foreach (SheetModel s in oldSlide.AnnotationSheets) { SheetModel newSheet = SheetModel.SheetDeepCopyHelper(s); newSlide.AnnotationSheets.Add(newSheet); // Queue up any image content to be added the deck below. ImageSheetModel ism = s as ImageSheetModel; if (ism != null) { images.Add(ism); } } } } // Add the slide content to the deck. foreach (ImageSheetModel ism in images) { System.Drawing.Image image = ism.Image; if (image == null) { using (Synchronizer.Lock(ism.Deck.SyncRoot)) using (Synchronizer.Lock(ism.SyncRoot)) image = ism.Deck.GetSlideContent(ism.MD5); } if (image != null) { qpDeck.AddSlideContent(ism.MD5, image); } } // Add the slide to the deck. qpDeck.InsertSlide(newSlide); // Add an entry to the deck traversal so that we can navigate to the slide using (Synchronizer.Lock(qpDeck.TableOfContents.SyncRoot)) { TableOfContentsModel.Entry e = new TableOfContentsModel.Entry(Guid.NewGuid(), qpDeck.TableOfContents, newSlide); qpDeck.TableOfContents.Entries.Add(e); } } } } }
public QuickPollInformationMessage(QuickPollModel poll) : base(poll) { }
public QuickPollMessage(Message parent, SerializedPacket p) : base(parent, p) { this.m_Model = (!SerializedPacket.IsNullPacket(p.PeekNextPart())) ? new QuickPollModel(p.PeekNextPart()) : null; p.GetNextPart(); }
/// <summary> /// Paints the text of the textsheetmodel onto the slide using the DrawString method. /// </summary> /// <param name="args"></param> public override void Paint(PaintEventArgs args) { Graphics g = args.Graphics; int startX, startY, endX, endY, width, height; RectangleF finalLocation; Font writingFont = new Font(FontFamily.GenericSansSerif, 12.0f); StringFormat format = new StringFormat(StringFormat.GenericDefault); format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; // Sanity Check using (Synchronizer.Lock(this.m_Sheet.SyncRoot)) { if (this.m_Sheet.QuickPoll == null) { return; } } // Get everything we need from the SlideDisplay using (Synchronizer.Lock(this.SlideDisplay.SyncRoot)) { ///transform what we will paint so that it will fit nicely into our slideview g.Transform = this.SlideDisplay.PixelTransform; if (this.SlideDisplay.Slide != null) { using (Synchronizer.Lock(this.SlideDisplay.Slide.SyncRoot)) { startX = (int)(this.SlideDisplay.Slide.Bounds.Width * 0.5f); endX = (int)(this.SlideDisplay.Slide.Bounds.Width * 0.95f); startY = (int)(this.SlideDisplay.Slide.Bounds.Height * 0.3f); endY = (int)(this.SlideDisplay.Slide.Bounds.Height * 0.85f); width = endX - startX; height = endY - startY; finalLocation = new RectangleF(startX, startY, width, height); } } else { startX = (int)(this.SlideDisplay.Bounds.Width * 0.5f); endX = (int)(this.SlideDisplay.Bounds.Width * 0.95f); startY = (int)(this.SlideDisplay.Bounds.Height * 0.3f); endY = (int)(this.SlideDisplay.Bounds.Height * 0.85f); width = endX - startX; height = endY - startY; finalLocation = new RectangleF(startX, startY, width, height); } } // Get the vote data System.Collections.ArrayList names; System.Collections.Hashtable table; using (Synchronizer.Lock(this.m_Sheet.SyncRoot)) { using (Synchronizer.Lock(this.m_Sheet.QuickPoll.SyncRoot)) { names = QuickPollModel.GetVoteStringsFromStyle(this.m_Sheet.QuickPoll.PollStyle); table = this.m_Sheet.QuickPoll.GetVoteCount(); } } // Draw the outline g.FillRectangle(Brushes.White, startX - 1, startY - 1, width, height); g.DrawRectangle(Pens.Black, startX - 1, startY - 1, width, height); switch (this.DisplayType) { case ResultDisplayType.Text: // Text // Get the results string string result = ""; foreach (string s in table.Keys) { result += QuickPollModel.GetLocalizedQuickPollString(s) + " - " + table[s].ToString() + System.Environment.NewLine; } g.DrawString(result, writingFont, Brushes.Black, finalLocation, format); break; case ResultDisplayType.Histogram: // Count the total number of results int totalVotes = 0; foreach (string s in table.Keys) { totalVotes += (int)table[s]; } // Draw the choices float columnWidth = width / names.Count; int columnStartY = (int)((height * 0.9f) + startY); int columnTotalHeight = columnStartY - startY; for (int i = 0; i < names.Count; i++) { // Draw the column int columnHeight = 0; if (totalVotes != 0) { columnHeight = (int)Math.Round((float)columnTotalHeight * ((int)table[names[i]] / (float)totalVotes)); } if (columnHeight == 0) { columnHeight = 1; } g.FillRectangle(this.columnBrushes[i], (int)(i * columnWidth) + startX, columnStartY - columnHeight, (int)columnWidth, columnHeight); // Draw the label g.DrawString(QuickPollModel.GetLocalizedQuickPollString(names[i].ToString()), writingFont, Brushes.Black, new RectangleF((i * columnWidth) + startX, columnStartY, columnWidth, endY - columnStartY), format); // Draw the number string percentage = String.Format("{0:0%}", (totalVotes == 0) ? 0 : (float)(((int)table[names[i]] / (float)totalVotes))); int numberHeight = (endY - columnStartY) * 2; RectangleF numberRectangle = new RectangleF((i * columnWidth) + startX, (numberHeight > columnHeight) ? (columnStartY - columnHeight - numberHeight) : (columnStartY - columnHeight), columnWidth, numberHeight); string numberString = percentage + System.Environment.NewLine + "(" + table[names[i]].ToString() + ")"; g.DrawString(numberString, writingFont, Brushes.Black, numberRectangle, format); } break; } }