private void LoadShares() { DatabaseConnection connection = DatabaseConnection.Instance; var database = connection.Client.GetDatabase(Properties.Settings.Default.mongodb_database); var sharesCollection = database.GetCollection <BsonDocument>(Properties.Settings.Default.mongodb_collection_shares); using (IAsyncCursor <BsonDocument> cursor = sharesCollection.FindSync(new BsonDocument())) { while (cursor.MoveNext()) { IEnumerable <BsonDocument> batch = cursor.Current; foreach (BsonDocument document in batch) { string shareLetter = document["share_letter"].AsString; string sharePath = document["share_path"].AsString; bool mounted = NetworkDrives.IsDriveMapped(shareLetter); NetworkShares.Instance.Shares.Add(new NetworkShare(shareLetter, sharePath, mounted)); } } } sharesListBox.DataSource = NetworkShares.Instance.Shares; sharesListBox.DisplayMember = "DisplayMember"; sharesListBox.ValueMember = "IsChecked"; }
private void unmountBtn_Click(object sender, EventArgs e) { foreach (Object item in sharesListBox.SelectedItems) { NetworkShare share = (NetworkShare)item; if (NetworkDrives.IsDriveMapped(share.ShareLetter)) { NetworkDrives.DisconnectNetworkDrive(share.ShareLetter, false); share.IsMounted = false; } else { MessageBox.Show("You can not unmount an unmounted drive.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } } NetworkShares.Instance.Sync(); }
private void addShareBtn_Click(object sender, EventArgs e) { foreach (Object item in sharesListBox.SelectedItems) { NetworkShare share = (NetworkShare)item; if (NetworkDrives.IsDriveMapped(share.ShareLetter)) { MessageBox.Show("Letter Drive (" + share.ShareLetter + ":) is already mounted!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { NetworkDrives.MapNetworkDrive(share.ShareLetter, share.SharePath); share.IsMounted = true; } } NetworkShares.Instance.Sync(); }