Exemple #1
0
        protected TLeafElement ReadLeaf(ExcelWorksheet sheet, int row, string parentKeyPath)
        {
            string leafName = sheet.Cells[row, Configuration.DataNameColumn].Value?.ToString().Trim();

            if (string.IsNullOrEmpty(leafName))
            {
                return(null);
            }
            TLeafElement leaf = new TLeafElement()
            {
                Name        = leafName,
                Description = sheet.Cells[row, Configuration.DataDescriptionColumn].Value?.ToString().Trim(),
                Guid        = GuidHelper.Create(Configuration.Guid_CompatibilityMode ? GuidHelper.LegacyGuids.DnsNamespace : LeafTypeGuid, (UseParentKeyInLeafGuid ? parentKeyPath + "++" : "") + leafName, false).ToString(),
                BaseType    = sheet.Cells[row, Configuration.BaseTypeColumn].Value?.ToString().Trim(),
                Type        = sheet.Cells[row, Configuration.DataTypeColumn].Value?.ToString().Trim().ToLower(),
            };

            ReadLeafProperties(leaf, sheet, row);
            try
            {
                if (leaf.BaseType is null && !string.IsNullOrEmpty(leaf.Type))
                {
                    DataTypeManager.SetDataType(leaf.Type, leaf);
                    SetLengthAndDecimals(sheet, row, leaf);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error parsing Data Type for row " + row);
                HandleException(sheet.Name, ex);
            }
            return(leaf);
        }
        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);
        }
Exemple #3
0
        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");
            }
        }