Hi guys,
the problems reported should be fixed in next update.
This is the new code, in case some of you want help testing it:
public bool IsScheduling(string cronExpression)
{
string buildExpression = "";
int p = 0;
while (p < cronExpression.Length)
{
char token = cronExpression[p];
if (token == '(' || token == ')' || token == ';' || token == ':')
{
buildExpression += token;
p++;
continue;
}
string currentExpression = token.ToString();
p++;
while (p < cronExpression.Length)
{
token = cronExpression[p];
if (token != '(' && token != ')' && token != ';' && token != ':')
{
currentExpression += token;
p++;
}
else
{
break;
}
}
currentExpression = currentExpression.Trim(new char[]{ ' ', ' ' });
if (String.IsNullOrEmpty(currentExpression)) continue;
bool isEntryActive = false;
if (currentExpression.StartsWith("@"))
{
// Check expresion from scheduled item with a given name
var eventItem = Get(currentExpression.Substring(1));
isEntryActive = (eventItem != null && eventItem.IsEnabled && EvaluateCronEntry(eventItem.CronExpression));
}
else
{
isEntryActive = EvaluateCronEntry(currentExpression);
}
buildExpression += (isEntryActive ? "1" : "0");
}
buildExpression = buildExpression.Replace(":", "+");
buildExpression = buildExpression.Replace(";", "*");
bool success = false;
try
{
ExpressionEval eval = new ExpressionEval();
eval.Expression = buildExpression;
success = eval.EvaluateBool();
}
catch (Exception ex)
{
masterControlProgram.HomeGenie.LogBroadcastEvent(
Domains.HomeAutomation_HomeGenie_Scheduler,
cronExpression,
"Scheduler Expression",
Properties.SCHEDULER_ERROR,
JsonConvert.SerializeObject(ex.Message));
}
return success;
}
Just added the code to skip empty expressions (white spaces).
I tested it against the expressions you guys posted here and it worked.
When using "@" to reference an item in the scheduler, ensure that the item is enabled from the UI, otherwise it will be evaluated as false.
Thanks!
g.