/// <summary> /// Append a new model to the history. /// </summary> /// <param name="model">The model to append.</param> /// <returns>The sequence number of this event.</returns> public int AddModel(SimpleWebModel model) { int sequenceNumber = 0; lock (this) { // Add the next sequence number this.CurrentSequenceNumber++; sequenceNumber = this.CurrentSequenceNumber; this.History.Add(this.CurrentSequenceNumber, model); // Occassionally remove a bunch of the web models if (this.History.Count > this.MaximumBufferEntries) { // Get the keys and sort them int[] keys = new int[this.History.Count]; this.History.Keys.CopyTo(keys, 0); Array.Sort <int>(keys); // Calculate how many we need to remove (N) int stopIndex = keys.Length - this.MaximumEntries; // Remove the smallest N keys for (int i = 0; i < stopIndex; i++) { if (this.History.ContainsKey(keys[i])) { this.History.Remove(keys[i]); } } } } return(sequenceNumber); }
/// <summary> /// Build a string that represents the current model /// </summary> /// <param name="model">The model to build the HTML string representation of</param> /// <returns>The string that is built</returns> public static string BuildModelString(SimpleWebModel model) { string result = ""; result += "<html>\n"; result += "<body onload=\"parent.Presenter.Network.RecvFunc()\">\n"; // Create the main div result += "<div id=\"S0\">\n"; result += "\t<div id=\"S0_PName\">" + model.Name + "</div>\n"; result += "\t<div id=\"S0_IDeck\">" + model.CurrentDeck + "</div>\n"; result += "\t<div id=\"S0_ISlide\">" + (model.CurrentSlide-1) + "</div>\n"; result += "\t<div id=\"S0_Linked\">" + false + "</div>\n"; result += "\t<div id=\"S0_AllowSS\">" + true + "</div>\n"; result += "\t<div id=\"S0_Decks\">\n"; for( int i=0; i<model.Decks.Count; i++ ) { result += BuildDeckString( "S0_Decks", i, (SimpleWebDeck)model.Decks[i] ); } result += "\t</div>\n"; result += "</div>\n"; result += "</body>\n"; result += "</html>\n"; return result; }
/// <summary> /// Helper to create a simple data structure representing the model. This data structure will have a /// one-to-one conversion to JSON. /// </summary> /// <param name="firstNum">The first sequence number</param> /// <param name="first">The first model</param> /// <param name="secondNum">The second sequence number</param> /// <param name="second">The second model</param> /// <returns>The data structure.</returns> protected List <KeyValuePair <string, object> > BuildModel(int firstNum, SimpleWebModel first, int secondNum, SimpleWebModel second) { List <KeyValuePair <string, object> > model = new List <KeyValuePair <string, object> >(); // Add the global data. model.Add(new KeyValuePair <string, object>(StartSNString, firstNum)); model.Add(new KeyValuePair <string, object>(EndSNString, secondNum)); // Optionally, add the presentation data. List <KeyValuePair <string, object> > modelData = BuildModelData(first, second); if (modelData != null) { model.Add(new KeyValuePair <string, object>(ModelDataString, modelData)); } return(model); }
/// <summary> /// Clone this model. /// </summary> /// <returns>The cloned model.</returns> public object Clone() { SimpleWebModel model = new SimpleWebModel(); foreach (SimpleWebDeck deck in this.Decks) { model.Decks.Add(deck.Clone()); } model.CurrentDeck = this.CurrentDeck; model.CurrentSlide = this.CurrentSlide; model.Name = (string)this.Name.Clone(); model.AcceptingSS = this.AcceptingSS; model.AcceptingQP = this.AcceptingQP; model.ForceLink = this.ForceLink; model.PollStyle = this.PollStyle; model.RequestSubmissionSignal = this.RequestSubmissionSignal; model.RequestLogSignal = this.RequestLogSignal; return(model); }
/// <summary> /// Build the values for the model decks. /// </summary> /// <param name="first">The first model.</param> /// <param name="second">The second model.</param> /// <returns>The data structure for the decks array.</returns> protected List <object> BuildDecksData(SimpleWebModel first, SimpleWebModel second) { bool nonNull = false; List <object> decks = new List <object>(); // We need an entry for every deck in the second model. for (int i = 0; i < second.Decks.Count; i++) { // Optionally, get the first deck if this deck existed in the first model. SimpleWebDeck firstDeck = null; if (first != null && i < first.Decks.Count) { firstDeck = (SimpleWebDeck)first.Decks[i]; } // Get the difference between the two decks, if the decks are the same add null. List <KeyValuePair <string, object> > deckData = BuildDeckData(firstDeck, (SimpleWebDeck)second.Decks[i]); if (deckData != null) { decks.Add(deckData); nonNull = true; } else { decks.Add(null); } } // Return the result only if some deck was updated. if (nonNull == true && decks.Count > 0) { return(decks); } else { return(null); } }
/// <summary> /// Build the values for the model presentation. /// </summary> /// <param name="first">The first model.</param> /// <param name="second">The second model.</param> /// <returns>The data structure.</returns> protected List <KeyValuePair <string, object> > BuildModelData(SimpleWebModel first, SimpleWebModel second) { List <KeyValuePair <string, object> > model = new List <KeyValuePair <string, object> >(); // Optionally, add the presentation name. if (first == null || first.Name != second.Name) { model.Add(new KeyValuePair <string, object>(ModelDataName, second.Name)); } // Optionally, add the presentation current deck index. if (first == null || first.CurrentDeck != second.CurrentDeck) { model.Add(new KeyValuePair <string, object>(ModelDataCurrentDeck, second.CurrentDeck)); } // Optionally, add the presentation current slide index. if (first == null || first.CurrentSlide != second.CurrentSlide) { model.Add(new KeyValuePair <string, object>(ModelDataCurrentSlide, second.CurrentSlide)); } // Optionally, add the presentation force navigation value. if (first == null || first.ForceLink != second.ForceLink) { model.Add(new KeyValuePair <string, object>(ModelDataForceLink, second.ForceLink)); } // Optionally, add the presentation student submission enabled value. if (first == null || first.AcceptingSS != second.AcceptingSS) { model.Add(new KeyValuePair <string, object>(ModelDataAcceptingSS, second.AcceptingSS)); } // Optionally, add the presentation quick poll enabled value. if (first == null || first.AcceptingQP != second.AcceptingQP) { model.Add(new KeyValuePair <string, object>(ModelDataAcceptingQP, second.AcceptingQP)); } // Optionally, add the presentation quick poll type value. if (first == null || first.PollStyle != second.PollStyle) { model.Add(new KeyValuePair <string, object>(ModelDataPollStyle, second.PollStyle)); } // Optionally, add the request submission signal value. if (first == null || first.RequestSubmissionSignal != second.RequestSubmissionSignal) { model.Add(new KeyValuePair <string, object>(ModelDataRequestSubmission, second.RequestSubmissionSignal)); } // Optionally, add the request log signal value. if (first == null || first.RequestLogSignal != second.RequestLogSignal) { model.Add(new KeyValuePair <string, object>(ModelDataRequestLog, second.RequestLogSignal)); } // Optionall, add the decks data. List <object> decksData = BuildDecksData(first, second); if (decksData != null) { model.Add(new KeyValuePair <string, object>(ModelDataDecks, decksData)); } // Return the result only if we added/updated data. if (model.Count > 0) { return(model); } else { return(null); } }
/// <summary> /// Clone this model. /// </summary> /// <returns>The cloned model.</returns> public object Clone() { SimpleWebModel model = new SimpleWebModel(); foreach (SimpleWebDeck deck in this.Decks) { model.Decks.Add(deck.Clone()); } model.CurrentDeck = this.CurrentDeck; model.CurrentSlide = this.CurrentSlide; model.Name = (string)this.Name.Clone(); model.AcceptingSS = this.AcceptingSS; model.AcceptingQP = this.AcceptingQP; model.ForceLink = this.ForceLink; model.PollStyle = this.PollStyle; model.RequestSubmissionSignal = this.RequestSubmissionSignal; model.RequestLogSignal = this.RequestLogSignal; return model; }
/// <summary> /// Build the values for the model presentation. /// </summary> /// <param name="first">The first model.</param> /// <param name="second">The second model.</param> /// <returns>The data structure.</returns> protected List<KeyValuePair<string, object>> BuildModelData(SimpleWebModel first, SimpleWebModel second) { List<KeyValuePair<string,object>> model = new List<KeyValuePair<string,object>>(); // Optionally, add the presentation name. if(first == null || first.Name != second.Name) { model.Add(new KeyValuePair<string,object>(ModelDataName, second.Name)); } // Optionally, add the presentation current deck index. if (first == null || first.CurrentDeck != second.CurrentDeck) { model.Add(new KeyValuePair<string,object>(ModelDataCurrentDeck, second.CurrentDeck)); } // Optionally, add the presentation current slide index. if (first == null || first.CurrentSlide != second.CurrentSlide) { model.Add(new KeyValuePair<string,object>(ModelDataCurrentSlide, second.CurrentSlide)); } // Optionally, add the presentation force navigation value. if (first == null || first.ForceLink != second.ForceLink) { model.Add(new KeyValuePair<string,object>(ModelDataForceLink, second.ForceLink)); } // Optionally, add the presentation student submission enabled value. if (first == null || first.AcceptingSS != second.AcceptingSS) { model.Add(new KeyValuePair<string,object>(ModelDataAcceptingSS, second.AcceptingSS)); } // Optionally, add the presentation quick poll enabled value. if (first == null || first.AcceptingQP != second.AcceptingQP) { model.Add(new KeyValuePair<string,object>(ModelDataAcceptingQP, second.AcceptingQP)); } // Optionally, add the presentation quick poll type value. if (first == null || first.PollStyle != second.PollStyle) { model.Add(new KeyValuePair<string,object>(ModelDataPollStyle, second.PollStyle)); } // Optionally, add the request submission signal value. if (first == null || first.RequestSubmissionSignal != second.RequestSubmissionSignal) { model.Add(new KeyValuePair<string, object>(ModelDataRequestSubmission, second.RequestSubmissionSignal)); } // Optionally, add the request log signal value. if (first == null || first.RequestLogSignal != second.RequestLogSignal) { model.Add(new KeyValuePair<string, object>(ModelDataRequestLog, second.RequestLogSignal)); } // Optionall, add the decks data. List<object> decksData = BuildDecksData(first, second); if(decksData != null) { model.Add(new KeyValuePair<string,object>(ModelDataDecks, decksData)); } // Return the result only if we added/updated data. if(model.Count > 0) return model; else return null; }
/// <summary> /// Helper to create a simple data structure representing the model. This data structure will have a /// one-to-one conversion to JSON. /// </summary> /// <param name="firstNum">The first sequence number</param> /// <param name="first">The first model</param> /// <param name="secondNum">The second sequence number</param> /// <param name="second">The second model</param> /// <returns>The data structure.</returns> protected List<KeyValuePair<string, object>> BuildModel(int firstNum, SimpleWebModel first, int secondNum, SimpleWebModel second) { List<KeyValuePair<string,object>> model = new List<KeyValuePair<string,object>>(); // Add the global data. model.Add(new KeyValuePair<string,object>(StartSNString, firstNum)); model.Add(new KeyValuePair<string,object>(EndSNString, secondNum)); // Optionally, add the presentation data. List<KeyValuePair<string,object>> modelData = BuildModelData(first, second); if(modelData != null) { model.Add(new KeyValuePair<string,object>(ModelDataString, modelData)); } return model; }
/// <summary> /// Build the values for the model decks. /// </summary> /// <param name="first">The first model.</param> /// <param name="second">The second model.</param> /// <returns>The data structure for the decks array.</returns> protected List<object> BuildDecksData(SimpleWebModel first, SimpleWebModel second) { bool nonNull = false; List<object> decks = new List<object>(); // We need an entry for every deck in the second model. for (int i = 0; i < second.Decks.Count; i++) { // Optionally, get the first deck if this deck existed in the first model. SimpleWebDeck firstDeck = null; if (first != null && i < first.Decks.Count) { firstDeck = (SimpleWebDeck)first.Decks[i]; } // Get the difference between the two decks, if the decks are the same add null. List<KeyValuePair<string, object>> deckData = BuildDeckData(firstDeck, (SimpleWebDeck)second.Decks[i]); if (deckData != null) { decks.Add(deckData); nonNull = true; } else { decks.Add(null); } } // Return the result only if some deck was updated. if (nonNull == true && decks.Count > 0) return decks; else return null; }
/// <summary> /// Append a new model to the history. /// </summary> /// <param name="model">The model to append.</param> /// <returns>The sequence number of this event.</returns> public int AddModel(SimpleWebModel model) { int sequenceNumber = 0; lock (this) { // Add the next sequence number this.CurrentSequenceNumber++; sequenceNumber = this.CurrentSequenceNumber; this.History.Add(this.CurrentSequenceNumber, model); // Occassionally remove a bunch of the web models if (this.History.Count > this.MaximumBufferEntries) { // Get the keys and sort them int[] keys = new int[this.History.Count]; this.History.Keys.CopyTo(keys, 0); Array.Sort<int>(keys); // Calculate how many we need to remove (N) int stopIndex = keys.Length - this.MaximumEntries; // Remove the smallest N keys for (int i = 0; i < stopIndex; i++) { if (this.History.ContainsKey(keys[i])) { this.History.Remove(keys[i]); } } } } return sequenceNumber; }
public string BuildModelDiffString(SimpleWebModel oldModel, SimpleWebModel newModel) { // Go recursive, only add if there is a change within return ""; }