Exemplo n.º 1
0
        public string GetDatabaseName(string fileName)
        {
            int    i      = 0;
            string name   = System.IO.Path.GetFileNameWithoutExtension(fileName);
            string dbname = name;

            while (DatabasesManager.Contains(dbname))
            {
                dbname = name + i;
            }
            return(dbname);
        }
Exemplo n.º 2
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);
                }
            }
        }
Exemplo n.º 3
0
        private void nameTextBox_Validating(object sender, CancelEventArgs e)
        {
            string name = nameTextBox.Text.Trim();

            if (String.IsNullOrEmpty(name))
            {
                errorProvider.SetError(nameTextBox, "Please specify a name");
                e.Cancel = true;
            }
            else if (!nameValidator.IsMatch(name))
            {
                errorProvider.SetError(nameTextBox, "Invalid identifier name");
                e.Cancel = true;
            }
            else if (!isUpdate && DatabasesManager.Contains(name))
            {
                errorProvider.SetError(nameTextBox, "It already exists a database with the name: " + name);
                e.Cancel = true;
            }
            else
            {
                errorProvider.Clear();
            }
        }