private void RemoveFromIndex(UrlSection section) { var key = section.HitCount; if (this.SectionIndex.TryGetValue(key, out var sections)) { sections.Remove(section); if (sections.Count == 0) { this.SectionIndex.Remove(key); } } }
private void AddToIndex(UrlSection section) { var key = section.HitCount; if (this.SectionIndex.TryGetValue(key, out var sections)) { sections.Add(section); } else { sections = new HashSet <UrlSection> { section }; this.SectionIndex.Add(section.HitCount, sections); } }
/// <summary> /// Process the specified log entry. /// </summary> /// <param name="logEntry">Log entry to process.</param> /// <returns>true if the entry was processed or false otherwise.</returns> public bool Process(ILogEntry logEntry) { var path = this.GetSectionPath(logEntry); if (path == null) { return(false); } if (this.Sections.TryGetValue(path, out var section)) { this.RemoveFromIndex(section); section.HitCount++; this.AddToIndex(section); } else { section = new UrlSection(path, 1); this.Sections[path] = section; this.AddToIndex(section); } return(true); }
private static Section GetSection(BsonDocument sectionBsonDocument) { Random rnd = new Random(); Section sectObj; string sectionType = sectionBsonDocument.GetValue("SectionType")?.ToString(); Debug.WriteLine("Section Type:" + sectionType); switch (sectionType?.ToLower()) { case "image": ImageSection imgSectObj = BsonSerializer.Deserialize <ImageSection>(sectionBsonDocument); Content imgContent = Contents.GetFor(imgSectObj); if (imgContent != null) { imgSectObj.Title = imgContent.Title; imgSectObj.Caption = imgContent.Caption; } sectObj = imgSectObj; break; case "text": TextSection textSectObj = BsonSerializer.Deserialize <TextSection>(sectionBsonDocument); Content textContent = Contents.GetFor(textSectObj); if (textContent != null) { textSectObj.Text = textContent.SectionText; } sectObj = textSectObj; break; case "graph": GraphSection gphObj = BsonSerializer.Deserialize <GraphSection>(sectionBsonDocument); Content docContent = Contents.GetFor(gphObj); if (docContent != null) { gphObj.Caption = docContent.Caption; gphObj.X.Label = docContent.XLabel; gphObj.Y.Label = docContent.YLabel; } gphObj.CoordinatesSet = new List <Coordinates>(); BsonArray coordinateSetBsonArray = sectionBsonDocument.GetValue("CoordinatesSet").AsBsonArray; if (coordinateSetBsonArray != null) { foreach (BsonDocument coordinateSetBsonDoc in coordinateSetBsonArray) { var coordinateListId = coordinateSetBsonDoc.GetValue("CoordinateListId")?.ToString(); if (!string.IsNullOrWhiteSpace(coordinateListId)) { continue; } var coordinatesObj = new Coordinates() { CoordinateListId = coordinateListId }; var coordinateContent = Contents.GetFor(coordinatesObj); coordinatesObj.LegendName = coordinateContent?.CoordinateListLegend; if (coordinateSetBsonDoc.TryGetValue("CoordinateList", out BsonValue tempCoordinateList)) { BsonArray coordinateListBsonArray = tempCoordinateList?.AsBsonArray; if (coordinateListBsonArray != null) { foreach (BsonDocument coordinateBsonDoc in coordinateListBsonArray) { string x = coordinateBsonDoc.GetValue("X")?.AsString; string y = coordinateBsonDoc.GetValue("Y")?.AsString; string coordinateText = coordinateContent?.CoordinateText; if (string.IsNullOrWhiteSpace(coordinateText)) { coordinatesObj.AddXYCoordinates(x, y); } else { coordinatesObj.AddXYCoordinates(x, y, coordinateText); } Debug.WriteLine(coordinatesObj.ToJson()); } } } gphObj.CoordinatesSet.Add(coordinatesObj); } } sectObj = gphObj; break; case "gif": GifSection gifObj = BsonSerializer.Deserialize <GifSection>(sectionBsonDocument); Content gifContent = Contents.GetFor(gifObj); if (gifContent != null) { gifObj.Title = gifContent.Title; gifObj.Caption = gifContent.Caption; } sectObj = gifObj; break; case "audio": AudioSection audioObj = BsonSerializer.Deserialize <AudioSection>(sectionBsonDocument); Content audioContent = Contents.GetFor(audioObj); if (audioContent != null) { audioObj.Title = audioContent.Title; audioObj.Caption = audioContent.Caption; } sectObj = audioObj; break; case "video": VideoSection videoObj = BsonSerializer.Deserialize <VideoSection>(sectionBsonDocument); Content videoContent = Contents.GetFor(videoObj); if (videoContent != null) { videoObj.Title = videoContent.Title; videoObj.Caption = videoContent.Caption; } sectObj = videoObj; break; case "link": UrlSection urlObj = BsonSerializer.Deserialize <UrlSection>(sectionBsonDocument); sectObj = urlObj; break; case "embeddedhtml": EmbeddedHtmlSection embeddedHtmlObj = BsonSerializer.Deserialize <EmbeddedHtmlSection>(sectionBsonDocument); Content embeddedHtmlContent = Contents.GetFor(embeddedHtmlObj); if (embeddedHtmlContent != null) { embeddedHtmlObj.Title = embeddedHtmlContent.Title; embeddedHtmlObj.Caption = embeddedHtmlContent.Caption; } sectObj = embeddedHtmlObj; break; default: sectObj = null; break; } return(sectObj); }
private static Section GetSection(BsonDocument sectionBsonDocument) { Section sectObj; string sectionType = sectionBsonDocument.GetValue("SectionType")?.ToString(); Debug.WriteLine("Section Type:" + sectionType); switch (sectionType?.ToLower()) { case "image": ImageSection imgSectObj = BsonSerializer.Deserialize <ImageSection>(sectionBsonDocument); Content imgContent = Contents.GetFor(imgSectObj); if (imgContent != null) { imgSectObj.Title = imgContent.Title; imgSectObj.Caption = imgContent.Caption; } sectObj = imgSectObj; break; case "text": TextSection textSectObj = BsonSerializer.Deserialize <TextSection>(sectionBsonDocument); Content textContent = Contents.GetFor(textSectObj); if (textContent != null) { textSectObj.Text = textContent.SectionText; if (textSectObj.DelayInMs == 0) { textSectObj.DelayInMs = Math.Min(Utils.Settings.MaxCapTimeTakenToType, textSectObj.Text.Length * (Utils.Settings.BaseTimeTakenToTypePerChar + rand.Next(0, Utils.Settings.VariableTimeTakenToTypePerChar))); } } sectObj = textSectObj; break; case "graph": { GraphSection gphObj = BsonSerializer.Deserialize <GraphSection>(sectionBsonDocument); Content docContent = Contents.GetFor(gphObj); if (docContent != null) { gphObj.Caption = docContent.Caption; gphObj.X.Label = docContent.XLabel; gphObj.Y.Label = docContent.YLabel; } gphObj.CoordinatesSet = new List <Coordinates>(); BsonArray coordinateSetBsonArray = sectionBsonDocument.GetValue("CoordinatesSet").AsBsonArray; if (coordinateSetBsonArray != null) { foreach (BsonDocument coordinateSetBsonDoc in coordinateSetBsonArray) { var coordinateListId = coordinateSetBsonDoc.GetValue("CoordinateListId")?.ToString(); if (!string.IsNullOrWhiteSpace(coordinateListId)) { continue; } var coordinatesObj = new Coordinates() { CoordinateListId = coordinateListId }; var coordinateContent = Contents.GetFor(coordinatesObj); coordinatesObj.LegendName = coordinateContent?.CoordinateListLegend; if (coordinateSetBsonDoc.TryGetValue("CoordinateList", out BsonValue tempCoordinateList)) { BsonArray coordinateListBsonArray = tempCoordinateList?.AsBsonArray; if (coordinateListBsonArray != null) { foreach (BsonDocument coordinateBsonDoc in coordinateListBsonArray) { string x = coordinateBsonDoc.GetValue("X")?.AsString; string y = coordinateBsonDoc.GetValue("Y")?.AsString; string coordinateText = coordinateContent?.CoordinateText; if (string.IsNullOrWhiteSpace(coordinateText)) { coordinatesObj.AddXYCoordinates(x, y); } else { coordinatesObj.AddXYCoordinates(x, y, coordinateText); } Debug.WriteLine(coordinatesObj.ToJson()); } } } gphObj.CoordinatesSet.Add(coordinatesObj); } } sectObj = gphObj; } break; case "gif": GifSection gifObj = BsonSerializer.Deserialize <GifSection>(sectionBsonDocument); Content gifContent = Contents.GetFor(gifObj); if (gifContent != null) { gifObj.Title = gifContent.Title; gifObj.Caption = gifContent.Caption; } sectObj = gifObj; break; case "audio": AudioSection audioObj = BsonSerializer.Deserialize <AudioSection>(sectionBsonDocument); Content audioContent = Contents.GetFor(audioObj); if (audioContent != null) { audioObj.Title = audioContent.Title; audioObj.Caption = audioContent.Caption; } sectObj = audioObj; break; case "video": VideoSection videoObj = BsonSerializer.Deserialize <VideoSection>(sectionBsonDocument); Content videoContent = Contents.GetFor(videoObj); if (videoContent != null) { videoObj.Title = videoContent.Title; videoObj.Caption = videoContent.Caption; } sectObj = videoObj; break; case "link": UrlSection urlObj = BsonSerializer.Deserialize <UrlSection>(sectionBsonDocument); sectObj = urlObj; break; case "embeddedhtml": EmbeddedHtmlSection embeddedHtmlObj = BsonSerializer.Deserialize <EmbeddedHtmlSection>(sectionBsonDocument); Content embeddedHtmlContent = Contents.GetFor(embeddedHtmlObj); if (embeddedHtmlContent != null) { embeddedHtmlObj.Title = embeddedHtmlContent.Title; embeddedHtmlObj.Caption = embeddedHtmlContent.Caption; } sectObj = embeddedHtmlObj; break; case "carousel": var carouselObj = BsonSerializer.Deserialize <CarouselSection>(sectionBsonDocument); var carContent = Contents.GetFor(carouselObj); if (carContent != null) { carouselObj.Title = carContent.Title; carouselObj.Caption = carContent.Caption; } if (carouselObj.Items != null) { foreach (var carItem in carouselObj.Items) { var content = Contents.GetFor(carItem); if (content != null) { carItem.Title = content.Title; carItem.Caption = content.Caption; } if (carItem.Buttons != null) { foreach (var carBtn in carItem.Buttons) { var carBtnContent = Contents.GetFor(carBtn); carBtn.Text = carBtnContent?.ButtonText; } } } } sectObj = carouselObj; break; case "printotp": PrintOTPSection printOTPSection = BsonSerializer.Deserialize <PrintOTPSection>(sectionBsonDocument); //No content to load for Section Type: PrintOTP sectObj = printOTPSection; break; default: sectObj = null; break; } return(sectObj); }