public DataSampler(String name, int historyLength, int sampleRate, Func <float> function) { Name = name; Function = function; SampleRate = sampleRate; Values = new FixedLengthQueue <float>(historyLength); }
public void TestEnqueueUnsetValues() { FixedLengthQueue <int> q = new FixedLengthQueue <int>(12); q.Enqueue(5); Assert.AreEqual(5, q[q.Length - 1]); }
public LoggerViewModel() { Streams = new ObservableCollection <StreamItem>(); LogItems = new FixedLengthQueue <LogItem>(500); LogItemsOld = new FixedLengthQueue <LogItem>(10000); _defaultStream = AddStreamItem("Default"); }
public void TestEnqueueDoesntChangeLength() { int length = 12; FixedLengthQueue <int> q = new FixedLengthQueue <int>(length); Assert.AreEqual(length, q.Length); q.Enqueue(5); Assert.AreEqual(length, q.Length); }
public void TestAccessIndexArbitraryHead() { int[] initialValues = new int[] { 4, 7, 3, 11, 215, -4 }; int head = 3; FixedLengthQueue <int> q = new FixedLengthQueue <int>(initialValues, head); Assert.AreEqual(initialValues[head], q[0]); Assert.AreEqual(initialValues[0], q[initialValues.Length - head]); }
public void TestEnqueue() { int[] initialValues = new int[] { 4, 7, 3, 11, 215, -4 }; int head = 3; FixedLengthQueue <int> q = new FixedLengthQueue <int>(initialValues, head); q.Enqueue(5); Assert.AreEqual(5, q[q.Length - 1]); }
public void TestAccessIndexHeadZero() { int[] initialValues = new int[] { 4, 7, 3, 11, 215, -4 }; int head = 0; FixedLengthQueue <int> q = new FixedLengthQueue <int>(initialValues, head); for (int i = 0; i < q.Length; i++) { Assert.AreEqual(initialValues[i], q[i]); } }
public void TestConstructorInitialValues() { int[] initialValues = new int[] { 4, 7, 3, 11, 215, -4 }; FixedLengthQueue <int> q = new FixedLengthQueue <int>(initialValues); Assert.AreEqual(initialValues.Length, q.Length); for (int i = 0; i < initialValues.Length; i++) { Assert.AreEqual(initialValues[i], q[i]); } }
public void TestEnqueueDequeue() { int[] initialValues = new int[] { 4, 7, 3, 11, 215, -4 }; int head = 3; FixedLengthQueue <int> q = new FixedLengthQueue <int>(initialValues, head); int newVal = 12; int expected = initialValues[head]; int actual = q.DequeueEnqueue(newVal); Assert.AreEqual(expected, actual); Assert.AreEqual(newVal, q[q.Length - 1]); }
public void TestConstructorInitialValuesAndHead() { int[] initialValues = new int[] { 4, 7, 3, 11, 215, -4 }; int head = 3; FixedLengthQueue <int> q = new FixedLengthQueue <int>(initialValues, head); Assert.AreEqual(initialValues.Length, q.Length); for (int i = 0; i < initialValues.Length; i++) { int j = (i + head) % initialValues.Length; Assert.AreEqual(initialValues[j], q[i]); } }
public LoggerManager() : base(GearsetSettings.Instance.LoggerConfig) { // Create the back-end collections Streams = new ObservableCollection <StreamItem>(); LogItems = new FixedLengthQueue <LogItem>(500); LogItemsOld = new FixedLengthQueue <LogItem>(10000); //LogItems.DequeueTarget = LogItemsOld; Streams.Add(defaultStream = new StreamItem { Name = "Default", Enabled = true, Color = colors[currentColor++] }); // Create the window. Window = new LoggerWindow(); Window.Top = Config.Top; Window.Left = Config.Left; Window.Width = Config.Width; Window.Height = Config.Height; Window.IsVisibleChanged += new DependencyPropertyChangedEventHandler(logger_IsVisibleChanged); Window.SoloRequested += new EventHandler <SoloRequestedEventArgs>(logger_SoloRequested); WindowHelper.EnsureOnScreen(Window); if (Config.Visible) { Window.Show(); } filteredView = CollectionViewSource.GetDefaultView(LogItems); filteredView.Filter = (a) => ((LogItem)a).Stream.Enabled; filteredView.GroupDescriptions.Add(new PropertyGroupDescription("UpdateNumber")); Window.LogListBox.DataContext = filteredView; Window.StreamListBox.DataContext = Streams; Window.LocationChanged += new EventHandler(logger_LocationChanged); Window.SizeChanged += new SizeChangedEventHandler(logger_SizeChanged); scrollViewer = GetDescendantByType(Window.LogListBox, typeof(ScrollViewer)) as ScrollViewer; }
public LoggerManager() : base(GearsetSettings.Instance.LoggerConfig) { // Create the back-end collections Streams = new ObservableCollection<StreamItem>(); LogItems = new FixedLengthQueue<LogItem>(500); LogItemsOld = new FixedLengthQueue<LogItem>(10000); //LogItems.DequeueTarget = LogItemsOld; Streams.Add(_defaultStream = new StreamItem { Name = "Default", Enabled = true, Color = _colors[_currentColor++] }); // Create the window. Window = new LoggerWindow(); Window.Top = Config.Top; Window.Left = Config.Left; Window.Width = Config.Width; Window.Height = Config.Height; Window.IsVisibleChanged += logger_IsVisibleChanged; Window.SoloRequested += logger_SoloRequested; WindowHelper.EnsureOnScreen(Window); if (Config.Visible) Window.Show(); FilteredView = CollectionViewSource.GetDefaultView(LogItems); FilteredView.Filter = a => ((LogItem)a).Stream.Enabled; FilteredView.GroupDescriptions.Add(new PropertyGroupDescription("UpdateNumber")); Window.LogListBox.DataContext = FilteredView; Window.StreamListBox.DataContext = Streams; Window.LocationChanged += logger_LocationChanged; Window.SizeChanged += logger_SizeChanged; _scrollViewer = GetDescendantByType(Window.LogListBox, typeof(ScrollViewer)) as ScrollViewer; }
public DataSampler(String name) { Name = name; SampleRate = 1; Values = new FixedLengthQueue <float>(GearsetResources.Console.Settings.DataSamplerConfig.DefaultHistoryLength); }
public static long FindNextOccurrence4BitDigit(Stream searchStream, byte[] lookFor, long fromIdx) { //Validation if (searchStream.Length == 0) { throw new ArgumentException("cannot be empty", nameof(searchStream)); } if (lookFor.Length == 0) { throw new ArgumentException("cannot be empty", nameof(lookFor)); } //Set the stream position (in bytes) searchStream.Position = fromIdx / 2; //Keep track of the index in the stream ready to return if we hit a result long idx = fromIdx; int rawByteRead; byte thisByte = byte.MaxValue; //If this is an odd index, read in the first byte in the stream so thisByte has a value (as it will expect it to have already been read) if (idx % 2 == 1) { rawByteRead = searchStream.ReadByte(); if (rawByteRead == -1) { return(-1); } thisByte = (byte)rawByteRead; } //Read in the first N chars bool fillingPrev = true; bool filledPrevThisIter = false; bool eos = false; FixedLengthQueue <byte> prev = new FixedLengthQueue <byte>(lookFor.Length); //Have one big loop for both fill & search modes while (true) { //If we're at an even index, read in the next byte byte digit; if (idx % 2 == 0) { rawByteRead = searchStream.ReadByte(); if (rawByteRead == -1) { eos = true; //End of stream digit = 15; } else //Otherwise read a value { thisByte = (byte)rawByteRead; //Get the first half of the byte as this digit digit = (byte)(thisByte >> 4); } } else //Otherwise we already have this byte read in { //Get the second half of the byte as this digit digit = (byte)(thisByte & 15); //mask 0000 1111 to get the last 4 bits //If this is (0000) 1111 => 15 then this is the end but the byte had to be padded if (digit == 15) { eos = true; //End of stream } } //If filling up the previous chars if (fillingPrev) { prev.Enqueue(digit); //Update fillingPrev if (prev.Count == lookFor.Length) { fillingPrev = false; idx++; //Also increment the index as we'll jump straight into the match tests on this iteration filledPrevThisIter = true; } } //If not filling up the previous chars (not equivelant to else because fillingPrev can be set in the previous if) if (!fillingPrev) { //If we currently have the digits being searched for bool match = true; for (int i = 0; i < prev.Length; i++) { if (lookFor[i] != prev[i]) { match = false; break; } } if (match) { return(idx - lookFor.Length); //Start idx } else if (eos) //Else if we haven't found a match & we're at the end of the stream, report back that nothing was found { return(-1); } //Update prev (if we haven't filled prev on this iter) if (!filledPrevThisIter) { prev.Enqueue(digit); } } //Update the current idx for next iter (if we haven't filled prev on this iter, as then it will have already been incremented) if (!filledPrevThisIter) { idx++; } else //Otherwise update filledPrevThisIter { filledPrevThisIter = false; } } }
public static int FindNextOccurrence(string toSearch, string lookFor, int fromIdx) { //Validation if (toSearch.Length == 0) { throw new ArgumentException("cannot be empty", nameof(toSearch)); } if (lookFor.Length == 0) { throw new ArgumentException("cannot be empty", nameof(lookFor)); } if (fromIdx <= toSearch.Length - lookFor.Length) { FixedLengthQueue <char> prevChars = new FixedLengthQueue <char>(lookFor.Length); //Read in the first N chars int i = fromIdx; for (int j = 0; j < lookFor.Length; i++, j++) { prevChars.Enqueue(toSearch[i]); } //For each of the remaining characters in the string to be searched for (;; i++) { //If we currently have the string being searched for bool match = true; for (int j = 0; j < lookFor.Length; j++) { if (prevChars[j] != lookFor[j]) { match = false; break; } } if (match) { return(i - lookFor.Length); //Start position } //If at the end of the string, break if (i == toSearch.Length) { break; } //Update prevChars prevChars.Enqueue(toSearch[i]); } //Didn't match anything return(-1); } else { return(-1); } }
private static IEnumerable<FastLogReader.Line> Filter(IEnumerable<FastLogReader.Line> lines, SearchModel search, MessagesModel output) { var regexOptions = RegexOptions.Compiled | (search.IsCaseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase); Func<string, Regex> buildStringMatcherFor = input => { if (String.IsNullOrEmpty(input)) return null; switch (search.MatchType) { case MatchTypes.PlainText: return new Regex(Regex.Escape(input), regexOptions); case MatchTypes.Wildcard: return new Regex("^" + Regex.Escape(input).Replace(@"\*", "(.*)").Replace(@"\?", ".") + "$", regexOptions); case MatchTypes.Regex: return new Regex(input, regexOptions); default: goto case MatchTypes.PlainText; } }; var nickMatcher = buildStringMatcherFor(search.Nickname); var userMatcher = buildStringMatcherFor(search.Username); var hostMatcher = buildStringMatcherFor(search.Hostname); var msgMatcher = buildStringMatcherFor(search.Message); Func<FastLogReader.Line, bool> isDirectLineMatch = line => { if (line.When < search.FromDate || line.When > search.ToDate) return false; if (nickMatcher != null && !nickMatcher.IsMatch(line.Nick ?? String.Empty)) return false; if (userMatcher != null && !userMatcher.IsMatch(line.User ?? String.Empty)) return false; if (hostMatcher != null && !hostMatcher.IsMatch(line.Host ?? String.Empty)) return false; if (msgMatcher != null && !msgMatcher.IsMatch(line.Message ?? String.Empty)) return false; return true; }; uint postContextCount = 0; var queue = new FixedLengthQueue<FastLogReader.Line>(search.Context == 0 ? 1 : search.Context); foreach (var line in lines) { // NOTE: The order of these if-statements matters. output.LinesSearched++; if (isDirectLineMatch(line)) { output.LinesMatching++; // We have a match, but we also have some outstanding context lines to // print prior to this one, so do that now. if (search.Context != 0) { while (queue.Count != 0) { output.LinesDisplaying++; yield return queue.Dequeue(); } postContextCount = search.Context; } } // Not a match, but we have some trailing lines to print, so do that. else if (postContextCount != 0) { postContextCount--; } // Not a match, not even a trailing line. Candidate for a pre-context line. Queue it. else if (search.Context != 0) { queue.Enqueue(line); continue; } // Not a context-dependant search, so drop it. else { continue; } // Fallthrough, print a direct match or one of the current trailing lines. output.LinesDisplaying++; yield return line; } }
public DataSampler(String name, int historyLength) { this.Name = name; this.SampleRate = 1; Values = new FixedLengthQueue <float>(historyLength); }
public void TestConstructorLength() { FixedLengthQueue <int> q = new FixedLengthQueue <int>(5); Assert.AreEqual(5, q.Length); }