Esempio n. 1
0
        private void ReadTables(CremaDataSet dataSet, IDataBase dataBase, string tableNames)
        {
            var authentication = this.CommandContext.GetAuthentication(this);
            var tables         = dataBase.Dispatcher.Invoke(() => this.GetFilterTables(dataBase.TableContext.Tables, tableNames));

            if (tables.Any() == false)
            {
                throw new CremaException("조건에 맞는 테이블이 존재하지 않습니다.");
            }
            var step = new StepProgress(new ConsoleProgress(this.Out)
            {
                Style = ConsoleProgressStyle.None
            });

            step.Begin(tables.Length);
            foreach (var item in tables)
            {
                dataBase.Dispatcher.Invoke(() =>
                {
                    var previewSet   = item.GetDataSet(authentication, -1);
                    var previewTable = previewSet.Tables[item.Name];
                    previewTable.CopyTo(dataSet);
                    var name = item.Name;
                    step.Next("read {0} : {1}", ConsoleProgress.GetProgressString(step.Step + 1, tables.Length), item.Name);
                });
            }
            step.Complete();
        }
Esempio n. 2
0
        private void ReadTypes(CremaDataSet dataSet, IDataBase dataBase, string typeNames)
        {
            var authentication = this.CommandContext.GetAuthentication(this);
            var types          = dataBase.Dispatcher.Invoke(() => this.GetFilterTypes(dataBase.TypeContext.Types, typeNames));

            if (types.Any() == false)
            {
                throw new CremaException("조건에 맞는 타입이 존재하지 않습니다.");
            }
            var step = new StepProgress(new ConsoleProgress(this.Out)
            {
                Style = ConsoleProgressStyle.None
            });

            step.Begin(types.Length);
            foreach (var item in types)
            {
                dataBase.Dispatcher.Invoke(() =>
                {
                    var previewSet  = item.GetDataSet(authentication, -1);
                    var previewType = previewSet.Types[item.Name];
                    CreateTable(previewType);
                    step.Next("reading {0}/{1} : {2}", step.Step + 1, types.Length, item.Name);
                });
            }

            step.Complete();

            void CreateTable(CremaDataType dataType)
            {
                var dataTable = dataSet.Tables.Add(dataType.Name);

                dataTable.Columns.Add(CremaSchema.Name);
                dataTable.Columns.Add(CremaSchema.Value, typeof(long));
                dataTable.Columns.Add(CremaSchema.Comment);

                dataTable.BeginLoad();
                foreach (var item in dataType.Members)
                {
                    var row = dataTable.NewRow();

                    row[CremaSchema.Name]    = item.Name;
                    row[CremaSchema.Value]   = item.Value;
                    row[CremaSchema.Comment] = item.Comment;

                    row.IsEnabled = item.IsEnabled;
                    row.Tags      = item.Tags;
                    row.SetAttribute(CremaSchema.Creator, item.CreationInfo.ID);
                    row.SetAttribute(CremaSchema.CreatedDateTime, item.CreationInfo.DateTime);
                    row.SetAttribute(CremaSchema.Modifier, item.ModificationInfo.ID);
                    row.SetAttribute(CremaSchema.ModifiedDateTime, item.ModificationInfo.DateTime);

                    dataTable.Rows.Add(row);
                }
                dataTable.EndLoad();
            }
        }
Esempio n. 3
0
        public void Read(CremaDataSet dataSet, IProgress progress)
        {
            var query = from sheet in this.workbook.Worksheets
                        join table in dataSet.Tables on sheet.Name equals SpreadsheetUtility.Ellipsis(table.Name)
                        orderby table.Name
                        select sheet;

            var items = query.ToArray();

            var step = new StepProgress(progress);

            step.Begin(items.Length);
            foreach (var item in query)
            {
                this.ReadSheet(item, dataSet);
                step.Next("read {0} : {1}", ConsoleProgress.GetProgressString(step.Step + 1, items.Length), item.Name);
            }
            step.Complete();
        }
Esempio n. 4
0
        private void WriteSheet(string filenamePattern, IProgress progress)
        {
            var csvConfiguration = new Configuration
            {
                HasHeaderRecord = true,
                Encoding        = Encoding.UTF8,
                Delimiter       = settings.Delimiter
            };

            var step = new StepProgress(progress);

            step.Begin(this.dataSet.Tables.Count);

            foreach (var item in this.dataSet.Tables)
            {
                var filePath = this.GetFilename(filenamePattern, item);
                if (this.settings.CreateDirectoryIfNotExists)
                {
                    var directoryPath = Path.GetDirectoryName(filePath);
                    DirectoryUtility.Prepare(directoryPath);
                }

                using (var writer = new StreamWriter(filePath))
                    using (var csv = new CsvWriter(writer, csvConfiguration))
                    {
                        this.WriteHeader(csv, item);

                        foreach (var row in item.Rows)
                        {
                            this.WriteRow(csv, item, item.Columns, row);
                            csv.NextRecord();
                        }
                    }

                step.Next("write {0} : {1}", ConsoleProgress.GetProgressString(step.Step + 1, this.dataSet.Tables.Count), item.Name);
            }
            step.Complete();
        }
Esempio n. 5
0
        private void WriteSheets(XLWorkbook workbook, IProgress progress)
        {
            var step = new StepProgress(progress);

            step.Begin(this.dataSet.Tables.Count);
            foreach (var item in this.dataSet.Tables)
            {
                var worksheet = workbook.AddWorksheet(this.settings.NameEllipsis(item.Name));

                if (item.Tags.Color != null)
                {
                    worksheet.SetTabColor(XLColor.FromHtml(item.Tags.Color));
                }

                this.WriteColumns(item, worksheet);
                this.WriteRows(item, worksheet);
                this.AdjustColumns(item, worksheet);

                worksheet.SheetView.Freeze(1, item.PrimaryKey.Length);
                step.Next("write {0} : {1}", ConsoleProgress.GetProgressString(step.Step + 1, this.dataSet.Tables.Count), item.Name);
            }
            step.Complete();
        }