public void Configure(CommandLineApplication command)
        {
            command.Description = "copies a tenant from a server to another server";

            var serverNameArg = command.Argument("server", "the source server name");
            var configDbArg   = command.Argument("config-db", "the target server's config db");
            var publicDbArg   = command.Argument("public-db", "the target server's public db");

            var maybeTargetServer = command.Option("-s|--target-server-id", "copy to a defined server (default is 'localhost')", CommandOptionType.SingleValue);
            var maybeAppName      = command.Option("-a|--set-appname", "set the tenant's appname", CommandOptionType.SingleValue);
            var maybeTenantId     = command.Option("-i|--set-tenant-id", "set the tenant's local id", CommandOptionType.SingleValue);

            var maybeNoIisSetup = command.Option("-x|--no-iis-setup", "prevent apps creation in IIS (allow running without admin role)", CommandOptionType.SingleValue);

            command.OnExecute(async() =>
            {
                var target = maybeTargetServer.HasValue() ?
                             _db.Servers.Find(maybeTargetServer.Value()) :
                             _db.Servers.First(_ => _.Hostname == "localhost");
                var source = _db.Servers.Find(serverNameArg.Value);

                await Task.WhenAll(
                    target.CopyDatabaseAsync(source, configDbArg.Value),
                    target.CopyDatabaseAsync(source, publicDbArg.Value));

                var newTenant = _tn(new Tenant
                {
                    ConfigDb = configDbArg.Value,
                    PublicDb = publicDbArg.Value,
                    ServerId = target.Id,
                });

                var tenantName = maybeAppName.HasValue() ? maybeAppName.Value() : newTenant.ApplicationName;
                var tenantId   = maybeTenantId.HasValue() ? maybeTenantId.Value() : tenantName;

                newTenant.ApplicationName = tenantName;
                newTenant.Dto.Id          = tenantId;

                _db.Upsert(newTenant.Dto, _ => _.Id);
                _db.SaveChanges();

                if (!maybeNoIisSetup.HasValue())
                {
                    newTenant.CreateAdminWebApp();
                    newTenant.CreatePublicWebApp();
                }

                return(0);
            });
        }
        public void Configure(CommandLineApplication command)
        {
            command.Description = "add a tenant to the local database";

            var nameArg     = command.Argument("[name]", "The tenant name");
            var serverIdArg = command.Argument("[server]", "The server hosting this tenant");
            var publicDbArg = command.Argument("[public-db]", "The tenant's public db");
            var configDbArg = command.Argument("[config-db]", "The tenant's config db");

            command.OnExecute(() =>
            {
                _db.Upsert(new Tenant
                {
                    Id       = nameArg.Value,
                    ServerId = serverIdArg.Value,
                    ConfigDb = configDbArg.Value,
                    PublicDb = publicDbArg.Value
                }, _ => _.Id);
                _db.SaveChanges();
                return(0);
            });
        }
Exemple #3
0
        public void Configure(CommandLineApplication command)
        {
            command.Description = "add a server to the local database";

            var nameArg     = command.Argument("[name]", "The server name");
            var hostnameArg = command.Argument("[hostname]", "The server hostname");
            var loginArg    = command.Argument("[login]", "The server login");
            var passwordArg = command.Argument("[password]", "The server password");

            command.OnExecute(() =>
            {
                _db.Upsert(new Server
                {
                    Id       = nameArg.Value,
                    Hostname = hostnameArg.Value,
                    Login    = loginArg.Value,
                    Password = passwordArg.Value,
                }, _ => _.Id);
                _db.SaveChanges();
                return(0);
            });
        }