public void BuildIndex(IEnumerable <FeatureLayer> featureLayers)
        {
            Collection <FeatureLayer> pendingLayersToBuildIndex        = new Collection <FeatureLayer>();
            Collection <FeatureLayer> pendingLayersToBuildInBackground = new Collection <FeatureLayer>();
            BuildLargeIndexMode       buildLargeIndexMode = BuildLargeIndexMode.Unknown;

            DisableNoIndexFeatureLayers(featureLayers, pendingLayersToBuildIndex);
            BuildIndexSync(pendingLayersToBuildIndex, pendingLayersToBuildInBackground, ref buildLargeIndexMode);
            BuildIndexAsync(pendingLayersToBuildInBackground);
        }
        private void BuildIndexSync(Collection <FeatureLayer> pendingLayersToBuildIndex, Collection <FeatureLayer> pendingLayersToBuildInBackground, ref BuildLargeIndexMode buildLargeIndexMode)
        {
            bool applyForAll = false;
            bool canceled    = false;

            Collection <FeatureLayer> notAddLayers = new Collection <FeatureLayer>();

            if (pendingLayersToBuildIndex.Count > 0)
            {
                foreach (var featureLayer in pendingLayersToBuildIndex)
                {
                    if (!applyForAll)
                    {
                        BuildIndexFileDialog buildIndexDialog = new BuildIndexFileDialog();
                        buildIndexDialog.HasMultipleFiles = pendingLayersToBuildIndex.Count > 1;
                        if (buildIndexDialog.ShowDialog().GetValueOrDefault())
                        {
                            canceled = false;
                            if (buildIndexDialog.BuildIndexFileMode == BuildIndexFileMode.BuildAll)
                            {
                                applyForAll = true;
                            }
                        }
                        else
                        {
                            canceled = true;
                            if (buildIndexDialog.BuildIndexFileMode == BuildIndexFileMode.DoNotBuildAll)
                            {
                                applyForAll = true;
                            }
                        }
                    }

                    if (applyForAll && canceled)
                    {
                        break;
                    }
                    else if (canceled)
                    {
                        continue;
                    }

                    if (CheckIsBuildSync(featureLayer))
                    {
                        BuildIndexSync(featureLayer);
                    }
                    else
                    {
                        if (!applyForAll || buildLargeIndexMode == BuildLargeIndexMode.Unknown)
                        {
                            BuildLargeIndexSyncWindow buildLargeIndexWindow = new BuildLargeIndexSyncWindow();
                            buildLargeIndexWindow.FileName = featureLayer.Name;
                            if (buildLargeIndexWindow.ShowDialog().GetValueOrDefault())
                            {
                                buildLargeIndexMode = buildLargeIndexWindow.BuildLargeIndexMode;
                            }
                        }

                        switch (buildLargeIndexMode)
                        {
                        case BuildLargeIndexMode.NormalBuild:
                            BuildIndexSync(featureLayer);
                            break;

                        case BuildLargeIndexMode.DoNotAdd:
                            featureLayer.IsVisible = false;
                            notAddLayers.Add(featureLayer);
                            break;

                        case BuildLargeIndexMode.BackgroundBuild:
                            featureLayer.IsVisible = false;
                            pendingLayersToBuildInBackground.Add(featureLayer);
                            break;

                        case BuildLargeIndexMode.DoNotBuild:
                        default:
                            break;
                        }
                    }
                }
            }

            if (notAddLayers.Count > 0)
            {
                notAddLayers.ForEach(l => pendingLayersToBuildIndex.Remove(l));
            }
        }