private void FillPrimaryKeysBasedOnLambdaExpression(DataRow dataRow, ResultsLoaderProfile profile) { ConvertTypeCalculator.Convert(dataRow); if (profile == null) { return; } foreach (DataColumn dataColumn in dataRow.Table.PrimaryKey) { IList <KeyValuePair <string, object> > list = this.GetExpressionCalculator().CalculateSpecifiedColumn(dataColumn.ColumnName, dataRow, profile.InputTable.Rows[0]); foreach (KeyValuePair <string, object> keyValuePair in list) { dataRow[keyValuePair.Key] = keyValuePair.Value; } } }
protected override void OnDoRefreshWork(RefreshRequestEventArgs e) { Stopwatch sw = Stopwatch.StartNew(); ExTraceGlobals.ProgramFlowTracer.TraceFunction <DataTableLoader>((long)this.GetHashCode(), "-->DataTableLoader.OnDoRefreshWork: {0}", this); this.expressionCalculator = null; DataTable dataTable = (e as DataTableLoader.IDataTableLoaderRefreshRequest).DataTable.Clone(); e.Result = dataTable; dataTable.RowChanging += delegate(object param0, DataRowChangeEventArgs param1) { if (e.CancellationPending) { e.Cancel = true; this.Cancel(e); e.Result = dataTable; } }; int rowCount = 0; int expectedRowCount = Math.Max(this.lastRowCount, this.BatchSize); ResultsLoaderProfile profile = e.Argument as ResultsLoaderProfile; if (profile != null) { foreach (AbstractDataTableFiller abstractDataTableFiller in profile.TableFillers) { abstractDataTableFiller.FillCompleted += delegate(object sender, FillCompletedEventArgs args) { AbstractDataTableFiller filler = sender as AbstractDataTableFiller; if (this.IsPreFillForResolving(filler) || profile.FillType == null) { expectedRowCount = Math.Max(expectedRowCount, rowCount + this.BatchSize + 1); bool flag = !this.IsPreFillForResolving(filler) && profile.FillType == 0; this.ReportDataTable(rowCount, expectedRowCount, args.DataTable, e, flag, sw.Elapsed); if (profile.IsResolving && profile.PipelineObjects != null && flag) { foreach (object obj in profile.PipelineObjects) { if (this.FindRowByIdentity(args.DataTable, obj) != null) { profile.ResolvedObjects.Add(obj); } } IEnumerable <object> source = from id in profile.PipelineObjects where !profile.ResolvedObjects.Contains(id) select id; profile.PipelineObjects = source.ToArray <object>(); profile.ResolvedObjects.Clear(); } } }; } } dataTable.RowChanged += delegate(object sender, DataRowChangeEventArgs rowChangedEvent) { if (rowChangedEvent.Action == DataRowAction.Add) { rowCount++; ExTraceGlobals.DataFlowTracer.Information <DataTableLoader, int, TimeSpan>((long)this.GetHashCode(), "DataTableLoader.OnDoRefreshWork: {0}, rowCount:{1}. ElapsedTime:{2}", this, rowCount, sw.Elapsed); ConvertTypeCalculator.Convert(rowChangedEvent.Row); if (dataTable.Rows.Count >= this.BatchSize && (profile == null || profile.FillType == null)) { expectedRowCount = Math.Max(expectedRowCount, rowCount + this.BatchSize + 1); this.ReportDataTable(rowCount, expectedRowCount, dataTable, e, true, sw.Elapsed); } } }; try { ExTraceGlobals.ProgramFlowTracer.TraceFunction <DataTableLoader, TimeSpan>((long)this.GetHashCode(), "-->DataTableLoader.OnDoRefreshWork: Fill: {0}. ElapsedTime:{1}", this, sw.Elapsed); this.Fill(e); } catch (MonadDataAdapterInvocationException ex) { if (!(ex.InnerException is ManagementObjectNotFoundException) && !(ex.InnerException is MapiObjectNotFoundException)) { throw; } } finally { ExTraceGlobals.ProgramFlowTracer.TraceFunction <DataTableLoader, TimeSpan>((long)this.GetHashCode(), "<--DataTableLoader.OnDoRefreshWork: Fill: {0}. ElapsedTime:{1}", this, sw.Elapsed); e.Result = dataTable; ExTraceGlobals.ProgramFlowTracer.TraceFunction((long)this.GetHashCode(), "-->DataTableLoader.OnDoRefreshWork: report last batch: {0}. dataTable.Rows.Count:{1}, this.BatchSize:{2}, rowCount:{3}, expectedRowCount:{4}", new object[] { this, dataTable.Rows.Count, this.BatchSize, rowCount, rowCount + 1 }); this.FillColumnsBasedOnLambdaExpression(dataTable, e.Argument as ResultsLoaderProfile); ColumnValueCalculator.CalculateAll(dataTable); if (!e.ReportedProgress) { ExTraceGlobals.ProgramFlowTracer.TracePerformance <DataTableLoader, string, string>(0L, "Time:{1}. {2} First batch data arrived in worker thread. {0}", this, ExDateTime.Now.ToString("MM/dd/yyyy HH:mm:ss.fff"), (this != null) ? this.Table.TableName : string.Empty); } e.ReportProgress(rowCount, rowCount + 1, this.ProgressText, this.MoveRows(dataTable, null, false)); ExTraceGlobals.ProgramFlowTracer.TraceFunction <DataTableLoader>((long)this.GetHashCode(), "<--DataTableLoader.OnDoRefreshWork: report last batch: {0}", this); } base.OnDoRefreshWork(e); e.Result = dataTable; ExTraceGlobals.ProgramFlowTracer.TraceFunction <DataTableLoader, TimeSpan>((long)this.GetHashCode(), "<--DataTableLoader.OnDoRefreshWork: {0}. Total ElapsedTime:{1}", this, sw.Elapsed); }