public UnsubscribeAction Connect(string key, IPipelineSink <T> sink)
        {
            _output.Set(sinks =>
            {
                MessageRouter <T> router;
                if (sinks.TryGetValue(key, out router) == false)
                {
                    router = new MessageRouter <T>();
                    router.Connect(sink);

                    return(new Dictionary <string, MessageRouter <T> >(sinks)
                    {
                        { key, router }
                    });
                }

                var result = new Dictionary <string, MessageRouter <T> >(sinks);

                router = new MessageRouter <T>(router.Sinks);
                router.Connect(sink);
                result[key] = router;

                return(result);
            });

            return(() => Disconnect(key, sink));
        }
Esempio n. 2
0
        public UnsubscribeAction Connect(TKey correlationId, IPipelineSink <T> sink)
        {
            _output.Set(sinks =>
            {
                CorrelatedMessageSinkRouter <T, TMessage, TKey> keySink;
                if (sinks.TryGetValue(correlationId, out keySink) == false)
                {
                    keySink = new CorrelatedMessageSinkRouter <T, TMessage, TKey>(correlationId);
                    keySink.Connect(sink);

                    return(new Dictionary <TKey, CorrelatedMessageSinkRouter <T, TMessage, TKey> >(sinks)
                    {
                        { correlationId, keySink }
                    });
                }

                var result = new Dictionary <TKey, CorrelatedMessageSinkRouter <T, TMessage, TKey> >(sinks);

                keySink = new CorrelatedMessageSinkRouter <T, TMessage, TKey>(correlationId, keySink.Sinks);
                keySink.Connect(sink);
                result[correlationId] = keySink;

                return(result);
            });

            return(() => Disconnect(correlationId, sink));
        }
Esempio n. 3
0
        public UnsubscribeAction Connect(IPipelineSink <T> sink)
        {
            _output.Set(sinks => new List <IPipelineSink <T> >(sinks)
            {
                sink
            });

            return(() => _output.Set(sinks => sinks.Where(x => x != sink).ToList()) != null);
        }
        public PresentedParameter PresentPopup(IParameterDescriptor param, Action updateCallback)
        {
            var factory = param.GetParameterizedObjectFactory();

            var grid = new Grid();

            grid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(4, GridUnitType.Star)
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(1, GridUnitType.Star), MinWidth = 110, MaxWidth = 130
            });

            var button = new Button {
                Content = "Configure →"
            };

            grid.Children.Add(button);
            Grid.SetColumn(button, 1);

            var container = new Atomic <IParameterizedObject>();

            void Setter(object obj) => container.Set((IParameterizedObject)obj);

            object Getter() => container.Get();

            void Updater(ParameterStateType state, bool value)
            {
                if (state != ParameterStateType.Enabled)
                {
                    return;
                }
                button.IsEnabled = value;
            }

            button.Click += (sender, e) =>
            {
                var subParams    = factory.GetParameters(param);
                var context      = factory.Parse(param, container.Get());
                var configWindow = new ParameterizedConfigWindow(param.Name ?? "Parameter", subParams, context)
                {
                    Width = 400
                };
                if (configWindow.ShowDialog(out var @params))
                {
                    container.Set(factory.Create(param, @params));
                    updateCallback();
                }
            };

            return(new PresentedParameter(param, grid, Getter, Setter, null, Updater));
        }
Esempio n. 5
0
 public override void AddEvent(EventBean theEvent)
 {
     if (_eventReference.Get() != null)
     {
         throw new EPException("Unique index violation, table '" + TableMetadata.TableName + "' " +
                               "is a declared to hold a single un-keyed row");
     }
     if (InstrumentationHelper.ENABLED)
     {
         InstrumentationHelper.Get().QTableAddEvent(theEvent);
     }
     _eventReference.Set((ObjectArrayBackedEventBean)theEvent);
     if (InstrumentationHelper.ENABLED)
     {
         InstrumentationHelper.Get().ATableAddEvent();
     }
 }
