示例#1
0
    private static async Task UpdateMasterGames()
    {
        _awsRegion  = ConfigurationManager.AppSettings["awsRegion"] !;
        _betaBucket = ConfigurationManager.AppSettings["betaBucket"] !;
        _productionReadOnlyConnectionString = ConfigurationManager.AppSettings["productionConnectionString"] !;
        _betaConnectionString = ConfigurationManager.AppSettings["betaConnectionString"] !;

        DapperNodaTimeSetup.Register();

        MySQLFantasyCriticUserStore productionUserStore      = new MySQLFantasyCriticUserStore(_productionReadOnlyConnectionString, _clock);
        MySQLFantasyCriticUserStore betaUserStore            = new MySQLFantasyCriticUserStore(_betaConnectionString, _clock);
        MySQLMasterGameRepo         productionMasterGameRepo = new MySQLMasterGameRepo(_productionReadOnlyConnectionString, productionUserStore);
        MySQLMasterGameRepo         betaMasterGameRepo       = new MySQLMasterGameRepo(_betaConnectionString, betaUserStore);
        MySQLBetaCleaner            cleaner = new MySQLBetaCleaner(_betaConnectionString);
        AdminService betaAdminService       = GetAdminService();

        _logger.Info("Getting master games from production");
        var productionMasterGameTags = await productionMasterGameRepo.GetMasterGameTags();

        var productionMasterGames = await productionMasterGameRepo.GetMasterGames();

        var betaMasterGameTags = await betaMasterGameRepo.GetMasterGameTags();

        var betaMasterGames = await betaMasterGameRepo.GetMasterGames();

        IReadOnlyList <MasterGameHasTagEntity> productionGamesHaveTagEntities = await GetProductionGamesHaveTagEntities();

        await cleaner.UpdateMasterGames(productionMasterGameTags, productionMasterGames, betaMasterGameTags,
                                        betaMasterGames, productionGamesHaveTagEntities);

        await betaAdminService.RefreshCaches();
    }
        public RequestChangeOfSupplierTests()
        {
            var services = new ServiceCollection();

            _connectionString =
                Environment.GetEnvironmentVariable("MarketData_IntegrationTests_ConnectionString");

            services.AddScoped <IDbConnectionFactory>(sp => new SqlDbConnectionFactory(_connectionString));
            services.AddScoped <IUnitOfWorkCallback, UnitOfWorkCallback>();
            services.AddScoped <ISystemDateTimeProvider, SystemDateTimeProviderStub>();
            services.AddScoped <IEventPublisher, EventPublisherStub>();
            services.AddScoped <IActorMessagePublisher, ActorMessagePublisher>();
            services.AddScoped <IMeteringPointRepository, MeteringPointRepository>();
            services.AddScoped <IEnergySupplierRepository, EnergySupplierRepository>();

            services.AddMediatR(new[]
            {
                typeof(RequestChangeSupplierCommandHandler).Assembly,
            });

            services.AddScoped(typeof(IPipelineBehavior <,>), typeof(UnitOfWorkHandlerBehavior <,>));
            services.AddScoped(typeof(IPipelineBehavior <,>), typeof(PublishIntegrationEventsHandlerBehavior <,>));
            services.AddScoped <IPipelineBehavior <RequestChangeOfSupplier, RequestChangeOfSupplierResult>, PublishActorMessageHandlerBehavior>();

            services.AddGreenEnergyHub(typeof(RequestChangeOfSupplier).Assembly);

            DapperNodaTimeSetup.Register();

            _serviceProvider          = services.BuildServiceProvider();
            _mediator                 = _serviceProvider.GetRequiredService <IMediator>();
            _meteringPointRepository  = _serviceProvider.GetRequiredService <IMeteringPointRepository>();
            _energySupplierRepository = _serviceProvider.GetRequiredService <IEnergySupplierRepository>();
            _unitOfWorkCallback       = _serviceProvider.GetRequiredService <IUnitOfWorkCallback>();
            _actorMessagePublisher    = _serviceProvider.GetRequiredService <IActorMessagePublisher>();
        }
