Example #1
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var errors = new List <ValidationResult>();

            FileResourceModelExtensions.ValidateFileSize(FileResourceData, errors, GeneralUtility.NameOf(() => FileResourceData));
            return(errors);
        }
Example #2
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var errors      = new List <ValidationResult>();
            var maxFileSize = (1024 ^ 2) * 50 * 1000; // 50 MB

            FileResourceModelExtensions.ValidateFileSize(FileResourceData, errors, GeneralUtility.NameOf(() => FileResourceData), maxFileSize);
            return(errors);
        }
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var errors = new List <ValidationResult>();

            FileResourceModelExtensions.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(FirmaWebConfiguration.Ogr2OgrExecutable,
                                                                            LtInfoGeometryConfiguration.DefaultCoordinateSystemId,
                                                                            FirmaWebConfiguration.HttpRuntimeExecutionTimeout.TotalMilliseconds);

                List <string> featureClassNames = null;
                try
                {
                    var ogrInfoFileInfo = new FileInfo(FirmaWebConfiguration.OgrInfoExecutable);
                    featureClassNames = OgrInfoCommandLineRunner.GetFeatureClassNamesFromFileGdb(ogrInfoFileInfo, gdbFile, gdbFile.Name, 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)
                {
                    var featureClasses = featureClassNames.ToDictionary(x => x,
                                                                        x =>
                    {
                        try
                        {
                            var geoJson = ogr2OgrCommandLineRunner.ImportFileGdbToGeoJson(gdbFile, x, false);
                            return(JsonTools.DeserializeObject <FeatureCollection>(geoJson));
                        }
                        catch (Exception e)
                        {
                            errors.Add(new ValidationResult($"There was a problem processing the Feature Class \"{x}\"."));
                            SitkaLogger.Instance.LogDetailedErrorMessage(e);
                            return(null);
                        }
                    }).Where(x => x.Value != null && OrganizationBoundaryStaging.IsUsableFeatureCollectionGeoJson(x.Value));

                    if (!featureClasses.Any())
                    {
                        errors.Add(new ValidationResult("There are no usable Feature Classes in the uploaded file. Feature Classes must contain Polygon and/or Multi-Polygon features."));
                    }
                }
            }

            return(errors);
        }
        public virtual IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            CheckForNotNullProjectId();
            var validationResults = new List <ValidationResult>();

            FileResourceModelExtensions.ValidateFileSize(UploadedFile, validationResults, "File");

            // Attachments must have unique display names at the project and attachment type level
            if (HttpRequestStorage.DatabaseEntities.ProjectAttachments.Any(x => x.ProjectID == ProjectID && x.DisplayName == DisplayName && x.AttachmentTypeID == AttachmentTypeID))
            {
                AttachmentTypePrimaryKey attachmentTypePrimaryKey = AttachmentTypeID;
                var attachmentType = attachmentTypePrimaryKey.EntityObject;

                validationResults.Add(new SitkaValidationResult <NewProjectAttachmentViewModel, string>($"There is already an attachment with the display name \"{DisplayName}\" under the {attachmentType.AttachmentTypeName} attachment type for this {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()}.", m => m.DisplayName));
            }

            return(validationResults);
        }
Example #5
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var errors         = new List <ValidationResult>();
            var reportTemplate = HttpRequestStorage.DatabaseEntities.ReportTemplates.SingleOrDefault(x => x.DisplayName == DisplayName);

            if (reportTemplate != null && reportTemplate.ReportTemplateID != ReportTemplateID)
            {
                errors.Add(new SitkaValidationResult <EditViewModel, string>("This Display Name is already being used by another Report Template", x => x.DisplayName));
            }

            if (FileResourceData == null && FileResourceInfoID == null)
            {
                errors.Add(new SitkaValidationResult <EditViewModel, HttpPostedFileBase>("You cannot have a report template without a template file.", x => x.FileResourceData));
            }

            if (FileResourceData != null)
            {
                FileResourceModelExtensions.ValidateFileSize(FileResourceData, errors, GeneralUtility.NameOf(() => FileResourceData));
            }
            return(errors);
        }