Ejemplo n.º 1
0
        public async Task InstallAsync()
        {
            InstalledApps = new List <Installable>();

            string tenant = TenantConvention.GetTenant(this.Url);

            InstallerLog.Verbose($"Creating database {tenant}.");
            var db = new DbInstaller(tenant);
            await db.InstallAsync().ConfigureAwait(false);

            InstallerLog.Verbose("Getting installables.");
            var installables = GetInstallables(tenant);

            foreach (var installable in installables)
            {
                try
                {
                    InstallerLog.Verbose($"Installing module {installable.ApplicationName}.");
                    await new AppInstaller(tenant, tenant, installable).InstallAsync().ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    InstallerLog.Error(ex.Message);
                    InstallerLog.Error($"Could not install module {installable.ApplicationName}.");
                }
            }
        }
Ejemplo n.º 2
0
        public async Task InstallAsync()
        {
            if (Installer.Tenant.Installer.InstalledApps.Contains(this.Installable))
            {
                return;
            }

            foreach (var dependency in this.Installable.Dependencies)
            {
                await new AppInstaller(this.Tenant, this.Database, this.WithoutSample, dependency).InstallAsync().ConfigureAwait(false);
            }

            InstallerLog.Verbose($"Installing module {this.Installable.ApplicationName}.");

            await this.CreateSchemaAsync().ConfigureAwait(false);

            await this.CreateMyAsync().ConfigureAwait(false);

            this.CreateOverride();
            Installer.Tenant.Installer.InstalledApps.Add(this.Installable);

            if (this.Installable.ApplicationName == "Frapid.Account")
            {
                var domain = TenantConvention.FindDomainByTenant(this.Tenant);
                await UserInstaller.CreateUserAsync(this.Tenant, domain).ConfigureAwait(false);
            }
        }
Ejemplo n.º 3
0
        private void Do(ApprovedDomain site)
        {
            string url = site.DomainName;

            InstallerLog.Verbose($"Installing frapid on domain {url}.");

            try
            {
                var installer = new Installer.Tenant.Installer(url, false);

                installer.Notification += delegate(object sender, string message)
                {
                    if (message.StartsWith("Error"))
                    {
                        this.OnError(sender, message);
                    }
                    else
                    {
                        this.OnNotification(sender, message);
                    }
                };

                installer.InstallAsync().GetAwaiter().GetResult();

                DbInstalledDomains.AddAsync(site).GetAwaiter().GetResult();
                new InstalledDomainSerializer().Add(site);
            }
            catch (Exception ex)
            {
                InstallerLog.Error("Could not install frapid on {url} due to errors. Exception: {Exception}", url, ex);
                throw;
            }
        }
Ejemplo n.º 4
0
        protected void CreateOverride()
        {
            if (string.IsNullOrWhiteSpace(this.Installable.OverrideTemplatePath) ||
                string.IsNullOrWhiteSpace(this.Installable.OverrideDestination))
            {
                return;
            }

            string source      = PathMapper.MapPath(this.Installable.OverrideTemplatePath);
            string destination = string.Format(CultureInfo.InvariantCulture, this.Installable.OverrideDestination,
                                               this.Database);

            destination = PathMapper.MapPath(destination);


            if (string.IsNullOrWhiteSpace(source) ||
                string.IsNullOrWhiteSpace(destination))
            {
                return;
            }

            if (!Directory.Exists(source))
            {
                return;
            }

            InstallerLog.Verbose($"Creating overide. Source: {source}, desitation: {destination}.");
            FileHelper.CopyDirectory(source, destination);
        }
Ejemplo n.º 5
0
 private async Task RunSqlAsync(string tenant, string database, string fromFile)
 {
     try
     {
         await Store.RunSqlAsync(tenant, database, fromFile).ConfigureAwait(false);
     }
     catch (Exception ex)
     {
         InstallerLog.Verbose($"{ex.Message}");
         throw;
     }
 }
Ejemplo n.º 6
0
        private void Notify(object sender, string message)
        {
            if (message.StartsWith("Error"))
            {
                InstallerLog.Error(message);
            }
            else
            {
                InstallerLog.Verbose(message);
            }

            var notificationReceived = this.Notification;

            notificationReceived?.Invoke(sender, message);
        }
