Пример #1
0
        //Testing, randomly macthes analysis to files
        private void randomlyMatchAnalysis()
        {
            using (DBConnection db = new DBConnection())
            {
                var cmd = new MySqlCommand();
                cmd.CommandText = @"SELECT FID FROM File";

                var tableF = db.getFromDB(cmd);
                cmd = new MySqlCommand();

                cmd.CommandText = @"SELECT AID FROM Analysis";
                var tableA = db.getFromDB(cmd);

                MessageBox.Show(tableA.Rows.Count.ToString());
                foreach (DataRow dr in tableF.Rows)
                {
                    foreach (DataRow drA in tableA.Rows)
                    {
                        Random random       = new Random();
                        int    randomNumber = random.Next(0, 10);
                        System.Diagnostics.Debug.WriteLine(randomNumber);
                        if (randomNumber < 2)
                        {
                            cmd             = new MySqlCommand();
                            cmd.CommandText = "INSERT IGNORE INTO File2Analysis (File_FID, Analysis_AID) VALUES (@FID2, @AID)";
                            cmd.Parameters.AddWithValue("@FID2", dr["FID"].ToString());
                            cmd.Parameters.AddWithValue("@AID", drA["AID"].ToString());
                            db.insertIntoDB(cmd);
                        }
                    }
                }
            }

            MessageBox.Show("DONE");
        }
Пример #2
0
        /*When a row in the projects grid is selected, load the relevent speech data into the
         * speech datagrid, and do so efficiently.*/
        private void dataGridProjects_GotCellFocus(object sender, RoutedEventArgs e)
        {
            this.emptyGrid.Visibility = System.Windows.Visibility.Hidden;

            if (e.OriginalSource.GetType() == typeof(DataGridCell) && sender != null)
            {
                DataGridRow dgr  = sender as DataGridRow;
                var         item = dgr.DataContext as Project;

                if (item != null)
                {
                    string projectName = item.PID.ToString();
                    dgl.loadSpeakers(projectName);
                    //rowS = dgl.getCollection("S");


                    buildDatagridGroups(new ListCollectionView(rowS));
                }
            }

            using (DBConnection db = new DBConnection())
            {
                var cmd = new MySqlCommand();

                if (!projectSelectedName.Equals(""))
                {
                    cmd.CommandText = "SELECT Description FROM Project WHERE PID = '" + projectSelectedName + "'";
                }
                var table = db.getFromDB(cmd);
                foreach (DataRow dr in table.Rows)
                {
                    descTextBlock.Text = dr["Description"].ToString();
                }
            }
        }
Пример #3
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.");
                    }
                }
            }
        }
Пример #4
0
        public ObservableCollection <AnalysisViewModel> loadAnalysis(string fileName)
        {
            analysis.Clear();
            using (DBConnection db = new DBConnection())
            {
                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = @"SELECT a.AID, a.Description, a.FileType FROM Analysis a 
                                                INNER JOIN File2Analysis f2a ON a.AID = f2a.Analysis_AID
                                                INNER JOIN File f ON f.FID = f2a.File_FID
                                                WHERE f.Name = @ID";

                cmd.Parameters.AddWithValue("@ID", fileName);

                var table = db.getFromDB(cmd);
                foreach (DataRow dr in table.Rows)
                {
                    analysis.Add(new AnalysisViewModel {
                        Analysis = new Analysis {
                            AID = dr["AID"].ToString(), Description = dr["Description"].ToString(), FileType = dr["FileType"].ToString()
                        }
                    });
                }
            }
            return(this.analysis);
        }
Пример #5
0
        public ObservableCollection <SpeakerViewModel> loadSpeakers(string PID)
        {
            //if (PID == null)
            //{
            //    PID = "DefaultProject";
            //}
            speakers.Clear();
            using (DBConnection db = new DBConnection())
            {
                MySqlCommand cmd = new MySqlCommand();



                cmd.CommandText = "SELECT * FROM File WHERE PID = @pName"; // @name" ; // WHERE ProjectName = '" + PID + "'";
                //cmd.Parameters.AddWithValue("@name", name);
                cmd.Parameters.AddWithValue("@pName", PID);

                var table = db.getFromDB(cmd);
                foreach (DataRow dr in table.Rows)
                {
                    var speaker = dr["Speaker"].ToString();
                    speakers.Add(new SpeakerViewModel {
                        Speaker = new Speaker {
                            ID = dr["FID"].ToString(), Name = dr["Name"].ToString(), PID = dr["PID"].ToString(), SpeakerName = speaker, FileType = dr["FileType"].ToString(), Age = speaker[0].ToString()
                        }
                    });
                }
            }

            return(this.speakers);
        }
