예제 #1
0
        protected override async void OnClick() => await ThreadService.RunOnBackground(async() => {
            Log.Debug("Running Authorization missing Action Validation");

            var progressDialog = new ProgressDialog("🔍 Finding issues...", 100, false);
            var progressor     = new CancelableProgressorSource(progressDialog).Progressor;
            progressDialog.Show();

            const string layerName = "UICAuthorizationAction";
            var layer = LayerService.GetStandaloneTable(layerName, MapView.Active.Map);

            if (layer == null)
            {
                NotificationService.NotifyOfMissingLayer(layerName);

                progressDialog.Hide();

                return;
            }

            progressor.Value = 10;

            const string parentLayerName = "UICAuthorization";
            var parentLayer = LayerService.GetStandaloneTable(parentLayerName, MapView.Active.Map);

            if (parentLayer == null)
            {
                NotificationService.NotifyOfMissingLayer(parentLayerName);

                progressDialog.Hide();

                return;
            }

            progressor.Value = 20;

            var foreignKeys = new HashSet <string>();
            var primaryKeys = new HashSet <string>();

            using (var cursor = layer.Search(new QueryFilter {
                SubFields = "Authorization_FK"
            })) {
                while (cursor.MoveNext())
                {
                    var fk = Convert.ToString(cursor.Current["AUTHORIZATION_FK"]);

                    foreignKeys.Add(fk);
                }
            }

            progressor.Value = 50;

            using (var cursor = parentLayer.Search(new QueryFilter {
                SubFields = "GUID"
            })) {
                while (cursor.MoveNext())
                {
                    var fk = Convert.ToString(cursor.Current["GUID"]);

                    primaryKeys.Add(fk);
                }
            }

            progressor.Value = 80;

            primaryKeys.ExceptWith(foreignKeys);

            if (primaryKeys.Count == 0)
            {
                NotificationService.NotifyOfValidationSuccess();

                progressDialog.Hide();

                return;
            }

            var problems = new List <long>(primaryKeys.Count);

            using (var cursor = parentLayer.Search(new QueryFilter {
                SubFields = "OBJECTID",
                WhereClause = $"GUID IN ({string.Join(",", primaryKeys.Select(x => $"'{x}'"))})"
            })) {
                while (cursor.MoveNext())
                {
                    var id = cursor.Current.GetObjectID();

                    problems.Add(id);
                }
            }

            progressor.Value = 90;

            MapView.Active.Map.SetSelection(new Dictionary <MapMember, List <long> > {
                { parentLayer, problems }
            });

            progressor.Value = 100;

            progressDialog.Hide();

            NotificationService.NotifyOfValidationFailure(problems.Count);

            Log.Verbose("Zooming to selected");

            await MapView.Active.ZoomToSelectedAsync(TimeSpan.FromSeconds(1.5));

            Log.Debug("Finished Authorization Validation");
        });
예제 #2
0
        protected override async void OnClick() => await ThreadService.RunOnBackground(async() => {
            Log.Debug("running authorization missing action validation");

            var progressDialog = new ProgressDialog("🔍 Finding issues...", "Cancel", 100, false);
            progressDialog.Show();

            const string layerName = "UICAuthorization";
            var layer = LayerService.GetStandaloneTable(layerName, MapView.Active.Map);

            if (layer == null)
            {
                NotificationService.NotifyOfMissingLayer(layerName);

                progressDialog.Hide();

                return;
            }

            IGPResult result = null;
            var parameters   = Geoprocessing.MakeValueArray(layer, "NEW_SELECTION", "Facility_FK IS NULL");
            var progSrc      = new CancelableProgressorSource(progressDialog);

            Log.Verbose("management.SelectLayerByAttribute on {layer} with {@params}", layerName, parameters);

            try {
                result = await Geoprocessing.ExecuteToolAsync(
                    "management.SelectLayerByAttribute",
                    parameters,
                    null,
                    new CancelableProgressorSource(progressDialog).Progressor,
                    GPExecuteToolFlags.Default
                    );
            } catch (Exception ex) {
                NotificationService.NotifyOfGpCrash(ex, parameters);

                progressDialog.Hide();

                return;
            }

            if (result.IsFailed || string.IsNullOrEmpty(result?.ReturnValue))
            {
                NotificationService.NotifyOfGpFailure(result, parameters);

                progressDialog.Hide();

                return;
            }

            var problems = Convert.ToInt32(result?.Values[1]);

            if (problems == 0)
            {
                NotificationService.NotifyOfValidationSuccess();

                progressDialog.Hide();

                return;
            }

            progressDialog.Hide();

            NotificationService.NotifyOfValidationFailure(problems);

            Log.Verbose("Zooming to selected");

            await MapView.Active.ZoomToSelectedAsync(TimeSpan.FromSeconds(1.5));

            Log.Debug("finished authorization missing facility fk validation");
        });
