示例#1
0
        public void TestMapDefinitionValidation()
        {
            var conn = CreateTestConnection();
            var mdf  = Utility.CreateMapDefinition(conn, "Test");

            mdf.ResourceID = "Library://UnitTests/Test.MapDefinition";

            var context = new ResourceValidationContext(conn);
            var issues  = ResourceValidatorSet.Validate(context, mdf, false);

            Assert.True(issues.Any(x => x.StatusCode == ValidationStatusCode.Warning_MapDefinition_MissingCoordinateSystem));

            conn.ResourceService.SetResourceXmlData("Library://UnitTests/Layers/HydrographicPolygons.LayerDefinition", File.OpenRead("TestData/MappingService/UT_HydrographicPolygons.ldf"));

            var layer = mdf.AddLayer(null, "bar", "Library://UnitTests/Layers/HydrographicPolygons.LayerDefinition");

            layer.Group = "foo"; //AddLayer no longer lets us put in bogus group names
            context     = new ResourceValidationContext(conn);
            issues      = ResourceValidatorSet.Validate(context, mdf, false);
            Assert.True(issues.Any(x => x.StatusCode == ValidationStatusCode.Error_MapDefinition_LayerWithNonExistentGroup));

            mdf.AddLayer(null, "bar", "Library://UnitTests/Layers/HydrographicPolygons.LayerDefinition");
            context = new ResourceValidationContext(conn);
            issues  = ResourceValidatorSet.Validate(context, mdf, false);
            Assert.True(issues.Any(x => x.StatusCode == ValidationStatusCode.Error_MapDefinition_DuplicateLayerName));

            var group = mdf.AddGroup("foo");

            group.Group = "bar";

            context = new ResourceValidationContext(conn);
            issues  = ResourceValidatorSet.Validate(context, mdf, false);
            Assert.True(issues.Any(x => x.StatusCode == ValidationStatusCode.Error_MapDefinition_GroupWithNonExistentGroup));
        }
示例#2
0
        protected object BackgroundValidate(BackgroundWorker worker, DoWorkEventArgs e, params object[] args)
        {
            //Collect all documents to be validated. Some of these selected items
            //may be folders.
            var documents = new List <string>();
            var conn      = (IServerConnection)args[0];

            foreach (object a in args.Skip(1))
            {
                string rid = a.ToString();
                if (ResourceIdentifier.Validate(rid))
                {
                    var resId = new ResourceIdentifier(rid);
                    if (resId.IsFolder)
                    {
                        foreach (IRepositoryItem o in conn.ResourceService.GetRepositoryResources(rid).Children)
                        {
                            if (!o.IsFolder)
                            {
                                documents.Add(o.ResourceId);
                            }
                        }
                    }
                    else
                    {
                        documents.Add(rid);
                    }
                }
            }

            worker.ReportProgress(0);
            var context = new ResourceValidationContext(conn);

            var set = new ValidationResultSet();
            int i   = 0;

            foreach (string s in documents)
            {
                worker.ReportProgress((int)((i / (double)documents.Count) * 100), s);
                IResource item = null;
                try
                {
                    item = conn.ResourceService.GetResource(s);
                    set.AddIssues(ResourceValidatorSet.Validate(context, item, true));
                }
                catch (Exception ex)
                {
                    string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                    set.AddIssue(new ValidationIssue(item, ValidationStatus.Error, ValidationStatusCode.Error_General_ValidationError, string.Format("Failed to validate resource: {0}", msg)));
                }
                i++;
                worker.ReportProgress((int)((i / (double)documents.Count) * 100), s);
            }

            return(set.GetAllIssues());
        }
