示例#1
0
 public static RecipesUnmarshaller GetInstance()
 {
     if (instance == null)
     {
         instance = new RecipesUnmarshaller();
     }
     return(instance);
 }
        public Layer Unmarshall(JsonUnmarshallerContext context)
        {
            if (context.CurrentTokenType == JsonToken.Null)
            {
                return(null);
            }

            Layer layer = new Layer();



            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            while (context.Read())
            {
                if (context.TestExpression("StackId", targetDepth))
                {
                    context.Read();
                    layer.StackId = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("LayerId", targetDepth))
                {
                    context.Read();
                    layer.LayerId = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("Type", targetDepth))
                {
                    context.Read();
                    layer.Type = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("Name", targetDepth))
                {
                    context.Read();
                    layer.Name = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("Shortname", targetDepth))
                {
                    context.Read();
                    layer.Shortname = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("Attributes", targetDepth))
                {
                    context.Read();
                    layer.Attributes = new Dictionary <String, String>();
                    KeyValueUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller> unmarshaller = new KeyValueUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.GetInstance(), StringUnmarshaller.GetInstance());
                    while (context.Read())
                    {
                        JsonToken token = context.CurrentTokenType;
                        if (token == JsonToken.ArrayStart || token == JsonToken.ObjectStart)
                        {
                            continue;
                        }
                        if (token == JsonToken.ArrayEnd || token == JsonToken.ObjectEnd)
                        {
                            break;
                        }
                        KeyValuePair <string, string> kvp = unmarshaller.Unmarshall(context);
                        layer.Attributes.Add(kvp.Key, kvp.Value);
                    }
                    continue;
                }

                if (context.TestExpression("CustomInstanceProfileArn", targetDepth))
                {
                    context.Read();
                    layer.CustomInstanceProfileArn = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("CustomSecurityGroupIds", targetDepth))
                {
                    context.Read();
                    layer.CustomSecurityGroupIds = new List <String>();
                    StringUnmarshaller unmarshaller = StringUnmarshaller.GetInstance();
                    while (context.Read())
                    {
                        JsonToken token = context.CurrentTokenType;
                        if (token == JsonToken.ArrayStart)
                        {
                            continue;
                        }
                        if (token == JsonToken.ArrayEnd)
                        {
                            break;
                        }
                        layer.CustomSecurityGroupIds.Add(unmarshaller.Unmarshall(context));
                    }
                    continue;
                }

                if (context.TestExpression("DefaultSecurityGroupNames", targetDepth))
                {
                    context.Read();
                    layer.DefaultSecurityGroupNames = new List <String>();
                    StringUnmarshaller unmarshaller = StringUnmarshaller.GetInstance();
                    while (context.Read())
                    {
                        JsonToken token = context.CurrentTokenType;
                        if (token == JsonToken.ArrayStart)
                        {
                            continue;
                        }
                        if (token == JsonToken.ArrayEnd)
                        {
                            break;
                        }
                        layer.DefaultSecurityGroupNames.Add(unmarshaller.Unmarshall(context));
                    }
                    continue;
                }

                if (context.TestExpression("Packages", targetDepth))
                {
                    context.Read();
                    layer.Packages = new List <String>();
                    StringUnmarshaller unmarshaller = StringUnmarshaller.GetInstance();
                    while (context.Read())
                    {
                        JsonToken token = context.CurrentTokenType;
                        if (token == JsonToken.ArrayStart)
                        {
                            continue;
                        }
                        if (token == JsonToken.ArrayEnd)
                        {
                            break;
                        }
                        layer.Packages.Add(unmarshaller.Unmarshall(context));
                    }
                    continue;
                }

                if (context.TestExpression("VolumeConfigurations", targetDepth))
                {
                    context.Read();
                    layer.VolumeConfigurations = new List <VolumeConfiguration>();
                    VolumeConfigurationUnmarshaller unmarshaller = VolumeConfigurationUnmarshaller.GetInstance();
                    while (context.Read())
                    {
                        JsonToken token = context.CurrentTokenType;
                        if (token == JsonToken.ArrayStart)
                        {
                            continue;
                        }
                        if (token == JsonToken.ArrayEnd)
                        {
                            break;
                        }
                        layer.VolumeConfigurations.Add(unmarshaller.Unmarshall(context));
                    }
                    continue;
                }

                if (context.TestExpression("EnableAutoHealing", targetDepth))
                {
                    context.Read();
                    layer.EnableAutoHealing = BoolUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("AutoAssignElasticIps", targetDepth))
                {
                    context.Read();
                    layer.AutoAssignElasticIps = BoolUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("AutoAssignPublicIps", targetDepth))
                {
                    context.Read();
                    layer.AutoAssignPublicIps = BoolUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("DefaultRecipes", targetDepth))
                {
                    context.Read();
                    layer.DefaultRecipes = RecipesUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("CustomRecipes", targetDepth))
                {
                    context.Read();
                    layer.CustomRecipes = RecipesUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("CreatedAt", targetDepth))
                {
                    context.Read();
                    layer.CreatedAt = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("InstallUpdatesOnBoot", targetDepth))
                {
                    context.Read();
                    layer.InstallUpdatesOnBoot = BoolUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.CurrentDepth <= originalDepth)
                {
                    return(layer);
                }
            }


            return(layer);
        }