예제 #3
0
        protected override void OnClick() => ThreadService.RunOnBackground(() => {
            Log.Debug("Running Area of Review Validation");

            var progressDialog = new ProgressDialog("🔍 Finding issues...", "Cancel", 100, false);
            var progressor     = new CancelableProgressorSource(progressDialog).Progressor;
            progressDialog.Show();

            var authorizations = new Dictionary <string, List <long> >();
            var noAreaOfReview = new HashSet <long>();

            var tableName = "UICWell";
            using (var table = LayerService.GetTableFromLayersOrTables("UICWell", MapView.Active.Map)) {
                progressor.Value = 10;

                if (table == null)
                {
                    NotificationService.NotifyOfMissingLayer(tableName);

                    progressDialog.Hide();

                    return;
                }

                var filter = new QueryFilter {
                    SubFields   = "OBJECTID,AUTHORIZATION_FK",
                    WhereClause = "Authorization_FK is not null AND AOR_FK is null"
                };

                Log.Verbose("Getting wells with an authorization but no area of review");

                using (var cursor = table.Search(filter)) {
                    while (cursor.MoveNext())
                    {
                        var oid  = Convert.ToInt64(cursor.Current["OBJECTID"]);
                        var guid = Convert.ToString(cursor.Current["AUTHORIZATION_FK"]);

                        if (authorizations.ContainsKey(guid))
                        {
                            authorizations[guid].Add(oid);

                            continue;
                        }

                        authorizations.Add(guid, new List <long> {
                            oid
                        });
                    }
                }
            }

            Log.Verbose("Got authorizations {dict}", authorizations);

            progressor.Value = 40;

            tableName        = "UICAuthorization";
            var table2       = LayerService.GetStandaloneTable(tableName, MapView.Active.Map);
            progressor.Value = 50;

            if (table2 == null)
            {
                NotificationService.NotifyOfMissingLayer(tableName);

                progressDialog.Hide();

                return;
            }

            var filter2 = new QueryFilter {
                SubFields   = "GUID",
                WhereClause = $"AuthorizationType IN ('IP', 'AP') AND GUID IN ({string.Join(",", authorizations.Keys.Select(x => $"'{x}'"))})"
            };

            Log.Verbose("searching for well authorizations with type IP or AP");

            using (var cursor = table2.Search(filter2)) {
                while (cursor.MoveNext())
                {
                    var guid = Convert.ToString(cursor.Current["GUID"]);

                    authorizations[guid].ForEach(x => noAreaOfReview.Add(x));
                }
            }

            Log.Verbose("got the guids {dict}", authorizations);

            progressor.Value = 90;

            if (noAreaOfReview.Count == 0)
            {
                NotificationService.NotifyOfValidationSuccess();

                progressDialog.Hide();

                return;
            }

            Log.Verbose("Found {count} wells with no AOR with an authorization of IP or AP", noAreaOfReview.Count);

            var layerName = "UICWell";
            var layer     = LayerService.GetLayer(layerName, MapView.Active.Map);

            if (layer == null)
            {
                NotificationService.NotifyOfMissingLayer(layerName);

                progressDialog.Hide();

                return;
            }

            Log.Verbose("Selecting Wells");

            progressor.Value = 95;

            MapView.Active.Map.SetSelection(new Dictionary <MapMember, List <long> > {
                { layer, noAreaOfReview.ToList() }
            });

            progressor.Value = 100;

            progressDialog.Hide();

            NotificationService.NotifyOfValidationFailure(noAreaOfReview.Count);

            Log.Verbose("Zooming to selected");

            MapView.Active.ZoomToSelectedAsync(TimeSpan.FromSeconds(1.5));

            Log.Debug("Finished Authorization Validation");
        });
