Пример #1
0
        public static void Import(this IRawSheetImporterPage page, RawSheetImporter importer, SheetConvertingContext context, ISheet sheet)
        {
            var idColumnName = page.GetCell(0, 0);

            if (idColumnName != nameof(ISheetRow.Id))
            {
                context.Logger.LogError("First column \"{ColumnName}\" must be named \"Id\"", idColumnName);
                return;
            }

            ISheetRow sheetRow = null;

            for (int pageRow = 1; !page.IsEmptyRow(pageRow); ++pageRow)
            {
                var rowId = page.GetCell(0, pageRow);

                if (!string.IsNullOrEmpty(rowId))
                {
                    using (context.Logger.BeginScope(rowId))
                    {
                        sheetRow = Activator.CreateInstance(sheet.RowType) as ISheetRow;

                        page.ImportToObject(importer, context, sheetRow, pageRow);

                        if (sheet.Contains(sheetRow.Id))
                        {
                            context.Logger.LogError("Already has row with id \"{RowId}\"", sheetRow.Id);
                            sheetRow = null;
                        }
                        else
                        {
                            sheet.Add(sheetRow);
                        }
                    }
                }

                if (sheetRow is ISheetRowArray sheetRowArray)
                {
                    using (context.Logger.BeginScope(sheetRow.Id))
                        using (context.Logger.BeginScope(sheetRowArray.Arr.Count))
                        {
                            var sheetElem = Activator.CreateInstance(sheetRowArray.ElemType);

                            page.ImportToObject(importer, context, sheetElem, pageRow);

                            sheetRowArray.Arr.Add(sheetElem);
                        }
                }
            }
        }