using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Collections.ObjectModel;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
public class ActiveDbPrimaryServer
public string serverName { get; set; }
public string serverAddress { get; set; }
public string mode { get; set; }
public string resourceName { get; set; }
public ActiveDbPrimaryServer activeDbPrimaryServer { get; set; }
public string activeDbCatalog { get; set; }
public string activeDBUserId { get; set; }
public string activeDBPassword { get; set; }
public string stepsType { get; set; }
public string wizardType { get; set; }
public Config config { get; set; }
public List<Step> steps { get; set; }
public static void Test()
Console.WriteLine("\n\nSimple navigation");
var jsonRoot = JsonConvert.DeserializeObject<Root>(GetJson());
var activesDBs = jsonRoot.steps.Select( x=> x.config.activeDbPrimaryServer);
foreach(var activesDB in activesDBs){
Console.WriteLine(activesDB.serverAddress);
Console.WriteLine(activesDB.serverName);
Console.WriteLine("\n\nnull expected. Wrong deserialization type.");
var jsonDB = JsonConvert.DeserializeObject<ActiveDbPrimaryServer>(GetJson());
Console.WriteLine("\n\nLet's try partial. ");
JObject rootObj = JObject.Parse(GetJson());
IList<JToken> results = rootObj["steps"].Children()
["config"]["activeDbPrimaryServer"].ToList();
IList<ActiveDbPrimaryServer> dbResults = new List<ActiveDbPrimaryServer>();
foreach (JToken result in results)
ActiveDbPrimaryServer dbResult = result.ToObject<ActiveDbPrimaryServer>();
""stepsType"": ""runWizard"",
""wizardType"": ""demoServer"",
""resourceName"": ""demo server 1"",
""activeDbPrimaryServer"": {
""serverAddress"": ""abc.demo.local""
""activeDbCatalog"": ""demoActiveDB"",
""activeDBUserId"": ""sa"",
""activeDBPassword"": ""xyz"",
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , GetNetCoreVersion());
Console.WriteLine("{0} version: {1}", typeof(JsonSerializer).Assembly.GetName().Name, typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");
public static string GetNetCoreVersion()
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];