Ejemplo n.º 1
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var errors = new List <ValidationResult>();

            FileResource.ValidateFileSize(FileResourceData, errors, GeneralUtility.NameOf(() => FileResourceData));

            using (var disposableTempFile = DisposableTempFile.MakeDisposableTempFileEndingIn(".gdb.zip"))
            {
                var gdbFile = disposableTempFile.FileInfo;
                FileResourceData.SaveAs(gdbFile.FullName);

                try
                {
                    var featureClassNames = OgrInfoCommandLineRunner.GetFeatureClassNamesFromFileGdb(
                        new FileInfo(NeptuneWebConfiguration.OgrInfoExecutable),
                        gdbFile,
                        Ogr2OgrCommandLineRunner.DefaultTimeOut);

                    if (featureClassNames?.Count == 0)
                    {
                        errors.Add(new ValidationResult(
                                       "The file geodatabase contained no feature class. Please upload a file geodatabase containing exactly one feature class."));
                        return(errors);
                    }

                    if (featureClassNames?.Count != 1)
                    {
                        errors.Add(new ValidationResult(
                                       "The file geodatabase contained more than one feature class. Please upload a file geodatabase containing exactly one feature class."));
                        return(errors);
                    }

                    var featureClassName = featureClassNames[0];
                    if (!OgrInfoCommandLineRunner.ConfirmAttributeExistsOnFeatureClass(
                            new FileInfo(NeptuneWebConfiguration.OgrInfoExecutable),
                            gdbFile,
                            Ogr2OgrCommandLineRunner.DefaultTimeOut, featureClassName, TreatmentBMPNameField))
                    {
                        errors.Add(new ValidationResult($"The feature class in the file geodatabase does not have an attribute named {TreatmentBMPNameField}. Please double-check the attribute name you entered and try again."));
                        return(errors);
                    }
                }
                catch (Exception e)
                {
                    SitkaLogger.Instance.LogAbridgedErrorMessage(e);
                    errors.Add(new ValidationResult(
                                   "There was a problem uploading your file geodatabase. Verify it meets the requirements and is not corrupt."));
                }
            }

            return(errors);
        }
