public void SetTypes() { DataTypeElement dte = new DataTypeElement(); DataTypeManager.SetDataType("Numeric(8.2)", dte); Assert.IsTrue(dte.Type == "Numeric" && dte.Length == 8 && dte.Decimals == 2 && dte.Sign == false); DataTypeManager.SetDataType("Num(8.2)", dte); Assert.IsTrue(dte.Type == "Numeric" && dte.Length == 8 && dte.Decimals == 2 && dte.Sign == false); DataTypeManager.SetDataType("Num(8)", dte); Assert.IsTrue(dte.Type == "Numeric" && dte.Length == 8 && dte.Decimals == 0 && dte.Sign == false); DataTypeManager.SetDataType("Num(8-)", dte); Assert.IsTrue(dte.Type == "Numeric" && dte.Length == 8 && dte.Decimals == 0 && dte.Sign == true); DataTypeManager.SetDataType("Num(12.4-)", dte); Assert.IsTrue(dte.Type == "Numeric" && dte.Length == 12 && dte.Decimals == 4 && dte.Sign == true); DataTypeManager.SetDataType("DateTime(12.4-)", dte); Assert.IsTrue(dte.Type == "DateTime" && dte.Length == null && dte.Decimals == null && dte.Sign == null); DataTypeManager.SetDataType("DateTime", dte); Assert.IsTrue(dte.Type == "DateTime" && dte.Length == null && dte.Decimals == null && dte.Sign == null); DataTypeManager.SetDataType("Video", dte); Assert.IsTrue(dte.Type == "Video" && dte.Length == null && dte.Decimals == null && dte.Sign == null); DataTypeManager.SetDataType("VIDEO", dte); Assert.IsTrue(dte.Type == "Video" && dte.Length == null && dte.Decimals == null && dte.Sign == null); DataTypeManager.SetDataType("Char(20.2)", dte); Assert.IsTrue(dte.Type == "Character" && dte.Length == 20 && dte.Decimals == null && dte.Sign == null); DataTypeManager.SetDataType("VarChar(200)", dte); Assert.IsTrue(dte.Type == "VarChar" && dte.Length == 200 && dte.Decimals == null && dte.Sign == null); DataTypeManager.SetDataType("VarChar()", dte); Assert.IsTrue(dte.Type == "VarChar" && dte.Length == 200 && dte.Decimals == null && dte.Sign == null); //DataTypeManager.SetDataType("Num(8.2)", att); //DataTypeManager.SetDataType("Num(8.2)", att); }
private void SetLengthAndDecimals(ExcelWorksheet sheet, int row, DataTypeElement dte) { try { string lenAndDecimals = sheet.Cells[row, Configuration.DataLengthColumn].Value?.ToString().Trim(); if (!string.IsNullOrEmpty(lenAndDecimals)) { if (lenAndDecimals.Length > 0 && lenAndDecimals.EndsWith("-")) { dte.Sign = true; lenAndDecimals = lenAndDecimals.Replace("-", ""); } string[] splitedData; if (lenAndDecimals.Contains(".")) { splitedData = lenAndDecimals.Trim().Split('.'); } else { splitedData = lenAndDecimals.Trim().Split(','); } if (splitedData.Length >= 1 && int.TryParse(splitedData[0], out int length)) { dte.Length = length; } if (splitedData.Length == 2 && int.TryParse(splitedData[1], out int decimals)) { dte.Decimals = decimals; } } } catch (Exception ex) //never fail because a wrong length/decimals definition, just use the defaults values. { Console.WriteLine("Error parsing Data Type for row " + row); HandleException(sheet.Name, ex); } }
public Column(object column, DataTypeElement type, params ConstraintElement[] constraints) { throw new InvalitContextException("new " + nameof(Column)); }
public Column(object column, DataTypeElement type) { throw new InvalitContextException("new " + nameof(Column)); }
public static void SetDataType(string text, DataTypeElement dte) { string normalizedText = text.ToUpper(); string [] vals = normalizedText.Split('('); BasicDataTypeInfo typeInfo = null; foreach (BasicDataTypeInfo dtInfo in BasicDataTypeInfo.Types().Values) { if (dtInfo.Name.ToUpper().StartsWith(vals[0])) { typeInfo = dtInfo; break; } } if (typeInfo != null) { dte.SetDataType(typeInfo); if (typeInfo.RegularExpression != null) { string fullText = normalizedText.Replace(vals[0], typeInfo.Name.ToUpper()); var match = typeInfo.RegularExpression.Match(fullText); if (match.Success) { if (typeInfo.AllowLength) { if (match.Groups["length"].Length > 0) { if (Format.ParseInteger(match.Groups["length"].Value, out int length)) { dte.Length = length; } } if (typeInfo.AllowDecimals) { int decimals = 0; // If decimals are not set but the expression is "complete" (e.g. "Numeric(4)"), // use 0 instead of the default value). if (match.Groups["decimals"].Length > 0) { Int32.TryParse(match.Groups["decimals"].Value, out decimals); } else if (text.EndsWith(")")) { decimals = 0; } dte.Decimals = decimals; } if (typeInfo.AllowSign && match.Groups["sign"].Length > 0) { dte.Sign = true; } } } } return; } throw new Exception($"Could not parse {text} as any known datatype"); }
public static TDst Cast<TDst>(object target, DataTypeElement destinationType) { throw new InvalitContextException(nameof(Cast)); }
protected override void ProcessFile(ExcelWorksheet sheet, TLevelElement obj) { Dictionary <int, TLevelElement> levels = new Dictionary <int, TLevelElement>(); TLevelElement level = obj; levels[0] = level; Levels[level.Name] = level; int row = Configuration.DataStartRow; int atts = 0; while (sheet.Cells[row, Configuration.DataStartColumn].Value != null) { level = ReadLevel(row, sheet, level, levels, out bool isLevel); if (!isLevel) { try { TLeafElement leaf = ReadLeaf(sheet, row, level.KeyPath); if (leaf.BaseType != null && leaf.Type != null && !Domains.ContainsKey(leaf.BaseType)) { DataTypeElement domain = new DataTypeElement { Name = leaf.BaseType, Guid = GuidHelper.Create(GuidHelper.ObjClass.Domain, leaf.BaseType, false).ToString() }; DataTypeManager.SetDataType(leaf.Type, domain); SetLengthAndDecimals(sheet, row, domain); Domains[domain.Name] = domain; } if (leaf != null) { if (Leafs.TryGetValue(leaf.Name, out var other) && leaf.ToString() != other.ToString()) { Console.WriteLine($"{leaf.Name} was already defined with a different data type {other.ToString()}, taking into account the last one {leaf.ToString()}"); } Leafs[leaf.Name] = leaf; atts++; level.Items.Add(leaf); Console.WriteLine($"Processing Attribute {leaf.Name}"); row++; } else { break; } } catch (Exception ex) when(HandleException($"at row:{row}", ex, true)) { } } else { ReadLevelProperties(level, sheet, row); row++; } } if (atts == 0) { throw new Exception($"Definition without content, check the {nameof(Configuration.DataStartRow)} and {nameof(Configuration.DataStartColumn)} values on the config file"); } }