Ejemplo n.º 7
0
        protected async Task CreateSchemaAsync()
        {
            string database = this.Database;

            if (this.Installable.IsMeta)
            {
                InstallerLog.Verbose(
                    $"Creating database of {this.Installable.ApplicationName} under meta database {Factory.GetMetaDatabase(this.Database)}.");
                database = Factory.GetMetaDatabase(this.Database);
            }

            if (string.IsNullOrWhiteSpace(this.Installable.DbSchema))
            {
                return;
            }


            if (await this.HasSchemaAsync(database).ConfigureAwait(false))
            {
                InstallerLog.Verbose(
                    $"Skipped {this.Installable.ApplicationName} schema ({this.Installable.DbSchema}) creation because it already exists.");
                return;
            }

            InstallerLog.Verbose($"Creating schema {this.Installable.DbSchema}");


            string db   = this.Installable.BlankDbPath;
            string path = PathMapper.MapPath(db);

            await this.RunSqlAsync(this.Tenant, database, path).ConfigureAwait(false);


            if (this.Installable.InstallSample && !string.IsNullOrWhiteSpace(this.Installable.SampleDbPath))
            {
                //Manually override sample data installation
                if (!this.WithoutSample)
                {
                    InstallerLog.Verbose($"Creating sample data of {this.Installable.ApplicationName}.");
                    db   = this.Installable.SampleDbPath;
                    path = PathMapper.MapPath(db);
                    await this.RunSqlAsync(database, database, path).ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 8
0
        public void Execute(IJobExecutionContext context)
        {
            string url = context.JobDetail.Key.Name;

            InstallerLog.Verbose($"Installing frapid on domain {url}.");

            try
            {
                var installer = new Tenant.Installer(url);
                installer.InstallAsync().Wait();

                var site = new ApprovedDomainSerializer().Get().FirstOrDefault(x => x.DomainName.Equals(url));
                DbInstalledDomains.AddAsync(site).Wait();
                new InstalledDomainSerializer().Add(site);
            }
            catch (Exception ex)
            {
                InstallerLog.Error("Could not install frapid on {url} due to errors. Exception: {Exception}", url, ex);
                throw;
            }
        }
Ejemplo n.º 9
0
        public async Task RunSqlAsync(string tenant, string database, string fromFile)
        {
            fromFile = fromFile.Replace("{DbServer}", "SQL Server");
            if (string.IsNullOrWhiteSpace(fromFile) || File.Exists(fromFile).Equals(false))
            {
                return;
            }

            string sql = File.ReadAllText(fromFile, Encoding.UTF8);


            InstallerLog.Verbose($"Running file {fromFile}");

            string connectionString = FrapidDbServer.GetSuperUserConnectionString(tenant, database);

            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();
                await this.RunScriptAsync(connection, sql).ConfigureAwait(false);
            }
        }
Ejemplo n.º 10
0
        public async Task <bool> InstallAsync()
        {
            string meta      = DbProvider.GetMetaDatabase(this.Tenant);
            var    inspector = new DbInspector(this.Tenant, meta);
            bool   hasDb     = await inspector.HasDbAsync().ConfigureAwait(false);

            bool isWellKnown = inspector.IsWellKnownDb();

            if (hasDb)
            {
                if (IsDevelopment())
                {
                    InstallerLog.Verbose("Cleaning up the database.");
                    await this.CleanUpDbAsync().ConfigureAwait(true);
                }
                else
                {
                    InstallerLog.Information("Warning: database already exists. Please remove the database first.");
                    InstallerLog.Verbose($"No need to create database \"{this.Tenant}\" because it already exists.");
                }
            }

            if (!isWellKnown)
            {
                InstallerLog.Verbose(
                    $"Cannot create a database under the name \"{this.Tenant}\" because the name is not a well-known tenant name.");
            }

            if (!hasDb && isWellKnown)
            {
                InstallerLog.Information($"Creating database \"{this.Tenant}\".");
                await this.CreateDbAsync().ConfigureAwait(false);

                return(true);
            }

            return(false);
        }