예제 #1
0
        public void Should_Create_New_Layer()
        {
            var fakeContext = new FakeContext("CreateNewLayer");

            var fakeLayer = new Layer();

            fakeLayer.Name = "full name";

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var repository    = new LayerRepository(context);
                var mockValidator = new Mock <IValidator <Layer> >(MockBehavior.Strict);

                mockValidator
                .Setup(x => x.Validate(fakeLayer))
                .Returns(new FluentValidation.Results.ValidationResult());

                var service = new LayerService(repository, mockValidator.Object);
                var actual  = service.Create(fakeLayer);
                var id      = actual.Id;

                Assert.NotEqual(0, id);
                repository.Dispose();
            }
        }
예제 #2
0
 public VmCars()
 {
     layerService = new LayerService();
     Cars         = new ObservableCollection <Auto>();
     Aktualisieren();
     GuiRefresh = new MVVMCommand((para) => Aktualisieren(), (para) => { return(true); });
 }
예제 #3
0
        static void ShowFiles(LayerService service)
        {
            Console.WriteLine("\\");
            var children = service.GetEntries("\\");

            foreach (var child in children)
            {
                ShowFiles(child, service);
            }
        }
예제 #4
0
        static void ShowFiles(Entry entry, LayerService service)
        {
            Console.WriteLine(entry.ToDisplayString());
            var children = service.GetEntries(entry.Path);

            foreach (var child in children)
            {
                ShowFiles(child, service);
            }
        }
예제 #5
0
        private ILayerService InitializeLayerService(int row, int col)
        {
            var layerService = new LayerService();

            this.LayerRows = row;
            this.LayerCols = col;
            var inputArgsStr = $"{this.LayerRows} {this.LayerCols}";

            layerService.GetLayerDimensions(inputArgsStr);

            return(layerService);
        }
예제 #6
0
        public void Works()
        {
            var validRowsNumber = 2;
            var validColsNumber = 4;

            var inputArgsStr = $"{validRowsNumber} {validColsNumber}";

            var layerService = new LayerService();

            var result = layerService.GetLayerDimensions(inputArgsStr);

            Assert.Equal(validRowsNumber, layerService.GetLayerRows());
            Assert.True(result);
        }
예제 #7
0
        public void Test_AddLayer()
        {
            string[] filenames = GetShapefileNames();

            var fileService = new Mock <IFileDialogService>();

            fileService.Setup(s => s.OpenFiles(It.Is <DataSourceType>(t => t == DataSourceType.Vector), out filenames)).Returns(true);

            var layerService = new LayerService(_context.Object, fileService.Object, _broadcaster.Object, _reprojectingService.Object);

            layerService.AddLayer(DataSourceType.Vector);

            _messageService.Verify(s => s.Warn(It.IsAny <string>()), Times.Never);
            _layerColection.Verify(l => l.Add(It.IsAny <ILayerSource>(), true), Times.AtLeast(filenames.Count()));
        }
예제 #8
0
        public void Should_Return_All_Layers()
        {
            var fakeContext = new FakeContext("GetAllLayers");

            fakeContext.FillWith <Layer>();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var layerCountIndDb = context.Layer.Count();
                var repository      = new LayerRepository(context);
                var validator       = new LayerValidator();
                var service         = new LayerService(repository, validator);

                Assert.Equal(layerCountIndDb, service.GetAll().Count());
                repository.Dispose();
            }
        }
예제 #9
0
        public void ReturnArgumentExceptionNotEnterRows()
        {
            var validColsNumber = 4;

            var inputArgsStr = $" {validColsNumber}";

            var layerService = new LayerService();

            try
            {
                layerService.GetLayerDimensions(inputArgsStr);
            }
            catch (ArgumentException e)
            {
                var errMsg = ErrMsg.LayerDimentionException;
                Assert.Equal(errMsg, e.Message);
            }
        }
예제 #10
0
        public void ReturnArgumentExceptionWrongRows()
        {
            var validRowsNumber = 3;
            var validColsNumber = 4;

            var inputArgsStr = $"{validRowsNumber} {validColsNumber}";

            var layerService = new LayerService();

            try
            {
                layerService.GetLayerDimensions(inputArgsStr);
            }
            catch (ArgumentException e)
            {
                var errMsg = string.Format(ErrMsg.NotCorrectRow, GeneralConstants.MaxLayerSize);
                Assert.Equal(errMsg, e.Message);
            }
        }