示例#3
0
        /// <summary>
        /// Performs any pre-save validation on the currently edited resource, by default
        /// this returns the results of a non-cascading <see cref="ResourceValidatorSet"/>
        /// validation run. Override this if you have a custom method of validation.
        /// </summary>
        protected virtual ICollection <ValidationIssue> ValidateEditedResource()
        {
            var conn    = _svc.CurrentConnection;
            var context = new ResourceValidationContext(conn);
            //Don't recurse as we only want to validate the current resource
            var issues = ResourceValidatorSet.Validate(context, this.Resource, false);
            var set    = new ValidationResultSet(issues);

            var errors = set.GetIssuesForResource(this.Resource.ResourceID, ValidationStatus.Error);

            return(errors);
        }
        protected override ICollection <ValidationIssue> ValidateEditedResource()
        {
            string[] warnings;
            string[] errors;

            Func <ValidationIssue[]> validator = () =>
            {
                ValidateXml(out errors, out warnings);
                var issues = new List <ValidationIssue>();
                foreach (string err in errors)
                {
                    issues.Add(new ValidationIssue(this.Resource, ValidationStatus.Error, ValidationStatusCode.Error_General_ValidationError, err));
                }
                foreach (string warn in warnings)
                {
                    issues.Add(new ValidationIssue(this.Resource, ValidationStatus.Warning, ValidationStatusCode.Warning_General_ValidationWarning, warn));
                }

                //Put through ValidationResultSet to weed out redundant messages
                var set = new ValidationResultSet(issues);

                try
                {
                    var res     = ObjectFactory.DeserializeXml(editor.XmlContent);
                    var conn    = _edSvc.CurrentConnection;
                    var context = new ResourceValidationContext(conn);
                    //We don't care about dependents, we just want to validate *this* resource
                    var resIssues = ResourceValidatorSet.Validate(context, res, false);
                    set.AddIssues(resIssues);
                }
                catch
                {
                    //This can fail because the XML may be for something that Maestro does not offer a strongly-typed class for yet.
                    //So the XML may be legit, just not for this version of Maestro that is doing the validating
                }

                //Only care about errors. Warnings and other types should not derail us from saving
                return(set.GetAllIssues(ValidationStatus.Error));
            };

            if (this.InvokeRequired)
            {
                return((ValidationIssue[])this.Invoke(validator));
            }
            else
            {
                return(validator());
            }
        }
