Esempio n. 1
0
            protected override MatchSet GetTextBetweenDoubleQuotes(string text)
            {
                if (text.Contains("„"))
                {
                    var result = BetweenDoubleQuotesDeRegex.Matches(text);

                    var matches = new List <Match>();

                    foreach (Match match in result)
                    {
                        matches.Add(match);
                    }

                    foreach (Match match in SplitDoubleQuotesDeRegex.Matches(text))
                    {
                        matches.Add(match);
                    }

                    return(new MatchSet(matches));
                }

                if (text.Contains(",,"))
                {
                    var result = new MatchSet(BetweenUnconventionalDoubleQuoteDeRegex.Matches(text));

                    return(result);
                }

                return(base.GetTextBetweenDoubleQuotes(text));
            }
Esempio n. 2
0
        protected void SaveMatch()
        {
            if (MatchSet == null)
            {
                throw new InvalidOperationException($"{nameof(MatchSet)} cannot be null");
            }
            if (EditModel == null)
            {
                throw new InvalidOperationException($"{nameof(EditModel)} cannot be null");
            }
            if (EditModel.GolferA == null)
            {
                throw new InvalidOperationException($"{nameof(EditModel.GolferA)} cannot be null");
            }
            if (EditModel.GolferB == null)
            {
                throw new InvalidOperationException($"{nameof(EditModel.GolferB)} cannot be null");
            }

            var match = MatchSet.AddResult(EditModel.GolferA, EditModel.ScoreA, EditModel.PointsA, EditModel.PlayAgainA,
                                           EditModel.GolferB, EditModel.ScoreB, EditModel.PointsB, EditModel.PlayAgainB);

            leagueData.Add(match);
            leagueData.Commit();
            RefreshData();

            EditModel = null;
        }
Esempio n. 3
0
        public void TestInvalidGoal()
        {
            var matchSet  = new MatchSet("UUUUUUUUUUUU");
            var isSuccess = matchSet.AddGoal("");

            Assert.IsFalse(isSuccess);
        }
Esempio n. 4
0
        private void btnRunBatch_Click(object sender, EventArgs e)
        {
            string   workingPath = null;
            MatchSet matches     = null;
            AutomatedMatchesSettingsForm form = new AutomatedMatchesSettingsForm();

            if (form.ShowDialog() == DialogResult.OK)
            {
                string       controlFileName = form.ControlFile;
                StreamReader reader          = new StreamReader(controlFileName);
                workingPath = Path.GetFullPath(controlFileName).Substring(0, Path.GetFullPath(controlFileName).LastIndexOf(Path.DirectorySeparatorChar));
                matches     = Program.Manager.LoadMatches(reader, workingPath);
                string outputFileName = workingPath + Path.DirectorySeparatorChar +
                                        "results " + DateTime.Now.ToString("yyyy-MM-dd HH_mm") + " " +
                                        controlFileName.Substring(controlFileName.LastIndexOf(Path.DirectorySeparatorChar) >= 0 ?
                                                                  controlFileName.LastIndexOf(Path.DirectorySeparatorChar) + 1 : 0);
                if (form.OutputFileToResume != null)
                {
                    outputFileName = form.OutputFileToResume;
                }
                if (matches != null)
                {
                    AutomatedMatchesProgressForm form2 = new AutomatedMatchesProgressForm(matches, workingPath, outputFileName);
                    form2.Show();
                }
            }
        }
Esempio n. 5
0
        public void CanCreateMatchSetResult()
        {
            var season = new Season()
            {
                Name = seasonName, Id = 310
            };
            var week = new MatchSet()
            {
                Date = matchSetDate
            };
            var matchSet = season.AddWeek(week);

            var golfer1 = new Golfer()
            {
                Id             = 1,
                LeagueHandicap = 10
            };

            var golfer2 = new Golfer
            {
                Id             = 2,
                LeagueHandicap = 7
            };

            var match = matchSet.AddResult(golfer1, 3, 3.5m, true, golfer2, 2, 7.5m, false);

            Assert.Equal(1, matchSet.Matches.Count);
            Assert.Equal(11, matchSet.Matches.First().Players.Sum(p => p.Points));
        }
Esempio n. 6
0
        // *** CONSTRUCTION *** //

        public AutomatedMatchesProgressForm(MatchSet matchSet, string workingPath, string outputFileName)
        {
            this.workingPath = workingPath;
            OutputFileName   = outputFileName;
            MatchSet         = matchSet;
            inProgress       = false;
            InitializeComponent();
        }
