/// <summary> /// Interprets a connect statement that instructs the Interface Booster to open a connection of a Provider Plugin. /// </summary> /// <param name="context"></param> public ProviderPluginConnectTask RunWithResult(SyneryParser.ProviderPluginConnectStatementContext context) { // get the instance reference name and the connection identifier from the Synery code // prepare the ConnectTask for the ProviderPluginManager ProviderPluginConnectTask connectTask = new ProviderPluginConnectTask(); connectTask.SyneryConnectionPath = context.ExternalPathIdentifier().GetText(); // e.g. \\csv\articleFile connectTask.ConnectionPath = IdentifierHelper.ParsePathIdentifier(connectTask.SyneryConnectionPath); // e.g. new string[] { "csv", "articleFile" } connectTask.InstanceReferenceSyneryIdentifier = LiteralHelper.ParseStringLiteral(context.providerPluginConnectStatementProviderPluginInstance().StringLiteral()); if (context.setCommand() != null) { // get all connection parameters from the synery code and append them to the ConnectCommand IDictionary <string[], IValue> listOfKeyValues = Controller.Interpret <SyneryParser.SetCommandContext, IDictionary <string[], IValue> >(context.setCommand()); foreach (var keyValue in listOfKeyValues) { connectTask.Parameters.Add(keyValue.Key, keyValue.Value.Value); } } return(connectTask); }
/// <summary> /// Interprets a statement that broadcasts a log message. /// </summary> /// <param name="context"></param> public void Run(SyneryParser.LogStatementContext context) { // set default channel string logChannel = "debug"; // evaluate expression for getting the log message IValue logValue = Controller.Interpret <SyneryParser.ExpressionContext, IValue>(context.expression()); if (logValue.Type != typeof(string)) { throw new SyneryInterpretationException(context, string.Format("The first value of a LOG statement must be a string value. Given: {0}", logValue.Value)); } if (context.StringLiteral() != null) { logChannel = LiteralHelper.ParseStringLiteral(context.StringLiteral()); } string logText = logValue.Value == null ? "" : logValue.Value.ToString(); if (Memory.Broadcaster != null) { Memory.Broadcaster.Broadcast(logChannel, logText); } }
private IValue GetDefaultForNullValue(IValue potentialNullValue, IValue secondValue) { if (potentialNullValue.Value == null) { if (potentialNullValue.Type != null) { // this value is a NULL value with a specified type (e.g. from a variable assignment) // get the default value for the specified type return(LiteralHelper.GetDefaultValue(potentialNullValue.Type)); } else if (secondValue.Type != null) { // only this value is a NULL value without a type // get for the NULL value a default value in the type of the second value return(LiteralHelper.GetDefaultValue(secondValue.Type)); } } return(potentialNullValue); }
public IValue RunWithResult(SyneryParser.LiteralContext context) { SyneryType type = null; object literalValue = null; if (context.StringLiteral() != null) { type = TypeHelper.STRING_TYPE; literalValue = LiteralHelper.ParseStringLiteral(context.StringLiteral()); } else if (context.VerbatimStringLiteral() != null) { type = TypeHelper.STRING_TYPE; literalValue = LiteralHelper.ParseVerbatimStringLiteral(context.VerbatimStringLiteral()); } else if (context.IntegerLiteral() != null) { type = TypeHelper.INT_TYPE; literalValue = Convert.ChangeType(context.GetText(), typeof(int)); } else if (context.DoubleLiteral() != null) { type = TypeHelper.DOUBLE_TYPE; literalValue = Convert.ToDouble(context.GetText(), new NumberFormatInfo() { NumberDecimalSeparator = "." }); } else if (context.DecimalLiteral() != null) { type = TypeHelper.DECIMAL_TYPE; string decimalValue = context.GetText().TrimEnd(new char[] { 'M', 'm' }); literalValue = Convert.ToDecimal(decimalValue, new NumberFormatInfo() { NumberDecimalSeparator = "." }); } else if (context.CharLiteral() != null) { type = TypeHelper.CHAR_TYPE; char[] chars = context.GetText().ToCharArray(1, 1); if (chars.Length == 1) { literalValue = Convert.ToChar(chars[0]); } else { throw new SyneryInterpretationException(context, String.Format("The value '{0}' is not a valid char literal.", context.GetText())); } } else if (context.BooleanLiteral() != null) { type = TypeHelper.BOOL_TYPE; if (context.BooleanLiteral().GetText() == "TRUE") { literalValue = true; } else if (context.BooleanLiteral().GetText() == "FALSE") { literalValue = false; } else { throw new SyneryInterpretationException(context, String.Format("The value '{0}' is not a valid boolean literal.", context.GetText())); } } else if (context.dateTimeLiteral() != null) { type = TypeHelper.DATETIME_TYPE; literalValue = Controller.Interpret <SyneryParser.DateTimeLiteralContext, DateTime>(context.dateTimeLiteral()); } else if (context.NullLiteral() != null) { type = null; literalValue = null; } else { throw new SyneryInterpretationException(context, String.Format("Unknown Literal type in {0} for the value '{0}'.", this.GetType().Name, context.GetText())); } return(new TypedValue(type, literalValue)); }