Esempio n. 1
0
        protected override void ProcessRecord()
        {
            var nestedresource = new Models.NestedResourceTemplate()
            {
                name = ResourceName
            };

            nestedresource.properties.templateLink.uri   = String.Format(NestedTemplateResourceUri, ResourceName);
            nestedresource.properties.parametersLink.uri = String.Format(NestedTemplateParameterUri, ResourceName);

            nestedtemplate.resources.Add(JObject.FromObject(nestedresource));
            var result = JObject.FromObject(nestedtemplate);

            WriteObject(result.ToString());
        }
Esempio n. 2
0
        protected override void ProcessRecord()
        {
            var nestedresource = new Models.NestedResourceTemplate()
            {
                name = ResourceName
            };

            nestedresource.properties.templateLink.uri = String.Format(NestedTemplateResourceUri, ResourceName);

            if (AddParameterlink)
            {
                nestedresource.properties.parametersLink.uri = String.Format(NestedTemplateParameterUri, ResourceName);
            }
            else
            {
                nestedresource.properties.parametersLink = null;
                nestedresource.properties.parameters     = new JObject();


                var fileName = Path.Combine(ResourcePath, Path.GetFileName(ResourcePath) + ".json");

                using (Stream stream = File.OpenRead(fileName))
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        var nestedTemplate2 = new JsonTextReader(reader);

                        JsonSerializer se         = new JsonSerializer();
                        dynamic        parsedData = se.Deserialize(nestedTemplate2);
                        JObject        parameters = parsedData["parameters"];

                        foreach (JProperty parameter in parameters.Properties())
                        {
                            JProperty param = parameter.DeepClone() as JProperty;

                            if (nestedtemplate.parameters.ContainsKey(parameter.Name))
                            {
                                dynamic v1 = nestedtemplate.parameters[parameter.Name]; //.Value["defaultValue"]?.Value<string>();\
                                                                                        //v1.Properties[""];


                                if (parameter.Contains("defaultValue") && !JToken.DeepEquals(v1.defaultValue, parameter.Value["defaultValue"]))
                                {
                                    var paramName = GetUniqueParamName(parameter.Name);

                                    param = new JProperty($"{paramName}", parameter.Value);


                                    nestedtemplate.parameters.Add(param);
                                }
                            }
                            else
                            {
                                nestedtemplate.parameters.Add(param);
                            }

                            nestedresource.properties.parameters.Add(parameter.Name, JObject.FromObject(new { value = $"[parameters('{param.Name}')]" }));
                        }
                    }
                }
            }
            nestedtemplate.resources.Add(JObject.FromObject(nestedresource));


            var result = JObject.FromObject(nestedtemplate);

            Sort(result["parameters"]);
            WriteObject(result.ToString());
        }