Beispiel #1
0
        public static SnookerBreak FromResult(Result res)
        {
            SnookerTableSizeEnum tableSize = SnookerTableSizeEnum.Unknown;

            if (res.Type1 != null)
            {
                tableSize = (SnookerTableSizeEnum)res.Type1.Value;
            }

            List <int> balls  = null;
            bool       isFoul = false;

            if (string.IsNullOrEmpty(res.Details1) == false)
            {
                if (res.Details1 == "foul")
                {
                    isFoul = true;
                }
                else
                {
                    balls = new List <int>();
                    string[] strs = res.Details1.Split(',');
                    foreach (string str in strs)
                    {
                        balls.Add(int.Parse(str));
                    }
                }
            }

            SnookerBreak snookerBreak = new SnookerBreak()
            {
                ID                   = res.ResultID,
                AthleteID            = res.AthleteID,
                Points               = res.Count ?? 0,
                NumberOfBalls        = res.Count2 ?? 0,
                Date                 = res.Date ?? new DateTime(2000, 1, 1),
                VenueID              = res.VenueID ?? 0,
                TableSize            = tableSize,
                Balls                = balls,
                IsFoul               = isFoul,
                OpponentAthleteID    = res.OpponentAthleteID ?? 0,
                OpponentConfirmation = (OpponentConfirmationEnum)res.OpponentConfirmation
            };

            return(snookerBreak);
        }
Beispiel #2
0
        public SnookerBreak Clone()
        {
            SnookerBreak obj = new SnookerBreak();

            obj.ID                   = this.ID;
            obj.AthleteID            = this.AthleteID;
            obj.AthleteName          = this.AthleteName;
            obj.OpponentConfirmation = this.OpponentConfirmation;
            obj.OpponentAthleteID    = this.OpponentAthleteID;
            obj.OpponentName         = this.OpponentName;
            obj.VenueID              = this.VenueID;
            obj.VenueName            = this.VenueName;
            obj.Date                 = this.Date;
            obj.TableSize            = this.TableSize;
            obj.Points               = this.Points;
            obj.NumberOfBalls        = this.NumberOfBalls;
            if (this.HasBalls)
            {
                obj.Balls = this.Balls.ToList();
            }
            obj.FrameNumber = this.FrameNumber;
            obj.IsFoul      = this.IsFoul;
            return(obj);
        }
        public static SnookerMatchScore FromScore(int athleteID, Score score)
        {
            SnookerMatchScore match = new SnookerMatchScore();

            match.ID                = score.ScoreID;
            match.YourAthleteID     = score.AthleteAID;
            match.OpponentAthleteID = score.AthleteBID;
            match.VenueID           = score.VenueID ?? 0;
            match.Date              = score.Date;
            match.IsUnfinished      = score.IsUnfinished;
            if (score.Type1 == null)
            {
                match.TableSize = SnookerTableSizeEnum.Unknown;
            }
            else
            {
                match.TableSize = (SnookerTableSizeEnum)score.Type1.Value;
            }
            match.MatchScoreA          = score.PointsA;
            match.MatchScoreB          = score.PointsB;
            match.OpponentConfirmation = (OpponentConfirmationEnum)score.AthleteBConfirmation;

            match.FrameScores = new List <SnookerFrameScore>();
            for (int i = 1; i <= 10; ++i)
            {
                int a = score.InnerPointsA[i - 1];
                int b = score.InnerPointsB[i - 1];
                if (a > 0 || b > 0)
                {
                    match.FrameScores.Add(new SnookerFrameScore()
                    {
                        A = a, B = b
                    });
                }
            }

            if (score.AthleteBID == athleteID)
            {
                // invert all
                match.YourAthleteID     = score.AthleteBID;
                match.OpponentAthleteID = score.AthleteAID;
                match.MatchScoreA       = score.PointsB;
                match.MatchScoreB       = score.PointsA;
                foreach (var frame in match.FrameScores)
                {
                    var a = frame.A;
                    frame.A = frame.B;
                    frame.B = a;
                }
            }

            // breaks
            if (score.ExtraData != null)
            {
                try
                {
                    List <SnookerBreakDataCompressed> breaks = Newtonsoft.Json.JsonConvert.DeserializeObject <List <SnookerBreakDataCompressed> >(score.ExtraData);
                    match.YourBreaks     = new List <SnookerBreak>();
                    match.OpponentBreaks = new List <SnookerBreak>();
                    foreach (SnookerBreakDataCompressed compressed in breaks)
                    {
                        SnookerBreak snookerBreak = new SnookerBreak()
                        {
                            Date          = compressed.Date,
                            Points        = compressed.Points,
                            NumberOfBalls = compressed.Number,
                            Balls         = compressed.Balls.ToList(),
                            FrameNumber   = compressed.Frame,
                            IsFoul        = compressed.IsFoul
                        };
                        if (compressed.AthleteID == match.OpponentAthleteID)
                        {
                            snookerBreak.AthleteID         = match.OpponentAthleteID;
                            snookerBreak.OpponentAthleteID = match.YourAthleteID;
                            match.OpponentBreaks.Add(snookerBreak);
                        }
                        else
                        {
                            snookerBreak.AthleteID         = match.YourAthleteID;
                            snookerBreak.OpponentAthleteID = match.OpponentAthleteID;
                            match.YourBreaks.Add(snookerBreak);
                        }
                    }
                }
                catch (Exception)
                {
                    match.YourBreaks     = null;
                    match.OpponentBreaks = null;
                }
            }

            return(match);
        }