Esempio n. 6
0
    public override void AddEvent(EventBean @event)
        {
            if (@event.EventType != table.MetaData.InternalEventType) {
                throw new IllegalStateException("Unexpected event type for add: " + @event.EventType.Name);
            }

            if (eventReference.Get() != null) {
                throw new EPException(
                    "Unique index violation, table '" +
                    table.MetaData.TableName +
                    "' " +
                    "is a declared to hold a single un-keyed row");
            }

            agentInstanceContext.InstrumentationProvider.QTableAddEvent(@event);
            eventReference.Set((ObjectArrayBackedEventBean) @event);
            agentInstanceContext.InstrumentationProvider.ATableAddEvent();
        }
Esempio n. 7
0
            public void Run(RegressionEnvironment env)
            {
                var fields       = "eq,neq,sqlneq,nneq".SplitCsv();
                var eplReference = new Atomic <string>();
                var builder      = new SupportEvalBuilder("SupportBean")
                                   .WithExpression(fields[0], "IntPrimitive=all(1,IntBoxed)")
                                   .WithExpression(fields[1], "IntPrimitive!=all(1,IntBoxed)")
                                   .WithExpression(fields[2], "IntPrimitive<>all(1,IntBoxed)")
                                   .WithExpression(fields[3], "not IntPrimitive=all(1,IntBoxed)")
                                   .WithStatementConsumer(stmt => eplReference.Set(stmt.GetProperty(StatementProperty.EPL).ToString()));

                // in the format IntPrimitive, IntBoxed
                int[][] testdata =
                {
                    new[] { 1, 1 },
                    new[] { 1, 2 },
                    new[] { 2, 2 },
                    new[] { 2, 1 },
                };

                object[][] result =
                {
                    new object[] { true,  false, false, false },  // 1, 1
                    new object[] { false, false, false, true  },  // 1, 2
                    new object[] { false, false, false, true  },  // 2, 2
                    new object[] { false, true,  true,  true  }   // 2, 1
                };

                for (var i = 0; i < testdata.Length; i++)
                {
                    var bean = new SupportBean("E", testdata[i][0]);
                    bean.IntBoxed = testdata[i][1];
                    builder.WithAssertion(bean).Expect(fields, result[i]);
                }

                builder.Run(env);
                env.UndeployAll();

                // test OM
                var epl   = eplReference.Get();
                var model = env.EplToModel(epl);

                Assert.AreEqual(epl.Replace("<>", "!="), model.ToEPL());
                env.CompileDeploy(model).AddListener("s0");

                for (var i = 0; i < testdata.Length; i++)
                {
                    var bean = new SupportBean("E", testdata[i][0]);
                    bean.IntBoxed = testdata[i][1];
                    env.SendEventBean(bean);
                    EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), fields, result[i]);
                }

                env.UndeployAll();
            }
        public async Task <byte[]> BuildZipFileSync()
        {
            counter.Set(i => i + 1);
            try
            {
                string url     = "";
                string empcode = "";
                if (HttpContext.Current != null)
                {
                    url = HttpContext.Current.Request.RawUrl;
                    var sessoin = SessionFactory.Create <IBLSessionPersisiter>();
                    var emp     = sessoin.BaseEmployee.EmpCode;

                    if (emp != null)
                    {
                        empcode = sessoin.BaseEmployee.EmpCode;
                    }
                }
                var start = DateTime.Now;
                if (EnableProfileLog)
                {
                    log.Info("exporting zipped report, uri={" + url + "}, emp=" + empcode + ", concurrency = " + counter.Value);
                }

                var ret = await BuildZipFileInternalSync();

                if (EnableProfileLog)
                {
                    log.Info("exported zipped report cost: " + (DateTime.Now - start).TotalMilliseconds + "ms, uri={" + url +
                             "}, emp=" + empcode);
                }

                return(ret);
            }
            finally
            {
                counter.Set(i => i - 1);
            }
        }
