Exemplo n.º 1
0
        public async Task ImportAsync(string filename)
        {
            var path           = PathUtility.GetFullPath(filename, this.CommandContext.BaseDirectory);
            var sheetNames     = SpreadsheetReader.ReadTableNames(path);
            var authentication = this.CommandContext.GetAuthentication(this);
            var dataBase       = await this.DataBaseContext.GetDataBaseAsync(this.DataBaseName);

            var tables = await dataBase.GetTablesAsync();

            var tableNames = tables.Select(item => item.Name).ToArray();
            var query      = from sheet in sheetNames
                             join table in tableNames on sheet equals SpreadsheetUtility.Ellipsis(table)
                                 where StringUtility.GlobMany(table, FilterProperties.FilterExpression)
                             orderby table
                             select sheet;

            var filterExpression = string.Join(";", query);
            var revision         = dataBase.Dispatcher.Invoke(() => dataBase.DataBaseInfo.Revision);
            var dataSet          = await dataBase.GetDataSetAsync(authentication, CremaDataSetFilter.Default, revision);

            this.ReadDataSet(dataSet, path);
            await dataBase.ImportAsync(authentication, dataSet, this.Message);

            this.Out.WriteLine($"importing data has been completed.");
        }
Exemplo n.º 2
0
        public string[] GetTableNames()
        {
            if (this.cremaAppHost.GetService(typeof(IDataBase)) is IDataBase dataBase)
            {
                var tableNames = dataBase.Dispatcher.Invoke(() =>
                {
                    return(dataBase.TableContext.Tables.Select(item => item.Name).ToArray());
                });

                var sheetNames = this.itemsSource.SelectMany(item => item.GetSelectedSheetNames()).ToArray();

                var query = from tableName in tableNames
                            let tableName2 = SpreadsheetUtility.Ellipsis(tableName)
                                             join sheetName in sheetNames on tableName2 equals sheetName
                                             select tableName;

                return(query.ToArray());
            }
            throw new NotImplementedException();
        }
Exemplo n.º 3
0
        private void ReadTables(CremaDataSet dataSet, IDataBase dataBase, string filename, string itemNames)
        {
            var sheetNames = SpreadsheetReader.ReadSheetNames(filename);
            var tableInfos = dataBase.Dispatcher.Invoke(() =>
            {
                var query = from table in dataBase.TableContext.Tables
                            let tableName2 = SpreadsheetUtility.Ellipsis(table.Name)
                                             join sheetName in sheetNames on tableName2 equals sheetName
                                             where table.Name.GlobMany(itemNames) || table.Path.GlobMany(itemNames)
                                             orderby table.Name
                                             select table.TableInfo;

                return(query.ToArray());
            });

            var typeInfos = dataBase.Dispatcher.Invoke(() =>
            {
                var query = from table in dataBase.TableContext.Tables
                            let tableName2 = SpreadsheetUtility.Ellipsis(table.Name)
                                             join sheetName in sheetNames on tableName2 equals sheetName
                                             where table.Name.GlobMany(itemNames) || table.Path.GlobMany(itemNames)
                                             from column in table.TableInfo.Columns
                                             where CremaDataTypeUtility.IsBaseType(column.DataType) == false
                                             let type = dataBase.TypeContext[column.DataType] as IType
                                                        where type != null
                                                        select type.TypeInfo;

                return(query.Distinct().ToArray());
            });

            foreach (var item in typeInfos)
            {
                dataSet.Types.Add(item);
            }

            foreach (var item in tableInfos)
            {
                if (item.TemplatedParent != string.Empty)
                {
                    continue;
                }
                if (item.ParentName == string.Empty)
                {
                    dataSet.Tables.Add(item);
                }
                else
                {
                    dataSet.Tables[item.ParentName].Childs.Add(item);
                }
            }

            foreach (var item in tableInfos)
            {
                if (item.TemplatedParent != string.Empty && item.ParentName == string.Empty)
                {
                    var dataTable = dataSet.Tables[item.TemplatedParent];
                    dataTable.Inherit(item.TableName);
                }
            }

            var progress = new ConsoleProgress(this.Out)
            {
                Style = ConsoleProgressStyle.None
            };

            using (var reader = new SpreadsheetReader(filename))
            {
                reader.Read(dataSet, progress);
            }
        }