/// <summary> /// take input and return its real value /// </summary> /// <param name="input">string to resolv</param> /// <param name="vars">variables to take values from</param> /// <returns>value of input</returns> public static object ParseValue(string input, Dictionary <string, object> vars) { // value if (input.Length > 1 && input[1] == '$') { return(DataType.ConvertTo(DataType.FromShortcut(input[0]), input.Substring(2))); } // variable else { try { return(GetChainedProperty(input, vars)); } // unknown variable catch (MissingFieldException) { Logger.Log.Warn($"Variable '{input}' not found in vars [{string.Join(", ", vars.Select(v => v.Key))}]"); return(null); } } }
public override void InnerRun(Dictionary <string, object> vars, Dictionary <string, object> outputVars, Dictionary <string, object> InvertedInputVars, Message message) { // init COREobject core = COREobject.i; DBConnection db = core.Entitron; string tableName = vars.ContainsKey("TableName") ? (string)vars["TableName"] : (string)vars["__TableName__"]; bool searchInShared = vars.ContainsKey("SearchInShared") ? (bool)vars["SearchInShared"] : false; string orderBy = vars.ContainsKey("OrderBy") ? (string)vars["OrderBy"] : null; bool isDescending = vars.ContainsKey("Descending") ? (bool)vars["Descending"] : false; ListJson <DBItem> columns = db.ExecuteRead(db.CommandSet.LIST_column(db, tableName), new DBTable(db) { Name = tableName }); // var delete = db.Table(tableName).Delete(); int CondCount = vars.Keys.Where(k => k.StartsWith("CondColumn[") && k.EndsWith("]")).Count(); // setConditions for (int i = 0; i < CondCount; i++) { string condOperator = vars.ContainsKey($"CondOperator[{i}]") ? (string)vars[$"CondOperator[{i}]"] : "Equal"; string condColumn = (string)vars[$"CondColumn[{i}]"]; object condValue = vars[$"CondValue[{i}]"]; DBItem column = columns.Single(c => (string)c["name"] == condColumn); object value = condOperator != "IsIn" ? DataType.ConvertTo(DataType.FromDBName((string)column["typeName"], db.Type), condValue) : column["typeName"]; switch (condOperator) { case "Less": delete.Where(c => c.Column(condColumn).Less(value)); break; case "LessOrEqual": delete.Where(c => c.Column(condColumn).LessOrEqual(value)); break; case "Greater": delete.Where(c => c.Column(condColumn).Greater(value)); break; case "GreaterOrEqual": delete.Where(c => c.Column(condColumn).GreaterOrEqual(value)); break; case "Equal": delete.Where(c => c.Column(condColumn).Equal(value)); break; case "IsIn": // string, multiple values if ((condValue is string) && ((string)condValue).Contains(",")) { delete.Where(c => c.Column(condColumn).In((condValue as string).Split(','))); } // Enumerable else { delete.Where(c => c.Column(condColumn).In((IEnumerable <object>)condValue)); } break; default: // == delete.Where(c => c.Column(condColumn).Equal(value)); break; } } // order delete.Run(); }
public override void InnerRun(Dictionary <string, object> vars, Dictionary <string, object> outputVars, Dictionary <string, object> invertedVars, Message message) { // init DBConnection db = COREobject.i.Entitron; bool searchInShared = vars.ContainsKey("SearchInShared") ? (bool)vars["SearchInShared"] : false; if (!vars.ContainsKey("TableName")) { throw new Exception("Tapestry action JSON 2 DBItemList: TableName is required"); } if (!vars.ContainsKey("BaseName")) { throw new Exception("Tapestry action JSON 2 DBItemList: BaseName is required"); } if (!vars.ContainsKey("Data")) { throw new Exception("Tapestry action JSON 2 DBItemList: Data is required"); } JToken data = (JToken)vars["Data"]; string tableName = (string)vars["TableName"]; string baseName = (string)vars["BaseName"]; string itemName = vars.ContainsKey("ItemName") ? (string)vars["ItemName"] : "item"; /**************************************************************************************** ** MOCKUP DATA ** ***************************************************************************************** * string jsonText; * try { * XmlDocument xml = new XmlDocument(); * xml.Load("c:/users/mnvk8/Downloads/response.xml"); * jsonText = JsonConvert.SerializeXmlNode(xml); * } * catch (Exception e) { * if (e is ArgumentNullException || e is XmlException) { * jsonText = "";// JsonConvert.SerializeObject(response); * } * else { * throw e; * } * } * JToken data = JToken.Parse(jsonText); ****************************************************************************************/ DBTable table = db.Table(tableName, searchInShared); Dictionary <string, DBColumn> columnExists = new Dictionary <string, DBColumn>(); Dictionary <string, DbType> columnType = new Dictionary <string, DbType>(); var items = data.SelectToken($"$..{baseName}.{itemName}"); foreach (JToken item in items) { DBItem entity = new DBItem(db, table); foreach (JProperty pair in item) { // Zjistíme, jestli ten slupec v tabulce vůbec existuje string columnName = pair.Name.ToLowerInvariant(); if (!columnExists.ContainsKey(columnName)) { DBColumn column = table.Columns.Where(c => c.Name.ToLowerInvariant() == columnName).FirstOrDefault(); columnExists.Add(columnName, column); if (column != null) { columnType.Add(columnName, column.Type); } } if (columnExists[columnName] != null) { var columnInfo = columnExists[columnName]; entity[columnInfo.Name] = DataType.ConvertTo(columnType[columnName], pair); } } table.Add(entity); } db.SaveChanges(); // return outputVars["Result"] = true; }
public override void InnerRun(Dictionary <string, object> vars, Dictionary <string, object> outputVars, Dictionary <string, object> invertedVars, Message message) { // init DBConnection db = COREobject.i.Entitron; string tableName = vars.ContainsKey("TableName") ? (string)vars["TableName"] : (string)vars["__TableName__"]; bool searchInShared = vars.ContainsKey("SearchInShared") ? (bool)vars["SearchInShared"] : false; string orderBy = vars.ContainsKey("OrderBy") ? (string)vars["OrderBy"] : null; AscDesc isDescending = vars.ContainsKey("Descending") && (bool)vars["Descending"] ? AscDesc.Desc : AscDesc.Asc; // Tabloid tabloid = db.Tabloid(tableName, searchInShared); Select select = tabloid.Select(); int CondCount = vars.Keys.Where(k => k.StartsWith("CondColumn[") && k.EndsWith("]")).Count(); // setConditions for (int i = 0; i < CondCount; i++) { string condOperator = vars.ContainsKey($"CondOperator[{i}]") ? (string)vars[$"CondOperator[{i}]"] : "Equal"; string condColumn = (string)vars[$"CondColumn[{i}]"]; object condValue = vars[$"CondValue[{i}]"]; DBColumn column = tabloid.Columns.Single(c => c.Name == condColumn); object value = condOperator != "IsIn" ? DataType.ConvertTo(column.Type, condValue) : condValue; switch (condOperator) { case "Less": select.Where(c => c.Column(condColumn).Less(value)); break; case "LessOrEqual": select.Where(c => c.Column(condColumn).LessOrEqual(value)); break; case "Greater": select.Where(c => c.Column(condColumn).Greater(value)); break; case "GreaterOrEqual": select.Where(c => c.Column(condColumn).GreaterOrEqual(value)); break; case "Equal": select.Where(c => c.Column(condColumn).Equal(value)); break; case "IsIn": // string, multiple values if ((condValue is string) && ((string)condValue).Contains(",")) { select.Where(c => c.Column(condColumn).In((condValue as string).Split(','))); } // Enumerable else { select.Where(c => c.Column(condColumn).In((IEnumerable <object>)condValue)); } break; default: // == select.Where(c => c.Column(condColumn).Equal(value)); break; } } // top if (vars.ContainsKey("Top")) { select = select.Limit((int)vars["Top"]); } // order if (!string.IsNullOrWhiteSpace(orderBy)) { select = select.Order(isDescending, orderBy); if (vars.ContainsKey("MaxRows")) { select.DropStep((int)vars["MaxRows"], ESqlFunction.LAST, isDescending, orderBy); } } // Group if (vars.ContainsKey("GroupBy") && !string.IsNullOrWhiteSpace((string)vars["GroupBy"])) { ESqlFunction function = ESqlFunction.SUM; if (vars.ContainsKey("GroupByFunction")) { switch ((string)vars["GroupByFunction"]) { case "none": function = ESqlFunction.none; break; case "MAX": function = ESqlFunction.MAX; break; case "MIN": function = ESqlFunction.MIN; break; case "AVG": function = ESqlFunction.AVG; break; case "COUNT": function = ESqlFunction.COUNT; break; case "SUM": function = ESqlFunction.SUM; break; case "FIRST": function = ESqlFunction.FIRST; break; case "LAST": function = ESqlFunction.LAST; break; } } select.Group(function, columns: (string)vars["GroupBy"]); } // return outputVars["Data"] = select.ToList(); }