public void Test() { var items = new[] { new PartySettings { Id = Guid.NewGuid().ToString(), ScopeId = Guid.NewGuid().ToString(), LastModificationDateTime = DateTime.UtcNow, }, new PartySettings { Id = Guid.NewGuid().ToString(), ScopeId = Guid.NewGuid().ToString(), PartyBoxesSettings = new PartyBoxesSettings { SupplierBoxSelectionStrategy = SupplierBoxSelectionStrategy.ShipperField }, } }; var properties = new List <string>(); var gettersList = new List <Func <object?, object?> >(); PropertyHelpers.BuildGettersForProperties(typeof(PartySettings), "", x => x, properties, gettersList, new CustomPropertyConfigurationProvider()); var getters = properties.Zip(gettersList, (name, getter) => (name, getter)).ToDictionary(x => x.name, x => x.getter); getters["Id"](items[0]).Should().Be(items[0].Id); getters["ScopeId"](items[0]).Should().Be(items[0].ScopeId); getters["PartyBoxesSettings.SupplierBoxSelectionStrategy"](items[0]).Should().BeNull(); getters["LastModificationDateTime"](items[0]).Should().Be(items[0].LastModificationDateTime); getters["Id"](items[1]).Should().Be(items[1].Id); getters["ScopeId"](items[1]).Should().Be(items[1].ScopeId); getters["PartyBoxesSettings.SupplierBoxSelectionStrategy"](items[1]).Should().Be(SupplierBoxSelectionStrategy.ShipperField); }
public async Task <DownloadResult> DownloadObjects([NotNull] string objectIdentifier, [NotNull][FromBody] ObjectSearchRequest query) { var type = schemaRegistry.GetTypeByTypeIdentifier(objectIdentifier); var schema = schemaRegistry.GetSchemaByTypeIdentifier(objectIdentifier); var downloadLimit = schema.Description.DownloadLimit; var count = await schemaRegistry.GetConnector(objectIdentifier).Count(query.GetFilters(), downloadLimit + 1).ConfigureAwait(false); if (count > downloadLimit) { return new DownloadResult { File = null, Count = (int)count, CountLimit = downloadLimit, } } ; var results = await schemaRegistry.GetConnector(objectIdentifier).Search(query.GetFilters(), query.GetSorts(), 0, downloadLimit).ConfigureAwait(false); var properties = new List <string>(); var getters = new List <Func <object, object> >(); PropertyHelpers.BuildGettersForProperties(type, "", x => x, properties, getters); var excludedIndices = properties.Select((x, i) => (x, i)).Where(x => query.ExcludedFields.Contains(x.x)).Select(x => x.i).ToArray(); var filteredProperties = properties.Where((x, i) => !excludedIndices.Contains(i)).ToArray(); var filteredGetters = getters.Where((x, i) => !excludedIndices.Contains(i)).ToArray(); var csvWriter = new CsvWriter(filteredProperties); foreach (var item in results) { csvWriter.AddRow(filteredGetters.Select(f => PropertyHelpers.ToString(f, item)).ToArray()); } return(new DownloadResult { Count = count ?? 0, CountLimit = downloadLimit, File = new FileInfo { Content = csvWriter.GetBytes(), ContentType = "text/csv", Name = $"{objectIdentifier}-{DateTime.UtcNow:yyyy-MM-dd-HHmm}.csv" } }); }