Esempio n. 7
0
        private bool DidChallangerWinThisSet(MatchSet set)
        {
            if (set.Challanger > set.Deffender && (set.ChallengerTieBreak == 0 && set.DeffenderTieBreak == 0))
            {
                return(true);
            }

            return(set.ChallengerTieBreak > set.DeffenderTieBreak);
        }
Esempio n. 8
0
        /// <summary>
        /// Given a MatchSet and a function delegate, return an object of generic type
        /// </summary>
        /// <typeparam name="T">
        /// The type of the object that should be returned by the call.  Need to match the return type
        /// of the delegate
        /// </typeparam>
        /// <param name="matches">
        /// A matchset as returned from a call to .Match()
        /// </param>
        /// <param name="function">
        /// A function delegate that accepts a MatchSet and returns a defined generic type.
        /// This is one way to provide a looser, inline technique for defining the conversion from
        /// Matched Tokens to an object of type T
        /// </param>
        /// <returns></returns>
        public static T Transform <T>(this MatchSet matches, Func <MatchSet, T> function)
        {
            if (matches.MatchedPatterns.Count() == 0)
            {
                return(default(T));
            }

            return(function.Invoke(matches));
        }
Esempio n. 9
0
        public void TestOneHomeGoal()
        {
            var matchSet = new MatchSet("UUUUUUUUUUUU");

            matchSet.AddGoal("h2");
            var text  = matchSet.GetText();
            var lines = text.Split('\n');

            Assert.AreEqual("Kamp 02 1-0 H Feil (Du tippet U)", lines[1]);
        }
Esempio n. 10
0
        public void Setup()
        {
            _response = JsonConvert.DeserializeObject <MatchSet <Model.HaloWars2.Stats.PlayerMatch> >(File.ReadAllText(Json));

            var mock = new Mock <IHaloSession>();

            mock.Setup(m => m.Get <MatchSet <Model.HaloWars2.Stats.PlayerMatch> >(It.IsAny <string>()))
            .ReturnsAsync(_response);

            _mockSession = mock.Object;
        }
Esempio n. 11
0
        public void TestNoGoals()
        {
            var matchSet = new MatchSet("UUUUUUUUUUUU");
            var text     = matchSet.GetText();
            var lines    = text.Split('\n');

            for (var i = 0; i < 12; i++)
            {
                Assert.AreEqual($"Kamp {(i + 1):D2} 0-0 U Riktig", lines[i]);
            }
        }
Esempio n. 12
0
        public void Setup()
        {
            _matchSet = JsonConvert.DeserializeObject <MatchSet <PlayerMatch> >(File.ReadAllText(Halo5Config.MatchesJsonPath));

            var mock = new Mock <IHaloSession>();

            mock.Setup(m => m.Get <MatchSet <PlayerMatch> >(It.IsAny <string>()))
            .ReturnsAsync(_matchSet);

            _mockSession = mock.Object;
        }
Esempio n. 13
0
        public void CanCeateSetOfMatches()
        {
            var season = new Season()
            {
                Name = seasonName, Id = 103
            };
            var week     = new MatchSet(matchSetDate);
            var matchSet = season.AddWeek(week);

            Assert.Equal(103, matchSet.SeasonId);
            Assert.Equal(matchSetDate, matchSet.Date);
        }
Esempio n. 14
0
 public void TestInvalidBet()
 {
     try
     {
         var matchSet = new MatchSet("sjkdg");
         Assert.Fail();
     }
     catch (ArgumentException e)
     {
         Assert.Pass();
     }
 }
