Пример #1
0
 internal void CopyFrom(SetResult setResult)
 {
     this.Number = setResult.Number;
     this.Player1Games = setResult.Player1Games;
     this.Player2Games = setResult.Player2Games;
     this.Player1TieBreak = setResult.Player1TieBreak;
     this.Player2TieBreak = setResult.Player2TieBreak;
 }
        private void ParseMatchResult(Match match, string result)
        {
            if (string.IsNullOrEmpty(result))
            {
                return;
            }

            var setResults = new List<SetResult>();

            var sets = result.Trim().Split(' ');
            for (var i = 0; i < sets.Length; i++)
            {
                var set = sets[i];

                var setResult = new SetResult();
                if (set.Contains('-') && set.Split(new[] { "-" }, StringSplitOptions.RemoveEmptyEntries).Length == 2)
                {
                    setResult.Number = i + 1;
                    setResult.Player1 = match.Player1;
                    setResult.Player2 = match.Player2;
                    setResult.Player1Games = int.Parse(set.Split('-')[0]);
                    setResult.Player2Games = int.Parse(set.Split('-')[1]);

                    if (match.SetResults != null && match.SetResults.Count > i)
                    {
                        var existingSetResult = match.SetResults[i];
                        existingSetResult.CopyFrom(setResult);
                        setResults.Add(existingSetResult);
                    }
                    else
                    {
                        setResults.Add(setResult);
                    }
                }
                else
                {
                    throw new ArgumentException("Set result has wrong format");
                }
            }
            match.SetResults = setResults;
        }