public override void Execute(ref bool destory)
        {
            string              correctedCriteriaName;
            int                 outstandingPostAggContext;
            CriteriaSetObj      aggCriteriaObj   = Global.criteriaSets[m_CriteriaIndex];
            ThresholdComparison typeOfComparison = aggCriteriaObj.postAggObj.comparison;

            correctedCriteriaName = Regex.Replace(aggCriteriaObj.criteriaSetName, "[^a-zA-Z0-9]", "");
            writeDirectory        = Path.Combine(Global.outputDirectory, correctedCriteriaName);
            Directory.CreateDirectory(writeDirectory);
            criteriaFilterDetailsWriter = new StreamWriter(Path.Combine(writeDirectory, CRITERIA_FILTER_DETAILS_FILE_NAME));
            criteriaFilterWriter        = new StreamWriter(Path.Combine(writeDirectory, CRITERIA_FILTER_FILE_NAME));
            criteriaThresholdWriter     = new StreamWriter(Path.Combine(writeDirectory, CRITERA_THRESHOLD_FILE_NAME));

            criteriaFilterWriter.WriteLine(FILTER_FILE_HEADING);
            // TODO: write header lines for details and threshold files

            switch (typeOfComparison)
            {
            case ThresholdComparison.Undefined:
            {
                // shouldn't EVER come in here, checks before this in CriteriaObj should prevent this.
                break;
            }

            case ThresholdComparison.Max:
            {
                // TODO: call associated method.
                break;
            }

            case ThresholdComparison.Crosses:
            {
                CrossesYesterdayValueComparison(aggCriteriaObj, typeOfComparison);
                break;
            }

            case ThresholdComparison.GreaterThan:
            case ThresholdComparison.GreaterThanOrEqualTo:
            case ThresholdComparison.LessThan:
            case ThresholdComparison.LessThanOrEqualTo:
            {
                ValueOfColumnComparison(aggCriteriaObj, typeOfComparison);
                break;
            }

            default:
            {
                // TODO: check criteria set text file he gave us with all criteria sets.
                break;
            }
            }

            outstandingPostAggContext = Interlocked.Decrement(ref postAggContextCount);
            if (outstandingPostAggContext == 0)
            {
                Global.mainThreadWait.Set();
            }
        }
        // This relates to the line that goes with '&'.
        internal void SetThresholdComparison(string compareValue)
        {
            switch (compareValue)
            {
            case CriteriaConstants.MAX_THRESHOLD_SPECIFIER:
            {
                comparison = ThresholdComparison.Max;
                break;
            }

            case CriteriaConstants.CROSSES_THRESHOLD_SPECIFIER:
            {
                comparison = ThresholdComparison.Crosses;
                break;
            }

            case CriteriaConstants.GREATER_THAN_COMPARER:
            {
                comparison = ThresholdComparison.GreaterThan;
                break;
            }

            case CriteriaConstants.GREATER_THAN_EQUAL_TO_COMPARERE:
            {
                comparison = ThresholdComparison.GreaterThanOrEqualTo;
                break;
            }

            case CriteriaConstants.LESS_THAN_COMPARER:
            {
                comparison = ThresholdComparison.LessThan;
                break;
            }

            case CriteriaConstants.LESS_THAN_OR_EQUAL_COMPARER:
            {
                comparison = ThresholdComparison.LessThanOrEqualTo;
                break;
            }

            default:
            {
                break;
            }
            }

            if (progress == PostAggProgress.HaveThresholdColumn)
            {
                progress = PostAggProgress.HaveThresholdComparison;
            }
        }
        private void CrossesYesterdayValueComparison(CriteriaSetObj criteriaObj, ThresholdComparison compare)
        {
            int    rawDataChunkIndex;
            int    stockDataIndex;
            double columnValue = 0.0, thresholdCrossed = 0.0;
            ThresholdComparison    comparison = compare;
            CriteriaSetObj         criteria = criteriaObj;
            ThresholdColumn        crossesColumn = criteria.postAggObj.thresholdColumn;
            IReadOnlyList <double> thresholds = criteria.postAggObj.GetRefToThresholdValues();
            IReadOnlyDictionary <string, AggValues> todaysParsedDataDictionary = criteria.GetRefToAggResults();
            IReadOnlyDictionary <string, AggValues> yesterdaysParsedDataDictionary = criteria.GetRefToYesterdayAggResults();
            AggValues todaysAgg;
            AggValues yestedayAgg;
            bool      keyExistsYesterday, todayGreaterYesterday;

            if (crossesColumn == ThresholdColumn.Undefiend)
            {
                // TODO: do something else
                return;
            }

            WriteThresholdHeader(criteria);

            foreach (string key in todaysParsedDataDictionary.Keys)
            {
                todaysParsedDataDictionary.TryGetValue(key, out todaysAgg); // should always find something
                keyExistsYesterday = yesterdaysParsedDataDictionary.TryGetValue(key, out yestedayAgg);
                if (!keyExistsYesterday)
                {
                    yestedayAgg = new AggValues(); // all values are 0 then.
                }

                switch (crossesColumn)
                {
                case ThresholdColumn.PrecentageSharesHeld:
                {
                    columnValue = todaysAgg.percentageSharesHeld;
                    if (columnValue > yestedayAgg.percentageSharesHeld)
                    {
                        todayGreaterYesterday = true;
                    }
                    else
                    {
                        todayGreaterYesterday = false;
                    }
                    thresholdCrossed = PreciseThresholdCrossed(todayGreaterYesterday, columnValue, thresholds);
                    break;
                }

                case ThresholdColumn.SharesHeld:
                {
                    columnValue = todaysAgg.sharesHeld;
                    if (columnValue > yestedayAgg.sharesHeld)
                    {
                        todayGreaterYesterday = true;
                    }
                    else
                    {
                        todayGreaterYesterday = false;
                    }
                    thresholdCrossed = PreciseThresholdCrossed(todayGreaterYesterday, columnValue, thresholds);
                    break;
                }

                case ThresholdColumn.Value:
                {
                    columnValue = todaysAgg.value;
                    if (columnValue > yestedayAgg.value)
                    {
                        todayGreaterYesterday = true;
                    }
                    else
                    {
                        todayGreaterYesterday = false;
                    }
                    thresholdCrossed = PreciseThresholdCrossed(todayGreaterYesterday, columnValue, thresholds);
                    break;
                }

                default:
                {
                    break;
                }
                }

                // TODO: write to files
                criteriaFilterWriter.WriteLine(GetAggValuesCommaSeparatedString(key, todaysAgg));

                IReadOnlyList <uint> unaggregatedDictEntry = todaysAgg.GetRefToRowsInChunk();
                for (int i = 0; i < unaggregatedDictEntry.Count; i++)
                {
                    rawDataChunkIndex = (int)unaggregatedDictEntry[i] >> 16;
                    stockDataIndex    = (int)unaggregatedDictEntry[i] & 0xffff;
                    StockDataEntry sde = Global.parsedRawData[rawDataChunkIndex].chunkDataParsed[stockDataIndex];
                    criteriaFilterDetailsWriter.WriteLine(GetCommaSeparatedStockDataEntryWithKey(sde, key));
                }

                criteriaThresholdWriter.WriteLine(GetCommaSeparatedThresholdEntry(key, columnValue, thresholdCrossed));
            }

            criteriaFilterWriter.Dispose();
            criteriaFilterDetailsWriter.Dispose();
            criteriaThresholdWriter.Dispose();
        }
        private bool ValuePassesComparison(double columnValue, double thresholdValue, ThresholdComparison tc)
        {
            switch (tc)
            {
            case ThresholdComparison.GreaterThan:
            {
                if (columnValue > thresholdValue)
                {
                    return(true);
                }
                break;
            }

            case ThresholdComparison.GreaterThanOrEqualTo:
            {
                if (columnValue >= thresholdValue)
                {
                    return(true);
                }
                break;
            }

            case ThresholdComparison.LessThan:
            {
                if (columnValue < thresholdValue)
                {
                    return(true);
                }
                break;
            }

            case ThresholdComparison.LessThanOrEqualTo:
            {
                if (columnValue <= thresholdValue)
                {
                    return(true);
                }
                break;
            }
            }
            return(false);
        }
        private void ValueOfColumnComparison(CriteriaSetObj criteriaObj, ThresholdComparison compare)
        {
            int rawDataChunkIndex;
            int stockDataIndex;
            ThresholdComparison comparison = compare;
            CriteriaSetObj      criteria   = criteriaObj;
            ThresholdColumn     column     = criteria.postAggObj.thresholdColumn;
            IReadOnlyDictionary <string, AggValues> readOnlyAggResults = criteria.GetRefToAggResults();
            AggValues aggValue;
            IReadOnlyList <double> thresholdValues = criteria.postAggObj.GetRefToThresholdValues(); // should only contain 1 value.
            double thresholdValue = thresholdValues[0];                                             // should be only 1 value here'
            double columnValue    = 0.0;
            bool   thresholdCheck = false;

            if (column == ThresholdColumn.Undefiend)
            {
                // TODO: Do something if it is undefined, shouldn't be.
                return;
            }

            WriteThresholdHeader(criteria);

            foreach (string key in readOnlyAggResults.Keys)
            {
                readOnlyAggResults.TryGetValue(key, out aggValue);

                switch (column)
                {
                case ThresholdColumn.PrecentageSharesHeld:
                {
                    columnValue    = aggValue.percentageSharesHeld;
                    thresholdCheck = ValuePassesComparison(columnValue, thresholdValue, comparison);
                    break;
                }

                case ThresholdColumn.SharesHeld:
                {
                    columnValue    = aggValue.sharesHeld;
                    thresholdCheck = ValuePassesComparison(columnValue, thresholdValue, comparison);
                    break;
                }

                case ThresholdColumn.Value:
                {
                    columnValue    = aggValue.value;
                    thresholdCheck = ValuePassesComparison(columnValue, thresholdValue, comparison);
                    break;
                }

                default:
                {
                    break;
                }
                }

                if (thresholdCheck)
                {
                    criteriaFilterWriter.WriteLine(GetAggValuesCommaSeparatedString(key, aggValue));

                    IReadOnlyList <uint> unaggregatedDictEntry = aggValue.GetRefToRowsInChunk();
                    for (int i = 0; i < unaggregatedDictEntry.Count; i++)
                    {
                        rawDataChunkIndex = (int)unaggregatedDictEntry[i] >> 16;
                        stockDataIndex    = (int)unaggregatedDictEntry[i] & 0xffff;
                        StockDataEntry sde = Global.parsedRawData[rawDataChunkIndex].chunkDataParsed[stockDataIndex];
                        criteriaFilterDetailsWriter.WriteLine(GetCommaSeparatedStockDataEntryWithKey(sde, key));
                    }
                    criteriaThresholdWriter.WriteLine(GetCommaSeparatedThresholdEntry(key, columnValue, thresholdValue));
                }
            }

            criteriaFilterWriter.Dispose();
            criteriaFilterDetailsWriter.Dispose();
            criteriaThresholdWriter.Dispose();
        }