public void Should_capture_all_of_the_nodes_involved() { var channel = new ConsumerChannel<int>(new SynchronousFiber(), x => { }); var filter = new FilterChannel<int>(new SynchronousFiber(), channel, x => true); new ChannelVisitor().Visit(filter); }
public void Should_capture_all_of_the_nodes_involved() { var channel = new ConsumerChannel <int>(new SynchronousFiber(), x => { }); var filter = new FilterChannel <int>(new SynchronousFiber(), channel, x => true); new ChannelVisitor().Visit(filter); }
protected override Channel <T> Visitor <T>(FilterChannel <T> channel) { _current = GetVertex(channel.GetHashCode(), () => "Filter", typeof(FilterChannel <T>), typeof(T)); if (_stack.Count > 0) { _edges.Add(new Edge(_stack.Peek(), _current, _current.TargetType.Name)); } return(WithVertex(() => base.Visitor(channel))); }
/* Use this method to do the calculations for a filter that can be based on one or more * channels of available and accessible projects. * begin: Start of the current time period. * end: End of the current time period. * data: Contains data of the preselected projects. * result: The resulting double array with length matching the time period and sample rate. */ public override void Filter(DateTime begin, DateTime end, FilterChannel filter, DataProvider dataProvider, double[] result) { /* This dataset has the same length as the result array. */ var t1 = dataProvider.IN_MEMORY_TEST_ACCESSIBLE.T1.DATASET_1_s_mean; for (int i = 0; i < result.Length; i++) { /* Example: Square each value. */ result[i] = Math.Pow(t1[i], 2); /* Example: Add +1 to each value (to demonstrate how to use shared code). */ // result[i] = Shared.AddOne(result[i]); } }
public static Guid ToGuid(this FilterChannel filterChannel, CodeDefinition codeDefinition) { // With the filter extension, channels are produced dynamically, so there // is no way to generate an ID once and store it somewhere. Therefore the // ID must be generated each time the filter code is instantiated. To avoid // having ever changing IDs, the ID is effectively a good hash code based // on the project ID and channel name. In the end this means that the // channel name determines the ID. And so renaming a channel means changing // the ID. var value = $"({codeDefinition.Id}) {filterChannel.ProjectId}/{filterChannel.ChannelName}"; var md5 = MD5.Create(); // compute hash is not thread safe! var hash = md5.ComputeHash(Encoding.UTF8.GetBytes(value)); // return(new Guid(hash)); }
public void Should_filter_out_unwanted_messages() { var update = new UserUpdate {LastActivity = DateTime.Now - 5.Minutes()}; Fiber fiber = new SynchronousFiber(); var future = new Future<UserUpdate>(); var filter = new FilterChannel<UserUpdate>(fiber, future, x => x.LastActivity > DateTime.Now); Channel<UserUpdate> channel = new PublishSubscribeChannel<UserUpdate>(fiber, new[] {filter}); channel.Send(update); Assert.IsFalse(future.WaitUntilCompleted(1.Seconds())); }
public void Should_filter_out_unwanted_messages() { var update = new UserUpdate { LastActivity = DateTime.Now - 5.Minutes() }; Fiber fiber = new SynchronousFiber(); var future = new FutureChannel <UserUpdate>(); var filter = new FilterChannel <UserUpdate>(fiber, future, x => x.LastActivity > DateTime.Now); Channel <UserUpdate> channel = new BroadcastChannel <UserUpdate>(new[] { filter }); channel.Send(update); Assert.IsFalse(future.WaitUntilCompleted(1.Seconds())); }
protected bool ShouldDisplay(FilterChannel channel, string msg) { Regex regexToUse = null; // Convert to bool for XOR later. Whitelist = 0, Blacklist = 1 bool filterMode = Settings.FilterMode == Settings.FilterModeEnum.Blacklist ? true : false; switch (channel) { case FilterChannel.Chat: regexToUse = Settings.ChatFilter; break; case FilterChannel.Debug: regexToUse = Settings.DebugFilter; break; } if (regexToUse != null) { // IsMatch and white/blacklist result can be represented using XOR // e.g. matched(true) ^ blacklist(true) => shouldn't log(false) return(regexToUse.IsMatch(msg) ^ filterMode); } else { return(true); } }
protected virtual Channel <T> Visitor <T>(FilterChannel <T> channel) { Visit(channel.Output); return(channel); }
protected override Channel <T> Visitor <T>(FilterChannel <T> channel) { Trace.WriteLine("FilterChannel<{0}>".FormatWith(typeof(T).Name)); return(base.Visitor(channel)); }
public abstract void Filter(DateTime begin, DateTime end, FilterChannel filterChannel, Func <string, string, string, DateTime, DateTime, double[]> getData, double[] result);
/* Use this method to do the calculations for a filter */ public override void Filter(DateTime begin, DateTime end, FilterChannel filter, DataProvider dataProvider, double[] result) { }