Ejemplo n.º 2
0
        public bool UpdateModel(Person currentPerson)
        {
            HttpRequestStorage.DatabaseEntities.DelineationStagings.DeleteDelineationStaging(currentPerson.DelineationStagingsWhereYouAreTheUploadedByPerson);
            HttpRequestStorage.DatabaseEntities.SaveChanges();

            using (var disposableTempFile = DisposableTempFile.MakeDisposableTempFileEndingIn(".gdb.zip"))
            {
                var gdbFile = disposableTempFile.FileInfo;
                FileResourceData.SaveAs(gdbFile.FullName);

                var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(NeptuneWebConfiguration.Ogr2OgrExecutable,
                                                                            Ogr2OgrCommandLineRunner.DefaultCoordinateSystemId,
                                                                            NeptuneWebConfiguration.HttpRuntimeExecutionTimeout.TotalMilliseconds * 10);

                try
                {
                    var featureClassNames = OgrInfoCommandLineRunner.GetFeatureClassNamesFromFileGdb(new FileInfo(NeptuneWebConfiguration.OgrInfoExecutable),
                                                                                                     gdbFile,
                                                                                                     Ogr2OgrCommandLineRunner.DefaultTimeOut);
                    if (featureClassNames != null)
                    {
                        var columns = new List <string>
                        {
                            $"{currentPerson.PersonID} as UploadedByPersonID",
                            $"{TreatmentBMPNameField} as TreatmentBMPName",
                            $"{StormwaterJurisdictionID} as StormwaterJurisdictionID"
                        };
                        ogr2OgrCommandLineRunner.ImportFileGdbToMsSql(gdbFile, featureClassNames[0], "DelineationStaging", columns,
                                                                      NeptuneWebConfiguration.DatabaseConnectionString, true, Ogr2OgrCommandLineRunner.GEOMETRY_TYPE_POLYGON);
                    }
                }
                catch (Exception e)
                {
                    SitkaLogger.Instance.LogAbridgedErrorMessage(e);
                    return(false);
                }
            }

            return(true);
        }
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var currentPerson = HttpRequestStorage.DatabaseEntities.People.Find(PersonID);

            HttpRequestStorage.DatabaseEntities.pLandUseBlockStagingDeleteByPersonID(currentPerson.PersonID);
            var errors = new List <ValidationResult>();

            FileResource.ValidateFileSize(FileResourceData, errors, GeneralUtility.NameOf(() => FileResourceData));

            using (var disposableTempFile = DisposableTempFile.MakeDisposableTempFileEndingIn(".gdb.zip"))
            {
                var gdbFile = disposableTempFile.FileInfo;
                FileResourceData.SaveAs(gdbFile.FullName);

                var ogr2OgrCommandLineRunner = new Ogr2OgrCommandLineRunner(NeptuneWebConfiguration.Ogr2OgrExecutable,
                                                                            Ogr2OgrCommandLineRunner.DefaultCoordinateSystemId,
                                                                            NeptuneWebConfiguration.HttpRuntimeExecutionTimeout.TotalMilliseconds * 10);

                List <string> featureClassNames = null;
                try
                {
                    featureClassNames = OgrInfoCommandLineRunner.GetFeatureClassNamesFromFileGdb(new FileInfo(NeptuneWebConfiguration.OgrInfoExecutable),
                                                                                                 gdbFile,
                                                                                                 Ogr2OgrCommandLineRunner.DefaultTimeOut);
                }
                catch (Exception e)
                {
                    errors.Add(new ValidationResult("There was a problem uploading your file geodatabase. Verify it meets the requirements and is not corrupt."));
                    SitkaLogger.Instance.LogDetailedErrorMessage(e);
                }

                if (featureClassNames != null)
                {
                    if (featureClassNames.Count == 0)
                    {
                        errors.Add(new ValidationResult("The file geodatabase contained no feature class. Please upload a file geodatabase containing exactly one feature class."));
                        return(errors);
                    }

                    if (featureClassNames.Count != 1)
                    {
                        errors.Add(new ValidationResult("The file geodatabase contained more than one feature class. Please upload a file geodatabase containing exactly one feature class."));
                        return(errors);
                    }

                    try
                    {
                        var columns = new List <string>
                        {
                            "PLU_Cat as PriorityLandUseType",
                            "LU_Descr as LandUseDescription",
                            "TGR as TrashGenerationRate",
                            "LU_for_TGR as LandUseForTGR",
                            "MHI as MedianHouseHoldIncome",
                            "Jurisdic as StormwaterJurisdiction",
                            "Permit as PermitType",
                            $"{PersonID} as UploadedByPersonID"
                        };
                        ogr2OgrCommandLineRunner.ImportFileGdbToMsSql(gdbFile, featureClassNames[0],
                                                                      "LandUseBlockStaging", columns,
                                                                      NeptuneWebConfiguration.DatabaseConnectionString, true,
                                                                      Ogr2OgrCommandLineRunner.GEOMETRY_TYPE_POLYGON);
                    }
                    catch (Ogr2OgrCommandLineException e)
                    {
                        if (e.Message.Contains("column does not allow nulls",
                                               StringComparison.InvariantCultureIgnoreCase))
                        {
                            errors.Add(new ValidationResult("The upload contained features with null values. All fields are required."));
                        }
                        else if (e.Message.Contains("Unrecognised field name",
                                                    StringComparison.InvariantCultureIgnoreCase))
                        {
                            errors.Add(new ValidationResult("The columns in the uploaded file did not match the Land Use Block schema. The file is invalid and cannot be uploaded."));
                        }
                        else
                        {
                            errors.Add(new ValidationResult($"There was a problem processing the Feature Class \"{featureClassNames[0]}\". The file may be corrupted or invalid."));
                            SitkaLogger.Instance.LogDetailedErrorMessage(e);
                        }
                    }
                    catch (Exception e)
                    {
                        errors.Add(new ValidationResult($"There was a problem processing the Feature Class \"{featureClassNames[0]}\". Feature Classes must contain Polygon and/or Multi-Polygon features."));
                        SitkaLogger.Instance.LogDetailedErrorMessage(e);
                    }
                }
            }

            return(errors);
        }