Пример #6
0
 // fill in the values of each project name in the combobox
 private void fillCombo()
 {
     using (DBConnection db = new DBConnection())
     {
         MySqlCommand cmd   = new MySqlCommand("SELECT * FROM Project");
         var          table = db.getFromDB(cmd);
         foreach (DataRow dr in table.Rows)
         {
             string projectName = dr["PID"].ToString();
             cbChooseFolder.Items.Add(projectName);
             folderNameCB = (string)cbChooseFolder.SelectedValue;
         }
     }
 }
Пример #7
0
        /* Downloads a selected project on a background thread. */
        private void backgroundWorker_DoWork(
            object sender,
            DoWorkEventArgs e)
        {
            string[] parameters = e.Argument as string[];
            string   PID        = parameters[1];
            string   path       = parameters[0];

            this.Dispatcher.Invoke((Action)(() =>
            {
                prog.Show();
            }));


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

            /* Get file data for every file in project and save it in the correct folder structure. */
            using (DBConnection db = new DBConnection())
            {
                var cmd = new MySqlCommand();
                cmd.CommandText = "SELECT f.Name, f.Speaker, f.FileType, fd.FileData FROM FileData fd INNER JOIN File f ON f.FID = fd.FID WHERE f.PID = @PID";
                cmd.Parameters.AddWithValue("@PID", PID);

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

                    Directory.CreateDirectory(path + PID + @"\" + dr["Speaker"].ToString());
                    fs = new FileStream(path + PID + @"\" + dr["Speaker"].ToString() + @"\" + dr["Name"].ToString() + dr["FileType"].ToString(), FileMode.OpenOrCreate, FileAccess.Write);

                    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();
                }
            }
        }
Пример #8
0
        public ObservableCollection<AnalysisViewModel> loadAnalysis(string fileName)
        {
            analysis.Clear();
            using (DBConnection db = new DBConnection())
            {
                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = @"SELECT a.AID, a.Description, a.FileType FROM Analysis a
                                                INNER JOIN File2Analysis f2a ON a.AID = f2a.Analysis_AID
                                                INNER JOIN File f ON f.FID = f2a.File_FID
                                                WHERE f.Name = @ID";

                cmd.Parameters.AddWithValue("@ID", fileName);

                var table = db.getFromDB(cmd);
                foreach (DataRow dr in table.Rows)
                {
                    analysis.Add(new AnalysisViewModel { Analysis = new Analysis { AID = dr["AID"].ToString(), Description = dr["Description"].ToString(), FileType = dr["FileType"].ToString() } });
                }
            }
            return this.analysis;
        }
Пример #9
0
        public ObservableCollection <ProjectViewModel> loadProjects()
        {
            projects.Clear();
            using (DBConnection db = new DBConnection())
            {
                MySqlCommand query = new MySqlCommand("SELECT PID, DateCreated, Description FROM Project");

                var table = db.getFromDB(query);
                foreach (DataRow dr in table.Rows)
                {
                    string[] dateOnly = dr["dateCreated"].ToString().Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
                    projects.Add(new ProjectViewModel {
                        Project = new Project {
                            PID = dr["PID"].ToString(), DateCreated = dateOnly[0], Description = dr["Description"].ToString()
                        }
                    });
                }
            }

            return(this.projects);
        }
Пример #10
0
        public ObservableCollection<ProjectViewModel> loadProjects()
        {
            projects.Clear();
            using (DBConnection db = new DBConnection())
            {
                MySqlCommand query = new MySqlCommand("SELECT PID, DateCreated, Description FROM Project");

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

                    string[] dateOnly = dr["dateCreated"].ToString().Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
                    projects.Add(new ProjectViewModel { Project = new Project { PID = dr["PID"].ToString(), DateCreated = dateOnly[0], Description = dr["Description"].ToString() } });
                }
            }

            return this.projects;
        }
Пример #11
0
        public ObservableCollection<SpeakerViewModel> loadSpeakers(string PID)
        {
            //if (PID == null)
            //{
            //    PID = "DefaultProject";
            //}
            speakers.Clear();
            using (DBConnection db = new DBConnection())
            {
                MySqlCommand cmd = new MySqlCommand();

                cmd.CommandText = "SELECT * FROM File WHERE PID = @pName"; // @name" ; // WHERE ProjectName = '" + PID + "'";
                //cmd.Parameters.AddWithValue("@name", name);
                cmd.Parameters.AddWithValue("@pName", PID);

                var table = db.getFromDB(cmd);
                foreach (DataRow dr in table.Rows)
                {
                    var speaker = dr["Speaker"].ToString();
                    speakers.Add(new SpeakerViewModel { Speaker = new Speaker { ID = dr["FID"].ToString(), Name = dr["Name"].ToString(), PID = dr["PID"].ToString(), SpeakerName = speaker, FileType = dr["FileType"].ToString(), Age = speaker[0].ToString() } });

                }

            }

            return this.speakers;
        }
