Esempio n. 1
0
        /// <summary>
        /// Read all competitions from the PES database.
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public async Task <List <Competition> > ReadCompetitionsAsync(string path)
        {
            MemoryStream memory = await this.CreateMemoryStreamAsync(path + competitionsPath);

            var reader = new BinaryReader(memory);

            int index;
            int length = Convert.ToInt32(reader.BaseStream.Length / competitionsBlock);

            reader.BaseStream.Position = 0;
            string all = System.Text.Encoding.UTF8.GetString(reader.ReadBytes(2952));


            List <PESCompetition> tempList = new List <PESCompetition>();

            for (int i = 0; i < length; i++)
            {
                index = (i * competitionsBlock);
                reader.BaseStream.Position = index;

                uint check = reader.ReadUInt32();
                //int check2 = (int)reader.ReadByte();
                //int check3 = (int)reader.ReadByte();

                reader.BaseStream.Position = index + 8;
                string name = System.Text.Encoding.UTF8.GetString(reader.ReadBytes(28)).TrimEnd('\0');

                uint id     = (check << 17) >> 25; // id
                uint region = (check << 11) >> 27; // region
                uint test   = check >> 31;
                uint test1  = (check << 2) >> 31;
                uint test2  = (check << 10) >> 27; // ?
                uint test3  = (check << 9) >> 27;
                uint test4  = (check << 8) >> 30;
                uint test5  = (check << 7) >> 31; // ?
                uint test6  = (check << 6) >> 31; // ?
                uint test7  = (check << 5) >> 31; // ?
                uint test8  = (check << 4) >> 31;
                uint test9  = (check << 3) >> 31;
                uint test10 = (check << 11) >> 26;
                uint test13 = (check << 24) >> 24;


                PESCompetition comp = new PESCompetition()
                {
                    Id       = id,
                    Name     = name,
                    Position = index,
                    RegionId = region
                };

                tempList.Add(comp);
            }

            return(await CompetitionConverter.ConvertMany(tempList));
        }
Esempio n. 2
0
        /// <summary>
        /// Convert a DB-Competition to the PES format.
        /// </summary>
        /// <param name="sourcePlayer"></param>
        /// <returns></returns>
        public static Task <PESCompetition> ConvertBack(Competition sourceCompetition)
        {
            PESCompetition converted = new PESCompetition()
            {
                Position = sourceCompetition.DatabasePosition,
                Id       = System.Convert.ToUInt32(sourceCompetition.SourceId),
                Name     = sourceCompetition.Name
            };

            return(Task.FromResult(converted));
        }
Esempio n. 3
0
        /// <summary>
        /// Converts a PES team to the DB format.
        /// </summary>
        /// <param name="sourcePlayer"></param>
        /// <returns></returns>
        public static Task <Competition> Convert(PESCompetition sourceCompetition)
        {
            var         guid      = Guid.NewGuid().ToString();
            Competition converted = new Competition()
            {
                CompetitionId    = guid,
                SourceId         = sourceCompetition.Id.ToString(),
                DatabasePosition = sourceCompetition.Position,
                Name             = sourceCompetition.Name,
                Teams            = new List <string>(),
                StartDate        = DateTime.Today
            };

            return(Task.FromResult(converted));
        }