예제 #1
0
        public static GeneratorDeclaration Parse(JObject transformationObject, string transformationName = null)
        {
            // when its an inline decl it gets the name from the property holding the decl object
            transformationName = transformationName ?? transformationObject.GetStringPropertyValue("name");
            var version         = transformationObject.GetStringPropertyValue("version");
            var parametersArray = transformationObject.GetValue("parameters") as JArray ?? new JArray();
            var parameters      = new List <ParameterDeclaration>();

            foreach (JObject parametersObject in parametersArray)
            {
                var parameterDeclaration = ParameterDeclaration.Parse(parametersObject);
                parameters.Add(parameterDeclaration);
            }

            var rulesArray = transformationObject.GetValue("rules") as JArray ?? new JArray();
            var rules      = new List <TransformationRuleDeclaration>();

            foreach (JObject ruleObject in rulesArray)
            {
                var ruleDeclaration = TransformationRuleDeclaration.Parse(ruleObject);
                rules.Add(ruleDeclaration);
            }

            var location = transformationObject.GetStringPropertyValue("location");

            var transformation = new GeneratorDeclaration();

            transformation.Name       = transformationName;
            transformation.Parameters = parameters;
            transformation.Rules      = rules;
            transformation.Location   = location;
            transformation.Version    = version;
            return(transformation);
        }
예제 #2
0
        public GeneratorRefDeclaration(string packageName, string packageVersion, GeneratorDeclaration inlineDecl)
        {
            if (string.IsNullOrWhiteSpace(packageName))
            {
                throw new ArgumentNullException(nameof(packageName));
            }

            if (string.IsNullOrWhiteSpace(packageVersion))
            {
                throw new ArgumentNullException(nameof(packageVersion));
            }

            PackageName    = packageName;
            PackageVersion = packageVersion;
            InlinDecl      = inlineDecl;
        }
예제 #3
0
        public static Solution Parse(JObject root)
        {
            var name = root.GetStringPropertyValue("name");

            var loaders    = new List <ModelLoaderDeclaration>();
            var generators = new List <GeneratorRefDeclaration>();
            var models     = new List <ModelDeclaration>();
            var pipelines  = new List <PipelineDeclaration>();

            var result = new Solution(name, loaders, generators, models, pipelines);

            var loadersObject = root.GetValue("loaders") as JObject;

            foreach (JProperty property in loadersObject?.Properties() ?? Enumerable.Empty <JProperty>())
            {
                var packageName    = property.Name;
                var packageVersion = property.Value.Value <string>();
                loaders.Add(new ModelLoaderDeclaration(packageName, packageVersion));
            }

            var generatorsObject = root.GetValue("generators") as JObject;

            foreach (JProperty property in generatorsObject?.Properties() ?? Enumerable.Empty <JProperty>())
            {
                var packageName = property.Name;
                if (property.Value.Type == JTokenType.Object)
                {
                    var declObject = property.Value as JObject;
                    var decl       = GeneratorDeclaration.Parse(declObject, packageName);
                    generators.Add(new GeneratorRefDeclaration(packageName, decl.Version, decl));
                }
                else if (property.Value.Type == JTokenType.String)
                {
                    var packageVersion = property.Value.Value <string>();
                    generators.Add(new GeneratorRefDeclaration(packageName, packageVersion));
                }
                else
                {
                    // maybe warn or throw?
                }
            }

            var modelsArray = root.GetValue("models") as JArray;

            foreach (JObject modelObject in modelsArray ?? new JArray())
            {
                ModelDeclaration modelDeclaration = ModelDeclaration.Parse(result, modelObject);
                models.Add(modelDeclaration);
            }

            var pipelinesArray = root.GetValue("pipelines") as JArray;

            foreach (JObject pipelineObject in pipelinesArray ?? new JArray())
            {
                PipelineDeclaration pipeline = PipelineDeclaration.Parse(pipelineObject);
                pipelines.Add(pipeline);
            }


            return(result);
        }