示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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)));
        }
示例#4
0
        /* 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]);
            }
        }
示例#5
0
        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));
        }
示例#6
0
        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()));
        }
示例#7
0
        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);
            }
        }
示例#9
0
        protected virtual Channel <T> Visitor <T>(FilterChannel <T> channel)
        {
            Visit(channel.Output);

            return(channel);
        }
示例#10
0
        protected override Channel <T> Visitor <T>(FilterChannel <T> channel)
        {
            Trace.WriteLine("FilterChannel<{0}>".FormatWith(typeof(T).Name));

            return(base.Visitor(channel));
        }
示例#11
0
 public abstract void Filter(DateTime begin, DateTime end, FilterChannel filterChannel, Func <string, string, string, DateTime, DateTime, double[]> getData, double[] result);
示例#12
0
 /* Use this method to do the calculations for a filter */
 public override void Filter(DateTime begin, DateTime end, FilterChannel filter, DataProvider dataProvider, double[] result)
 {
 }