Exemplo n.º 1
1
        /// <summary>
        /// If there is no real life data between seasons,
        /// change some match dates to around now for testing purposes
        /// </summary>
        private static void ChangeMatchDates(TtcDbContext context)
        {
            bool endOfSeason = !context.Matches.Any(match => match.Date > DateTime.Now);
            if (true || endOfSeason)
            {
                var passedMatches = context.Matches
                    .Where(x => x.FrenoySeason == Constants.FrenoySeason)
                    //.Where(x => x.Date < DateTime.Today)
                    .OrderByDescending(x => x.Date)
                    .Take(42);

                var timeToAdd = DateTime.Today - passedMatches.First().Date;
                foreach (var match in passedMatches.Take(20))
                {
                    match.Date = match.Date.Add(timeToAdd);
                }

                var rnd = new Random();
                foreach (var match in passedMatches.Take(20))
                {
                    match.Date = DateTime.Today.Add(TimeSpan.FromDays(rnd.Next(1, 20))).AddHours(rnd.Next(10, 20));
                    match.Description = "";
                    match.AwayScore = null;
                    match.HomeScore = null;
                    //match.IsSyncedWithFrenoy = true;
                    match.WalkOver = false;

                    context.MatchComments.RemoveRange(match.Comments.ToArray());
                    context.MatchGames.RemoveRange(match.Games.ToArray());
                    context.MatchPlayers.RemoveRange(match.Players.ToArray());
                }
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            using (var context = new TtcDbContext())
            {
                try
                {
                    //var vttlPlayers = new FrenoyPlayersApi(context, Competition.Vttl);
                    //vttlPlayers.StopAllPlayers();
                    //vttlPlayers.SyncPlayers();
                    //var sportaPlayers = new FrenoyPlayersApi(context, Competition.Sporta);
                    //sportaPlayers.SyncPlayers();


                    //Configuration.Seed(context, false);

                    //var vttl = new FrenoyMatchesApi(context, Competition.Vttl);
                    //vttl.SyncTeamsAndMatches();
                    //var sporta = new FrenoyMatchesApi(context, Competition.Sporta);
                    //sporta.SyncTeamsAndMatches();

                    ChangeMatchDates(context);

                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    Console.ReadKey();
                }
            }
        }
 private static void CreateSystemUser(TtcDbContext context)
 {
     // Clublokaal user account
     context.Players.AddOrUpdate(p => p.NaamKort, new PlayerEntity
     {
         Gestopt   = 1,
         FirstName = "SYSTEM",
         NaamKort  = "SYSTEM",
         Toegang   = PlayerToegang.System
     });
     //context.Database.ExecuteSqlCommand("UPDATE speler SET paswoord=MD5('system') WHERE FirstName='SYSTEM' AND paswoord IS NULL");
 }
        /// <summary>
        /// Adds the matches and syncs the players for the new season
        /// </summary>
        /// <returns>The new season year</returns>
        public static async Task <int> Seed(TtcDbContext context, bool clearMatches)
        {
            // TODO: Season 2020: Add GetOpponentMatches to initial seed (remove from MatchService)

            //if (clearMatches)
            //{
            //    context.Database.ExecuteSqlCommand("DELETE FROM matchplayer");
            //    context.Database.ExecuteSqlCommand("DELETE FROM matchgame");
            //    context.Database.ExecuteSqlCommand("DELETE FROM matchcomment");
            //    context.Database.ExecuteSqlCommand("DELETE FROM matches");
            //}

            //int newYear = context.CurrentFrenoySeason + 1;
            int newYear       = DateTime.Today.Year;
            int newFrenoyYear = newYear - 2000 + 1;

            if (DateTime.Today.Month < 7)
            {
                throw new Exception($"Starting new season {newYear}? That doesn't seem right?");
            }
            if (!context.Matches.Any(x => x.FrenoySeason == newFrenoyYear))
            {
                // VTTL
                var vttlPlayers = new FrenoyPlayersApi(context, Competition.Vttl);
                await vttlPlayers.StopAllPlayers(true);

                await vttlPlayers.SyncPlayers();

                var vttl = new FrenoyMatchesApi(context, Competition.Vttl);
                await vttl.SyncTeamsAndMatches();


                // Sporta
                var sportaPlayers = new FrenoyPlayersApi(context, Competition.Sporta);
                await sportaPlayers.StopAllPlayers(true);

                await sportaPlayers.SyncPlayers();

                var sporta = new FrenoyMatchesApi(context, Competition.Sporta);
                await sporta.SyncTeamsAndMatches();
            }

            //CreateSystemUser(context);

            return(newYear);
        }
Exemplo n.º 5
0
        public FrenoySync(FrenoySyncOptions options, bool isVttl = true)
        {
            _db = new TtcDbContext();

            #region Switch between VTTL and Sporta here
            // TODO: Pointless to use the EF logging: Parameter values are not part of the output...
            //_logFileInfo = new FileInfo(@"C:\temp\log" + DateTime.Now.ToString("hh:mm:ss").Replace(":", "") + ".txt");
            //_logFile = new StreamWriter(_logFileInfo.FullName);
            //_db.Database.Log = message => _log.AppendLine(message);

            // TODO: The logs contain parameters without the values, so the queries are useless
            // -> Perhaps Glimpse can help here? It got some parameter replacement thingie

            _options = options;
            //CheckPlayers();

            _isVttl = isVttl;
            //string wsdl;
            if (isVttl)
            {
                _thuisClubId = _db.Clubs.Single(x => x.CodeVttl == options.FrenoyClub).Id;
                //wsdl = FrenoyVttlWsdlUrl;
            }
            else
            {
                // Sporta
                _thuisClubId = _db.Clubs.Single(x => x.CodeSporta == options.FrenoyClub).Id;
                //wsdl = FrenoySportaWsdlUrl;
            }

            // Aparently the signatures for VTTL and Sporta are not identical
            // Problem is probably stuff like: xmlns="http://api.frenoy.net/TabTAPI" in the body
            //var binding = new BasicHttpBinding();
            //binding.Security.Mode = BasicHttpSecurityMode.None;
            //var endpoint = new EndpointAddress(wsdl);
            //_frenoy = new TabTAPI_PortTypeClient(binding, endpoint);
            #endregion

            // Right click the Service Reference and update with different Url...
            _frenoy = new FrenoyVttl.TabTAPI_PortTypeClient();
        }