Beispiel #1
0
        public FarmResponse ConvertFarm(string yaml)
        {
            FarmResponse response = new FarmResponse();

            Farm <string, string> animalStringString = null;
            Farm <Dog, string>    animalDogString    = null;
            Farm <string, Barn>   animalStringBarn   = null;
            Farm <Dog, Barn>      animalDogBarn      = null;

            try
            {
                animalStringString = DeserializeStringString(yaml);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                try
                {
                    animalDogString = DeserializeObjectString(yaml);
                }
                catch
                {
                    try
                    {
                        animalStringBarn = DeserializeStringObject(yaml);
                    }
                    catch
                    {
                        animalDogBarn = DeserializeObjectObject(yaml);
                    }
                    Console.WriteLine(ex.ToString());
                }
            }
            if (animalStringString != null)
            {
                response.Items.Add(animalStringString.FarmItem1);
                response.AnimalLegCount += 0;
                response.Items.Add(animalStringString.FarmItem2);
                response.BuildingCount += 0;
            }
            if (animalDogString != null)
            {
                response.Items.Add(animalDogString.FarmItem1.Name);
                response.AnimalLegCount += 4;

                response.Items.Add(animalDogString.FarmItem2);
                response.BuildingCount += 0;
            }
            if (animalStringBarn != null)
            {
                response.Items.Add(animalStringBarn.FarmItem1);
                response.AnimalLegCount += 0;

                response.Items.Add(animalStringBarn.FarmItem2.BarnType);
                response.BuildingCount += 1;
                response.BarnTools.AddRange(animalStringBarn.FarmItem2.Tools);
            }
            if (animalDogBarn != null)
            {
                response.Items.Add(animalDogBarn.FarmItem1.Name);
                response.AnimalLegCount += 4;

                response.Items.Add(animalDogBarn.FarmItem2.BarnType);
                response.BuildingCount += 1;
                response.BarnTools.AddRange(animalDogBarn.FarmItem2.Tools);
            }

            return(response);
        }
        public FarmResponse ConvertFarm(string yaml)
        {
            FarmResponse response = new FarmResponse();

            bool success = false;

            if (!success)
            {
                var animalStringString = DeserializeStringString(yaml);
                if (animalStringString != null)
                {
                    success = true;
                    response.Items.Add(animalStringString.FarmItem1);
                    response.AnimalLegCount += 0;
                    response.Items.Add(animalStringString.FarmItem2);
                    response.BuildingCount += 0;
                }
            }

            if (!success)
            {
                var animalDogString = DeserializeObjectString(yaml);
                if (animalDogString != null)
                {
                    success = true;
                    response.Items.Add(animalDogString.FarmItem1.Name);
                    response.AnimalLegCount += 4;

                    response.Items.Add(animalDogString.FarmItem2);
                    response.BuildingCount += 0;
                }
            }

            if (!success)
            {
                var animalStringBarn = DeserializeStringObject(yaml);
                if (animalStringBarn != null)
                {
                    success = true;
                    response.Items.Add(animalStringBarn.FarmItem1);
                    response.AnimalLegCount += 0;

                    response.Items.Add(animalStringBarn.FarmItem2.BarnType);
                    response.BuildingCount += 1;
                    response.BarnTools.AddRange(animalStringBarn.FarmItem2.Tools);
                }
            }

            if (!success)
            {
                var animalDogBarn = DeserializeObjectObject(yaml);
                if (animalDogBarn != null)
                {
                    success = true;
                    response.Items.Add(animalDogBarn.FarmItem1.Name);
                    response.AnimalLegCount += 4;

                    response.Items.Add(animalDogBarn.FarmItem2.BarnType);
                    response.BuildingCount += 1;
                    response.BarnTools.AddRange(animalDogBarn.FarmItem2.Tools);
                }
            }

            if (!success)
            {
                response = null;
            }

            return(response);
        }