Beispiel #1
0
        public static void LoadDatabases()
        {
            var databasesFile = DatabasesFileName;

            if (File.Exists(databasesFile))
            {
                var document = new XmlDocument();
                document.Load(databasesFile);
                foreach (XmlNode node in document.DocumentElement.ChildNodes)
                {
                    var providerName = node.Name;
                    var name         = (node.Attributes["Name"] != null) ? node.Attributes["Name"].Value : null;
                    var provider     = DbProvider.GetProvider(providerName);
                    if (provider != null && name != null)
                    {
                        string connectionString = node.InnerText;
                        if (!DatabasesManager.Contains(name))
                        {
                            var database = provider.CreateDatabase(name, connectionString);
                            DatabasesManager.Add(database);
                        }
                    }
                }
                DatabasesManager.IsCollectionDirty = false;
            }
            if (DatabasesManager.Databases.Count == 0)
            {
                var worldDbFile = new FileInfo(Path.Combine(GetDataDirectory(), "World.db"));
                if (ApplicationDeployment.IsNetworkDeployed)
                {
                    if (!worldDbFile.Exists)
                    {
                        var deployWorldDb = new FileInfo(Path.Combine(Application.StartupPath, "World.db"));
                        if (deployWorldDb.Exists)
                        {
                            deployWorldDb.CopyTo(worldDbFile.FullName);
                        }
                    }
                }
                if (worldDbFile.Exists)
                {
                    var sqliteProvider          = DbProvider.GetProvider("SQLite");
                    var connectionStringBuilder = sqliteProvider.CreateConnectionStringBuilder();
                    connectionStringBuilder["Data Source"]     = worldDbFile.FullName;
                    connectionStringBuilder["Fail If Missing"] = true;
                    var worldDb = sqliteProvider.CreateDatabase("World", connectionStringBuilder.ToString());
                    DatabasesManager.Add(worldDb);
                }
            }
        }
 private void AddNewDatabase(Database database)
 {
     treeView.Nodes.Add(CreateDatabaseNode(database));
     DatabasesManager.Add(database);
 }