示例#3
0
        public static IServiceCollection RegisterCommonStuff(this IServiceCollection services, IConfiguration configuration)
        {
            DapperNodaTimeSetup.Register();
            services.AddSingleton(configuration.UrlProvider());
            var serilogLogger = ContainerExtensions.Logger.get(configuration);

            services.AddSingleton <Serilog.ILogger>(serilogLogger);
            var loggerFactory = new LoggerFactory(); // lowTODO figure out if we need to dispose

            services.AddDbContextPool <CardOverflowDb>(optionsBuilder => {
                //loggerFactory.AddSerilog(serilogLogger);
                optionsBuilder
                //.UseLoggerFactory(loggerFactory)
                //.EnableSensitiveDataLogging()
                .UseSnakeCaseNamingConvention()
                .UseNpgsql(configuration.GetConnectionString("DefaultConnection"), x => x.UseNodaTime());
            });
            services.AddSingleton <DbExecutor>();
            services.AddSingleton <Func <Task <NpgsqlConnection> > >(_ => async() => {
                var conn = new NpgsqlConnection(configuration.GetConnectionString("DefaultConnection"));
                await conn.OpenAsync();
                return(conn);
            });
            Log.Logger = serilogLogger;
            services.AddLogging(x => x
                                .AddFilter("Microsoft.AspNetCore", LogLevel.Warning)
                                .AddFilter("Microsoft.EntityFrameworkCore", LogLevel.Warning));
            return(services);
        }
 public VendaRepository(IDatabaseConfig config)
 {
     DapperNodaTimeSetup.Register();
     _action = config.DbAction;
     _itemVendaDataAccess = new ItemVendaDataAccess();
     _tableVenda          = DatabaseUtils.Table <Venda>();
     _tableItemVenda      = DatabaseUtils.Table <ItemVenda>();
     _tableDisco          = DatabaseUtils.Table <Disco>();
 }
示例#5
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.AddGreenEnergyHub(typeof(RequestChangeOfSupplier).Assembly, typeof(RequestChangeSupplierCommandHandler).Assembly);
            builder.Services.AddUnitOfWork("MARKET_DATA_DB_CONNECTION_STRING");
            builder.Services.AddSingleton <IJsonSerializer, JsonSerializer>();
            builder.Services.AddScoped <IHubRehydrator, JsonMessageDeserializer>();

            builder.Services.AddScoped <IDbConnectionFactory>(serviceProvider =>
            {
                var configuration    = serviceProvider.GetService <IConfiguration>();
                var connectionString = configuration.GetValue <string>("MARKET_DATA_DB_CONNECTION_STRING");
                return(new SqlDbConnectionFactory(connectionString));
            });

            builder.Services.AddScoped(serviceProvider =>
            {
                var configuration    = serviceProvider.GetService <IConfiguration>();
                var connectionString = configuration.GetValue <string>("POST_OFFICE_QUEUE_CONNECTION_STRING");
                var topicName        = configuration.GetValue <string>("POST_OFFICE_QUEUE_TOPIC_NAME");
                var client           = new ServiceBusClient(connectionString);
                return(client.CreateSender(topicName));
            });

            DapperNodaTimeSetup.Register();

            builder.Services.AddScoped <IUnitOfWorkCallback, UnitOfWorkCallback>();
            builder.Services.AddScoped <ISystemDateTimeProvider, SystemDateTimeProvider>();
            builder.Services.AddScoped <IEventPublisher, EventPublisher>();
            builder.Services.AddScoped <IActorMessagePublisher, ActorMessagePublisher>();
            builder.Services.AddScoped <IMeteringPointRepository, MeteringPointRepository>();
            builder.Services.AddScoped <IEnergySupplierRepository, EnergySupplierRepository>();
            builder.Services.AddScoped <IInternalCommandRepository, InternalCommandRepository>();
            builder.Services.AddScoped <IInternalCommandService, InternalCommandService>();
            builder.Services.AddScoped <IForwardMessageRepository, ForwardMessageRepository>();
            builder.Services.AddScoped <IForwardMessageService, ForwardMessageService>();
            builder.Services.AddScoped <IPostOfficeService, PostOfficeService>();
            builder.Services.AddScoped <DomainEventsContext>();

            builder.Services.AddScoped(typeof(IPipelineBehavior <,>), typeof(DomainEventPublisherBehavior <,>));
            builder.Services.AddScoped(typeof(IPipelineBehavior <,>), typeof(UnitOfWorkHandlerBehavior <,>));
            builder.Services.AddScoped(typeof(IPipelineBehavior <,>), typeof(PublishIntegrationEventsHandlerBehavior <,>));
            builder.Services.AddScoped <IPipelineBehavior <RequestChangeOfSupplier, RequestChangeOfSupplierResult>, PublishActorMessageHandlerBehavior>();
        }
