public async void setDomainValuesFile(string db, string dataset, string fieldName, string sourceTarget, bool resetUI)
        {
            List <ComboData> domain = new List <ComboData>();
            await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
            {
                ArcGIS.Core.Data.TableDefinition def = null;
                try
                {
                    string table = dataset.Substring(dataset.LastIndexOf("\\") + 1);
                    ArcGIS.Core.Data.Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(db)));
                    using (ArcGIS.Core.Data.Table tab = geodatabase.OpenDataset <ArcGIS.Core.Data.Table>(table))
                    {
                        def    = tab.GetDefinition();
                        domain = getDomainValuesforTable(def, fieldName);
                    }
                }
                catch { raiseDomainErrorMessage(dataset, fieldName); }
                return;
            });

            if (resetUI == true)
            {
                resetDomainValuesUI(domain, sourceTarget);
            }
            else
            {
                resetDomainValuesUIFromConfig(domain, sourceTarget);
            }
            return;
        }
        //public async void GetTotalValues()
        public async void GetTotalValues()
        {
            long   TotalValueLow      = 0;
            long   TotalValueMedium   = 0;
            long   TotalValueHigh     = 0;
            long   targetSettingValue = 0;
            double lowSettingValue    = 0;
            double mediumSettingValue = 0;
            double highSettingValue   = 0;


            await QueuedTask.Run(() =>
            {
                // FeatureLayer CrowdLayer = MapView.Active.Map.FindLayer("CrowdPlanning") as FeatureLayer;
                FeatureLayer CrowdLayer = MapView.Active.Map.Layers.First(layer => layer.Name.Equals("CrowdPlanning")) as FeatureLayer;
                if (CrowdLayer == null)
                {
                    ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Layer is not found");
                    return;
                }

                //CrowdLayer.Search(null)
                ArcGIS.Core.Data.Table CrowdTable = CrowdLayer.GetTable();
                QueryFilter QF = new QueryFilter
                {
                    WhereClause = "LOW > 0"
                };

                RowCursor CrowdRow = CrowdTable.Search(QF, false);

                long lowValue;
                long mediumValue;
                long highValue;


                while (CrowdRow.MoveNext())
                {
                    lowValue    = 0;
                    mediumValue = 0;
                    highValue   = 0;
                    using (Row currentRow = CrowdRow.Current)
                    {
                        lowValue      = Convert.ToInt32(currentRow["Low"]);
                        TotalValueLow = TotalValueLow + lowValue;

                        mediumValue      = Convert.ToInt32(currentRow["Medium"]);
                        TotalValueMedium = TotalValueMedium + mediumValue;

                        highValue      = Convert.ToInt32(currentRow["High"]);
                        TotalValueHigh = TotalValueHigh + highValue;

                        targetSettingValue = Convert.ToInt32(currentRow["TargetSetting"]);
                        lowSettingValue    = Convert.ToDouble(currentRow["LowSetting"]);
                        mediumSettingValue = Convert.ToDouble(currentRow["MediumSetting"]);
                        highSettingValue   = Convert.ToDouble(currentRow["HighSetting"]);
                    }
                }
            });

            // Assign values to properties
            TotalHigh   = TotalValueHigh;
            TotalMedium = TotalValueMedium;
            TotalLow    = TotalValueLow;
            // Assign setting values
            TargetSetting = targetSettingValue;
            LowSetting    = lowSettingValue;
            MediumSetting = mediumSettingValue;
            HighSetting   = highSettingValue;


            // UPDATE PIE CHARTS
            // Chart 1 - High Estimate
            KeyValuePair <string, int>[] myKeyValuePairHigh = new KeyValuePair <string, int>[]
            {
                new KeyValuePair <string, int>("High Estimate Allocated", Convert.ToInt32(TotalValueHigh)),
                new KeyValuePair <string, int>("Remaining to Estimate", Convert.ToInt32(TargetSetting))
            };
            PieChartResult = myKeyValuePairHigh;
            NotifyPropertyChanged(() => PieChartResult);

            // Chart 2 - Medium Estimate
            KeyValuePair <string, int>[] myKeyValuePairMedium = new KeyValuePair <string, int>[]
            {
                new KeyValuePair <string, int>("Medium Estimate Allocated", Convert.ToInt32(TotalValueMedium)),
                new KeyValuePair <string, int>("Remaining to Estimate", Convert.ToInt32(TargetSetting))
            };
            PieChartResultMedium = myKeyValuePairMedium;
            NotifyPropertyChanged(() => PieChartResultMedium);

            // Chart 3 - Low Estimate
            KeyValuePair <string, int>[] myKeyValuePairLow = new KeyValuePair <string, int>[]
            {
                new KeyValuePair <string, int>("Low Estimate Allocated", Convert.ToInt32(TotalValueLow)),
                new KeyValuePair <string, int>("Remaining to Estimate", Convert.ToInt32(TargetSetting))
            };
            PieChartResultLow = myKeyValuePairLow;
            NotifyPropertyChanged(() => PieChartResultLow);

            //end of GetTotalValues
        }
        // Reset Settings Based on Current Settings
        public async void ResetValues(string settingsValue)
        {
            // ***  Check to ensure the densitysettings are set.  If not, show a warning and deactivate tool.
            if (HighSetting == 0 || MediumSetting == 0 || LowSetting == 0 || TargetSetting == 0)
            {
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("An empty setting value exists. All settings are required to use this tool.", "Warning!");
                // ** End if there are not complete settings
                return;
            }
            // else proceed with confirming a reset is desired.
            else
            {
                if (settingsValue == "current")
                {
                    // Prompt for confirmation, and if answer is no, return.
                    var result = ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Reset all values to CURRENT settings?", "RESET VALUES", MessageBoxButton.OKCancel, MessageBoxImage.Asterisk);
                    // Return if cancel value is chosen
                    if (Convert.ToString(result) == "Cancel")
                    {
                        return;
                    }
                }

                else if (settingsValue == "default")
                {
                    // Prompt for confirmation, and if answer is no, return.
                    var result = ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Reset all values to DEFAULT settings?", "RESET VALUES", MessageBoxButton.OKCancel, MessageBoxImage.Asterisk);
                    // Return if cancel value is chosen
                    if (Convert.ToString(result) == "Cancel")
                    {
                        return;
                    }
                }
            }

            FeatureLayer CrowdLayer = MapView.Active.Map.Layers.First(layer => layer.Name.Equals("CrowdPlanning")) as FeatureLayer;

            if (CrowdLayer == null)
            {
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("CrowdPlanning Layer is not found");
                return;
            }
            ArcGIS.Core.Data.Table CrowdTable = await QueuedTask.Run(() => CrowdLayer.GetTable());

            var editOperation = new EditOperation();

            editOperation.Callback(context =>
            {
                QueryFilter QF = new QueryFilter
                {
                    WhereClause = "LOW > 0"
                };

                RowCursor CrowdRow = CrowdTable.Search(QF, false);

                while (CrowdRow.MoveNext())
                {
                    using (Row currentRow = CrowdRow.Current)
                    {
                        var squarefeetValue = currentRow["Shape_Area"];
                        long squarefeetValueLong;
                        squarefeetValueLong = Convert.ToInt64(squarefeetValue);

                        if (settingsValue == "current")
                        {
                            currentRow["High"]          = (squarefeetValueLong / HighSetting);
                            currentRow["Medium"]        = (squarefeetValueLong / MediumSetting);
                            currentRow["Low"]           = (squarefeetValueLong / LowSetting);
                            currentRow["TargetSetting"] = TargetSetting;
                            currentRow["HighSetting"]   = HighSetting;
                            currentRow["MediumSetting"] = MediumSetting;
                            currentRow["LowSetting"]    = LowSetting;
                        }

                        else if (settingsValue == "default")
                        {
                            currentRow["High"]          = squarefeetValueLong / 2.5;
                            currentRow["Medium"]        = squarefeetValueLong / 4.5;
                            currentRow["Low"]           = squarefeetValueLong / 10;
                            currentRow["TargetSetting"] = TargetSetting;
                            currentRow["HighSetting"]   = 2.5;
                            currentRow["MediumSetting"] = 4.5;
                            currentRow["LowSetting"]    = 10;
                        }

                        // Store the values
                        currentRow.Store();

                        // Has to be called after the store too.
                        context.Invalidate(currentRow);
                    }
                }
                CrowdTable.Dispose();
                // close the editOperation.Callback(context
            }, CrowdTable);

            await editOperation.ExecuteAsync();

            GetTotalValues();
        }
        //public async void GetTotalValues()
        public async void GetTotalValues()
        {
            long   TotalValueLow      = 0;
            long   TotalValueMedium   = 0;
            long   TotalValueHigh     = 0;
            long   targetSettingValue = 0;
            double lowSettingValue    = 0;
            double mediumSettingValue = 0;
            double highSettingValue   = 0;
            double targetRemaining    = 0;

            // Check for CrowdPlanning layer, exit if not present in current Map.
            if (MapView.Active == null)
            {
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("CrowdPlanning Layer is not found. Please open the map view of the Crowd Planner data project.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            var CrowdLayerTest = MapView.Active.Map.FindLayers("CrowdPlanning").FirstOrDefault() as BasicFeatureLayer;

            if (CrowdLayerTest == null)
            {
                ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("CrowdPlanning Layer is not found. Please use with the Crowd Planner data project.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }

            await QueuedTask.Run(() =>
            {
                // FeatureLayer CrowdLayer = MapView.Active.Map.FindLayer("CrowdPlanning") as FeatureLayer;
                FeatureLayer CrowdLayer = MapView.Active.Map.GetLayersAsFlattenedList().FirstOrDefault(layer => layer.Name.Equals("CrowdPlanning")) as FeatureLayer;

                //CrowdLayer.Search(null)
                ArcGIS.Core.Data.Table CrowdTable = CrowdLayer.GetTable();
                QueryFilter QF = new QueryFilter
                {
                    WhereClause = "LOW > 0"
                };

                RowCursor CrowdRow = CrowdTable.Search(QF, false);

                long lowValue;
                long mediumValue;
                long highValue;


                while (CrowdRow.MoveNext())
                {
                    lowValue    = 0;
                    mediumValue = 0;
                    highValue   = 0;
                    using (Row currentRow = CrowdRow.Current)
                    {
                        lowValue      = Convert.ToInt32(currentRow["Low"]);
                        TotalValueLow = TotalValueLow + lowValue;

                        mediumValue      = Convert.ToInt32(currentRow["Medium"]);
                        TotalValueMedium = TotalValueMedium + mediumValue;

                        highValue      = Convert.ToInt32(currentRow["High"]);
                        TotalValueHigh = TotalValueHigh + highValue;

                        targetSettingValue = Convert.ToInt32(currentRow["TargetSetting"]);
                        lowSettingValue    = Convert.ToDouble(currentRow["LowSetting"]);
                        mediumSettingValue = Convert.ToDouble(currentRow["MediumSetting"]);
                        highSettingValue   = Convert.ToDouble(currentRow["HighSetting"]);
                    }
                }
            });

            // Assign total values
            TotalHigh   = TotalValueHigh;
            TotalMedium = TotalValueMedium;
            TotalLow    = TotalValueLow;
            // Assign setting values
            TargetSetting = targetSettingValue;
            LowSetting    = lowSettingValue;
            MediumSetting = mediumSettingValue;
            HighSetting   = highSettingValue;


            // UPDATE PIE CHARTS
            // Chart 1 - High Estimate
            if (TotalValueHigh > TargetSetting)
            {
                targetRemaining = 0;
                _highBackground = "#9BBB59";
                NotifyPropertyChanged(() => ColorBrush);
            }
            else
            {
                targetRemaining = (TargetSetting - TotalValueHigh);
                _highBackground = textboxBackground;
                NotifyPropertyChanged(() => ColorBrush);
            }
            KeyValuePair <string, int>[] myKeyValuePairHigh = new KeyValuePair <string, int>[]
            {
                new KeyValuePair <string, int>("High Estimate Allocated", Convert.ToInt32(TotalValueHigh)),
                new KeyValuePair <string, int>("Remaining to Estimate", Convert.ToInt32(targetRemaining))
            };
            PieChartResult = myKeyValuePairHigh;
            NotifyPropertyChanged(() => PieChartResult);

            // Chart 2 - Medium Estimate
            if (TotalValueMedium > TargetSetting)
            {
                targetRemaining   = 0;
                _mediumBackground = "#9BBB59";
                NotifyPropertyChanged(() => ColorBrushMedium);
            }
            else
            {
                targetRemaining   = (TargetSetting - TotalValueMedium);
                _mediumBackground = textboxBackground;
                NotifyPropertyChanged(() => ColorBrushMedium);
            }

            KeyValuePair <string, int>[] myKeyValuePairMedium = new KeyValuePair <string, int>[]
            {
                new KeyValuePair <string, int>("Medium Estimate Allocated", Convert.ToInt32(TotalValueMedium)),
                new KeyValuePair <string, int>("Remaining to Estimate", Convert.ToInt32(targetRemaining))
            };
            PieChartResultMedium = myKeyValuePairMedium;
            NotifyPropertyChanged(() => PieChartResultMedium);

            // Chart 3 - Low Estimate
            if (TotalValueLow > TargetSetting)
            {
                targetRemaining = 0;
                _lowBackground  = "#9BBB59";
                NotifyPropertyChanged(() => ColorBrushLow);
            }
            else
            {
                targetRemaining = (TargetSetting - TotalValueLow);
                _lowBackground  = textboxBackground;
                NotifyPropertyChanged(() => ColorBrushLow);
            }

            KeyValuePair <string, int>[] myKeyValuePairLow = new KeyValuePair <string, int>[]
            {
                new KeyValuePair <string, int>("Low Estimate Allocated", Convert.ToInt32(TotalValueLow)),
                new KeyValuePair <string, int>("Remaining to Estimate", Convert.ToInt32(targetRemaining))
            };
            PieChartResultLow = myKeyValuePairLow;
            NotifyPropertyChanged(() => PieChartResultLow);

            //end of GetTotalValues
        }