Esempio n. 15
0
        public async Task <CreateMatchSetResult> Handle(CreateMatchSetCommand command, CancellationToken cancel)
        {
            var set = new MatchSet
            {
                SeasonId       = command.SeasonId,
                MatchSetNumber = _db.MatchSets.Max(ms => ms.MatchSetNumber) + 1
            };

            _db.MatchSets.Add(set);
            await _db.SaveChangesAsync();

            return(new CreateMatchSetResult {
                MatchSet = set
            });
        }
        public void CanSaveSeasonGraph()
        {
            using var dbInstance = new LeagueDbInstance(nameof(CanSaveSeasonGraph));
            var data = new LeagueData(dbInstance.NewContext());

            var season = new Season()
            {
                Name = nameof(CanSaveSeasonGraph)
            };
            var golferA = new Golfer {
                Id = 1, LeagueHandicap = 8
            };
            var golferB = new Golfer {
                Id = 3, LeagueHandicap = 2
            };
            var golferC = new Golfer {
                Id = 5, LeagueHandicap = 2
            };
            var golferD = new Golfer {
                Id = 7, LeagueHandicap = 2
            };

            var week1 = new MatchSet(DateTime.Now);

            season.AddWeek(week1);
            week1.AddResult(golferA, 44, 7, true, golferB, 36, 4, false);
            week1.AddResult(golferC, 44, 7, true, golferD, 36, 4, false);

            var week2 = new MatchSet(DateTime.Now);

            season.AddWeek(week2);
            week2.AddResult(golferA, 44, 7, true, golferD, 36, 4, false);
            week2.AddResult(golferB, 44, 7, true, golferC, 36, 4, false);

            data.Add(season, golferA, golferB, golferC, golferD);
            data.Commit();

            var checkData   = new LeagueData(dbInstance.NewContext());
            var query       = new SeasonDetailQuery(season.Id);
            var checkSeason = checkData.Execute(query);

            Assert.Equal(2, checkSeason.Weeks.Count);
            Assert.Equal(2, checkSeason.Weeks.First().Matches.Count);
        }
Esempio n. 17
0
        IEnumerable <MatchSet> CreateTestSets()
        {
            var golfers = new List <Golfer>()
            {
                new Golfer {
                    Id = 1, FirstName = "Scott", LastName = "Allen", LeagueHandicap = 12
                },
                new Golfer {
                    Id = 2, FirstName = "Two", LastName = "Allen", LeagueHandicap = 1
                },
                new Golfer {
                    Id = 3, FirstName = "Three", LastName = "Allen", LeagueHandicap = 2
                },
                new Golfer {
                    Id = 4, FirstName = "Four", LastName = "Allen", LeagueHandicap = 3
                },
                new Golfer {
                    Id = 5, FirstName = "Five", LastName = "Allen", LeagueHandicap = 4
                },
                new Golfer {
                    Id = 6, FirstName = "Six", LastName = "Allen", LeagueHandicap = 5
                },
            };

            var sets = new List <MatchSet>();

            for (var i = 0; i < 15; i++)
            {
                var set = new MatchSet(DateTime.Now.AddDays(-i));
                sets.Add(set);
                CreateTestResult(set, golfers);
            }

            var lastSet = new MatchSet(DateTime.Now.AddDays(-100));

            sets.Add(lastSet);
            lastSet.AddResult(golfers[0], 50, 1, true, golfers[1], 34, 10, true);
            lastSet.AddResult(golfers[2], 50, 1, true, golfers[3], 37, 10, true);
            lastSet.AddResult(golfers[4], 50, 1, true, golfers[5], 38, 10, true);

            return(sets);
        }
Esempio n. 18
0
        public MatchSet Match(List <TaggedToken> tokens)
        {
            if (tokens == null)
            {
                throw new ArgumentNullException("tokens");
            }

            var validation = this.ValidateMatcher();

            if (!validation.IsValid)
            {
                var ex = new InvalidOperationException("The Matcher is in an invalid state.  Check the Data Collection for more details");
                ex.Data["messages"] = validation.ValidationMessages;
                throw ex;
            }


            MatchSet       ret        = new MatchSet();
            List <Pattern> candidates = PatternMaker.MakePatterns(tokens);

            // For the reference of callers that recieve the MatchSet, the original set of
            // tokens is included.
            ret.Tokens = tokens;

            // Iterate over all of the candidate.  For matches, include them in a matched list.  For
            // Unmatched items, put in the unmatched list.
            foreach (var candidate in candidates)
            {
                if (IsMatch(candidate))
                {
                    ret.MatchedPatterns.Add(candidate);
                }
                else
                {
                    ret.UnmatchedPatterns.Add(candidate);
                }
            }

            return(ret);
        }
Esempio n. 19
0
        public void MatchPointsAlwaysTotalEleven(decimal scoreA, decimal scoreB)
        {
            var season = new Season()
            {
                Name = seasonName
            };
            var matchSet = new MatchSet(matchSetDate);

            season.AddWeek(matchSet);

            var golfer1 = new Golfer {
                Id = 1, LeagueHandicap = 10
            };
            var golfer2 = new Golfer {
                Id = 2, LeagueHandicap = 7
            };


            var match = matchSet.AddResult(golfer1, 3, scoreA, true, golfer2, 2, scoreB, false);

            Assert.Equal(11, match.Players.Sum(p => p.Points));
        }
