Exemplo n.º 1
0
        /*Downlaods and opens the file selected, or plays it if its a .wav(audio) */
        private void openOrPlayFile(MySqlCommand cmd, string fileName, string fileType, string projectName, Object row)
        {
            using (DBConnection db = new DBConnection())
            {
                byte[]     rawData;
                FileStream fs;
                string     filePath = "";

                //Checks for the file type (speaker or analysis) and then puts it in the correct folder location
                if (row is Analysis)
                {
                    Directory.CreateDirectory(testDBRoot + "\\ANALYSIS");
                    fs = new FileStream(testDBRoot + "\\ANALYSIS\\" + fileName + fileType, FileMode.OpenOrCreate, FileAccess.Write);
                }
                else
                {
                    Directory.CreateDirectory(@"..\..\..\..\testOutput\" + projectName + "\\" + ((Speaker)row).SpeakerName);
                    fs = new FileStream(@"..\..\..\..\testOutput\" + projectName + "\\" + ((Speaker)row).SpeakerName + "\\" + fileName + fileType, FileMode.OpenOrCreate, FileAccess.Write);
                }

                var table = db.getFromDB(cmd);
                foreach (DataRow dr in table.Rows)
                {
                    rawData = (byte[])dr["FileData"]; // convert successfully to byte[]


                    filePath = fs.Name;

                    //Fixed access denied error
                    File.SetAttributes(filePath, FileAttributes.Normal);

                    // Writes a block of bytes to this stream using data from
                    // a byte array.
                    fs.Write(rawData, 0, rawData.Length);

                    // close file stream
                    fs.Close();
                }


                // Filter audio, images etc. to open appropriate program
                if (fileType.Equals(".wav") || fileType.Equals(".WAV"))
                {
                    var audio = new AudioWindow(filePath);
                    audio.Show();
                }
                else
                {
                    try
                    {
                        Process.Start("notepad++.exe", filePath);
                        //Process.Start(filePath);
                    }
                    catch
                    {
                        MessageBox.Show("Access denied, please run application with administrator privileges.");
                    }
                }
            }
        }
Exemplo n.º 2
0
        /*Downlaods and opens the file selected, or plays it if its a .wav(audio) */
        private void openOrPlayFile(MySqlCommand cmd, string fileName, string fileType, string projectName, Object row)
        {
            using (DBConnection db = new DBConnection())
            {

                byte[] rawData;
                FileStream fs;
                string filePath = "";

                //Checks for the file type (speaker or analysis) and then puts it in the correct folder location
                if (row is Analysis)
                {
                    Directory.CreateDirectory(testDBRoot + "\\ANALYSIS");
                    fs = new FileStream(testDBRoot + "\\ANALYSIS\\" + fileName + fileType, FileMode.OpenOrCreate, FileAccess.Write);
                }
                else
                {

                    Directory.CreateDirectory(@"..\..\..\..\testOutput\" + projectName + "\\" + ((Speaker)row).SpeakerName);
                    fs = new FileStream(@"..\..\..\..\testOutput\" + projectName + "\\" + ((Speaker)row).SpeakerName + "\\" + fileName + fileType, FileMode.OpenOrCreate, FileAccess.Write);
             }

                var table = db.getFromDB(cmd);
                foreach (DataRow dr in table.Rows)
                {

                    rawData = (byte[])dr["FileData"]; // convert successfully to byte[]

                    filePath = fs.Name;

                    //Fixed access denied error
                    File.SetAttributes(filePath, FileAttributes.Normal);

                    // Writes a block of bytes to this stream using data from
                    // a byte array.
                    fs.Write(rawData, 0, rawData.Length);

                    // close file stream
                    fs.Close();

                }

                // Filter audio, images etc. to open appropriate program
                if (fileType.Equals(".wav") || fileType.Equals(".WAV"))
                {
                    var audio = new AudioWindow(filePath);
                    audio.Show();

                }
                else
                {

                    try
                    {
                        Process.Start("notepad++.exe", filePath);
                        //Process.Start(filePath);
                    }
                    catch
                    {
                        MessageBox.Show("Access denied, please run application with administrator privileges.");
                    }
                }
            }
        }