public static ValueList AddListWithSyntax(this ValueTable table, string name) { if (table.MirrorSyntax == null) { throw new ArgumentException("Table must have syntax", nameof(table)); } // Create a new list and matching syntax var newSyntaxList = new ArraySyntax() { OpenBracket = SyntaxFactory.Token(TokenKind.OpenBracket), CloseBracket = SyntaxFactory.Token(TokenKind.CloseBracket), }; newSyntaxList.OpenBracket.TrailingTrivia = new List <SyntaxTrivia>() { SyntaxFactory.NewLineTrivia(), }; var newList = new ValueList() { MirrorSyntax = newSyntaxList, }; // Add the model to the parent table model table.Add(name, new Value(newList)); // Add the new syntax to the parent table syntax switch (table.MirrorSyntax) { case DocumentSyntax documentSyntax: documentSyntax.KeyValues.Add(new KeyValueSyntax(name, newSyntaxList)); break; case TableSyntaxBase tableSyntax: tableSyntax.Items.Add(new KeyValueSyntax(name, newSyntaxList)); break; default: throw new InvalidOperationException($"Unknown Syntax on ValueTable {table.MirrorSyntax?.GetType()}"); } return(newList); }
public static void AddItemWithSyntax(this ValueTable table, string key, string value) { // Create a new item and matching syntax var newSyntaxValue = new StringValueSyntax(value); var newValue = new Value(value) { // TODO: MirrorSyntax = newSyntaxTable, }; // Add the model to the parent table model table.Add(key, newValue); switch (table.MirrorSyntax) { case InlineTableSyntax inlineTableSyntax: // Add the new syntax to the parent table syntax var inlineTableItemSyntax = new InlineTableItemSyntax( new KeyValueSyntax() { EqualToken = SyntaxFactory.Token(TokenKind.Equal), Key = new KeySyntax(key), Value = newSyntaxValue, }); inlineTableItemSyntax.AddLeadingWhitespace(); inlineTableItemSyntax.KeyValue.EqualToken.AddLeadingWhitespace(); inlineTableItemSyntax.KeyValue.EqualToken.AddTrailingWhitespace(); // A comma can not be on the last item // Add a comma to the previous item var previousItem = inlineTableSyntax.Items.LastOrDefault(); if (previousItem != null) { previousItem.Comma = SyntaxFactory.Token(TokenKind.Comma); } inlineTableSyntax.Items.Add(inlineTableItemSyntax); break; default: throw new InvalidOperationException("Unknown Syntax on ValueList"); } }
private static ValueTable ReadValueTable(System.IO.BinaryReader reader) { // Write out the table size var size = reader.ReadUInt32(); var table = new ValueTable(); for (var i = 0; i < size; i++) { // Read the key var key = ReadString(reader); // Read the value var value = ReadValue(reader); table.Add(key, value); } return(table); }
public SDKConfig EnsureSDK(string name) { // Check the existing entries IValueList?values; if (_table.TryGetValue(Property_SDKs, out var sdksValue)) { values = sdksValue.AsList(); foreach (var value in values) { var config = new SDKConfig((ValueTable)value.AsTable()); if (config.HasName() && config.Name == name) { return(config); } } } else { values = new ValueList(); _table.Add(Property_SDKs, new Value(values)); } // No matching SDK as a table array entry var sdkSyntax = new TableArraySyntax(Property_SDKs); _mirrorSyntax.Tables.Add(sdkSyntax); var sdkValueTable = new ValueTable() { MirrorSyntax = sdkSyntax, }; values.Add(new Value(sdkValueTable)); return(new SDKConfig(sdkValueTable) { Name = name, }); }
public QueryResult(DbDataReader reader) { for (int ColIdx = 0; ColIdx < reader.FieldCount; ColIdx++) { _resultTable.Columns.Add(reader.GetName(ColIdx)); } using (reader) { foreach (DbDataRecord record in reader) { ValueTableRow row = _resultTable.Add(); for (int ColIdx = 0; ColIdx < reader.FieldCount; ColIdx++) { if (record.IsDBNull(ColIdx)) { row.Set(ColIdx, ValueFactory.Create()); continue; } if (record.GetFieldType(ColIdx) == typeof(Int32)) { row.Set(ColIdx, ValueFactory.Create((int)record.GetValue(ColIdx))); } if (record.GetFieldType(ColIdx) == typeof(Int64)) { row.Set(ColIdx, ValueFactory.Create(record.GetInt64(ColIdx))); } if (record.GetFieldType(ColIdx) == typeof(Boolean)) { row.Set(ColIdx, ValueFactory.Create(record.GetBoolean(ColIdx))); } if (record.GetFieldType(ColIdx) == typeof(UInt64)) { row.Set(ColIdx, ValueFactory.Create(record.GetValue(ColIdx).ToString())); } if (record.GetFieldType(ColIdx) == typeof(System.Double)) { double val = record.GetDouble(ColIdx); row.Set(ColIdx, ValueFactory.Create(val.ToString())); } if (record.GetFieldType(ColIdx) == typeof(Single)) { float val = record.GetFloat(ColIdx); row.Set(ColIdx, ValueFactory.Create(val.ToString())); } if (record.GetFieldType(ColIdx) == typeof(Decimal)) { row.Set(ColIdx, ValueFactory.Create(record.GetDecimal(ColIdx))); } if (record.GetFieldType(ColIdx) == typeof(System.String)) { row.Set(ColIdx, ValueFactory.Create(record.GetString(ColIdx))); } if (record.GetFieldType(ColIdx) == typeof(System.DateTime)) { row.Set(ColIdx, ValueFactory.Create(record.GetDateTime(ColIdx))); } if (record.GetFieldType(ColIdx) == typeof(System.Byte[])) { var data = (byte[])record[ColIdx]; var newData = new BinaryDataContext(data); row.Set(ColIdx, ValueFactory.Create(newData)); } } } } }
private TableMapping CreateDefaultTableMapping(ValueTableRow tableRow, Dictionary <string, TableMapping> tableMappingByQueryName) { var queryTableName = tableRow.GetString("ИмяТаблицы"); if (string.IsNullOrEmpty(queryTableName)) { return(null); } var dbTableName = tableRow.GetString("ИмяТаблицыХранения"); if (string.IsNullOrEmpty(dbTableName)) { return(null); } var purpose = tableRow.GetString("Назначение"); ConfigurationItemDescriptor descriptor; object comObject; TableType tableType; if (purpose == "Основная" || purpose == "Константа") { var configurationName = ConfigurationName.ParseOrNull(queryTableName); if (!configurationName.HasValue) { return(null); } tableType = TableType.Main; descriptor = MetadataHelpers.GetDescriptorOrNull(configurationName.Value.Scope); if (descriptor == null) { comObject = null; } else { var configurationItem = globalContext.FindMetaByName(configurationName.Value); comObject = configurationItem.ComObject; } } else if (purpose == "ТабличнаяЧасть") { descriptor = MetadataHelpers.tableSectionDescriptor; var fullname = TableSectionQueryNameToFullName(queryTableName); comObject = ComHelpers.Invoke(globalContext.Metadata, "НайтиПоПолномуИмени", fullname); if (comObject == null) { return(null); } tableType = TableType.TableSection; } else { return(null); } var propertyDescriptors = comObject == null ? new Dictionary <string, string[]>() : MetadataHelpers.GetAttributes(comObject, descriptor) .ToDictionary(Call.Имя, GetConfigurationTypes); var propertyMappings = new ValueTable(tableRow["Поля"]) .Select(x => new { queryName = x.GetString("ИмяПоля"), dbName = x.GetString("ИмяПоляХранения") }) .Where(x => !string.IsNullOrEmpty(x.queryName)) .Where(x => !string.IsNullOrEmpty(x.dbName)) .GroupBy(x => x.queryName, (x, y) => new { queryName = x, columns = y.Select(z => z.dbName).ToArray() }, StringComparer.OrdinalIgnoreCase) .Select(x => { var propertyName = x.queryName.ExcludeSuffix("Кт").ExcludeSuffix("Дт"); var propertyTypes = propertyName == "Счет" ? new[] { "ПланСчетов.Хозрасчетный" } : propertyDescriptors.GetOrDefault(propertyName); if (propertyTypes == null || propertyTypes.Length == 1) { if (x.columns.Length != 1) { return(null); } var nestedTableName = propertyTypes == null ? null : propertyTypes[0]; var singleLayout = new SingleLayout(x.columns[0], nestedTableName); return(new PropertyMapping(x.queryName, singleLayout, null)); } var unionLayout = x.queryName == "Регистратор" ? new UnionLayout( null, GetColumnBySuffixOrNull("_RecorderTRef", x.columns), GetColumnBySuffixOrNull("_RecorderRRef", x.columns), propertyTypes) : new UnionLayout( GetColumnBySuffixOrNull("_type", x.columns), GetColumnBySuffixOrNull("_rtref", x.columns), GetColumnBySuffixOrNull("_rrref", x.columns), propertyTypes); return(new PropertyMapping(x.queryName, null, unionLayout)); }) .NotNull() .ToList(); if (tableType == TableType.TableSection) { if (!HasProperty(propertyMappings, PropertyNames.id)) { var refLayout = new SingleLayout(GetTableSectionIdColumnNameByTableName(dbTableName), null); propertyMappings.Add(new PropertyMapping(PropertyNames.id, refLayout, null)); } if (!HasProperty(propertyMappings, PropertyNames.area)) { var mainQueryName = TableMapping.GetMainQueryNameByTableSectionQueryName(queryTableName); TableMapping mainTableMapping; if (!tableMappingByQueryName.TryGetValue(mainQueryName, out mainTableMapping)) { return(null); } PropertyMapping mainAreaProperty; if (!mainTableMapping.TryGetProperty(PropertyNames.area, out mainAreaProperty)) { return(null); } propertyMappings.Add(mainAreaProperty); } } return(new TableMapping(queryTableName, dbTableName, tableType, propertyMappings.ToArray())); }
/// <summary> /// Execute the entire operation graph that is referenced by this build generate engine. /// </summary> public async Task GenerateAsync(Path soupTargetDirectory) { // Run all build operations in the correct order with incremental build checks Log.Diag("Build generate start"); // Load the parameters file var parametersFile = soupTargetDirectory + BuildConstants.GenerateParametersFileName; if (!ValueTableManager.TryLoadState(parametersFile, out var parametersState)) { Log.Error("Failed to load the parameter file: " + parametersFile.ToString()); throw new InvalidOperationException("Failed to load parameter file."); } // Load the read access file var readAccessFile = soupTargetDirectory + BuildConstants.GenerateReadAccessFileName; var readAccessList = new List <Path>(); if (!await PathListManager.TryLoadFileAsync(readAccessFile, readAccessList)) { Log.Error("Failed to load the read access file: " + readAccessFile.ToString()); throw new InvalidOperationException("Failed to load read access file."); } // Load the write access file var writeAccessFile = soupTargetDirectory + BuildConstants.GenerateWriteAccessFileName; var writeAccessList = new List <Path>(); if (!await PathListManager.TryLoadFileAsync(writeAccessFile, writeAccessList)) { Log.Error("Failed to load the write access file: " + writeAccessFile.ToString()); throw new InvalidOperationException("Failed to load write access file."); } // Get the required input state from the parameters var targetDirectory = new Path(parametersState["TargetDirectory"].AsString().ToString()); var packageDirectory = new Path(parametersState["PackageDirectory"].AsString().ToString()); // Load the recipe file var recipeFile = packageDirectory + BuildConstants.RecipeFileName; var(isSuccess, recipe) = await RecipeExtensions.TryLoadRecipeFromFileAsync(recipeFile); if (!isSuccess) { Log.Error("Failed to load the recipe: " + recipeFile.ToString()); throw new InvalidOperationException("Failed to load recipe."); } // Combine all the dependencies shared state var dependenciesSharedState = LoadDependenciesSharedState(parametersState); // Generate the set of build extension libraries var buildExtensionLibraries = GenerateBuildExtensionSet(recipe, dependenciesSharedState); // Start a new active state that is initialized to the recipe itself var activeState = new ValueTable(); // Initialize the Recipe Root Table var recipeState = recipe.Table; activeState.Add("Recipe", new Value(recipeState)); // Initialize the Parameters Root Table activeState.Add("Parameters", new Value(parametersState)); // Initialize the Dependencies Root Table activeState.Add("Dependencies", new Value(dependenciesSharedState)); // Keep the extension libraries open while running the build system // to ensure their memory is kept alive var evaluateGraph = new OperationGraph(); IValueTable sharedState = new ValueTable(); { // Create a new build system for the requested build var buildTaskManager = new BuildTaskManager(); // Run all build extension register callbacks foreach (var buildExtension in buildExtensionLibraries) { var library = LoadPlugin(buildExtension); FindAllCommands(library, buildTaskManager); } // Run the build var buildState = new BuildState( activeState, _fileSystemState, readAccessList, writeAccessList); buildTaskManager.Execute(buildState, soupTargetDirectory); // Grab the build results so the dependency libraries can be released asap evaluateGraph = buildState.BuildOperationGraph(); sharedState = buildState.SharedState; } // Save the operation graph so the evaluate phase can load it var evaluateGraphFile = soupTargetDirectory + BuildConstants.GenerateEvaluateOperationGraphFileName; OperationGraphManager.SaveState(evaluateGraphFile, evaluateGraph, _fileSystemState); // Save the shared state that is to be passed to the downstream builds var sharedStateFile = soupTargetDirectory + BuildConstants.GenerateSharedStateFileName; ValueTableManager.SaveState(sharedStateFile, sharedState); Log.Diag("Build generate end"); }
public void Build_Executable() { // Register the test process manager var processManager = new MockProcessManager(); // Register the test listener var testListener = new TestTraceListener(); using (var scopedTraceListener = new ScopedTraceListenerRegister(testListener)) using (var scopedProcesManager = new ScopedSingleton <IProcessManager>(processManager)) { // Setup the input build state var buildState = new MockBuildState(); var state = buildState.ActiveState; // Setup build table var buildTable = new ValueTable(); state.Add("Build", new Value(buildTable)); buildTable.Add("TargetName", new Value("Program")); buildTable.Add("TargetType", new Value((long)BuildTargetType.Executable)); buildTable.Add("SourceRootDirectory", new Value("C:/source/")); buildTable.Add("TargetRootDirectory", new Value("C:/target/")); buildTable.Add("ObjectDirectory", new Value("obj/")); buildTable.Add("BinaryDirectory", new Value("bin/")); buildTable.Add( "Source", new Value(new ValueList() { new Value("TestFile.cs"), })); // Setup parameters table var parametersTable = new ValueTable(); state.Add("Parameters", new Value(parametersTable)); parametersTable.Add("Architecture", new Value("x64")); parametersTable.Add("Compiler", new Value("MOCK")); // Register the mock compiler var compiler = new Compiler.Mock.Compiler(); var compilerFactory = new Dictionary <string, Func <IValueTable, ICompiler> >(); compilerFactory.Add("MOCK", (IValueTable state) => { return(compiler); }); var factory = new ValueFactory(); var uut = new BuildTask(buildState, factory, compilerFactory); uut.Execute(); // Verify expected process manager requests Assert.Equal( new List <string>() { "GetCurrentProcessFileName", "GetCurrentProcessFileName", "GetCurrentProcessFileName", }, processManager.GetRequests()); // Verify expected logs Assert.Equal( new List <string>() { "INFO: Build Generate Done" }, testListener.GetMessages()); var expectedCompileArguments = new CompileArguments() { Target = new Path("./bin/Program.mock.dll"), ReferenceTarget = new Path("./bin/ref/Program.mock.dll"), TargetType = LinkTarget.Executable, SourceRootDirectory = new Path("C:/source/"), TargetRootDirectory = new Path("C:/target/"), ObjectDirectory = new Path("obj/"), SourceFiles = new List <Path>() { new Path("TestFile.cs") }, }; // Verify expected compiler calls Assert.Equal( new List <CompileArguments>() { expectedCompileArguments, }, compiler.GetCompileRequests()); // Verify build state var expectedBuildOperations = new List <BuildOperation>() { new BuildOperation( "MakeDir [./obj/]", new Path("C:/target/"), new Path("C:/mkdir.exe"), "\"./obj/\"", new List <Path>(), new List <Path>() { new Path("./obj/"), }), new BuildOperation( "MakeDir [./bin/]", new Path("C:/target/"), new Path("C:/mkdir.exe"), "\"./bin/\"", new List <Path>(), new List <Path>() { new Path("./bin/"), }), new BuildOperation( "MakeDir [./bin/ref/]", new Path("C:/target/"), new Path("C:/mkdir.exe"), "\"./bin/ref/\"", new List <Path>(), new List <Path>() { new Path("./bin/ref/"), }), new BuildOperation( "MockCompile: 1", new Path("MockWorkingDirectory"), new Path("MockCompiler.exe"), "Arguments", new List <Path>() { new Path("./InputFile.in"), }, new List <Path>() { new Path("./OutputFile.out"), }), new BuildOperation( "WriteFile [./bin/Program.runtimeconfig.json]", new Path("C:/target/"), new Path("./writefile.exe"), @"""./bin/Program.runtimeconfig.json"" ""{ ""runtimeOptions"": { ""tfm"": ""net5.0"", ""framework"": { ""name"": ""Microsoft.NETCore.App"", ""version"": ""5.0.0"" } } }""", new List <Path>(), new List <Path>() { new Path("./bin/Program.runtimeconfig.json"), }), }; Assert.Equal( expectedBuildOperations, buildState.GetBuildOperations()); } }
public void Build_Library_MultipleFiles() { // Register the test process manager var processManager = new MockProcessManager(); // Register the test listener var testListener = new TestTraceListener(); using (var scopedTraceListener = new ScopedTraceListenerRegister(testListener)) using (var scopedProcesManager = new ScopedSingleton <IProcessManager>(processManager)) { // Setup the input build state var buildState = new MockBuildState(); var state = buildState.ActiveState; // Setup build table var buildTable = new ValueTable(); state.Add("Build", new Value(buildTable)); buildTable.Add("TargetName", new Value("Library")); buildTable.Add("TargetType", new Value((long)BuildTargetType.Library)); buildTable.Add("SourceRootDirectory", new Value("C:/source/")); buildTable.Add("TargetRootDirectory", new Value("C:/target/")); buildTable.Add("ObjectDirectory", new Value("obj/")); buildTable.Add("BinaryDirectory", new Value("bin/")); buildTable.Add("Source", new Value(new ValueList() { new Value("TestFile1.cpp"), new Value("TestFile2.cpp"), new Value("TestFile3.cpp"), })); buildTable.Add("IncludeDirectories", new Value(new ValueList() { new Value("Folder"), new Value("AnotherFolder/Sub"), })); buildTable.Add("ModuleDependencies", new Value(new ValueList() { new Value("../Other/bin/OtherModule1.mock.bmi"), new Value("../OtherModule2.mock.bmi"), })); buildTable.Add("OptimizationLevel", new Value((long)BuildOptimizationLevel.None)); // Setup parameters table var parametersTable = new ValueTable(); state.Add("Parameters", new Value(parametersTable)); parametersTable.Add("Architecture", new Value("x64")); parametersTable.Add("Compiler", new Value("MOCK")); // Register the mock compiler var compiler = new Compiler.Mock.Compiler(); var compilerFactory = new Dictionary <string, Func <IValueTable, ICompiler> >(); compilerFactory.Add("MOCK", (IValueTable state) => { return(compiler); }); var factory = new ValueFactory(); var uut = new BuildTask(buildState, factory, compilerFactory); uut.Execute(); // Verify expected process manager requests Assert.Equal( new List <string>() { "GetCurrentProcessFileName", "GetCurrentProcessFileName", "GetCurrentProcessFileName", }, processManager.GetRequests()); // Verify expected logs Assert.Equal( new List <string>() { "INFO: Build Generate Done", }, testListener.GetMessages()); // Setup the shared arguments var expectedCompileArguments = new CompileArguments() { Target = new Path("./bin/Library.mock.dll"), ReferenceTarget = new Path("./bin/ref/Library.mock.dll"), SourceRootDirectory = new Path("C:/source/"), TargetRootDirectory = new Path("C:/target/"), ObjectDirectory = new Path("obj/"), SourceFiles = new List <Path>() { new Path("TestFile1.cpp"), new Path("TestFile2.cpp"), new Path("TestFile3.cpp"), }, }; // Verify expected compiler calls Assert.Equal( new List <CompileArguments>() { expectedCompileArguments, }, compiler.GetCompileRequests()); // Verify build state var expectedBuildOperations = new List <BuildOperation>() { new BuildOperation( "MakeDir [./obj/]", new Path("C:/target/"), new Path("C:/mkdir.exe"), "\"./obj/\"", new List <Path>(), new List <Path>() { new Path("./obj/"), }), new BuildOperation( "MakeDir [./bin/]", new Path("C:/target/"), new Path("C:/mkdir.exe"), "\"./bin/\"", new List <Path>(), new List <Path>() { new Path("./bin/"), }), new BuildOperation( "MakeDir [./bin/ref/]", new Path("C:/target/"), new Path("C:/mkdir.exe"), "\"./bin/ref/\"", new List <Path>(), new List <Path>() { new Path("./bin/ref/"), }), new BuildOperation( "MockCompile: 1", new Path("MockWorkingDirectory"), new Path("MockCompiler.exe"), "Arguments", new List <Path>() { new Path("./InputFile.in"), }, new List <Path>() { new Path("./OutputFile.out"), }), }; Assert.Equal( expectedBuildOperations, buildState.GetBuildOperations()); } }
public void Execute() { // Register the test systems var testListener = new TestTraceListener(); using (var scopedTraceListener = new ScopedTraceListenerRegister(testListener)) { // Setup the input build state var buildState = new MockBuildState(); var state = buildState.ActiveState; // Set the sdks var sdks = new ValueList(); sdks.Add(new Value(new ValueTable() { { "Name", new Value("MSVC") }, { "Properties", new Value(new ValueTable() { { "Version", new Value("1.0.0") }, { "VCToolsRoot", new Value("C:/VCTools/Root/") }, }) }, })); sdks.Add(new Value(new ValueTable() { { "Name", new Value("Windows") }, { "Properties", new Value(new ValueTable() { { "Version", new Value("10.0.0") }, { "RootPath", new Value("C:/WindowsKit/Root/") }, }) }, })); // Setup parameters table var parametersTable = new ValueTable(); state.Add("Parameters", new Value(parametersTable)); parametersTable.Add("SDKs", new Value(sdks)); parametersTable.Add("System", new Value("win32")); parametersTable.Add("Architecture", new Value("x64")); var factory = new ValueFactory(); var uut = new ResolveToolsTask(buildState, factory); uut.Execute(); // Verify expected logs Assert.Equal( new List <string>() { "INFO: Using VC Version: 1.0.0", "INFO: Using Windows Kit Version: 10.0.0", }, testListener.GetMessages()); // Verify build state var expectedBuildOperations = new List <BuildOperation>(); Assert.Equal( expectedBuildOperations, buildState.GetBuildOperations()); } }
public ValueTable RunQuery() { ValueTable tbl = new ValueTable(); OdbcCommand dbCommand = (OdbcCommand)dbСonnection.CreateCommand(); // Добавляем параметры в запрос string pattern = @"@[A-z0-9]*"; Regex regex = new Regex(pattern); Match match = regex.Match(QueryText); while (match.Success) { string currParam = match.Value; var currValue = parameters[currParam]; dbCommand.Parameters.AddWithValue(currParam, currValue); match = match.NextMatch(); } string prepareQuery = regex.Replace(QueryText, "?"); dbCommand.CommandText = prepareQuery; // Выполняем запрос IDataReader dbReader = dbCommand.ExecuteReader(); // Создаем ТаблицуЗначений в которую будем выводить результат запроса for (int i = 0; i < dbReader.FieldCount; i++) { string ColumnName = dbReader.GetName(i); tbl.Columns.Add(ColumnName); } while (dbReader.Read()) { for (int i = 0; i < dbReader.FieldCount; i++) { string ColumnName = dbReader.GetName(i); ValueTableRow row = tbl.Add(); var value = dbReader[ColumnName]; System.Type valueType = value.GetType(); if (valueType == typeof(int)) { row.Set(i, ValueFactory.Create((int)value)); } else if (valueType == typeof(Int16)) { row.Set(i, ValueFactory.Create((Int16)value)); } else if (valueType == typeof(Int32)) { row.Set(i, ValueFactory.Create((Int32)value)); } else if (valueType == typeof(string)) { row.Set(i, ValueFactory.Create((string)value)); } else if (valueType == typeof(DateTime)) { row.Set(i, ValueFactory.Create((DateTime)value)); } } } dbReader.Close(); dbReader = null; dbCommand.Dispose(); dbCommand = null; return(tbl); }
public ValueTable Unload() { ValueTable resultTable = new ValueTable(); for (int ColIdx = 0; ColIdx < _reader.FieldCount; ColIdx++) { resultTable.Columns.Add(_reader.GetName(ColIdx)); } foreach (DbDataRecord record in _reader) { ValueTableRow row = resultTable.Add(); for (int ColIdx = 0; ColIdx < _reader.FieldCount; ColIdx++) { if (record.IsDBNull(ColIdx)) { row.Set(ColIdx, ValueFactory.Create()); continue; } //Console.WriteLine("queryresult-col-type:" + record.GetFieldType(ColIdx).ToString() + "::" + record.GetDataTypeName(ColIdx)); if (record.GetFieldType(ColIdx) == typeof(Int32)) { row.Set(ColIdx, ValueFactory.Create((int)record.GetValue(ColIdx))); } if (record.GetFieldType(ColIdx) == typeof(Int64)) { row.Set(ColIdx, ValueFactory.Create(record.GetInt64(ColIdx))); } if (record.GetFieldType(ColIdx) == typeof(Boolean)) { row.Set(ColIdx, ValueFactory.Create(record.GetBoolean(ColIdx))); } if (record.GetFieldType(ColIdx) == typeof(UInt64)) { row.Set(ColIdx, ValueFactory.Create(record.GetValue(ColIdx).ToString())); } if (record.GetFieldType(ColIdx).ToString() == "System.Double") { double val = record.GetDouble(ColIdx); row.Set(ColIdx, ValueFactory.Create(val.ToString())); } if (record.GetFieldType(ColIdx) == typeof(Single)) { float val = record.GetFloat(ColIdx); row.Set(ColIdx, ValueFactory.Create(val.ToString())); } if (record.GetFieldType(ColIdx) == typeof(Decimal)) { row.Set(ColIdx, ValueFactory.Create(record.GetDecimal(ColIdx))); } if (record.GetFieldType(ColIdx).ToString() == "System.String") { row.Set(ColIdx, ValueFactory.Create(record.GetString(ColIdx))); } if (record.GetFieldType(ColIdx).ToString() == "System.DateTime") { row.Set(ColIdx, ValueFactory.Create(record.GetDateTime(ColIdx))); } if (record.GetFieldType(ColIdx).ToString() == "System.Byte[]") { var data = (byte[])record[ColIdx]; var newData = new BinaryDataContext(data); row.Set(ColIdx, ValueFactory.Create(newData)); } } } _reader.Close(); return(resultTable); }