internal static void GetDataFromSourceDataTable(DataTable dt, IntegrationContext context) { foreach (DataRow dr in dt.Rows) { DataItem item = GetDataItemFromSource(dr, context.Schema); if (item != null) { if (item.IsValid) { context.AddData(item); } else { context.AddSkippedData(item); } } } }
internal override void GetData(IntegrationContext context) { string sourcePath = context.State[ContextState.SourcePath] as string; if (string.IsNullOrEmpty(sourcePath)) { throw new ArgumentNullException(string.Format("argument [{0}] missed!", ContextState.SourcePath)); } if (!File.Exists(sourcePath)) { throw new FileNotFoundException(string.Format("File [{0}] not found!", sourcePath)); } bool skipfirstline = (bool)context.State[ContextState.FlatFileSkipFirstLine]; bool skiplastline = (bool)context.State[ContextState.FlatFileSkipLastLine]; encoding = StringUtil.GetFileEncoding(sourcePath); using ( StreamReader reader = new StreamReader(new FileStream(sourcePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), encoding)) { if (skipfirstline) { GetLine(reader); } string row = null; while (!reader.EndOfStream) { if (skiplastline) { if (row == null) { row = GetLine(reader); continue; } } else { row = GetLine(reader); } if (row.Trim().Length == 0) { continue; } DataItem item = GetDataItem(row, context.Schema, true); if (item != null) { if (item.IsValid) { context.AddData(item); } else { context.AddSkippedData(item); } } if (skiplastline) { row = GetLine(reader); } } } }