public void Validate(string id, string epl) { // id can be empty or null for validation call InternalValidate(epl); try { // check if the input contains any our delimiters // such as [DO NOT FIRE ALERT BLOCK START] ... [DO NOT FIRE ALERT BLOCK STOP] var parser = new EplParser(); bool shouldParse = parser.HasSubscriptionMarkers(epl); // Check if a block is present if (shouldParse) // yes { EplParsedTuple tuple = parser.Parse(epl); // Compile stage 1 // Read block of statements that doesn't require alert subscriber into module Module module = _engine.EPAdministrator.DeploymentAdmin.Parse(tuple.EplScript); // iterate through each epl separated by a semicolon ";" foreach (var item in module.Items) { _engine.EPAdministrator.CompileEPL(item.Expression); } // Compile stage 2 _engine.EPAdministrator.CompileEPL(tuple.StatementToFireAlert); } else // no parsing needed, just compile whatever we have { _engine.EPAdministrator.CompileEPL(epl); } } catch (Exception ex) { string newMessage = string.Concat("Rule ", id, " is invalid"); throw new ArgumentException(newMessage, ex); } }
private EPStatement InsertEplStatementIntoNesper(string id, string epl) { _log.Info($"Epl: {epl}"); InternalValidate(); // check if the input contains any our delimiters // such as [DO NOT FIRE ALERT BLOCK START] ... [DO NOT FIRE ALERT BLOCK STOP] var parser = new EplParser(); bool shouldParse = parser.HasSubscriptionMarkers(epl); EPStatement epStatement = null; // Check if a block is present if (shouldParse) // yes { _log.Info("Scripting block found"); // read the two parts // first should just be imported into NEsper // without adding any subscriber // second part should contain a single epl that // will fire an alert EplParsedTuple tuple = parser.Parse(epl); var md5 = new Md5(); string hash = md5.GetHashAsHex(tuple.EplScript); var kvp = LoadedModules.FirstOrDefault(x => x.Value.Checksum == hash); bool isNewModule = kvp.Value == null; if (isNewModule) { _log.Info("Creating module from script"); var result = _engine.EPAdministrator.DeploymentAdmin.ParseDeploy(tuple.EplScript); var mi = new NesperModuleItem { Id = result.DeploymentId, UseCount = 1, Checksum = hash }; _log.Info($"Scripting block contained {result.Statements.Count} statements"); LoadedModules.Add(id, mi); } else { kvp.Value.UseCount++; } // create epl that will be linked with a subscriber _log.Info("Creating statement that fires alert"); if (!string.IsNullOrWhiteSpace(tuple.StatementToFireAlert)) //we can now potentially have some statements which don't actually need to be attached. { epStatement = _engine.EPAdministrator.CreateEPL(tuple.StatementToFireAlert, id); } } else { _log.Info("Creating statement that fires alert"); epStatement = _engine.EPAdministrator.CreateEPL(epl, id); _log.Info("Created id: " + epStatement.Name); } return(epStatement); }