public static DataTableDataSource GeneratePersonSourceWithDemoData(int itemsToGenerate = 10, int firstId = 1001, bool useCacheForSpeed = true)
        {
            if(useCacheForSpeed && _cachedDs.ContainsKey(itemsToGenerate))
                return _cachedDs[itemsToGenerate];

            var dataTable = new DataTable();
            dataTable.Columns.AddRange(new[]
            {
                new DataColumn(DataTableDataSource.EntityIdDefaultColumnName, typeof (int)),
                new DataColumn("FullName"),
                new DataColumn("FirstName"),
                new DataColumn("LastName"),
                new DataColumn("City"),
                new DataColumn("IsMale", typeof (bool)),
                new DataColumn("Birthdate", typeof (DateTime)),
                new DataColumn("Height", typeof (int)),
                new DataColumn("CityMaybeNull", typeof(string)),
                new DataColumn("InternalModified", typeof(DateTime)),
            });
            AddSemirandomPersons(dataTable, itemsToGenerate, firstId);

            var source = new DataTableDataSource(dataTable, "Person", titleField: "FullName", modifiedField: "InternalModified")
            {
                ConfigurationProvider = new ValueProvider.ValueCollectionProvider_Test().ValueCollection()
            };

            // now enumerate all, to be sure that the time counted for DS creation isn't part of the tracked test-time
            var temp = source.LightList.LastOrDefault();

            if (useCacheForSpeed)
                _cachedDs.Add(itemsToGenerate, source);
            return source;
        }
示例#2
0
        private void LoadFnL()
        {
            EnsureConfigurationIsLoaded();

            // Preferred way in Form and List
            var udt = new UserDefinedTableController();
            var ds = udt.GetDataSet(ModuleId);
            DtDs = DataSource.GetDataSource<DataTableDataSource>(valueCollectionProvider: ConfigurationProvider);
            DtDs.Source = ds.Tables["Data"];
            DtDs.EntityIdField = "UserDefinedRowId";         // default column created by UDT
            DtDs.ContentType = ContentType;

            // clean up column names if possible, remove spaces in the column-names
            for (var i = 0; i < DtDs.Source.Columns.Count; i++)
                DtDs.Source.Columns[i].ColumnName = DtDs.Source.Columns[i].ColumnName
                    .Replace(" ", "");

            // Set the title-field - either the configured one, or if missing, just the first column we find
            if (string.IsNullOrWhiteSpace(TitleField))
                TitleField = DtDs.Source.Columns[1].ColumnName;
            DtDs.TitleField = TitleField;
        }