Esempio n. 9
0
            public void Run(RegressionEnvironment env)
            {
                var fields       = "g,ge".SplitCsv();
                var eplReference = new Atomic <string>();
                var builder      = new SupportEvalBuilder("SupportBeanArrayCollMap")
                                   .WithExpressions(fields, "LongBoxed>all({1,2},IntArr,IntCol)", "LongBoxed>=all({1,2},IntArr,IntCol)")
                                   .WithStatementConsumer(stmt => eplReference.Set(stmt.GetProperty(StatementProperty.EPL).ToString()));

                var arrayBean = MakeBean();

                arrayBean.IntCol    = Arrays.AsList(1, 2);
                arrayBean.LongBoxed = 3L;
                builder.WithAssertion(arrayBean).Expect(fields, true, true);

                arrayBean           = MakeBean();
                arrayBean.LongBoxed = 2L;
                env.SendEventBean(arrayBean);
                builder.WithAssertion(arrayBean).Expect(fields, false, true);

                arrayBean           = new SupportBeanArrayCollMap(new[] { 1, 3 });
                arrayBean.IntCol    = Arrays.AsList(1, 2);
                arrayBean.LongBoxed = 3L;
                env.SendEventBean(arrayBean);
                builder.WithAssertion(arrayBean).Expect(fields, false, true);

                arrayBean           = new SupportBeanArrayCollMap(new[] { 1, 2 });
                arrayBean.IntCol    = Arrays.AsList(1, 3);
                arrayBean.LongBoxed = 3L;
                env.SendEventBean(arrayBean);
                builder.WithAssertion(arrayBean).Expect(fields, false, true);

                builder.Run(env);
                env.UndeployAll();

                // test OM
                var epl   = eplReference.Get();
                var model = env.EplToModel(epl);

                Assert.AreEqual(epl.Replace("<>", "!="), model.ToEPL());
                env.CompileDeploy(model).AddListener("s0");

                arrayBean           = new SupportBeanArrayCollMap(new[] { 1, 2 });
                arrayBean.IntCol    = Arrays.AsList(1, 2);
                arrayBean.LongBoxed = 3L;
                env.SendEventBean(arrayBean);
                EPAssertionUtil.AssertProps(env.Listener("s0").AssertOneGetNewAndReset(), fields, true, true);

                env.UndeployAll();
            }
Esempio n. 10
0
            public void Run(RegressionEnvironment env)
            {
                var fields       = "eq,neq,sqlneq,nneq".SplitCsv();
                var eplReference = new Atomic <string>();
                var builder      = new SupportEvalBuilder("SupportBean")
                                   .WithExpression(fields[0], "IntPrimitive=any(1,IntBoxed)")
                                   .WithExpression(fields[1], "IntPrimitive!=any(1,IntBoxed)")
                                   .WithExpression(fields[2], "IntPrimitive<>any(1,IntBoxed)")
                                   .WithExpression(fields[3], "not IntPrimitive=any(1,IntBoxed)")
                                   .WithStatementConsumer(stmt => eplReference.Set(stmt.GetProperty(StatementProperty.EPL).ToString()));

                // in the format IntPrimitive, IntBoxed
                int[][] testdata =
                {
                    new[] { 1, 1 },
                    new[] { 1, 2 },
                    new[] { 2, 2 },
                    new[] { 2, 1 },
                };

                object[][] result =
                {
                    new object[] { true,  false, false, false }, // 1, 1
                    new object[] { true,  true,  true,  false }, // 1, 2
                    new object[] { true,  true,  true,  false }, // 2, 2
                    new object[] { false, true,  true,  true  } // 2, 1
                };

                for (var i = 0; i < testdata.Length; i++)
                {
                    var bean = new SupportBean("E", testdata[i][0]);
                    bean.IntBoxed = testdata[i][1];
                    builder.WithAssertion(bean).Expect(fields, result[i]);
                }

                builder.Run(env);
                env.UndeployAll();
            }
Esempio n. 11
0
        public void TestActiveCallbackRemove()
        {
            var spec        = SupportFilterSpecBuilder.Build(_eventTypeOne, new Object[0]).GetValueSet(null, null, null);
            var callbackTwo = new SupportFilterHandle();

            // callback that removes another matching filter spec callback
            Atomic <FilterServiceEntry> filterServiceEntryOne = new Atomic <FilterServiceEntry>();
            FilterHandleCallback        callbackOne           = new ProxyFilterHandleCallback
            {
                ProcStatementId = () => "",
                ProcIsSubselect = () => false,
                ProcMatchFound  = (e, allStmtMatches) =>
                {
                    Log.Debug(".matchFound Removing callbackTwo");
                    _filterService.Remove(callbackTwo, filterServiceEntryOne.Value);
                }
            };

            FilterServiceEntry filterServiceEntry = _filterService.Add(spec, callbackOne);

            filterServiceEntryOne.Set(filterServiceEntry);
            _filterService.Add(spec, callbackTwo);

            // send event
            var theEvent = MakeTypeOneEvent(1, "HELLO", false, 1);
            var matches  = new List <FilterHandle>();

            _filterService.Evaluate(theEvent, matches);
            foreach (FilterHandle match in matches)
            {
                var handle = (FilterHandleCallback)match;
                handle.MatchFound(theEvent, null);
            }

            // Callback two MUST be invoked, was removed by callback one, but since the
            // callback invocation order should not matter, the second one MUST also execute
            Assert.AreEqual(1, callbackTwo.GetAndResetCountInvoked());
        }
