Пример #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}.");
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Create New Logs
        /// </summary>
        public Boolean InsertInstallerLog(string result, string license, string type, string remoteIp, string step, string message, out int?objId)
        {
            objId = null;
            var installerLog = new InstallerLog
            {
                Result    = result,
                LicenseId = license,
                Type      = type,
                RemoteIp  = remoteIp,
                Step      = step,
                Message   = message,
                Created   = DateTime.UtcNow,
                Updated   = DateTime.UtcNow,
                Version   = "1.0"
            };

            using (var context = new CustomerInfoRepository())
            {
                context.InstallerLogs.Add(installerLog);
                try
                {
                    context.SaveChanges();
                    objId = installerLog.Id;
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
Пример #3
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);
            }
        }
Пример #4
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;
            }
        }
Пример #5
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);
        }
Пример #6
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;
     }
 }
Пример #7
0
        public async Task CleanupDbAsync(string tenant, string database)
        {
            string sql = @"SET NOCOUNT ON;
                            DECLARE @sql nvarchar(MAX);
                            DECLARE @queries TABLE(id int identity, query nvarchar(500), done bit DEFAULT(0));
                            DECLARE @id int;
                            DECLARE @query nvarchar(500);


                            INSERT INTO @queries(query)
                            SELECT 
	                            'EXECUTE dbo.drop_schema ''' + sys.schemas.name + ''''+ CHAR(13) AS query
                            FROM sys.schemas
                            WHERE principal_id = 1
                            AND name != 'dbo'
                            ORDER BY schema_id;



                            WHILE(SELECT COUNT(*) FROM @queries WHERE done = 0) > 0
                            BEGIN
                                SELECT TOP 1 
		                            @id = id,
		                            @query = query
	                            FROM @queries 
	                            WHERE done = 0
	
	                            EXECUTE(@query);

                                UPDATE @queries SET done = 1 WHERE id=@id;
                            END;";

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

            using (var connection = new SqlConnection(connectionString))
            {
                using (var command = new SqlCommand(sql, connection))
                {
                    connection.Open();

                    var message = await command.ExecuteScalarAsync().ConfigureAwait(false);

                    if (message != null)
                    {
                        InstallerLog.Information($"Could not completely clean database \"{tenant}\" due to dependency issues. Trying again.");
                        await CleanupDbAsync(tenant, database).ConfigureAwait(false);
                    }
                }
            }
        }
Пример #8
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);
        }
Пример #9
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);
                }
            }
        }
Пример #10
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;
            }
        }
Пример #11
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);
            }
        }
Пример #12
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);
        }
Пример #13
0
        private static IStore GetDbServer(string tenant)
        {
            var    site         = TenantConvention.GetSite(tenant);
            string providerName = site.DbProvider;

            try
            {
                var iType   = typeof(IStore);
                var members = iType.GetTypeMembers <IStore>();

                foreach (var member in members.Where(member => member.ProviderName.Equals(providerName)))
                {
                    return(member);
                }
            }
            catch (Exception ex)
            {
                InstallerLog.Error("{Exception}", ex);
                throw;
            }

            return(new PostgreSQL());
        }