示例#1
0
        private void testConnectionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bool isReachable = DatabaseConnection.Instance.Test();

            if (!isReachable)
            {
                MessageBox.Show("MongoDB is not reachable. Please configure.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                ConnectionForm connectionForm = new ConnectionForm();
                connectionForm.ShowDialog();
            }
            else
            {
                MessageBox.Show("MongoDB is reachable.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
示例#2
0
        private void TestConnection()
        {
            string host = Properties.Settings.Default.mongodb_host;
            int    port = Properties.Settings.Default.mongodb_port;

            DatabaseAddress    address    = new DatabaseAddress(host, port);
            DatabaseConnection connection = DatabaseConnection.Instance;

            connection.Address = address;
            connection.Connect();
            bool isReachable = connection.Test();

            if (!isReachable)
            {
                MessageBox.Show("MongoDB is not reachable. Please configure.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                ConnectionForm connectionForm = new ConnectionForm();
                connectionForm.ShowDialog();
            }
            else
            {
                if (!connection.HasDatabaseCollection(Properties.Settings.Default.mongodb_database, Properties.Settings.Default.mongodb_collection_shares))
                {
                    connection.CreateCollection(Properties.Settings.Default.mongodb_collection_shares);
                    var database         = connection.Client.GetDatabase(Properties.Settings.Default.mongodb_database);
                    var sharesCollection = database.GetCollection <BsonDocument>(Properties.Settings.Default.mongodb_collection_shares);

                    /*
                     * var options = new CreateIndexOptions() { Unique = true };
                     * var field = new StringFieldDefinition<BsonDocument>("string_letter");
                     * var index = new IndexKeysDefinitionBuilder<BsonDocument>().Ascending(field);
                     */
                    // db.network_shares.createIndex({ "share_letter": 1}, { unique: true});
                    // var keys = Builders<BsonDocument>.IndexKeys.Ascending("i");
                    // collection.Indexes.CreateOne(keys);

                    sharesCollection.Indexes.CreateOne("{share_letter : 1}", new CreateIndexOptions()
                    {
                        Unique = true
                    });
                }
            }
        }
示例#3
0
        private void editToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ConnectionForm cf = new ConnectionForm();

            cf.ShowDialog();
        }