예제 #11
0
        public void Should_Update_Existing_Layer(int id)
        {
            var fakeContext = new FakeContext("UpdateLayer");

            fakeContext.FillWith <Layer>();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var repository  = new LayerRepository(context);
                var validator   = new LayerValidator();
                var service     = new LayerService(repository, validator);
                var curretLayer = service.GetById(id);

                curretLayer.Name = "Testing";
                service.Update(curretLayer);
                Assert.Equal("Testing", service.GetById(id).Name);
                repository.Dispose();
            }
        }
예제 #12
0
        public void Should_Return_Right_Layer_When_Find_By_Id(int id)
        {
            var fakeContext = new FakeContext("LayerById");

            fakeContext.FillWith <Layer>();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var expected = fakeContext.GetFakeData <Layer>().Find(x => x.Id == id);

                var repository = new LayerRepository(context);
                var validator  = new LayerValidator();
                var service    = new LayerService(repository, validator);
                var actual     = service.GetById(id);

                Assert.Equal(expected, actual, new LayerIdComparer());
                repository.Dispose();
            }
        }
예제 #13
0
        public void Should_Delete_Layer()
        {
            var fakeContext = new FakeContext("DeleteLayer");

            fakeContext.FillWith <Layer>();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var repository   = new LayerRepository(context);
                var validator    = new LayerValidator();
                var service      = new LayerService(repository, validator);
                var currentCount = context.Layer.Count();

                Assert.NotEqual(0, currentCount);
                service.Delete(1);
                Assert.NotEqual(currentCount, context.Layer.Count());
                repository.Dispose();
            }
        }
예제 #14
0
        public void ReturnArgumentOutOfRangeExceptionIfRowBelowMin()
        {
            var validRowsNumber = 0;
            var validColsNumber = 4;

            var inputArgsStr = $"{validRowsNumber} {validColsNumber}";

            var layerService = new LayerService();

            try
            {
                layerService.GetLayerDimensions(inputArgsStr);
            }
            catch (ArgumentOutOfRangeException e)
            {
                var errorsMsg = e;
                var errMsg    = string.Format(ErrMsg.NotCorrectRow, GeneralConstants.MaxLayerSize);
                Assert.Equal(errMsg, e.ParamName);
            }
        }
예제 #15
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var target = new Target
            {
                RootPath     = @"C:\Users\ibuki\source\repos\ModLinker\ModLinker.Cli\TestDir\Root",
                BasePath     = @"C:\Users\ibuki\source\repos\ModLinker\ModLinker.Cli\TestDir\Base",
                ModDirectory = @"C:\Users\ibuki\source\repos\ModLinker\ModLinker.Cli\TestDir\Mods",
                Mods         = new[]
                {
                    new Mod
                    {
                        Description = "Mod1", ModPath = @"C:\Users\ibuki\source\repos\ModLinker\ModLinker.Cli\TestDir\Mods\Mod1", Order = 1, Name = "Mod1", RootPath = "Layers",
                        Links       = new[] { new Link {
                                                  ModPath = "Layer1", TargetPath = "Layer"
                                              } }
                    }
                },
                OverlayPath = @"C:\Users\ibuki\source\repos\ModLinker\ModLinker.Cli\TestDir\Overlay"
            };

            var provider = new DirectoryLayerProvider();

            var manager = new LayerService(new[] { new DirectoryLayerProvider() });

            if (args.Length < 2)
            {
                Console.CancelKeyPress += (sender, eventArgs) => manager.Dispose();
                ShowFiles(manager);
                while (Console.Read() != 'q')
                {
                    ;
                }
            }
            else
            {
                var op = new ModLinkerOperation(manager);
                op.Mount(target.RootPath);
            }
        }