예제 #4
0
        protected override async void OnClick() => await ThreadService.RunOnBackground(async() => {
            Log.Debug("running violation without return to compliance date");

            var progressDialog = new ProgressDialog("🔍 Finding issues...", "Cancel", 100, false);
            progressDialog.Show();

            var layerName = "UICViolation";
            var table     = LayerService.GetStandaloneTable(layerName, MapView.Active.Map);

            if (table == null)
            {
                NotificationService.NotifyOfMissingLayer(layerName);

                progressDialog.Hide();

                return;
            }

            IGPResult result = null;
            var parameters   = Geoprocessing.MakeValueArray(table, "NEW_SELECTION", "ReturnToComplianceDate IS NULL");
            var progSrc      = new CancelableProgressorSource(progressDialog);

            Log.Verbose("management.SelectLayerByAttribute on {layer} with {@params}", layerName, parameters);

            try {
                result = await Geoprocessing.ExecuteToolAsync(
                    "management.SelectLayerByAttribute",
                    parameters,
                    null,
                    new CancelableProgressorSource(progressDialog).Progressor,
                    GPExecuteToolFlags.Default
                    );
            } catch (Exception ex) {
                NotificationService.NotifyOfGpCrash(ex, parameters);

                progressDialog.Hide();

                return;
            }

            if (result.IsFailed || string.IsNullOrEmpty(result?.ReturnValue))
            {
                NotificationService.NotifyOfGpFailure(result, parameters);

                progressDialog.Hide();

                return;
            }

            var problems = Convert.ToInt32(result?.Values[1]);

            Log.Debug("found {problems} problems", problems);

            if (problems == 0)
            {
                NotificationService.NotifyOfValidationSuccess();

                progressDialog.Hide();

                return;
            }

            progressDialog.Hide();

            NotificationService.NotifyOfValidationFailure(problems);


            Log.Debug("finished violation missing return to compliance date");
        });
예제 #5
0
        protected override async void OnClick() => await ThreadService.RunOnBackground(() => {
            Log.Debug("running inspection validation looking for not no deficiency with a missing correction");

            var progressDialog = new ProgressDialog("🔍 Finding issues...", "Cancel", 100, false);
            var progressor     = new CancelableProgressorSource(progressDialog).Progressor;
            progressDialog.Show();

            var idMap       = new Dictionary <string, long>();
            var primaryKeys = new HashSet <string>();
            var foreignKeys = new HashSet <string>();

            var tableName        = "UICInspection";
            var relatedTableName = "UICCorrection";
            using (var table = LayerService.GetTableFromLayersOrTables(tableName, MapView.Active.Map))
                using (var relatedTable = LayerService.GetTableFromLayersOrTables(relatedTableName, MapView.Active.Map)) {
                    progressor.Value = 10;

                    if (table == null)
                    {
                        NotificationService.NotifyOfMissingLayer(tableName);

                        progressDialog.Hide();

                        return;
                    }

                    if (relatedTable == null)
                    {
                        NotificationService.NotifyOfMissingLayer(relatedTableName);

                        progressDialog.Hide();

                        return;
                    }

                    var filter = new QueryFilter {
                        SubFields   = "OBJECTID,GUID",
                        WhereClause = "InspectionDeficiency!='NO'"
                    };

                    Log.Verbose("searching for inspections value other than no deficiency");

                    using (var cursor = table.Search(filter, true)) {
                        var guidIndex = cursor.FindField("GUID");

                        while (cursor.MoveNext())
                        {
                            var id   = cursor.Current.GetObjectID();
                            var guid = cursor.Current[guidIndex].ToString();

                            idMap[guid] = id;
                            primaryKeys.Add(guid);
                        }
                    }

                    progressor.Value = 60;

                    Log.Verbose("built set of primary keys");

                    filter = new QueryFilter {
                        SubFields = "Inspection_FK"
                    };

                    using (var cursor = relatedTable.Search(filter, true)) {
                        var guidIndex = cursor.FindField("Inspection_FK");

                        while (cursor.MoveNext())
                        {
                            var guid = cursor.Current[guidIndex].ToString();

                            foreignKeys.Add(guid);
                        }
                    }

                    Log.Verbose("built set of foreign keys");
                    progressor.Value = 90;

                    primaryKeys.ExceptWith(foreignKeys);

                    Log.Information("found {count} issues", primaryKeys.Count);

                    if (primaryKeys.Count == 0)
                    {
                        NotificationService.NotifyOfValidationSuccess();

                        progressDialog.Hide();

                        return;
                    }

                    var problems = new List <long>(primaryKeys.Count);
                    problems.AddRange(idMap.Where(x => primaryKeys.Contains(x.Key)).Select(x => x.Value));

                    Log.Debug("problem records {items}", problems);

                    progressor.Value = 100;

                    Log.Verbose("Setting selection");

                    MapView.Active.Map.SetSelection(new Dictionary <MapMember, List <long> > {
                        { LayerService.GetStandaloneTable(tableName, MapView.Active.Map), problems }
                    });

                    progressor.Value = 100;

                    progressDialog.Hide();

                    NotificationService.NotifyOfValidationFailure(problems.Count);

                    Log.Debug("finished inspection_correction validation");
                }
        });