Ejemplo n.º 1
0
        public static IEnumerable <SchemaVersion> GetVersionsOnDisk(Installable app, string tenant)
        {
            var    versions  = new List <SchemaVersion>();
            string directory = DatabaseConvention.GetRootDbDirectory(app, tenant);

            if (string.IsNullOrWhiteSpace(directory) || !Directory.Exists(directory))
            {
                return(versions);
            }

            var directories = Directory.GetDirectories(directory, "*.update", SearchOption.TopDirectoryOnly);

            foreach (string path in directories)
            {
                string fileName  = Path.GetFileName(path);
                string candidate = fileName.Or("").Replace(".update", "");
                double value;
                double.TryParse(candidate, out value);

                if (value > 0)
                {
                    versions.Add(
                        new SchemaVersion
                    {
                        SchemaName    = app.DbSchema,
                        VersionNumber = candidate
                    }
                        );
                }
            }

            return(versions);
        }
Ejemplo n.º 2
0
        private static UpdateBase GetUpdater(string tenant, Installable app)
        {
            var site = TenantConvention.GetSite(tenant);

            if (site == null)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Not an approved domain.");
                Console.ForegroundColor = ConsoleColor.White;

                return(null);
            }

            string providerName = site.DbProvider;

            switch (providerName)
            {
            case "Npgsql":
                return(new PostgresqlUpdater(tenant, app));

            case "System.Data.SqlClient":
                return(new SqlServerUpdater(tenant, app));

            default:
                throw new SchemaUpdaterException("Frapid schema updater does not support provider " + providerName);
            }
        }
Ejemplo n.º 3
0
 public AppInstaller(string tenant, string database, bool withoutSample, Installable installable)
 {
     this.Tenant        = tenant;
     this.Database      = database;
     this.WithoutSample = withoutSample;
     this.Installable   = installable;
 }
Ejemplo n.º 4
0
 public UpdateCandidate(Installable app, string tenant)
 {
     this.AppInfo           = app;
     this.AllVersions       = VersionInvestigator.GetVersionsOnDisk(app, tenant);
     this.InstalledVersions = VersionManager.GetVersions(tenant, app.DbSchema);
     this.VersionToUpdate   = this.AllVersions.OrderByDescending(x => x.VersionNumber.To <double>()).FirstOrDefault();
     this.PathToUpdateFile  = VersionPathConvention.GetFilePath(app, tenant, this.VersionToUpdate);
 }
Ejemplo n.º 5
0
    public void Uninstall()
    {
        if (installedObject == null)
        {
            Debug.Log("Could not Uninstall() from Tile (" + X + ", " + Y + ") because it has no object installed.");
            return;
        }

        installedObject.OnUninstall();
        installedObject = null;
    }
Ejemplo n.º 6
0
        public static async Task <string> UpdateAsync(string tenant, Installable app)
        {
            var updater = GetUpdater(tenant, app);

            if (updater != null)
            {
                return(await updater.UpdateAsync().ConfigureAwait(false));
            }

            return($"Could not install updates for {app.ApplicationName} due to errors.");
        }
Ejemplo n.º 7
0
    public void Install(Installable installable)
    {
        if (installedObject != null)
        {
            Debug.Log("Could not install" + installable.name + " because Tile (" + X + ", " + Y + ") already has " + installedObject.name + " installed.");
            return;
        }

        installable.OnInstall();
        installable.transform.position = obj.transform.position;
        installedObject = installable;
    }
Ejemplo n.º 8
0
        public static string GetFilePath(Installable app, string tenant, SchemaVersion version)
        {
            if (version == null)
            {
                return(string.Empty);
            }

            string directory = DatabaseConvention.GetRootDbDirectory(app, tenant);

            directory = Path.Combine(directory, version.VersionNumber + ".update");

            string updateFile = Directory.GetFiles(directory, "*.update.sql", SearchOption.TopDirectoryOnly).FirstOrDefault();

            return(updateFile);
        }
Ejemplo n.º 9
0
        public static void InstallSystem(bool reset)
        {
            var notInstalled = Installable.InstallAll(GetInstallables, reset);

            if (notInstalled.Count > 0)
            {
                var names = from module in notInstalled
                            let type = module.Key.GetType()
                                       let errorType = module.Value.GetType()
                                                       let errorMessage = module.Value.Message
                                                                          select $"\n\t[{type.Name}] {errorType.Name}: {errorMessage}";
                var nameList = string.Join("", names);
                Debug.LogError("Juniper: ERROR: components were not installed correctly." + nameList);
            }
        }
Ejemplo n.º 10
0
        public static string GetRootDbDirectory(Installable app, string tenant)
        {
            string dbms   = DbServerUtility.GetDbmsName(tenant);
            string dbPath = PathMapper.MapPath(app.BlankDbPath.Or(string.Empty).Replace("{DbServer}", dbms));

            try
            {
                return(new FileInfo(dbPath).DirectoryName);
            }
            catch (DirectoryNotFoundException)
            {
                Log.Warning("The app {ApplicationName} does not have {dbms} implementation.", app.ApplicationName, dbms);
            }

            return(string.Empty);
        }
Ejemplo n.º 11
0
        private void CreateResource(Installable app)
        {
            Console.WriteLine("Creating resource on " + app.ApplicationName);
            var approved = new ApprovedDomainSerializer().Get().FirstOrDefault();

            if (approved == null)
            {
                return;
            }

            string tenant = TenantConvention.GetTenant(approved.DomainName);

            var writer = new ResourceWriter(tenant, app);

            writer.WriteAsync().GetAwaiter().GetResult();
        }