예제 #16
0
        /// <summary>
        /// Экспорт блоков квартир в отдельные файлы dwg квартир.
        /// </summary>
        /// <returns>Количество экспортированных квартир.</returns>
        public static int ExportToFiles(List <Apartment> apartments)
        {
            int      count = 0;
            DateTime now   = DateTime.Now;

            // Бекап старых подложек
            BackupOldApartmentsFile();

            // Выключение слоев штриховки
            layersOff = LayerService.LayersOff(Options.Instance.LayersOffMatch);

            var apartsToFile = apartments.Where(a => !a.BaseStatus.HasFlag(EnumBaseStatus.NotInDwg));

            using (var progress = new ProgressMeter())
            {
                progress.SetLimit(apartsToFile.Count());
                progress.Start("Экспорт квартир в файлы...");

                foreach (var apart in apartsToFile)
                {
                    progress.MeterProgress();
                    try
                    {
                        apart.ExportToFile();
                        apart.ExportDate = now;
                        count++;
                    }
                    catch (System.Exception ex)
                    {
                        Inspector.AddError($"Ошибка при экспорте блока '{apart.Name}' - {ex.Message}", icon: System.Drawing.SystemIcons.Error);
                    }
                }
                progress.Stop();
            }

            // Восстановление слоев
            LayerService.LayersOn(layersOff);

            return(count);
        }
예제 #17
0
        public void Should_Create_Correct_LayerDTO_Object(int id)
        {
            var fakeContext = new FakeContext("LayerDTOTest");

            fakeContext.FillWithAll();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var repository = new LayerRepository(context);
                var validator  = new LayerValidator();
                var service    = new LayerService(repository, validator);
                var mockMapper = new MapperConfiguration(cfg =>
                {
                    cfg.AddProfile <AutoMapperProfile>();;
                });
                var mapper = mockMapper.CreateMapper();

                var testLayer = service.GetById(id);
                var layerDTO  = mapper.Map <Layer, LayerDTO>(testLayer);

                Assert.IsType <LayerDTO>(layerDTO);
                Assert.Equal(testLayer.Name, layerDTO.Name);
            }
        }
예제 #18
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");
                }
            }
        });
예제 #19
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");
        });
예제 #20
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");
        });
예제 #21
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");
        });
예제 #22
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");
                }
        });
예제 #23
0
        public async Task CreateLayer()
        {
            var layerMoq = new Mock <ILayer>();

            layerMoq.SetupGet(layer => layer.Id).Returns(Guid.NewGuid().ToString());
            layerMoq.Setup(layer => layer.GetPreloadEntries())
            .Returns(new[]
            {
                new EntryData(
                    true,
                    "dir5",
                    @"D:\dir3\dir4\dir5",
                    @"D:\dir3\dir4",
                    true,
                    layerMoq.Object,
                    DateTime.Now,
                    DateTime.Now,
                    DateTime.Now,
                    0,
                    false,
                    1
                    )
            });
            layerMoq.Setup(layer => layer.GetEntries(@"D:\dir3\dir4\dir5"))
            .Returns(new[]
            {
                new EntryData(
                    true,
                    "file1",
                    @"D:\dir3\dir4\dir5\file1",
                    @"D:\dir3\dir4\dir5",
                    false,
                    layerMoq.Object,
                    DateTime.Now,
                    DateTime.Now,
                    DateTime.Now,
                    10,
                    false,
                    1
                    )
            });

            var entryMoq = new Mock <IEntry>();

            entryMoq.SetupGet(entry => entry.CreationTime).Returns(DateTime.Now);
            entryMoq.SetupGet(entry => entry.LastAccessTime).Returns(DateTime.Now);
            entryMoq.SetupGet(entry => entry.LastWriteTime).Returns(DateTime.Now);
            entryMoq.SetupGet(entry => entry.Name).Returns("file1");
            entryMoq.SetupGet(entry => entry.Length).Returns(10);

            layerMoq.Setup(layer => layer.GetEntry(@"D:\dir3\dir4\dir5\file1"))
            .Returns(entryMoq.Object)
            ;
            var service = new LayerService(new[] { layerMoq.Object }, @"D:\dir3\dir4");
            await service.PreLoad();

            var             operation = new ModLinkerOperation(service);
            FileInformation fileInformation;
            var             result = operation.GetFileInformation(@"D:\dir3\dir4\dir5\file1", out fileInformation, new TestFileInfo());

            Assert.Equal(DokanResult.Success, result);
            Assert.Equal("file1", fileInformation.FileName);
        }
예제 #24
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");
        });
예제 #25
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");
        });