示例#1
0
        protected static AnimalAbstract readBaseArgument(BinaryReader br)
        {
            int            type = br.ReadInt16();
            int            id   = br.ReadInt32();
            AnimalAbstract animal;

            switch (type)
            {
            case GOAT_TYPE:
                animal = new Goat(id);
                break;

            case CATTLE_TYPE:
                animal = new Cattle(id);
                break;

            case HORSE_TYPE:
                animal = new Horse(id);
                break;

            case PIG_TYPE:
                animal = new Pig(id);
                break;

            case POULTRY_TYPE:
                animal = new Poultry(id);
                break;

            case BEE_TYPE:
                animal = new Bee(id);
                break;

            default:
                return(null);
            }

            // read base info
            animal.isEncrypt       = br.ReadBoolean();
            animal.key             = br.ReadString();
            animal.year            = br.ReadInt16();
            animal.month           = br.ReadInt16();
            animal.day             = br.ReadInt16();
            animal.species         = br.ReadString();
            animal.country         = br.ReadInt32();
            animal.region          = br.ReadString();
            animal.latitudeDegree  = br.ReadInt32();
            animal.latitudeMinute  = br.ReadInt32();
            animal.latitudeSecond  = br.ReadDouble();
            animal.longitudeDegree = br.ReadInt32();
            animal.longitudeMinute = br.ReadInt32();
            animal.longitudeSecond = br.ReadDouble();
            animal.comment         = br.ReadString();
            animal.lengthUnit      = br.ReadByte();
            animal.weightUnit      = br.ReadByte();
            readImg(br, animal);
            return(animal);
        }
示例#2
0
        public static Cattle load(string url)
        {
            FileStream   fs     = new FileStream(url, FileMode.Open);
            BinaryReader br     = new BinaryReader(fs);
            Cattle       cattle = (Cattle)readBaseArgument(br);

            try
            {
                // byte data
                cattle.gender = br.ReadByte();

                // double data
                cattle.age               = br.ReadDouble();
                cattle.liveWeight        = br.ReadDouble();
                cattle.carcassWeight     = br.ReadDouble();
                cattle.pureMeat          = br.ReadDouble();
                cattle.skinThickness     = br.ReadDouble();
                cattle.boneWeight        = br.ReadDouble();
                cattle.eyeMuscleArea     = br.ReadDouble();
                cattle.slaughterRate     = br.ReadDouble();
                cattle.meatBoneRatio     = br.ReadDouble();
                cattle.bodyLength        = br.ReadDouble();
                cattle.bodyHeight        = br.ReadDouble();
                cattle.bodyObliqueLength = br.ReadDouble();
                cattle.chest             = br.ReadDouble();
                cattle.tube              = br.ReadDouble();
                cattle.bodyWeight        = br.ReadDouble();

                // string data
                cattle.coatColor = br.ReadString();
            }
            catch (Exception e)
            {
                Console.WriteLine("data output error.");
                Console.WriteLine("error message: " + e.Message);
                Console.WriteLine("error source: " + e.Source);
                return(null);
            }
            finally
            {
                br.Close();
                fs.Close();
            }
            return(cattle);
        }