Пример #12
0
        // fill in the values of each project name in the combobox
        private void fillCombo()
        {
            using (DBConnection db = new DBConnection())
            {
                MySqlCommand cmd = new MySqlCommand("SELECT * FROM Project");
                var table = db.getFromDB(cmd);
                foreach (DataRow dr in table.Rows)
                {

                    string projectName = dr["PID"].ToString();
                    cbChooseFolder.Items.Add(projectName);
                    folderNameCB = (string)cbChooseFolder.SelectedValue;
                }

            }
        }
Пример #13
0
        //Testing, randomly macthes analysis to files
        private void randomlyMatchAnalysis()
        {
            using (DBConnection db = new DBConnection())
            {
                var cmd = new MySqlCommand();
                cmd.CommandText = @"SELECT FID FROM File";

                var tableF = db.getFromDB(cmd);
                cmd = new MySqlCommand();

                cmd.CommandText = @"SELECT AID FROM Analysis";
                var tableA = db.getFromDB(cmd);

                MessageBox.Show(tableA.Rows.Count.ToString());
                foreach (DataRow dr in tableF.Rows)
                {
                    foreach (DataRow drA in tableA.Rows)
                    {

                        Random random = new Random();
                        int randomNumber = random.Next(0, 10);
                        System.Diagnostics.Debug.WriteLine(randomNumber);
                        if (randomNumber < 2)
                        {
                            cmd = new MySqlCommand();
                            cmd.CommandText = "INSERT IGNORE INTO File2Analysis (File_FID, Analysis_AID) VALUES (@FID2, @AID)";
                            cmd.Parameters.AddWithValue("@FID2", dr["FID"].ToString());
                            cmd.Parameters.AddWithValue("@AID", drA["AID"].ToString());
                            db.insertIntoDB(cmd);

                        }
                    }
                }

            }

            MessageBox.Show("DONE");
        }
Пример #14
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.");
                    }
                }
            }
        }
Пример #15
0
        /*When a row in the projects grid is selected, load the relevent speech data into the
         * speech datagrid, and do so efficiently.*/
        private void dataGridProjects_GotCellFocus(object sender, RoutedEventArgs e)
        {
            this.emptyGrid.Visibility = System.Windows.Visibility.Hidden;

            if (e.OriginalSource.GetType() == typeof(DataGridCell) && sender != null)
            {
                DataGridRow dgr = sender as DataGridRow;
                var item = dgr.DataContext as Project;

                if (item != null)
                {

                    string projectName = item.PID.ToString();
                    dgl.loadSpeakers(projectName);
                    //rowS = dgl.getCollection("S");

                    buildDatagridGroups(new ListCollectionView(rowS));
                }

            }

            using (DBConnection db = new DBConnection())
            {
                var cmd = new MySqlCommand();

                if (!projectSelectedName.Equals(""))
                {
                    cmd.CommandText = "SELECT Description FROM Project WHERE PID = '" + projectSelectedName + "'";
                }
                var table = db.getFromDB(cmd);
                foreach (DataRow dr in table.Rows)
                {
                    descTextBlock.Text = dr["Description"].ToString();
                }
            }
        }
Пример #16
0
        /* Downloads a selected project on a background thread. */
        private void backgroundWorker_DoWork(
            object sender,
            DoWorkEventArgs e)
        {
            string[] parameters = e.Argument as string[];
            string PID = parameters[1];
            string path = parameters[0];

            this.Dispatcher.Invoke((Action)(() =>
            {
                prog.Show();
            }));

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

            /* Get file data for every file in project and save it in the correct folder structure. */
            using (DBConnection db = new DBConnection())
            {
                var cmd = new MySqlCommand();
                cmd.CommandText = "SELECT f.Name, f.Speaker, f.FileType, fd.FileData FROM FileData fd INNER JOIN File f ON f.FID = fd.FID WHERE f.PID = @PID";
                cmd.Parameters.AddWithValue("@PID", PID);

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

                    rawData = (byte[])dr["FileData"];

                    Directory.CreateDirectory(path + PID + @"\" + dr["Speaker"].ToString());
                    fs = new FileStream(path + PID + @"\" + dr["Speaker"].ToString() + @"\" + dr["Name"].ToString() + dr["FileType"].ToString(), FileMode.OpenOrCreate, FileAccess.Write);

                    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();
                }

            }
        }