コード例 #1
0
ファイル: Form1.cs プロジェクト: nemanjaMet/MongoDB
        private void button10_Click(object sender, EventArgs e)
        {
            var client = new MongoClient("mongodb://localhost");
            var database = client.GetDatabase("docs");
            var fs = new GridFSBucket(database);

            //var aaa = fs.Find()
            var test = fs.DownloadAsBytesByName("Muzika");

            MemoryStream memStream = new MemoryStream(test);

            //OpenFileDialog open = new OpenFileDialog();
            //open.Filter = "Audio File (*.mp3;*.wav)|*.mp3;*.wav;";
            //if (open.ShowDialog() != DialogResult.OK) return;

            DisposeWave();

               // if (open.FileName.EndsWith(".mp3"))
               // {
                NAudio.Wave.WaveStream pcm = NAudio.Wave.WaveFormatConversionStream.CreatePcmStream(new NAudio.Wave.Mp3FileReader(memStream));
                stream = new NAudio.Wave.BlockAlignReductionStream(pcm);
               // }
               // else if (open.FileName.EndsWith(".wav"))
            //{
            //    NAudio.Wave.WaveStream pcm = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(open.FileName));
            //    stream = new NAudio.Wave.BlockAlignReductionStream(pcm);
            //}
            //else throw new InvalidOperationException("Not a correct audio file type.");

            output = new NAudio.Wave.DirectSoundOut();
            output.Init(stream);
            output.Play();
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: nemanjaMet/MongoDB
        private void button7_Click(object sender, EventArgs e)
        {
            var client = new MongoClient("mongodb://localhost");
            var database = client.GetDatabase("docs");
            var fs = new GridFSBucket(database);

            var test = fs.DownloadAsBytesByName("Test");

            //System.Drawing.ImageConverter converter = new System.Drawing.ImageConverter();
            //Image img = (Image)converter.ConvertFrom(test);

            //MemoryStream mem = new MemoryStream(test);

            Image returnImage = null;
            using (MemoryStream ms = new MemoryStream(test))
            {
                returnImage = Image.FromStream(ms);
            }
            //return returnImage;
            //Bitmap x = new Bitmap(mem, true);

            this.pictureBox1.Image = returnImage;
            this.pictureBox1.Height = returnImage.Height;
            this.pictureBox1.Width = returnImage.Width;
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: nemanjaMet/MongoDB
        private void button6_Click(object sender, EventArgs e)
        {
            //string host = "localhost";
            //int port = 27017;
            //string databaseName = "docs";

            //var _client = new MongoClient();
            //// var _database = (MongoDatabase)_client.GetDatabase("docs");

            //MemoryStream m = new MemoryStream();

            //var grid = new MongoGridFS(new MongoServer(new MongoServerSettings { Server = new MongoServerAddress(host, port) }), databaseName, new MongoGridFSSettings());

            //var file = grid.FindOne("Test");
            ////MongoGridFSStream read = grid.OpenRead("Test");
            ////read.CopyTo(m);
            //Image slika;
            //var newFileName = "D:\\new_Untitled.jpg";
            //using (var stream = file.OpenRead())
            //{
            //    var bytes = new byte[stream.Length];
            //    stream.Read(bytes, 0, (int)stream.Length);

            //    using (var newFs = new FileStream(newFileName, FileMode.Create))
            //    {

            //        newFs.Write(bytes, 0, bytes.Length);
            //        //slika = Image.FromStream(newFs);
            //    }
            //}

            var client = new MongoClient("mongodb://localhost");
            var database = client.GetDatabase("docs");
            var fs = new GridFSBucket(database);

            //var aaa = fs.Find()
            var test = fs.DownloadAsBytesByName("nebo");

            MemoryStream stream = new MemoryStream(test);

            this.pictureBox1.Image = Image.FromStream(stream);
        }
コード例 #4
0
ファイル: AuxLib.cs プロジェクト: perinjo/MongoDB
        public static byte[] LoadSoundFromGridFS(string reprezentacija)
        {
            var client = new MongoClient("mongodb://localhost");
            var database = client.GetDatabase("docs");
            var fs = new GridFSBucket(database);

            var data = fs.DownloadAsBytesByName(reprezentacija);
            
            return data;
        }
コード例 #5
0
ファイル: AuxLib.cs プロジェクト: perinjo/MongoDB
        public static Image LoadImageFromGridFS(string imeSlike)
        {
            try
            {
                var client = new MongoClient("mongodb://localhost");
                var database = client.GetDatabase("docs");
                var fs = new GridFSBucket(database);

                
                var data = fs.DownloadAsBytesByName(imeSlike);

                MemoryStream stream = new MemoryStream(data);

                return Image.FromStream(stream);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
        }
コード例 #6
0
ファイル: AuxLib.cs プロジェクト: darko14velickovic/MongoDB
        public static byte[] LoadSoundFromGridFS(string reprezentacija)
        {
            try
            {
                var client = new MongoClient("mongodb://localhost");
                var database = client.GetDatabase("docs");
                var fs = new GridFSBucket(database);

                var data = fs.DownloadAsBytesByName(reprezentacija);

                return data;
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
                return null;
            }
        }