示例#3
0
        public Layer Unmarshall(JsonUnmarshallerContext context)
        {
            Layer layer = new Layer();

            layer.Attributes                = null;
            layer.CustomSecurityGroupIds    = null;
            layer.DefaultSecurityGroupNames = null;
            layer.Packages             = null;
            layer.VolumeConfigurations = null;

            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            while (context.Read())
            {
                if ((context.IsKey) && (context.CurrentDepth == targetDepth))
                {
                    context.Read();
                    context.Read();

                    if (context.TestExpression("StackId", targetDepth))
                    {
                        layer.StackId = StringUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("LayerId", targetDepth))
                    {
                        layer.LayerId = StringUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("Type", targetDepth))
                    {
                        layer.Type = StringUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("Name", targetDepth))
                    {
                        layer.Name = StringUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("Shortname", targetDepth))
                    {
                        layer.Shortname = StringUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("Attributes", targetDepth))
                    {
                        layer.Attributes = new Dictionary <String, String>();
                        KeyValueUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller> unmarshaller = new KeyValueUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.GetInstance(), StringUnmarshaller.GetInstance());
                        while (context.Read())
                        {
                            if (((context.IsStartArray || context.IsStartElement || context.IsLeafValue) && (context.CurrentDepth == targetDepth)) ||
                                ((context.IsKey) && (context.CurrentDepth == targetDepth + 1)))
                            {
                                KeyValuePair <string, string> kvp = unmarshaller.Unmarshall(context);
                                layer.Attributes.Add(kvp.Key, kvp.Value);
                            }
                            else if (context.IsEndElement)
                            {
                                break;
                            }
                        }
                        continue;
                    }

                    if (context.TestExpression("CustomInstanceProfileArn", targetDepth))
                    {
                        layer.CustomInstanceProfileArn = StringUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("CustomSecurityGroupIds", targetDepth))
                    {
                        layer.CustomSecurityGroupIds = new List <String>();
                        StringUnmarshaller unmarshaller = StringUnmarshaller.GetInstance();
                        while (context.Read())
                        {
                            if ((context.IsArrayElement) && (context.CurrentDepth == targetDepth))
                            {
                                layer.CustomSecurityGroupIds.Add(unmarshaller.Unmarshall(context));
                            }
                            else if (context.IsEndArray)
                            {
                                break;
                            }
                        }
                        continue;
                    }

                    if (context.TestExpression("DefaultSecurityGroupNames", targetDepth))
                    {
                        layer.DefaultSecurityGroupNames = new List <String>();
                        StringUnmarshaller unmarshaller = StringUnmarshaller.GetInstance();
                        while (context.Read())
                        {
                            if ((context.IsArrayElement) && (context.CurrentDepth == targetDepth))
                            {
                                layer.DefaultSecurityGroupNames.Add(unmarshaller.Unmarshall(context));
                            }
                            else if (context.IsEndArray)
                            {
                                break;
                            }
                        }
                        continue;
                    }

                    if (context.TestExpression("Packages", targetDepth))
                    {
                        layer.Packages = new List <String>();
                        StringUnmarshaller unmarshaller = StringUnmarshaller.GetInstance();
                        while (context.Read())
                        {
                            if ((context.IsArrayElement) && (context.CurrentDepth == targetDepth))
                            {
                                layer.Packages.Add(unmarshaller.Unmarshall(context));
                            }
                            else if (context.IsEndArray)
                            {
                                break;
                            }
                        }
                        continue;
                    }

                    if (context.TestExpression("VolumeConfigurations", targetDepth))
                    {
                        layer.VolumeConfigurations = new List <VolumeConfiguration>();
                        VolumeConfigurationUnmarshaller unmarshaller = VolumeConfigurationUnmarshaller.GetInstance();
                        while (context.Read())
                        {
                            if ((context.IsArrayElement) && (context.CurrentDepth == targetDepth))
                            {
                                layer.VolumeConfigurations.Add(unmarshaller.Unmarshall(context));
                            }
                            else if (context.IsEndArray)
                            {
                                break;
                            }
                        }
                        continue;
                    }

                    if (context.TestExpression("EnableAutoHealing", targetDepth))
                    {
                        layer.EnableAutoHealing = BoolUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("AutoAssignElasticIps", targetDepth))
                    {
                        layer.AutoAssignElasticIps = BoolUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("DefaultRecipes", targetDepth))
                    {
                        layer.DefaultRecipes = RecipesUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("CustomRecipes", targetDepth))
                    {
                        layer.CustomRecipes = RecipesUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("CreatedAt", targetDepth))
                    {
                        layer.CreatedAt = StringUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }

                    if (context.TestExpression("InstallUpdatesOnBoot", targetDepth))
                    {
                        layer.InstallUpdatesOnBoot = BoolUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth <= originalDepth)
                {
                    return(layer);
                }
            }


            return(layer);
        }
        public Layer Unmarshall(JsonUnmarshallerContext context)
        {
            context.Read();
            if (context.CurrentTokenType == JsonToken.Null)
            {
                return(null);
            }
            Layer layer = new Layer();


            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("StackId", targetDepth))
                {
                    layer.StackId = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("LayerId", targetDepth))
                {
                    layer.LayerId = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("Type", targetDepth))
                {
                    layer.Type = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("Name", targetDepth))
                {
                    layer.Name = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("Shortname", targetDepth))
                {
                    layer.Shortname = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("Attributes", targetDepth))
                {
                    var unmarshaller = new DictionaryUnmarshaller <String, String, StringUnmarshaller, StringUnmarshaller>(
                        StringUnmarshaller.GetInstance(), StringUnmarshaller.GetInstance());
                    layer.Attributes = unmarshaller.Unmarshall(context);

                    continue;
                }

                if (context.TestExpression("CustomInstanceProfileArn", targetDepth))
                {
                    layer.CustomInstanceProfileArn = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("CustomSecurityGroupIds", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <String, StringUnmarshaller>(
                        StringUnmarshaller.GetInstance());
                    layer.CustomSecurityGroupIds = unmarshaller.Unmarshall(context);

                    continue;
                }

                if (context.TestExpression("DefaultSecurityGroupNames", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <String, StringUnmarshaller>(
                        StringUnmarshaller.GetInstance());
                    layer.DefaultSecurityGroupNames = unmarshaller.Unmarshall(context);

                    continue;
                }

                if (context.TestExpression("Packages", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <String, StringUnmarshaller>(
                        StringUnmarshaller.GetInstance());
                    layer.Packages = unmarshaller.Unmarshall(context);

                    continue;
                }

                if (context.TestExpression("VolumeConfigurations", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <VolumeConfiguration, VolumeConfigurationUnmarshaller>(
                        VolumeConfigurationUnmarshaller.GetInstance());
                    layer.VolumeConfigurations = unmarshaller.Unmarshall(context);

                    continue;
                }

                if (context.TestExpression("EnableAutoHealing", targetDepth))
                {
                    layer.EnableAutoHealing = BoolUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("AutoAssignElasticIps", targetDepth))
                {
                    layer.AutoAssignElasticIps = BoolUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("AutoAssignPublicIps", targetDepth))
                {
                    layer.AutoAssignPublicIps = BoolUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("DefaultRecipes", targetDepth))
                {
                    layer.DefaultRecipes = RecipesUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("CustomRecipes", targetDepth))
                {
                    layer.CustomRecipes = RecipesUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("CreatedAt", targetDepth))
                {
                    layer.CreatedAt = StringUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("InstallUpdatesOnBoot", targetDepth))
                {
                    layer.InstallUpdatesOnBoot = BoolUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("UseEbsOptimizedInstances", targetDepth))
                {
                    layer.UseEbsOptimizedInstances = BoolUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }
            }

            return(layer);
        }