示例#6
0
        /// <summary>
        /// Use the SqlStateProvider as StateProvider
        /// </summary>
        /// <param name="host">The workerHost</param>
        /// <param name="config">The config</param>
        public static void UseSqlStateProvider <TFile, TMetadata, TQueryFilter>
            (this WorkerHost <TFile, TMetadata, TQueryFilter> host, ISqlStateProviderConfig config)
            where TFile : class, IResource <TMetadata>
            where TMetadata : class, IResourceMetadata
            where TQueryFilter : class, new()
        {
            DapperNodaTimeSetup.Register();

            Dapper.SqlMapper.AddTypeMap(typeof(DateTime), DbType.DateTime2);
            Dapper.SqlMapper.AddTypeMap(typeof(DateTime?), DbType.DateTime2);

            host.UseStateProvider <SqlStateProvider>(r =>
            {
                r.Container.RegisterSingleton <IDbConnectionManager, ReliableSqlConnectionManager>();
                r.Container.RegisterInstance(config);
                r.OnBeforeStart += () => r.Container.GetInstance <SqlStateProvider>().EnsureTableAreCreated();
            });
        }
示例#7
0
    private static async Task RefreshAndCleanDatabase()
    {
        var productionRDSName = ConfigurationManager.AppSettings["productionRDSName"] !;
        var betaRDSName       = ConfigurationManager.AppSettings["betaRDSName"] !;

        DapperNodaTimeSetup.Register();

        RDSRefresher rdsRefresher = new RDSRefresher(productionRDSName, betaRDSName);
        await rdsRefresher.CopySourceToDestination();

        MySQLFantasyCriticUserStore betaUserStore = new MySQLFantasyCriticUserStore(_betaConnectionString, _clock);
        MySQLBetaCleaner            cleaner       = new MySQLBetaCleaner(_betaConnectionString);

        _logger.Info("Cleaning emails/passwords for non-beta users");
        var allUsers = await betaUserStore.GetAllUsers();

        var betaUsers = await betaUserStore.GetUsersInRoleAsync("BetaTester", CancellationToken.None);

        await cleaner.CleanEmailsAndPasswords(allUsers, betaUsers);
    }
示例#8
0
        private static void Main(string[] args)
        {
            DapperNodaTimeSetup.Register();
            var connectionString = args[0];

            var connection = new SqlConnection(connectionString);

            Stuff.GetDbRetryPolicy().Execute(() => connection.Open());


            var areas = connection.Query <dynamic>("select [gitlocalpath], lastchangeset from MigStatus");

            foreach (var area in areas)
            {
                var gitlocal = (string)area.gitlocalpath;

                if (!Directory.Exists(gitlocal))
                {
                    continue;
                }

                var startchangeset = (int)area.lastchangeset;

                var paths = connection.Query <syncpath>(
                    $"select gitrepolocalpath, tfslocalpath, tfspath from MigrationPaths where gitrepolocalpath like '{gitlocal}\\%'")
                            .ToArray();


                var sqlpaths = "(\'" + string.Join("', '", paths.Select(p => p.tfspath)) + "\')";

                do
                {
                    var noCommitsToBeMerged = connection.QueryFirst <int>(
                        $"select count(*) from changesets where changesetid > {startchangeset} and TfsPath in {sqlpaths}");
                    if (noCommitsToBeMerged == 0)
                    {
                        break;
                    }


                    var commitid = connection.QueryFirst <int>(
                        $"select min(changesetid) from changesets where changesetid > {startchangeset} and TfsPath in {sqlpaths}");


                    var changeset = connection.QueryFirst <CheckIn>(
                        $"select ChangesetId as Id, comment, trim(committer) as committerName, trim(committerEmail),  [CommitterDate] as date from changesets where changesetid  = {commitid}");


                    var tfsPaths = paths.Select(p => p.tfslocalpath).ToArray();

                    var tfsRootPath =
                        new string(
                            tfsPaths
                            .First()
                            .Substring(0, tfsPaths.Min(s => s.Length))
                            .TakeWhile((c, i) => tfsPaths.All(s => s[i] == c))
                            .ToArray());


                    foreach (var path in paths)
                    {
                        UpdateTfsPath(path.tfslocalpath, commitid);
                    }


                    var proc = new Process
                    {
                        StartInfo = new ProcessStartInfo("cmd",
                                                         $"/c Robocopy {tfsRootPath} . /MIR /XD .git /XF .gitattributes /XF .gitignore")
                        {
                            UseShellExecute  = false,
                            WorkingDirectory = gitlocal
                        }
                    };
                    proc.Start();
                    proc.WaitForExit();

                    proc = new Process
                    {
                        StartInfo = new ProcessStartInfo("cmd", "/c git add .")
                        {
                            UseShellExecute  = false,
                            WorkingDirectory = gitlocal
                        }
                    };
                    proc.Start();
                    proc.WaitForExit();

                    if (changeset.committerEmail == null)
                    {
                        changeset.committerEmail = changeset.committerName.ToLower().Replace(' ', '.') + "@unit4.com";
                    }

                    var d = changeset.date.ToStringWithOffset();

                    var commitcli =
                        $"git commit -m '{changeset.comment}' -m 'https://team47system1.corp.u4agr.com/tfs/DefaultCollection/Platform/_versionControl/changeset/{changeset.Id}' --author '{changeset.committerName} <{changeset.committerEmail}>' --date '{d}'";
                    proc = new Process
                    {
                        StartInfo = new ProcessStartInfo(@"pwsh", $"-c {commitcli}")
                        {
                            UseShellExecute  = false,
                            WorkingDirectory = gitlocal
                        }
                    };
                    proc.Start();
                    proc.WaitForExit();
                    startchangeset = commitid;


                    connection.Execute(
                        $"update MigStatus set lastchangeset = {startchangeset} where [gitlocalpath] = '{gitlocal}'");
                } while (true);
            }
        }
