/// <summary> /// Handles the DoWorker event for the worker /// </summary> /// <param name="sender">Object that fired the event</param> /// <param name="e">.NET supplied event parameters</param> private void worker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { lock (syncLock) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToProcessingState)); this.Dispatcher.BeginInvoke(new SimpleCallback(ClearResults)); AddLineListGridDelegate addGrid = new AddLineListGridDelegate(AddLineListGrid); SetGridTextDelegate setText = new SetGridTextDelegate(SetGridText); SetGridImageDelegate setImage = new SetGridImageDelegate(SetGridImage); AddGridRowDelegate addRow = new AddGridRowDelegate(AddGridRow); RenderFrequencyHeaderDelegate renderHeader = new RenderFrequencyHeaderDelegate(RenderFrequencyHeader); DrawFrequencyBordersDelegate drawBorders = new DrawFrequencyBordersDelegate(DrawFrequencyBorders); Configuration config = dashboardHelper.Config; string yesValue = config.Settings.RepresentationOfYes; string noValue = config.Settings.RepresentationOfNo; try { DataTable dictionaryTable = dashboardHelper.FieldTable.Copy(); foreach (KeyValuePair<string, string> kvp in dashboardHelper.TableColumnNames) { DataRow row = dictionaryTable.Rows.Find(kvp.Key); if(row == null) { dictionaryTable.Rows.Add(kvp.Key, kvp.Value); } } if (dashboardHelper.IsUsingEpiProject) { dictionaryTable.Columns.Add("Page", typeof(int)); dictionaryTable.Columns.Add("Tab", typeof(int)); dictionaryTable.Columns.Add("Prompt", typeof(string)); dictionaryTable.Columns.Add("Items", typeof(string)); foreach (DataRow fieldRow in dictionaryTable.Rows) { if (fieldRow["epifieldtype"] is RenderableField) { RenderableField renderableField = fieldRow["epifieldtype"] as RenderableField; fieldRow["Page"] = renderableField.Page.Position + 1; fieldRow["Tab"] = renderableField.TabIndex; fieldRow["Prompt"] = renderableField.PromptText; if (renderableField is GroupField) { GroupField groupField = renderableField as GroupField; fieldRow["Items"] = groupField.ChildFieldNames; } else if (renderableField is OptionField) { OptionField optionField = renderableField as OptionField; fieldRow["Items"] = optionField.GetOptionsString(); } } } dictionaryTable.Columns["columnname"].SetOrdinal(0); dictionaryTable.Columns["Prompt"].SetOrdinal(1); dictionaryTable.Columns["formname"].SetOrdinal(2); dictionaryTable.Columns["Page"].SetOrdinal(3); dictionaryTable.Columns["Tab"].SetOrdinal(4); dictionaryTable.Columns["datatype"].SetOrdinal(5); dictionaryTable.Columns["epifieldtype"].SetOrdinal(6); dictionaryTable.Columns["tablename"].SetOrdinal(7); dictionaryTable.Columns["Items"].SetOrdinal(8); } if (dictionaryTable == null || dictionaryTable.Rows.Count == 0) { this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), "There are no valid fields to display."); } else if (worker.CancellationPending) { this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), SharedStrings.DASHBOARD_GADGET_STATUS_OPERATION_CANCELLED); this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToFinishedState)); Debug.Print("Data dictionary thread cancelled"); return; } else { this.Dispatcher.BeginInvoke(addGrid, "", "", dictionaryTable.Columns.Count); string formatString = string.Empty; this.Dispatcher.BeginInvoke(renderHeader, "", "", dictionaryTable.Columns); int rowCount = 1; int columnCount = 1; foreach (System.Data.DataRow row in dictionaryTable.Rows) { bool isGroup = false; this.Dispatcher.Invoke(addRow, "", 30); this.Dispatcher.BeginInvoke(setText, "", new TextBlockConfig(StringLiterals.SPACE + rowCount.ToString() + StringLiterals.SPACE, new Thickness(2, 0, 2, 0), VerticalAlignment.Center, HorizontalAlignment.Center, rowCount, 0, Visibility.Visible), FontWeights.Normal); columnCount = 1; foreach (DataColumn column in dictionaryTable.Columns) { string displayValue = row[column.ColumnName].ToString(); if (column.ColumnName.Equals("epifieldtype")) { displayValue = displayValue.Replace("Epi.Fields.", ""); if (isGroup) { displayValue = "GroupField"; } } else if (column.ColumnName.Equals("columnname")) { isGroup = dashboardHelper.GetGroupFieldsAsList().Contains(displayValue); } this.Dispatcher.BeginInvoke(setText, "", new TextBlockConfig(displayValue, new Thickness(8, 8, 8, 8), VerticalAlignment.Center, HorizontalAlignment.Left, rowCount, columnCount, Visibility.Visible), FontWeights.Normal); columnCount++; } rowCount++; } this.Dispatcher.BeginInvoke(drawBorders, ""); } this.Dispatcher.BeginInvoke(new SimpleCallback(RenderFinish)); this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToFinishedState)); } catch (Exception ex) { this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), ex.Message); this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToFinishedState)); } finally { stopwatch.Stop(); Debug.Print("Data dictionary gadget took " + stopwatch.Elapsed.ToString() + " seconds to complete with " + dashboardHelper.RecordCount.ToString() + " records and the following filters:"); Debug.Print(dashboardHelper.DataFilters.GenerateDataFilterString()); } } }
/// <summary> /// Handles the DoWorker event for the worker /// </summary> /// <param name="sender">Object that fired the event</param> /// <param name="e">.NET supplied event parameters</param> private void worker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { lock (syncLock) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToProcessingState)); this.Dispatcher.BeginInvoke(new SimpleCallback(ClearResults)); AddLineListGridDelegate addGrid = new AddLineListGridDelegate(AddLineListGrid); Configuration config = DashboardHelper.Config; string yesValue = config.Settings.RepresentationOfYes; string noValue = config.Settings.RepresentationOfNo; try { DataTable dictionaryTable = DashboardHelper.FieldTable.Copy(); foreach (KeyValuePair<string, string> kvp in DashboardHelper.TableColumnNames) { DataRow row = dictionaryTable.Rows.Find(kvp.Key); if(row == null) { dictionaryTable.Rows.Add(kvp.Key, kvp.Value); } } if (DashboardHelper.IsUsingEpiProject) { dictionaryTable.Columns.Add("Page", typeof(int)); dictionaryTable.Columns.Add("Tab", typeof(int)); dictionaryTable.Columns.Add("Prompt", typeof(string)); dictionaryTable.Columns.Add("Items", typeof(string)); dictionaryTable.Columns.Add("FieldType", typeof(string)); foreach (DataRow fieldRow in dictionaryTable.Rows) { if (fieldRow["epifieldtype"] is RenderableField) { RenderableField renderableField = fieldRow["epifieldtype"] as RenderableField; fieldRow["Page"] = renderableField.Page.Position + 1; fieldRow["Tab"] = renderableField.TabIndex; fieldRow["Prompt"] = renderableField.PromptText; fieldRow["FieldType"] = fieldRow["epifieldtype"].ToString().Replace("Epi.Fields.", String.Empty); if (renderableField is GroupField) { GroupField groupField = renderableField as GroupField; fieldRow["Items"] = groupField.ChildFieldNames; } else if (renderableField is OptionField) { OptionField optionField = renderableField as OptionField; fieldRow["Items"] = optionField.GetOptionsString(); } } fieldRow["datatype"] = fieldRow["datatype"].ToString().Replace("System.", String.Empty); } dictionaryTable.Columns["columnname"].SetOrdinal(0); dictionaryTable.Columns["Prompt"].SetOrdinal(1); dictionaryTable.Columns["formname"].SetOrdinal(2); dictionaryTable.Columns["Page"].SetOrdinal(3); dictionaryTable.Columns["Tab"].SetOrdinal(4); dictionaryTable.Columns["datatype"].SetOrdinal(5); dictionaryTable.Columns["FieldType"].SetOrdinal(6); dictionaryTable.Columns["tablename"].SetOrdinal(7); dictionaryTable.Columns["Items"].SetOrdinal(8); } if (dictionaryTable == null || dictionaryTable.Rows.Count == 0) { this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), "There are no valid fields to display."); } else if (worker.CancellationPending) { this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), SharedStrings.DASHBOARD_GADGET_STATUS_OPERATION_CANCELLED); this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToFinishedState)); Debug.Print("Data dictionary thread cancelled"); return; } else { this.Dispatcher.BeginInvoke(addGrid, dictionaryTable.AsDataView()); string formatString = string.Empty; } this.Dispatcher.BeginInvoke(new SimpleCallback(RenderFinish)); this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToFinishedState)); } catch (Exception ex) { this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), ex.Message); this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToFinishedState)); } finally { stopwatch.Stop(); Debug.Print("Data dictionary gadget took " + stopwatch.Elapsed.ToString() + " seconds to complete with " + DashboardHelper.RecordCount.ToString() + " records and the following filters:"); Debug.Print(DashboardHelper.DataFilters.GenerateDataFilterString()); } } }
/// <summary> /// Handles the DoWorker event for the worker /// </summary> /// <param name="sender">Object that fired the event</param> /// <param name="e">.NET supplied event parameters</param> private void worker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { lock (syncLock) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToProcessingState)); this.Dispatcher.BeginInvoke(new SimpleCallback(ClearResults)); AddLineListGridDelegate addGrid = new AddLineListGridDelegate(AddLineListGrid); Configuration config = DashboardHelper.Config; string yesValue = config.Settings.RepresentationOfYes; string noValue = config.Settings.RepresentationOfNo; try { DataTable dictionaryTable = DashboardHelper.FieldTable.Copy(); foreach (KeyValuePair <string, string> kvp in DashboardHelper.TableColumnNames) { DataRow row = dictionaryTable.Rows.Find(kvp.Key); if (row == null) { dictionaryTable.Rows.Add(kvp.Key, kvp.Value); } } if (DashboardHelper.IsUsingEpiProject) { dictionaryTable.Columns.Add("Page", typeof(int)); dictionaryTable.Columns.Add("Tab", typeof(int)); dictionaryTable.Columns.Add("Prompt", typeof(string)); dictionaryTable.Columns.Add("Items", typeof(string)); dictionaryTable.Columns.Add("FieldType", typeof(string)); foreach (DataRow fieldRow in dictionaryTable.Rows) { if (fieldRow["epifieldtype"] is RenderableField) { RenderableField renderableField = fieldRow["epifieldtype"] as RenderableField; fieldRow["Page"] = renderableField.Page.Position + 1; fieldRow["Tab"] = renderableField.TabIndex; fieldRow["Prompt"] = renderableField.PromptText; fieldRow["FieldType"] = fieldRow["epifieldtype"].ToString().Replace("Epi.Fields.", String.Empty); if (renderableField is GroupField) { GroupField groupField = renderableField as GroupField; fieldRow["Items"] = groupField.ChildFieldNames; } else if (renderableField is OptionField) { OptionField optionField = renderableField as OptionField; fieldRow["Items"] = optionField.GetOptionsString(); } } fieldRow["datatype"] = fieldRow["datatype"].ToString().Replace("System.", String.Empty); } dictionaryTable.Columns["columnname"].SetOrdinal(0); dictionaryTable.Columns["Prompt"].SetOrdinal(1); dictionaryTable.Columns["formname"].SetOrdinal(2); dictionaryTable.Columns["Page"].SetOrdinal(3); dictionaryTable.Columns["Tab"].SetOrdinal(4); dictionaryTable.Columns["datatype"].SetOrdinal(5); dictionaryTable.Columns["FieldType"].SetOrdinal(6); dictionaryTable.Columns["tablename"].SetOrdinal(7); dictionaryTable.Columns["Items"].SetOrdinal(8); } if (dictionaryTable == null || dictionaryTable.Rows.Count == 0) { this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), "There are no valid fields to display."); } else if (worker.CancellationPending) { this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), SharedStrings.DASHBOARD_GADGET_STATUS_OPERATION_CANCELLED); this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToFinishedState)); Debug.Print("Data dictionary thread cancelled"); return; } else { this.Dispatcher.BeginInvoke(addGrid, dictionaryTable.AsDataView()); string formatString = string.Empty; } this.Dispatcher.BeginInvoke(new SimpleCallback(RenderFinish)); this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToFinishedState)); } catch (Exception ex) { this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), ex.Message); this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToFinishedState)); } finally { stopwatch.Stop(); Debug.Print("Data dictionary gadget took " + stopwatch.Elapsed.ToString() + " seconds to complete with " + DashboardHelper.RecordCount.ToString() + " records and the following filters:"); Debug.Print(DashboardHelper.DataFilters.GenerateDataFilterString()); } } }