Exemplo n.º 1
0
        public ResourceLinkModel(ResourceLink link, ResourceDescriptor destinationResourceDescriptor)
            : this()
        {
            Id = link.Id;
            Relation = link.Relation;
            DestinationResourceName = link.DestinationResourceName;

            foreach (var linkParam in link.Parameters)
            {
                var param = destinationResourceDescriptor.InputPramameters.FirstOrDefault(p => p.Name == linkParam.Name);
                if (param != null)
                {
                    var paramModel = new ResourceLinkParameterModel
                    {
                        Name = linkParam.Name,
                        Value = linkParam.Value,
                        UseFixedValue = linkParam.UseFixedValue,
                        Required = param.Required,
                        ParameterType = param.ParameterType.Name
                    };

                    if (param.Required)
                    {
                        RequiredParameters.Add(paramModel);
                    }
                    else
                    {
                        OptionalParameters.Add(paramModel);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public ActionResult LoadLinkParametersWithDefault(string sourceResourceName, string destinationResourceName)
        {
            var sourceResource = _resourceDescriptorProvider.GetDescriptor(sourceResourceName);
            var destinationResource = _resourceDescriptorProvider.GetDescriptor(destinationResourceName);

            var requiredParams = new List<ResourceLinkParameterModel>();
            var optionalParams = new List<ResourceLinkParameterModel>();

            foreach (var param in destinationResource.InputPramameters)
            {
                var paramModel = new ResourceLinkParameterModel
                {
                    Name = param.Name,
                    ParameterType = param.ParameterType.Name,
                    Required = param.Required
                };

                // Populate default value for required parameters
                var fromParam = sourceResource.OutputParameters.FirstOrDefault(p => p.ParameterType == param.ParameterType
                                                                                    && p.Name.Equals(paramModel.Name, StringComparison.OrdinalIgnoreCase));

                if (fromParam != null)
                {
                    paramModel.Value = fromParam.Name;
                }

                if (param.Required)
                {
                    requiredParams.Add(paramModel);
                }
                else
                {
                    optionalParams.Add(paramModel);
                }
            }

            return JsonNet(new
            {
                RequiredParameters = requiredParams,
                OptionalParameters = optionalParams
            })
            .UsingClientConvention();
        }