示例#5
0
        public void TestSymbolDefinitionValidation()
        {
            Skip.If(_skip, _skipReason);

            var conn = CreateTestConnection();
            var ssym = Utility.CreateSimpleSymbol(conn, "Test", "Test");

            ssym.ResourceID = "Library://UnitTests/Test.SymbolDefinition";

            var context = new ResourceValidationContext(conn);
            var issues  = ResourceValidatorSet.Validate(context, ssym, true);

            Assert.Contains(issues, x => x.StatusCode == ValidationStatusCode.Error_SymbolDefinition_NoGeometryUsageContexts);

            var param = ssym.CreateParameter();

            param.Identifier = "TEST";
            ssym.ParameterDefinition.AddParameter(param);

            context = new ResourceValidationContext(conn);
            issues  = ResourceValidatorSet.Validate(context, ssym, true);
            Assert.Contains(issues, x => x.StatusCode == ValidationStatusCode.Warning_SymbolDefinition_SymbolParameterNotUsed);

            var imgRef = ssym.CreateImageReference("Library://UnitTest/IDontExist.LayerDefinition", "Foo.png");
            var img    = ssym.CreateImageGraphics();

            img.Item = imgRef;

            ssym.AddGraphics(img);

            context = new ResourceValidationContext(conn);
            issues  = ResourceValidatorSet.Validate(context, ssym, true);
            Assert.Contains(issues, x => x.StatusCode == ValidationStatusCode.Error_SymbolDefinition_ImageGraphicReferenceResourceIdNotFound);

            conn.ResourceService.SetResourceXmlData("Library://UnitTests/Layers/HydrographicPolygons.LayerDefinition", File.OpenRead("TestData/MappingService/UT_HydrographicPolygons.ldf"));

            imgRef   = ssym.CreateImageReference("Library://UnitTests/Layers/HydrographicPolygons.LayerDefinition", "Foo.png");
            img      = ssym.CreateImageGraphics();
            img.Item = imgRef;

            ssym.AddGraphics(img);

            context = new ResourceValidationContext(conn);
            issues  = ResourceValidatorSet.Validate(context, ssym, true);
            Assert.Contains(issues, x => x.StatusCode == ValidationStatusCode.Error_SymbolDefinition_ImageGraphicReferenceResourceDataNotFound);
        }
        /// <summary>
        /// Loads the default set of validators in this assembly
        /// </summary>
        /// <remarks>
        /// This method only needs to be called once. Subsequent calls return immediately. As such it is ideal
        /// to put this call in your application's startup/initialization code.
        /// </remarks>
        public static void LoadStockValidators()
        {
            if (m_initialized)
            {
                return;
            }

            ResourceValidatorSet.RegisterValidator(new DrawingSourceValidator());
            ResourceValidatorSet.RegisterValidator(new SymbolLibraryValidator());
            ResourceValidatorSet.RegisterValidator(new PrintLayoutValidator());
            ResourceValidatorSet.RegisterValidator(new FeatureSourceValidator());
            ResourceValidatorSet.RegisterValidator(new ApplicationDefinitionValidator());

            //NOTE: As of right now, all resources (regardless of version) are validated
            //with the same logic with each respective validator. In the event that a specific
            //resource requires its own validation class, it should be registered here.

            ResourceValidatorSet.RegisterValidator(new LayerDefinitionValidator("1.0.0"));
            ResourceValidatorSet.RegisterValidator(new LayerDefinitionValidator("1.1.0"));
            ResourceValidatorSet.RegisterValidator(new LayerDefinitionValidator("1.2.0"));
            ResourceValidatorSet.RegisterValidator(new LayerDefinitionValidator("1.3.0"));
            ResourceValidatorSet.RegisterValidator(new LayerDefinitionValidator("2.3.0"));
            ResourceValidatorSet.RegisterValidator(new LayerDefinitionValidator("2.4.0"));
            ResourceValidatorSet.RegisterValidator(new MapDefinitionValidator("1.0.0"));
            ResourceValidatorSet.RegisterValidator(new MapDefinitionValidator("2.3.0"));
            ResourceValidatorSet.RegisterValidator(new MapDefinitionValidator("2.4.0"));
            ResourceValidatorSet.RegisterValidator(new WebLayoutValidator("1.0.0"));
            ResourceValidatorSet.RegisterValidator(new WebLayoutValidator("1.1.0"));
            ResourceValidatorSet.RegisterValidator(new WebLayoutValidator("2.4.0"));
            ResourceValidatorSet.RegisterValidator(new WebLayoutValidator("2.6.0"));
            ResourceValidatorSet.RegisterValidator(new LoadProcedureValidator("1.0.0"));
            ResourceValidatorSet.RegisterValidator(new LoadProcedureValidator("1.1.0"));
            ResourceValidatorSet.RegisterValidator(new LoadProcedureValidator("2.2.0"));
            ResourceValidatorSet.RegisterValidator(new SymbolDefinitionValidator("1.0.0"));
            ResourceValidatorSet.RegisterValidator(new SymbolDefinitionValidator("1.1.0"));
            ResourceValidatorSet.RegisterValidator(new SymbolDefinitionValidator("2.4.0"));

            m_initialized = true;
        }
        /// <summary>
        /// Registers validators, serializers and instance factories of all known extended resource data types.
        ///
        /// Invoke this method as part of your application's startup process before using any other part of the Maestro API
        /// </summary>
        /// <remarks>
        /// This only needs to be called once, and should generally be done as part of your application's startup routine
        /// </remarks>
        public static void Initialize()
        {
            //By default the ObjectFactory, ResourceTypeRegistry and ResourceValidatorSet only
            //support v1.0.0 of all resource types. To support additional types we need to inject
            //this information as part of the consuming application's init/startup process
            //
            //This is our application's entry point, so we do this here.

            //Layer Definition 1.1.0
            ResourceValidatorSet.RegisterValidator(new Ldf110.LayerDefinitionValidator());
            ResourceTypeRegistry.RegisterResource(
                new ResourceTypeDescriptor(ResourceTypes.LayerDefinition.ToString(), "1.1.0"),
                new ResourceSerializationCallback(Ldf110.LdfEntryPoint.Serialize),
                new ResourceDeserializationCallback(Ldf110.LdfEntryPoint.Deserialize));
            ObjectFactory.RegisterLayerFactoryMethod(new Version(1, 1, 0), new LayerCreatorFunc(Ldf110.LdfEntryPoint.CreateDefault));

            //Layer Definition 1.2.0
            ResourceValidatorSet.RegisterValidator(new Ldf120.LayerDefinitionValidator());
            ResourceTypeRegistry.RegisterResource(
                new ResourceTypeDescriptor(ResourceTypes.LayerDefinition.ToString(), "1.2.0"),
                new ResourceSerializationCallback(Ldf120.LdfEntryPoint.Serialize),
                new ResourceDeserializationCallback(Ldf120.LdfEntryPoint.Deserialize));
            ObjectFactory.RegisterLayerFactoryMethod(new Version(1, 2, 0), new LayerCreatorFunc(Ldf120.LdfEntryPoint.CreateDefault));

            //Layer Definition 1.3.0
            ResourceValidatorSet.RegisterValidator(new Ldf130.LayerDefinitionValidator());
            ResourceTypeRegistry.RegisterResource(
                new ResourceTypeDescriptor(ResourceTypes.LayerDefinition.ToString(), "1.3.0"),
                new ResourceSerializationCallback(Ldf130.LdfEntryPoint.Serialize),
                new ResourceDeserializationCallback(Ldf130.LdfEntryPoint.Deserialize));
            ObjectFactory.RegisterLayerFactoryMethod(new Version(1, 3, 0), new LayerCreatorFunc(Ldf130.LdfEntryPoint.CreateDefault));

            //Layer Definition 2.3.0
            ResourceValidatorSet.RegisterValidator(new Ldf230.LayerDefinitionValidator());
            ResourceTypeRegistry.RegisterResource(
                new ResourceTypeDescriptor(ResourceTypes.LayerDefinition.ToString(), "2.3.0"),
                new ResourceSerializationCallback(Ldf230.LdfEntryPoint.Serialize),
                new ResourceDeserializationCallback(Ldf230.LdfEntryPoint.Deserialize));
            ObjectFactory.RegisterLayerFactoryMethod(new Version(2, 3, 0), new LayerCreatorFunc(Ldf230.LdfEntryPoint.CreateDefault));

            //Layer Definition 2.4.0
            ResourceValidatorSet.RegisterValidator(new Ldf240.LayerDefinitionValidator());
            ResourceTypeRegistry.RegisterResource(
                new ResourceTypeDescriptor(ResourceTypes.LayerDefinition.ToString(), "2.4.0"),
                new ResourceSerializationCallback(Ldf240.LdfEntryPoint.Serialize),
                new ResourceDeserializationCallback(Ldf240.LdfEntryPoint.Deserialize));
            ObjectFactory.RegisterLayerFactoryMethod(new Version(2, 4, 0), new LayerCreatorFunc(Ldf240.LdfEntryPoint.CreateDefault));

            //Load Procedure 1.1.0
            ResourceValidatorSet.RegisterValidator(new Lp110.LoadProcedureValidator());
            ResourceTypeRegistry.RegisterResource(
                new ResourceTypeDescriptor(ResourceTypes.LoadProcedure.ToString(), "1.1.0"),
                new ResourceSerializationCallback(Lp110.LoadProcEntryPoint.Serialize),
                new ResourceDeserializationCallback(Lp110.LoadProcEntryPoint.Deserialize));

            //Load Procedure 1.1.0 schema offers nothing new for the ones we want to support, so nothing to register
            //with the ObjectFactory

            //Load Procedure 2.2.0
            ResourceValidatorSet.RegisterValidator(new Lp220.LoadProcedureValidator());
            ResourceTypeRegistry.RegisterResource(
                new ResourceTypeDescriptor(ResourceTypes.LoadProcedure.ToString(), "2.2.0"),
                new ResourceSerializationCallback(Lp220.LoadProcEntryPoint.Serialize),
                new ResourceDeserializationCallback(Lp220.LoadProcEntryPoint.Deserialize));
            ObjectFactory.RegisterLoadProcedureFactoryMethod(LoadType.Sqlite, new LoadProcCreatorFunc(Lp220.LoadProcEntryPoint.CreateDefaultSqlite));

            //Web Layout 1.1.0
            ResourceValidatorSet.RegisterValidator(new WL110.WebLayoutValidator());
            ResourceTypeRegistry.RegisterResource(
                new ResourceTypeDescriptor(ResourceTypes.WebLayout.ToString(), "1.1.0"),
                new ResourceSerializationCallback(WL110.WebLayoutEntryPoint.Serialize),
                new ResourceDeserializationCallback(WL110.WebLayoutEntryPoint.Deserialize));
            ObjectFactory.RegisterWebLayoutFactoryMethod(new Version(1, 1, 0), new WebLayoutCreatorFunc(WL110.WebLayoutEntryPoint.CreateDefault));

            //Web Layout 2.4.0
            ResourceValidatorSet.RegisterValidator(new WL240.WebLayoutValidator());
            ResourceTypeRegistry.RegisterResource(
                new ResourceTypeDescriptor(ResourceTypes.WebLayout.ToString(), "2.4.0"),
                new ResourceSerializationCallback(WL240.WebLayoutEntryPoint.Serialize),
                new ResourceDeserializationCallback(WL240.WebLayoutEntryPoint.Deserialize));
            ObjectFactory.RegisterWebLayoutFactoryMethod(new Version(2, 4, 0), new WebLayoutCreatorFunc(WL240.WebLayoutEntryPoint.CreateDefault));

            //Web Layout 2.6.0
            ResourceValidatorSet.RegisterValidator(new WL260.WebLayoutValidator());
            ResourceTypeRegistry.RegisterResource(
                new ResourceTypeDescriptor(ResourceTypes.WebLayout.ToString(), "2.6.0"),
                new ResourceSerializationCallback(WL260.WebLayoutEntryPoint.Serialize),
                new ResourceDeserializationCallback(WL260.WebLayoutEntryPoint.Deserialize));
            ObjectFactory.RegisterWebLayoutFactoryMethod(new Version(2, 6, 0), new WebLayoutCreatorFunc(WL260.WebLayoutEntryPoint.CreateDefault));

            //Symbol Definition 1.1.0
            ResourceValidatorSet.RegisterValidator(new Sym110.SymbolDefinitionValidator());
            ResourceTypeRegistry.RegisterResource(
                new ResourceTypeDescriptor(ResourceTypes.SymbolDefinition.ToString(), "1.1.0"),
                new ResourceSerializationCallback(Sym110.SymbolDefEntryPoint.Serialize),
                new ResourceDeserializationCallback(Sym110.SymbolDefEntryPoint.Deserialize));
            ObjectFactory.RegisterCompoundSymbolFactoryMethod(new Version(1, 1, 0), new CompoundSymbolDefCreatorFunc(Sym110.SymbolDefEntryPoint.CreateDefaultCompound));
            ObjectFactory.RegisterSimpleSymbolFactoryMethod(new Version(1, 1, 0), new SimpleSymbolDefCreatorFunc(Sym110.SymbolDefEntryPoint.CreateDefaultSimple));

            //Symbol Definition 2.4.0
            ResourceValidatorSet.RegisterValidator(new Sym240.SymbolDefinitionValidator());
            ResourceTypeRegistry.RegisterResource(
                new ResourceTypeDescriptor(ResourceTypes.SymbolDefinition.ToString(), "2.4.0"),
                new ResourceSerializationCallback(Sym240.SymbolDefEntryPoint.Serialize),
                new ResourceDeserializationCallback(Sym240.SymbolDefEntryPoint.Deserialize));
            ObjectFactory.RegisterCompoundSymbolFactoryMethod(new Version(2, 4, 0), new CompoundSymbolDefCreatorFunc(Sym240.SymbolDefEntryPoint.CreateDefaultCompound));
            ObjectFactory.RegisterSimpleSymbolFactoryMethod(new Version(2, 4, 0), new SimpleSymbolDefCreatorFunc(Sym240.SymbolDefEntryPoint.CreateDefaultSimple));

            //Map Definition 2.3.0
            ResourceValidatorSet.RegisterValidator(new Mdf230.MapDefinitionValidator());
            ResourceTypeRegistry.RegisterResource(
                new ResourceTypeDescriptor(ResourceTypes.MapDefinition.ToString(), "2.3.0"),
                new ResourceSerializationCallback(Mdf230.MdfEntryPoint.Serialize),
                new ResourceDeserializationCallback(Mdf230.MdfEntryPoint.Deserialize));
            ObjectFactory.RegisterMapDefinitionFactoryMethod(new Version(2, 3, 0), new MapDefinitionCreatorFunc(Mdf230.MdfEntryPoint.CreateDefault));

            //Map Definition 2.4.0
            ResourceValidatorSet.RegisterValidator(new Mdf240.MapDefinitionValidator());
            ResourceTypeRegistry.RegisterResource(
                new ResourceTypeDescriptor(ResourceTypes.MapDefinition.ToString(), "2.4.0"),
                new ResourceSerializationCallback(Mdf240.MdfEntryPoint.Serialize),
                new ResourceDeserializationCallback(Mdf240.MdfEntryPoint.Deserialize));
            ObjectFactory.RegisterMapDefinitionFactoryMethod(new Version(2, 4, 0), new MapDefinitionCreatorFunc(Mdf240.MdfEntryPoint.CreateDefault));

            //Watermark Definition 2.3.0
            ResourceTypeRegistry.RegisterResource(
                new ResourceTypeDescriptor(ResourceTypes.WatermarkDefinition.ToString(), "2.3.0"),
                new ResourceSerializationCallback(Wdf230.WdfEntryPoint.Serialize),
                new ResourceDeserializationCallback(Wdf230.WdfEntryPoint.Deserialize));
            ObjectFactory.RegisterWatermarkDefinitionFactoryMethod(new Version(2, 3, 0), new WatermarkCreatorFunc(Wdf230.WdfEntryPoint.CreateDefault));

            //Watermark Definition 2.4.0
            ResourceTypeRegistry.RegisterResource(
                new ResourceTypeDescriptor(ResourceTypes.WatermarkDefinition.ToString(), "2.4.0"),
                new ResourceSerializationCallback(Wdf240.WdfEntryPoint.Serialize),
                new ResourceDeserializationCallback(Wdf240.WdfEntryPoint.Deserialize));
            ObjectFactory.RegisterWatermarkDefinitionFactoryMethod(new Version(2, 4, 0), new WatermarkCreatorFunc(Wdf240.WdfEntryPoint.CreateDefault));
        }