Ejemplo n.º 12
0
        private static UpdateBase GetUpdater(string tenant, Installable app)
        {
            var    site         = TenantConvention.GetSite(tenant);
            string providerName = site.DbProvider;

            switch (providerName)
            {
            case "Npgsql":
                return(new PostgresqlUpdater(tenant, app));

            case "System.Data.SqlClient":
                return(new SqlServerUpdater(tenant, app));

            default:
                throw new SchemaUpdaterException("Frapid schema updater does not support provider " + providerName);
            }
        }
Ejemplo n.º 13
0
        private void OnAddClick(object sender, RoutedEventArgs e)
        {
            _ = MainWindow.GetMainWindow.ChangeCurrentControl(new ServerList());

            ComboBox    comboBox    = Items[0] as ComboBox;
            string      key         = comboBox.SelectedValue as string;
            Installable installable = Initializer.Installables[key];

            string path = Path.Combine(GlobalConfig.ServersPath, ServerName.Text);

            if (Directory.Exists(path))
            {
                return;
            }

            _ = Initializer.CreateServer(path, installable.ServerType, installable.InstallAction);
        }
Ejemplo n.º 14
0
 public ResourceWriter(string tenant, Installable app)
 {
     this.Tenant = tenant;
     this.App = app;
 }
Ejemplo n.º 15
0
        public async Task <Dictionary <string, string> > GetResourcesAsync(string tenant, Installable app, string path)
        {
            var resources = new Dictionary <string, string>();

            using (var db = DbProvider.Get(FrapidDbServer.GetConnectionString(tenant), tenant).GetDatabase())
            {
                var sql = new Sql("SELECT i18n_key, menu_name FROM core.menus");
                sql.Where("app_name=@0", app.ApplicationName);

                var columns = await db.SelectAsync <dynamic>(sql).ConfigureAwait(false);

                foreach (var column in columns)
                {
                    string key   = column.I18nKey;
                    string value = column.MenuName;

                    resources.Add(key, value);
                }
            }

            return(resources);
        }
Ejemplo n.º 16
0
        public static async Task <string> UpdateAsync(string tenant, Installable app)
        {
            var updater = GetUpdater(tenant, app);

            return(await updater.UpdateAsync().ConfigureAwait(false));
        }
Ejemplo n.º 17
0
        public async Task <Dictionary <string, string> > GetResourcesAsync(string tenant, Installable app, string path)
        {
            var resources = new Dictionary <string, string>();

            if (string.IsNullOrWhiteSpace(app.DbSchema))
            {
                return(resources);
            }

            using (var db = DbProvider.Get(FrapidDbServer.GetConnectionString(tenant), tenant).GetDatabase())
            {
                var sql = new Sql("SELECT DISTINCT column_name FROM information_schema.columns");
                sql.Where("table_schema=@0", app.DbSchema);

                var columns = await db.SelectAsync <dynamic>(sql).ConfigureAwait(false);

                foreach (var column in columns)
                {
                    string name = column.ColumnName;

                    string key   = name.ToPascalCase();
                    string value = name.ToSentence().ToTitleCaseSentence();

                    if (!resources.ContainsKey(key))
                    {
                        resources.Add(key, value);
                    }
                }
            }
            return(resources);
        }
Ejemplo n.º 18
0
 public static void UninstallSystem()
 {
     Installable.UninstallAll(JuniperSystem.GetInstallables);
 }
Ejemplo n.º 19
0
 public AppInstaller(string tenant, string database, Installable installable)
 {
     this.Tenant      = tenant;
     this.Database    = database;
     this.Installable = installable;
 }
Ejemplo n.º 20
0
 public AppInstaller(string database, Installable installable)
 {
     this.Database    = database;
     this.Installable = installable;
 }
Ejemplo n.º 21
0
 public SqlServerUpdater(string tenant, Installable app) : base(tenant, app)
 {
 }
Ejemplo n.º 22
0
 protected UpdateBase(string tenant, Installable app)
 {
     this.Tenant    = tenant;
     this.App       = app;
     this.Candidate = new UpdateCandidate(app, tenant);
 }
Ejemplo n.º 23
0
 public AppInstaller(string catalog, Installable installable)
 {
     this.Catalog     = catalog;
     this.Installable = installable;
 }
Ejemplo n.º 24
0
        public async Task <Dictionary <string, string> > GetResourcesAsync(string tenant, Installable app, string path)
        {
            await Task.Delay(0).ConfigureAwait(false);

            if (string.IsNullOrWhiteSpace(path))
            {
                return(new Dictionary <string, string>());
            }

            string contents     = File.ReadAllText(path, Encoding.UTF8);
            var    deserializer = new Deserializer();

            return(deserializer.Deserialize <Dictionary <string, string> >(contents));
        }
Ejemplo n.º 25
0
        public static async Task <Dictionary <string, string> > GetResourcesAsync(string tenant, Installable app, string path)
        {
            var resources = new Dictionary <string, string>();
            var readers   = FindReaders();

            foreach (var reader in readers)
            {
                resources.Merge(await reader.GetResourcesAsync(tenant, app, path).ConfigureAwait(false));
            }


            return(resources);
        }
Ejemplo n.º 26
0
 public PostgresqlUpdater(string tenant, Installable app) : base(tenant, app)
 {
 }