Esempio n. 20
0
        public override IList <SrcOp> Set(GrammarAST setAST, GrammarAST labelAST, bool invert)
        {
            MatchSet matchOp;

            if (invert)
            {
                matchOp = new MatchNotSet(this, setAST);
            }
            else
            {
                matchOp = new MatchSet(this, setAST);
            }
            if (labelAST != null)
            {
                string       label = labelAST.Text;
                RuleFunction rf    = GetCurrentRuleFunction();
                if (labelAST.Parent.Type == ANTLRParser.PLUS_ASSIGN)
                {
                    DefineImplicitLabel(setAST, matchOp);
                    TokenListDecl l = GetTokenListLabelDecl(label);
                    rf.AddContextDecl(setAST.GetAltLabel(), l);
                }
                else
                {
                    Decl d = GetTokenLabelDecl(label);
                    matchOp.labels.Add(d);
                    rf.AddContextDecl(setAST.GetAltLabel(), d);
                }
            }
            if (controller.NeedsImplicitLabel(setAST, matchOp))
            {
                DefineImplicitLabel(setAST, matchOp);
            }
            AddToLabelList listLabelOp = GetAddToListOpIfListLabelPresent(matchOp, labelAST);

            return(List(matchOp, listLabelOp));
        }
Esempio n. 21
0
        public List <Name> Transform(MatchSet set)
        {
            var ret  = new List <Name>();
            var name = new Name();

            if (set.MatchedPatterns.Count == 0)
            {
                return(ret);
            }

            name.First = set.Tokens[0].Value;
            name.Last  = set.Tokens[1].Value;

            ret.Add(name);

            name = new Name();

            name.First = set.Tokens[2].Value;
            name.Last  = set.Tokens[3].Value;

            ret.Add(name);

            return(ret);
        }
Esempio n. 22
0
		internal MatchScore()
		{
			for (Int16 i = 0; i <= 4; i++)
			{
				_Sets[i] = new MatchSet(i + 1, this);
			}
		}
Esempio n. 23
0
 private void CreateTestResult(MatchSet set, List <Golfer> golfers)
 {
     set.AddResult(golfers[0], 44, 10, true, golfers[1], 34, 1, true);
     set.AddResult(golfers[2], 40, 9, true, golfers[3], 37, 2, true);
     set.AddResult(golfers[4], 42, 8, true, golfers[5], 38, 3, true);
 }
Esempio n. 24
0
 private void UpdateSet(int challanger, int challengerTieBreak, int deffender, int deffenderTieBreak, MatchSet set)
 {
     set.Challanger = challanger;
     set.Deffender  = deffender;
     if (this.WasTieBreakPlayed(challengerTieBreak, deffenderTieBreak))
     {
         set.ChallengerTieBreak = challengerTieBreak;
         set.DeffenderTieBreak  = deffenderTieBreak;
     }
     else
     {
         set.ChallengerTieBreak = 0;
         set.DeffenderTieBreak  = 0;
     }
 }
Esempio n. 25
0
		internal MatchScore()
		{
			for (Int16 i = 0; i <= 4; i++)
			{
				_Sets[i] = new MatchSet(i + 1, this);
				_Sets[i].PropertyChanged += Child_PropertyChangedGeneric;
				_Sets[i].PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(MatchScore_PropertyChanged);
				//_Sets[i].PreviousSet.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_Sets[i].PreviousSet_PropertyChanged);
				//Saved += new EventHandler<Csla.Core.SavedEventArgs>(_Sets[i].MatchScore_Saved);
			}
		}
Esempio n. 26
0
 /// <summary>
 /// Given a matchset and an implementation of ITransformer<T>, return an object of type T
 /// </summary>
 /// <typeparam name="T">
 /// the type of the object that should be return by the call
 /// </typeparam>
 /// <param name="matches">
 /// A MatchSet as what might be returned from a call to .Match()
 /// </param>
 /// <param name="transformer">
 /// An implementation of ITransformer[T].  This technique is a more OO method for defining
 /// and extending behaviors that transform list of tokens and patterns to an object.
 /// </param>
 /// <returns>
 /// an instance of T
 /// </returns>
 public static T Transform <T>(this MatchSet matches, ITransformer <T> transformer) where T : new()
 {
     return(transformer.Transform(matches));
 }