Adding multiple FeatureClasses & StandAloneTables to a map gives weird results

300
1
Jump to solution
02-16-2024 11:50 AM
PierreMasson
Occasional Contributor

Hi, I've created a button that create a new map and adds many layers and standAlone table to it. 

After playing with it a bit, I found that it seams to work well. But when I looked at it more closely it's missing 7 or 8 of the 80 tables I've added. Those missing are random because from trying it many time, it`s not always the same tables that are missiing.. 

Here an extract of my code:

await QueuedTask.Run(async () =>
            {

                if (!checkPortalSignIn())
                {
                    showError(resPublishSAM.errRequireSigningInActiveServer);
                    return;
                }

                if (ext == ".sde")
                {
                    DatabaseConnectionFile dbcf = new DatabaseConnectionFile(new Uri(mainModule.Current.AquaGeoSettings.SDEConnectionFilePath));
                    pGeodatabase = new Geodatabase(dbcf);
                }
                else if (ext == ".gdb")
                {
                    FileGeodatabaseConnectionPath fileGeodatabaseConnectionPath = new FileGeodatabaseConnectionPath(new Uri(mainModule.Current.AquaGeoSettings.SDEConnectionFilePath));
                    pGeodatabase = new Geodatabase(fileGeodatabaseConnectionPath);
                }

                await addMapToTheProject(packageName);
                int total = 91;
                int c = 0;

                await addFeatureClassToMap("aga_AirValves", c++);
                updateProgress(resPublishSAM.Adding + "aga_AirValves", c, total);
                await addFeatureClassToMap("aga_ChamberAccess", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberAccess", c, total);
                await addFeatureClassToMap("aga_Chambers", c++);
                updateProgress(resPublishSAM.Adding + "aga_Chambers", c, total);
                await addFeatureClassToMap("aga_DrainValves", c++);
                updateProgress(resPublishSAM.Adding + "aga_DrainValves", c, total);
                await addFeatureClassToMap("aga_FireHydrants", c++);
                updateProgress(resPublishSAM.Adding + "aga_FireHydrants", c, total);
                await addFeatureClassToMap("aga_Nodes", c++);
                updateProgress(resPublishSAM.Adding + "aga_Nodes", c, total);
                await addFeatureClassToMap("aga_Pipes", c++);
                updateProgress(resPublishSAM.Adding + "aga_Pipes", c, total);
                await addFeatureClassToMap("aga_Reducers", c++);
                updateProgress(resPublishSAM.Adding + "aga_Reducers", c, total);
                await addFeatureClassToMap("aga_Reservoirs", c++);
                updateProgress(resPublishSAM.Adding + "aga_Reservoirs", c, total);
                await addFeatureClassToMap("aga_Valves", c++);
                updateProgress(resPublishSAM.Adding + "aga_Valves", c, total);
                await addFeatureClassToMap("aga_WaterMeters", c++);
                updateProgress(resPublishSAM.Adding + "aga_WaterMeters", c, total);
                await addFeatureClassToMap("aga_WaterPumps", c++);
                updateProgress(resPublishSAM.Adding + "aga_WaterPumps", c, total);
                await addFeatureClassToMap("ags_AccessPoints", c++);
                updateProgress(resPublishSAM.Adding + "ags_AccessPoints", c, total);
                await addFeatureClassToMap("ags_Sections", c++);
                updateProgress(resPublishSAM.Adding + "ags_Sections", c, total);
                await addTableToMap("aga_ChamberCrossSections", "aga_ChamberCrossSections", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberCrossSections", c, total);
                await addTableToMap("aga_ChamberDefs", "aga_ChamberDefs", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberDefs", c, total);
                await addTableToMap("aga_ChamberInspectionPaths", "aga_ChamberInspectionPaths", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberInspectionPaths", c, total);
                await addTableToMap("aga_ChamberManufacturers", "aga_ChamberManufacturers", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberManufacturers", c, total);
                await addTableToMap("aga_ChamberModels", "aga_ChamberModels", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberModels", c, total);
                await addTableToMap("aga_ChamberParameters", "aga_ChamberParameters", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberParameters", c, total);
                await addTableToMap("aga_ChamberPriorities", "aga_ChamberPriorities", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberPriorities", c, total);
                await addTableToMap("aga_ChamberReportDefs", "aga_ChamberReportDefs", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberReportDefs", c, total);
                await addTableToMap("aga_ChamberReportDefTypes", "aga_ChamberReportDefTypes", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberReportDefTypes", c, total);
                await addTableToMap("aga_ChamberWorkSheets", "aga_ChamberWorkSheets", c++);
                updateProgress(resPublishSAM.Adding + "aga_ChamberWorkSheets", c, total);
                await addTableToMap("aga_FHCrossSections", "aga_FHCrossSections", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHCrossSections", c, total);
                await addTableToMap("aga_FHDefs", "aga_FHDefs", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHDefs", c, total);
                await addTableToMap("aga_FHInspectionPaths", "aga_FHInspectionPaths", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHInspectionPaths", c, total);
                await addTableToMap("aga_FHManufacturers", "aga_FHManufacturers", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHManufacturers", c, total);
                await addTableToMap("aga_FHModels", "aga_FHModels", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHModels", c, total);
                await addTableToMap("aga_FHNutModels", "aga_FHNutModels", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHNutModels", c, total);
                await addTableToMap("aga_FHOtherModels", "aga_FHOtherModels", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHOtherModels", c, total);
                await addTableToMap("aga_FHOtherModelValues", "aga_FHOtherModelValues", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHOtherModelValues", c, total);
                await addTableToMap("aga_FHOutletModels", "aga_FHOutletModels", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHOutletModels", c, total);
                await addTableToMap("aga_FHParameters", "aga_FHParameters", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHParameters", c, total);
                await addTableToMap("aga_FHPriorities", "aga_FHPriorities", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHPriorities", c, total);
                await addTableToMap("aga_FHReportDefs", "aga_FHReportDefs", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHReportDefs", c, total);
                await addTableToMap("aga_FHReportDefTypes", "aga_FHReportDefTypes", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHReportDefTypes", c, total);
                await addTableToMap("aga_FHWorkSheets", "aga_FHWorkSheets", c++);
                updateProgress(resPublishSAM.Adding + "aga_FHWorkSheets", c, total);
                await addTableToMap("aga_Materials", "aga_Materials", c++);
                updateProgress(resPublishSAM.Adding + "aga_Materials", c, total);
                await addTableToMap("aga_MeterTypes", "aga_MeterTypes", c++);
                updateProgress(resPublishSAM.Adding + "aga_MeterTypes", c, total);
                await addTableToMap("aga_PipeClasses", "aga_PipeClasses", c++);
                updateProgress(resPublishSAM.Adding + "aga_PipeClasses", c, total);
                await addTableToMap("aga_PIVCrossSections", "aga_PIVCrossSections", c++);
                updateProgress(resPublishSAM.Adding + "aga_PIVCrossSections", c, total);
                await addTableToMap("aga_PIVManufacturers", "aga_PIVManufacturers", c++);
                updateProgress(resPublishSAM.Adding + "aga_PIVManufacturers", c, total);
                await addTableToMap("aga_PIVModels", "aga_PIVModels", c++);
                updateProgress(resPublishSAM.Adding + "aga_PIVModels", c, total);
                await addTableToMap("aga_Relinings", "aga_Relinings", c++);
                updateProgress(resPublishSAM.Adding + "aga_Relinings", c, total);
                await addTableToMap("aga_RoadCenters", "aga_RoadCenters", c++);
                updateProgress(resPublishSAM.Adding + "aga_RoadCenters", c, total);
                await addTableToMap("aga_Sectors", "aga_Sectors", c++);
                updateProgress(resPublishSAM.Adding + "aga_Sectors", c, total);
                await addTableToMap("aga_ServiceBoxCrossSections", "aga_ServiceBoxCrossSections", c++);
                updateProgress(resPublishSAM.Adding + "aga_ServiceBoxCrossSections", c, total);
                await addTableToMap("aga_ServiceBoxManufacturers", "aga_ServiceBoxManufacturers", c++);
                updateProgress(resPublishSAM.Adding + "aga_ServiceBoxManufacturers", c, total);
                await addTableToMap("aga_ServiceBoxModels", "aga_ServiceBoxModels", c++);
                updateProgress(resPublishSAM.Adding + "aga_ServiceBoxModels", c, total);
                await addTableToMap("aga_UsageTypes", "aga_UsageTypes", c++);
                updateProgress(resPublishSAM.Adding + "aga_UsageTypes", c, total);
                await addTableToMap("aga_ValveAccess", "aga_ValveAccess", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveAccess", c, total);
                await addTableToMap("aga_ValveBox", "aga_ValveBox", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveBox", c, total);
                await addTableToMap("aga_ValveBoxCrossSections", "aga_ValveBoxCrossSections", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveBoxCrossSections", c, total);
                await addTableToMap("aga_ValveBoxManufacturers", "aga_ValveBoxManufacturers", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveBoxManufacturers", c, total);
                await addTableToMap("aga_ValveBoxModels", "aga_ValveBoxModels", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveBoxModels", c, total);
                await addTableToMap("aga_ValveDefs", "aga_ValveDefs", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveDefs", c, total);
                await addTableToMap("aga_ValveInspectionPaths", "aga_ValveInspectionPaths", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveInspectionPaths", c, total);
                await addTableToMap("aga_ValveModelCrossSections", "aga_ValveModelCrossSections", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveModelCrossSections", c, total);
                await addTableToMap("aga_ValveModelManufacturers", "aga_ValveModelManufacturers", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveModelManufacturers", c, total);
                await addTableToMap("aga_ValveModels", "aga_ValveModels", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveModels", c, total);
                await addTableToMap("aga_ValveNutModels", "aga_ValveNutModels", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveNutModels", c, total);
                await addTableToMap("aga_ValveParameters", "aga_ValveParameters", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveParameters", c, total);
                await addTableToMap("aga_ValvePriorities", "aga_ValvePriorities", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValvePriorities", c, total);
                await addTableToMap("aga_ValveReportDefs", "aga_ValveReportDefs", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveReportDefs", c, total);
                await addTableToMap("aga_ValveReportDefTypes", "aga_ValveReportDefTypes", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveReportDefTypes", c, total);
                await addTableToMap("aga_ValveWorkSheets", "aga_ValveWorkSheets", c++);
                updateProgress(resPublishSAM.Adding + "aga_ValveWorkSheets", c, total);
                await addTableToMap("agc_aquaGeoSettings", "agc_aquaGeoSettings", c++);
                updateProgress(resPublishSAM.Adding + "agc_aquaGeoSettings", c, total);
                await addTableToMap("agc_Employees", "agc_Employees", c++);
                updateProgress(resPublishSAM.Adding + "agc_Employees", c, total);
                await addTableToMap("agc_streets", "agc_streets", c++);
                updateProgress(resPublishSAM.Adding + "agc_streets", c, total);
                await addTableToMap("ags_Canlite_Field_Job", "ags_Canlite_Field_Job", c++);
                updateProgress(resPublishSAM.Adding + "ags_Canlite_Field_Job", c, total);
                await addTableToMap("ags_Canlite_Field_Job_Events", "ags_Canlite_Field_Job_Events", c++);
                updateProgress(resPublishSAM.Adding + "ags_Canlite_Field_Job_Events", c, total);
                await addTableToMap("ags_Code_Substitutions", "ags_Code_Substitutions", c++);
                updateProgress(resPublishSAM.Adding + "ags_Code_Substitutions", c, total);
                await addTableToMap("ags_MH_Conditions", "ags_MH_Conditions", c++);
                updateProgress(resPublishSAM.Adding + "ags_MH_Conditions", c, total);
                await addTableToMap("ags_MH_Conditions_Media", "ags_MH_Conditions_Media", c++);
                updateProgress(resPublishSAM.Adding + "ags_MH_Conditions_Media", c, total);
                await addTableToMap("ags_MH_Connections", "ags_MH_Connections", c++);
                updateProgress(resPublishSAM.Adding + "ags_MH_Connections", c, total);
                await addTableToMap("ags_MH_Connections_Media", "ags_MH_Connections_Media", c++);
                updateProgress(resPublishSAM.Adding + "ags_MH_Connections_Media", c, total);
                await addTableToMap("ags_MH_Inspections", "ags_MH_Inspections", c++);
                updateProgress(resPublishSAM.Adding + "ags_MH_Inspections", c, total);
                await addTableToMap("ags_MH_Inspections_Media", "ags_MH_Inspections_Media", c++);
                updateProgress(resPublishSAM.Adding + "ags_MH_Inspections_Media", c, total);
                await addTableToMap("ags_PACP_Conditions", "ags_PACP_Conditions", c++);
                updateProgress(resPublishSAM.Adding + "ags_PACP_Conditions", c, total);
                await addTableToMap("ags_PACP_Inspections", "ags_PACP_Inspections", c++);
                updateProgress(resPublishSAM.Adding + "ags_PACP_Inspections", c, total);
                await addTableToMap("ags_PACP_Media_Conditions", "ags_PACP_Media_Conditions", c++);
                updateProgress(resPublishSAM.Adding + "ags_PACP_Media_Conditions", c, total);
                await addTableToMap("ags_PACP_Media_Inspections", "ags_PACP_Media_Inspections", c++);
                updateProgress(resPublishSAM.Adding + "ags_PACP_Media_Inspections", c, total);
                await addTableToMap("ags_Pipe_Records", "ags_Pipe_Records", c++);
                updateProgress(resPublishSAM.Adding + "ags_Pipe_Records", c, total);
                await addTableToMap("ags_Segments", "ags_Segments", c++);
                updateProgress(resPublishSAM.Adding + "ags_Segments", c, total);
                await addTableToMap("ags_WorkOrder_Categories", "ags_WorkOrder_Categories", c++);
                updateProgress(resPublishSAM.Adding + "ags_WorkOrder_Categories", c, total);
                await addTableToMap("ags_WorkOrder_Config", "ags_WorkOrder_Config", c++);
                updateProgress(resPublishSAM.Adding + "ags_WorkOrder_Config", c, total);
                await addTableToMap("ags_WorkOrder_CustomFields", "ags_WorkOrder_CustomFields", c++);
                updateProgress(resPublishSAM.Adding + "ags_WorkOrder_CustomFields", c, total);
                await addTableToMap("ags_WorkOrders", "ags_WorkOrders", c++);
                updateProgress(resPublishSAM.Adding + "ags_WorkOrders", c, total);
                await addTableToMap("ags_WorkOrders_Manholes", "ags_WorkOrders_Manholes", c++);
                updateProgress(resPublishSAM.Adding + "ags_WorkOrders_Manholes", c, total);
                await addTableToMap("ags_WorkOrders_Sections", "ags_WorkOrders_Sections", c++);
                updateProgress(resPublishSAM.Adding + "ags_WorkOrders_Sections", c, total);

                StringBuilder sb = new StringBuilder();
                await publishMapToPortal(packageName, settingsVM, sb);

                success = true;
            }, progressor: WindowService.ProgressorSource.Progressor);

 

Then the method I use:

private async Task addFeatureClassToMap(string fcName, int index)
        {
            pMapDrawn = false;
            FeatureClass fc = pGeodatabase.OpenDataset<FeatureClass>(fcName);
            LayerFactory.Instance.CreateLayer(fc.GetPath(), MapView.Active.Map, index, fcName);
            await WaitForMapToBeDrawn();
        }

        private async Task addTableToMap(string tableName, string layerName, int index)
        {
            tableAdded = false;
            Table tbl = pGeodatabase.OpenDataset<Table>(tableName);
            StandaloneTableFactory.Instance.CreateStandaloneTable(tbl.GetPath(), MapView.Active.Map, index, layerName);
            await WaitForTableAdded();
        }

I found that I have better results if I wait for Arcgis to add the layers and table to the map before adding the next one. I'm using those event to do that:

            ArcGIS.Desktop.Mapping.Events.DrawCompleteEvent.Subscribe(OnDrawComplete);
            ArcGIS.Desktop.Mapping.Events.StandaloneTablesAddedEvent.Subscribe(OnTableAdded);
        private async Task<bool> WaitForTableAdded()
        {
            int count = 0;
            while (!tableAdded)
            {
                await Task.Delay(500);
                count++;

                if (count > 20)
                {
                    WindowService.DoEvents();
                    return false;
                }
            }
            WindowService.DoEvents();
            return true;
        }

        private async Task<bool> WaitForMapToBeDrawn()
        {
            int count = 0;
            // waiting for the map to be drawn
            while (!pMapDrawn)
            {
                await Task.Delay(500);
                count++;

                if (count > 20)
                {
                    WindowService.DoEvents();
                    return false;
                }
            }
            WindowService.DoEvents();
            return true;
        }

 

But even with that, instead of having 90 layers and tables, i get 86, 88, it varies.. 

Can you help please?

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

I would recommend you put QueuedTask.Run inside your methods addFeatureClassToMap and addTableToMap and delete one at the start. Sometimes using one QueuedTask.Run for few processes following each other does not work as expected.

View solution in original post

1 Reply
GKmieliauskas
Esri Regular Contributor

Hi,

I would recommend you put QueuedTask.Run inside your methods addFeatureClassToMap and addTableToMap and delete one at the start. Sometimes using one QueuedTask.Run for few processes following each other does not work as expected.