/// <summary> /// Validates the inputs of the <see cref="DmnModel"/> (<paramref name="source"/> and populates <see cref="InputData"/> and related <see cref="Variables"/> /// </summary> /// <param name="source">Source DMN Model parsed from XML</param> /// <param name="inputDataById">Temporary dictionary of input data (by ID) - input data are populated here</param> /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="inputDataById"/> is null.</exception> /// <exception cref="DmnParserException">Missing input id</exception> /// <exception cref="DmnParserException">Duplicate input data name</exception> protected void ProcessInputDataSource(DmnModel source, IDictionary <string, DmnVariableDefinition> inputDataById) { if (source == null) { throw Logger.Fatal <ArgumentNullException>($"{nameof(source)} is null"); } if (inputDataById == null) { throw Logger.Fatal <ArgumentNullException>($"{nameof(inputDataById)} is null"); } if (source.InputData == null || source.InputData.Count == 0) { return; //it's not common, but OK to have no input data } //TODO ?Input name in form varName:varType for (complex) input types foreach (var sourceInput in source.InputData) { if (string.IsNullOrWhiteSpace(sourceInput.Id)) { throw Logger.Fatal <DmnParserException>($"Missing input id"); } var inputName = !string.IsNullOrWhiteSpace(sourceInput.Name) ? sourceInput.Name : sourceInput.Id; var variableName = DmnVariableDefinition.NormalizeVariableName(inputName); if (InputData.ContainsKey(variableName)) { throw Logger.Fatal <DmnParserException>($"Duplicate input data name {variableName} (from {inputName})"); } var variable = new DmnVariableDefinition(variableName, inputName); InputData.Add(variableName, variable); Variables.Add(variableName, variable); inputDataById.Add(sourceInput.Id, variable); } }
public virtual T GetInput <T>(string key) { if (!InputData.ContainsKey(key)) { return(default(T)); } var value = InputData[key]; if (value is T variable) { return(variable); } else { try { return((T)Convert.ChangeType(value, typeof(T))); } catch (InvalidCastException) { return(default(T)); } } }
/// <summary> /// Validates the inputs of the <see cref="DmnModel"/> (<paramref name="source"/> and populates <see cref="InputData"/> and related <see cref="Variables"/> /// </summary> /// <param name="source">Source DMN Model parsed from XML</param> /// <param name="inputDataById">Temporary dictionary of input data (by ID) - input data are populated here</param> ///<exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="inputDataById"/> is null.</exception> /// <exception cref="DmnParserException">Missing input id</exception> /// <exception cref="DmnParserException">Duplicate input data name</exception> protected void ProcessInputDataSource(DmnModel source, IDictionary <string, DmnVariableDefinition> inputDataById) { if (source == null) { throw Logger.Fatal <ArgumentNullException>($"{nameof(source)} is null"); } if (inputDataById == null) { throw Logger.Fatal <ArgumentNullException>($"{nameof(inputDataById)} is null"); } if (source.InputData == null || source.InputData.Count == 0) { return; //it's not common, but OK to have no input data } var inputExpressionTypeByNames = source.Decisions?.Where(d => d.DecisionTable?.Inputs != null).SelectMany(d => d.DecisionTable?.Inputs)? .ToDictionary(i => string.IsNullOrEmpty(i.InputExpression?.Text) ? i.Label : i.InputExpression.Text, i => i.InputExpression?.TypeRef) ?? new Dictionary <string, string>(); //TODO ?Input name in form varName:varType for (complex) input types //TODO ?Required input parameters check for null?? foreach (var sourceInput in source.InputData) { if (string.IsNullOrWhiteSpace(sourceInput.Id)) { throw Logger.Fatal <DmnParserException>($"Missing input id"); } var inputName = !string.IsNullOrWhiteSpace(sourceInput.Name) ? sourceInput.Name : sourceInput.Id; var variableName = NormalizeVariableName(inputName); if (InputData.ContainsKey(variableName)) { throw Logger.Fatal <DmnParserException>($"Duplicate input data name {variableName} (from {inputName})"); } var variable = new DmnVariableDefinition(variableName) { IsInputParameter = true, HasValueSetter = true }; // try to evaluate variable type from expression type if (inputExpressionTypeByNames.TryGetValue(variableName, out var expressionType)) { CheckAndUpdateVariableType(variable, expressionType); } variable.ValueSetters.Add($"Input: {inputName}"); InputData.Add(variableName, variable); Variables.Add(variableName, variable); inputDataById.Add(sourceInput.Id, variable); } }
public (DataType type, string value) GetData(TickTime time) { if (!time.IsDefault) { lock (_locker) { if (InputData.ContainsKey(time)) { return(DataType.Input, InputData[time]); } if (ErrorData.ContainsKey(time)) { return(DataType.Error, ErrorData[time]); } if (OutputData.ContainsKey(time)) { return(DataType.Output, OutputData[time]); } } } return(DataType.None, null); }
public override async Task <IList <IEvent> > ProcessAction(int actionNumber) { if (actionNumber == 1) { return(new List <IEvent>() { new CancelInputDialog(), }); } else if (actionNumber == 0) { var fromEmail = GetValue("EmailFromAddress"); var host = GetValue("EmailHost"); var username = GetValue("EmailUserName"); var password = GetValue("EmailPassword"); var port = GetValue <int>("EmailPort"); var enableSsl = GetValue <bool>("EmailEnableSsl"); var dateFormat = GetValue("DateFormat"); var timeOffset = GetValue <int>("TimeOffset"); var websiteBaseUrl = GetValue("WebsiteUrl"); using (var session = DataService.OpenSession()) { var systemSettings = session.QueryOver <Models.SystemSettings>().List <Models.SystemSettings>().FirstOrDefault(); if (systemSettings == null) { systemSettings = new Models.SystemSettings(); } systemSettings.EmailFromAddress = fromEmail; systemSettings.EmailHost = host; systemSettings.EmailUserName = username; if (!String.IsNullOrWhiteSpace(password)) { systemSettings.EmailPassword = Encryption.Encrypt(password, AppSettings.ApplicationPassPhrase); } systemSettings.EmailPort = port; systemSettings.EmailEnableSsl = enableSsl; systemSettings.DateFormat = dateFormat; systemSettings.TimeOffset = timeOffset; systemSettings.WebsiteBaseUrl = websiteBaseUrl; DataService.SaveOrUpdate(session, systemSettings); var additionalSettings = AppSettings.GetAdditionalSystemSettings(session); foreach (var setting in additionalSettings) { if (InputData.ContainsKey(setting.Key)) { var value = InputData[setting.Key]?.ToString(); var dbSetting = session.QueryOver <SystemSettingValue>().Where(s => s.KeyName == setting.Key).SingleOrDefault(); if (dbSetting == null) { dbSetting = new SystemSettingValue() { KeyName = setting.Key }; } dbSetting.Value = value; DataService.SaveOrUpdate(session, dbSetting); } } session.Flush(); } WebsiteUtils.DateFormat = dateFormat; return(new List <IEvent>() { new CancelInputDialog(), new ShowMessage("System settings modified successfully") }); } return(new List <IEvent>()); }