예제 #1
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");
        });
예제 #2
0
        protected override void OnClick() => ThreadService.RunOnBackground(async() => {
            Log.Debug("running well missing operating status validation");

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

            const string tableName        = "UICWell";
            const string relatedTableName = "UICWellOperatingStatus";

            var layer = LayerService.GetLayer(tableName, MapView.Active.Map);

            progressor.Value = 10;

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

                progressDialog.Hide();

                return;
            }

            IGPResult result = null;
            var parameters   = Geoprocessing.MakeValueArray(layer);

            Log.Verbose("management.GetCount on {layer}", tableName);

            var cts = new CancellationTokenSource();
            try {
                result = await Geoprocessing.ExecuteToolAsync(
                    "management.GetCount",
                    parameters,
                    null,
                    cts.Token
                    );
            } catch (Exception ex) {
                NotificationService.NotifyOfGpCrash(ex, parameters);

                progressDialog.Hide();

                return;
            }

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

                progressDialog.Hide();

                return;
            }

            progressor.Value = 20;

            var total = Convert.ToInt32(result?.Values[0]);
            Log.Verbose("found {records} well records", total);

            var perRecordTick   = 60F / total;
            float startingPoint = 20;

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

            using (var parentTable = LayerService.GetTableFromLayersOrTables(tableName, MapView.Active.Map))
                using (var relatedTable = LayerService.GetTableFromLayersOrTables(relatedTableName, MapView.Active.Map)) {
                    if (relatedTable == null)
                    {
                        NotificationService.NotifyOfMissingLayer(relatedTableName);

                        progressDialog.Hide();

                        return;
                    }

                    var filter = new QueryFilter {
                        SubFields = "OBJECTID,GUID"
                    };

                    using (var cursor = parentTable.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);

                            startingPoint += perRecordTick;
                            var tick       = Convert.ToUInt32(startingPoint);

                            if (tick - 5 > progressor.Value)
                            {
                                progressor.Value = tick;
                            }
                        }
                    }

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

                    filter.SubFields = "WELL_FK";

                    using (var cursor = relatedTable.Search(filter, true)) {
                        var guidIndex = cursor.FindField("WELL_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> > {
                { layer, problems }
            });

            progressDialog.Hide();

            NotificationService.NotifyOfValidationFailure(problems.Count);

            Log.Verbose("Zooming to selected");

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

            Log.Debug("Finished Well Operating Status Validation");
        });
예제 #3
0
        protected override async void OnClick() => await ThreadService.RunOnBackground(async() => {
            Log.Debug("Running Authorization Validation");

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

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

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

                progressDialog.Hide();

                return;
            }

            IGPResult result;
            var parameters = Geoprocessing.MakeValueArray(layer, "NEW_SELECTION", "Authorization_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 Validation");
        });
예제 #4
0
        protected override async void OnClick() => await ThreadService.RunOnBackground(async() => {
            /*
             * The UICAreaOfReview tbl has a field NoArtPenDate.
             * This is the date it was determined that there were no artificial penetrations
             * If this field is empty there should be at least one UICArtPen well associated with the AOR.
             *
             * Also, remember there is a many to many relationship between UICAreaOfReview and UICArtPen
             * so there isn't an AOR_FK in the UICArtPen record.
             */

            Log.Debug("Running area of review missing artificial penetration validation");

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

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

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

                    progressDialog.Hide();

                    return;
                }

                var filter = new QueryFilter {
                    SubFields   = "OBJECTID",
                    WhereClause = "NoArtPenDate IS NULL"
                };

                Log.Verbose("searching for area of review records with no art pen date");

                var problems = new List <long>();
                using (var gdb = table.GetDatastore() as Geodatabase) {
                    if (gdb == null)
                    {
                        Log.Warning("Could not get geodatabase object");

                        progressDialog.Hide();
                    }

                    Log.Verbose("Got datastore as a geodatabase");

                    Log.Verbose("Opening relationship class and selecting {table} records", tableName);

                    var dbSchema = LayerService.GetDbSchema(MapView.Active.Map);

                    Log.Verbose("Using db and schema {schema}", dbSchema);

                    using (var relationshipClass = gdb.OpenDataset <RelationshipClass>($"{dbSchema}AreaOfReviewToArtPen"))
                        using (var selection = table.Select(filter, SelectionType.ObjectID, SelectionOption.Normal)) {
                            progressor.Value = 40;

                            var ids = selection.GetObjectIDs().ToList();

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

                                progressDialog.Hide();

                                return;
                            }

                            Log.Verbose("Finding related records to {ids}", ids);

                            foreach (var id in ids)
                            {
                                var rows = relationshipClass.GetRowsRelatedToDestinationRows(new[] { id });
                                if (!rows.Any())
                                {
                                    problems.Add(id);
                                }
                                else
                                {
                                    foreach (var row in rows)
                                    {
                                        row.Dispose();
                                    }
                                }
                            }

                            progressor.Value = 75;
                        }

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

                        progressDialog.Hide();

                        return;
                    }

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

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

                        progressDialog.Hide();

                        return;
                    }

                    MapView.Active.Map.SetSelection(new Dictionary <MapMember, List <long> > {
                        { layer, 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 aor artpen Validation");
                }
            }
        });