示例#9
0
 public static void AddDapperNodaTime()
 {
     DapperNodaTimeSetup.Register();
     Dapper.SqlMapper.AddTypeHandler(new Helpers.InstantHandler());
 }
示例#10
0
        private static void Main(string[] args)
        {
            DapperNodaTimeSetup.Register();
            var connectionString = args[0];


            var connection = new SqlConnection(connectionString);

            Stuff.GetDbRetryPolicy().Execute(() => connection.Open());

            var syncpaths = connection.Query <SyncPath>(
                "SELECT [TfsUrl], [TfsPath], [LastChangeSetId] FROM [TfsPathsToSync]");

            foreach (var syncpath in syncpaths)
            {
                Console.WriteLine($"Processing {syncpath.TfsPath}");
                var tfs     = new TfsUtil(syncpath.TfsUrl);
                var history = tfs.GetHistory(syncpath.TfsPath);

                int newLastChangesetId = 0;

                foreach (var changeset in history)
                {
                    newLastChangesetId = Math.Max(newLastChangesetId, changeset.Id);

                    if (changeset.Id > syncpath.LastChangeSetId)
                    {
                        var count = connection.QuerySingle <int>(
                            "select count(*) from Changesets where TfsPath = @TfsPath and ChangeSetId = @ChangesetId",
                            new
                        {
                            // ReSharper disable once RedundantAnonymousTypePropertyName
                            TfsPath     = syncpath.TfsPath,
                            ChangesetId = changeset.Id
                        });

                        if (count == 0)
                        {
                            connection.Execute(
                                @"insert into Changesets (TfsPath, ChangesetId, Comment, Committer, CommitterEmail, CommitterDate) values 
                            (@TfsPath, @ChangesetId, @Comment, @Committer, @CommitterEmail, @CommitterDate) ",
                                new[]
                            {
                                new
                                {
                                    syncpath.TfsPath,
                                    ChangesetId    = changeset.Id,
                                    Comment        = changeset.comment,
                                    Committer      = changeset.committerName,
                                    CommitterEmail = changeset.committerEmail,
                                    CommitterDate  = changeset.date
                                }
                            });
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                if (syncpath.LastChangeSetId != newLastChangesetId)
                {
                    int rows = connection.Execute(
                        @"update TfsPathsToSync set LastChangeSetId = @newMaxId where TfsUrl =  @tfsUrl and TfsPath = @tfsPath",
                        new
                    {
                        newMaxId = newLastChangesetId,
                        tfsUrl   = syncpath.TfsUrl,
                        tfsPath  = syncpath.TfsPath
                    });

                    if (rows != 1)
                    {
                        Console.WriteLine($"Error updateing LastChangeSetId for {syncpath.TfsPath}");
                    }

                    Console.WriteLine($"Updated {syncpath.TfsPath} up to commit {newLastChangesetId}");
                }
            }
        }