Esempio n. 12
0
        public static ExprTimePeriod TimePeriodGetExprAllParams(EsperEPL2GrammarParser.TimePeriodContext ctx, IDictionary <ITree, ExprNode> astExprNodeMap, VariableService variableService, StatementSpecRaw spec, ConfigurationInformation config)
        {
            var nodes = new ExprNode[8];

            for (var i = 0; i < ctx.ChildCount; i++)
            {
                var unitRoot = ctx.GetChild(i);

                ExprNode valueExpr;
                if (ASTUtil.IsTerminatedOfType(unitRoot.GetChild(0), EsperEPL2GrammarLexer.IDENT))
                {
                    var ident = unitRoot.GetChild(0).GetText();
                    valueExpr = ASTExprHelper.ResolvePropertyOrVariableIdentifier(ident, variableService, spec);
                }
                else
                {
                    var        @ref   = new Atomic <ExprNode>();
                    ExprAction action = (exprNode, astExprNodeMapX, nodeX) => {
                        astExprNodeMapX.Remove(nodeX);
                        @ref.Set(exprNode);
                    };
                    ASTExprHelper.RecursiveFindRemoveChildExprNode(unitRoot.GetChild(0), astExprNodeMap, action);
                    valueExpr = @ref.Get();
                }

                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_millisecondPart)
                {
                    nodes[7] = valueExpr;
                }
                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_secondPart)
                {
                    nodes[6] = valueExpr;
                }
                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_minutePart)
                {
                    nodes[5] = valueExpr;
                }
                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_hourPart)
                {
                    nodes[4] = valueExpr;
                }
                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_dayPart)
                {
                    nodes[3] = valueExpr;
                }
                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_weekPart)
                {
                    nodes[2] = valueExpr;
                }
                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_monthPart)
                {
                    nodes[1] = valueExpr;
                }
                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_yearPart)
                {
                    nodes[0] = valueExpr;
                }
            }

            ExprTimePeriod timeNode = new ExprTimePeriodImpl(config.EngineDefaults.ExpressionConfig.TimeZone,
                                                             nodes[0] != null, nodes[1] != null, nodes[2] != null, nodes[3] != null, nodes[4] != null, nodes[5] != null, nodes[6] != null, nodes[7] != null);

            if (nodes[0] != null)
            {
                timeNode.AddChildNode(nodes[0]);
            }
            if (nodes[1] != null)
            {
                timeNode.AddChildNode(nodes[1]);
            }
            if (nodes[2] != null)
            {
                timeNode.AddChildNode(nodes[2]);
            }
            if (nodes[3] != null)
            {
                timeNode.AddChildNode(nodes[3]);
            }
            if (nodes[4] != null)
            {
                timeNode.AddChildNode(nodes[4]);
            }
            if (nodes[5] != null)
            {
                timeNode.AddChildNode(nodes[5]);
            }
            if (nodes[6] != null)
            {
                timeNode.AddChildNode(nodes[6]);
            }
            if (nodes[7] != null)
            {
                timeNode.AddChildNode(nodes[7]);
            }
            return(timeNode);
        }
Esempio n. 13
0
 /// <summary>
 /// Atomically replaces the current output sink with the argument.
 /// </summary>
 /// <param name="sink">The argument sink.</param>
 /// <returns>The passed argument when the replace operation is done.</returns>
 public IPipelineSink <IConsumeContext> ReplaceOutputSink(IPipelineSink <IConsumeContext> sink)
 {
     return(_output.Set(output => sink));
 }