Exemplo n.º 1
0
 public ComplexSampleTables(IAnalysisStatisticContext AnalysisStatisticContext)
 {
     CSTables = new StatisticsRepository.ComplexSampleTables();
     this.Construct(AnalysisStatisticContext);
 }
        /// <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>
        protected override void worker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            lock (syncLock)
            {
                Dictionary<string, string> inputVariableList = ((GadgetParameters)e.Argument).InputVariableList;

                this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToProcessingState));
                this.Dispatcher.BeginInvoke(new SimpleCallback(ClearResults));
                CreateComplexSampleTableGridDelegate createGrid = new CreateComplexSampleTableGridDelegate(AddComplexSampleTableGrid);

                string freqVar = GadgetOptions.MainVariableName;
                string weightVar = GadgetOptions.WeightVariableName;
                string strataVar = string.Empty;
                bool includeMissing = GadgetOptions.ShouldIncludeMissing;

                if (inputVariableList.ContainsKey("stratavar"))
                {
                    strataVar = inputVariableList["stratavar"];
                }

                List<string> stratas = new List<string>();
                if (!string.IsNullOrEmpty(strataVar))
                {
                    stratas.Add(strataVar);
                }

                try
                {
                    Configuration config = dashboardHelper.Config;
                    string yesValue = config.Settings.RepresentationOfYes;
                    string noValue = config.Settings.RepresentationOfNo;

                    RequestUpdateStatusDelegate requestUpdateStatus = new RequestUpdateStatusDelegate(RequestUpdateStatusMessage);
                    CheckForCancellationDelegate checkForCancellation = new CheckForCancellationDelegate(IsCancelled);

                    GadgetOptions.GadgetStatusUpdate += new GadgetStatusUpdateHandler(requestUpdateStatus);
                    GadgetOptions.GadgetCheckForCancellation += new GadgetCheckForCancellationHandler(checkForCancellation);

                    if (this.DataFilters != null && this.DataFilters.Count > 0)
                    {
                        GadgetOptions.CustomFilter = this.DataFilters.GenerateDataFilterString(false);
                    }
                    else
                    {
                        GadgetOptions.CustomFilter = string.Empty;
                    }

                    List<string> columnNames = new List<string>();
                    columnNames.Add(GadgetOptions.MainVariableName);
                    columnNames.Add(GadgetOptions.CrosstabVariableName);
                    columnNames.Add(GadgetOptions.PSUVariableName);
                    if(GadgetOptions.StrataVariableNames != null && GadgetOptions.StrataVariableNames.Count == 1 && !string.IsNullOrEmpty(GadgetOptions.StrataVariableNames[0]))
                    {
                        columnNames.Add(GadgetOptions.StrataVariableNames[0]);
                    }
                    if(!string.IsNullOrEmpty(GadgetOptions.WeightVariableName))
                    {
                        columnNames.Add(GadgetOptions.WeightVariableName);
                    }

                    DataTable csTable = dashboardHelper.GenerateTable(columnNames, GadgetOptions.CustomFilter);

                    if (csTable == null || csTable.Rows.Count == 0)
                    {
                        this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), SharedStrings.NO_RECORDS_SELECTED);
                        this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToFinishedState));
                        return;
                    }
                    else if (worker.CancellationPending)
                    {
                        this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), SharedStrings.DASHBOARD_GADGET_STATUS_OPERATION_CANCELLED);
                        this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToFinishedState));
                        return;
                    }
                    else
                    {
                        lock (staticSyncLock)
                        {
                            // Complex sample frequency actually uses the CS Tables class.
                            StatisticsRepository.ComplexSampleTables csTables = new StatisticsRepository.ComplexSampleTables();
                            StatisticsRepository.ComplexSampleTables.CSTablesResults results = csTables.ComplexSampleTables(GadgetOptions.InputVariableList, csTable);

                            if (!string.IsNullOrEmpty(results.ErrorMessage))
                            {
                                throw new ApplicationException(results.ErrorMessage);
                            }

                            if (results.Rows == null || results.Rows.Count == 0)
                            {
                                throw new ApplicationException("No data was returned from the statistics repository.");
                            }

                            StatisticsRepository.ComplexSampleTables.TablesRow totalRow = new StatisticsRepository.ComplexSampleTables.TablesRow();
                            totalRow.Cells = new List<StatisticsRepository.ComplexSampleTables.CSRow>();
                            this.Dispatcher.BeginInvoke(createGrid, results);
                        }
                    }
                    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("CS Frequency gadget took " + stopwatch.Elapsed.ToString() + " seconds to complete with " + dashboardHelper.RecordCount.ToString() + " records and the following filters:");
                    //Debug.Print(dashboardHelper.DataFilters.GenerateDataFilterString());
                }
            }
        }
Exemplo n.º 3
0
 public ComplexSampleTables(IAnalysisStatisticContext AnalysisStatisticContext)
 {
     CSTables = new StatisticsRepository.ComplexSampleTables();
     this.Construct(AnalysisStatisticContext);
 }