Ejemplo n.º 1
0
        public static void TestConnection(AppWorking f, bool alertUser, bool addToServers)
        {
            var server = f.textBox4.Text;// "localhost";
            var db = (string)(f.comboBoxDatabases.SelectedItem);
            var uid = f.textBoxUsername.Text;
            var pwd = f.textBoxPassword.Text;

            AppWorking.TestConnection(f, server, db, uid, pwd, alertUser, addToServers);
        }
Ejemplo n.º 2
0
        private void bgw_RunWorkerCompleted_SQLBlast(object sender, RunWorkerCompletedEventArgs e)
        {
            var backgroundWorker = (BackgroundWorker)sender;

            if (this._loadingForm == null)
                return;

            this._loadingForm.Close();
            if (!this._loadingForm.IsProgressComplete())
            {
                this._loadingForm = null;
                return;
            }
            this._loadingForm = null;

            if (!backgroundWorker.CancellationPending)
                this.LocalBlast(true);
        }
Ejemplo n.º 3
0
        //Background Blast Worker
        void bgw_RunWorkerCompleted_LocalBlast(object sender, RunWorkerCompletedEventArgs e)
        {
            var backgroundWorker = (BackgroundWorker)sender;
            if (backgroundWorker.CancellationPending)
                return;

            if (this._loadingForm == null)
                return;

            this._loadingForm.Close();

            if (this._loadingForm == null)
                return;

            if (!this._loadingForm.IsProgressComplete())
            {
                this._loadingForm = null;
                return;
            }
            this._loadingForm = null;

            var dbp = Program.LocalDatabaseDirectory;// this.textBoxLBDWD.Text;
            var outBlastFilePath = dbp + @"~tempBlast.txt";
            var b = File.Exists(outBlastFilePath);

            var tt = Management.GetTextFromFile(outBlastFilePath);
            this.richTextBoxLocalBlast.Lines = tt;
            this.BlastSplitContainer.Panel2.Enabled = true;
            //this.Show();
            //this.Invalidate();
        }
Ejemplo n.º 4
0
 //Setters
 public void ClearLoadingForm()
 {
     this._loadingForm = null;
 }
Ejemplo n.º 5
0
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            var bgw = new BackgroundWorker();

            //if (tt == "Local")
            //    bgw.DoWork += bgw_DoWork_LocalBlast;
            //else if (tt == "URL")
            //    bgw.DoWork += bgw_DoWork_LocalBlast;
            //else
            //{
            //    MessageBox.Show("Invalid blast source.", "Error");
            //    return;
            //}

            //bgw.RunWorkerCompleted += bgw_RunWorkerCompleted_LocalBlast;
            this._loadingForm = new AppWorking(AppWorking.Type.LoadMySQLDatabase, "Provide the information below to connect to a SQL database.", this, bgw);
            this.Enabled = false;

            return;

            /*SqlConnection myConnection = new SqlConnection("user id=root;" +
                                       "password=rjw30181;server=localhost:3306;" +
                                       "Trusted_Connection=yes;" +
                                       "database=main; " +
                                       "connection timeout=3");*/

            var cs = "uid = admin;" +
                "pwd = bios455;" +
                "server = 127.0.0.1;" +
                "database = localhost; " +
                "connection timeout = 3";

            //Server=myServerAddress;Port=1234;Database=myDataBase;Uid=myUsername;
            //Pwd = myPassword;
            var server = "localhost";// "localhost";
            var database = "arcogs";
            var uid = "admin";
            var password = "******";
            var connectionString = "server=" + server + ";" + "database=" +
                database + ";" + "userid=" + uid + ";" + "password="******";" +
                "Connection Timeout=3";

            var sc = new MySqlConnection(connectionString);
            while (true)
            {
                var os = "";
                try
                {
                    using (sc)
                    {
                        sc.Open();
                        os += "ServerVersion: " + sc.ServerVersion + "\n";
                        os += "Database: " + sc.Database;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("The connection to the database has timed out with the given parameters.\n\n" + ex.ToString(), this.Text);
                    break;
                }

                MessageBox.Show("User " + uid + " successfully connected to databse " + database + " on server " + server + ".\n\n" + os, this.Text);
                this.AppSQL.AddDatabase(uid, password, server, database);

                break;
            }

            try
            {
                sc.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("The connection to the database was unable to succesfully close.\n\n" + ex.ToString(), this.Text);
            }

            return;
        }
Ejemplo n.º 6
0
        private bool SQLBlast(bool perform)
        {
            var db = (string)this.listBoxBlastSQLDB.SelectedItem;
            var table = (string)this.listBoxBlastSQLTable.SelectedItem;

            if (db == null || db == "" || table == null || table == "")
            {
                if (this.listBoxBlastSQLDB.Items.Count == 0)
                    MessageBox.Show("A database containing a fasta table is required.", this.TitleText + " - Error");
                else
                    MessageBox.Show("Invalid database query parameters.", this.TitleText + " - Error");
                return false;
            }

            if (!this.LocalBlast(false))
                return false;

            if (!perform)
                return true;

            //Create the loading form, which runs the blast in the background.
            var bgw = new BackgroundWorker();
            Program.SelectedDatabase = db;
            Program.SelectedTable = table;
            bgw.DoWork += bgw_DoWork_SQLBlast;
            bgw.RunWorkerCompleted += bgw_RunWorkerCompleted_SQLBlast;
            this._loadingForm = new AppWorking("Downloading SQL database for local blast...", this, bgw);
            this._loadingForm.RunWorker();
            this.Enabled = false;

            return true;

            //var cols = this.AppSQL.GetColumnsInTable
        }
Ejemplo n.º 7
0
        private bool LocalBlast(bool perform)
        {
            var filePath = this.textBoxLBDFP.Text;
            var databasePath = this.textBoxLBDWD.Text;
            var exePath = this.textBoxLBEXED.Text;
            var outBlastFilePath = databasePath + @"~tempLocalBlast.txt";

            this.pictureBox1.Image = null;
            this.pictureBox2.Image = null;
            this.pictureBox3.Image = null;
            this.pictureBox4.Image = null;
            this.richTextBoxLocalBlast.Text = "";
            this.BlastSplitContainer.Panel2.Enabled = false;
            if (!File.Exists(filePath))
            {
                this.pictureBox1.Image = ((System.Drawing.Image)
                    (new System.ComponentModel.ComponentResourceManager(typeof(AppForm)).GetObject("pictureBox2.Image")));
                MessageBox.Show("Invalid sequence file path for database construction.", this.TitleText + " - Error");
                return false;
            }
            else
                this.pictureBox1.Image = ((System.Drawing.Image)
                    (new System.ComponentModel.ComponentResourceManager(typeof(AppForm)).GetObject("pictureBox1.Image")));

            if (!Directory.Exists(databasePath))
            {
                this.pictureBox2.Image = ((System.Drawing.Image)
                    (new System.ComponentModel.ComponentResourceManager(typeof(AppForm)).GetObject("pictureBox2.Image")));
                MessageBox.Show("Invalid path for local blast database.", this.TitleText + " - Error");
                return false;
            }
            else
                this.pictureBox2.Image = ((System.Drawing.Image)
                    (new System.ComponentModel.ComponentResourceManager(typeof(AppForm)).GetObject("pictureBox1.Image")));

            if (!Directory.Exists(exePath) || !File.Exists(exePath + @"\makeblastdb.exe"))
            {
                this.pictureBox4.Image = ((System.Drawing.Image)
                    (new System.ComponentModel.ComponentResourceManager(typeof(AppForm)).GetObject("pictureBox2.Image")));
                MessageBox.Show("Invalid path for NCBI executables.", this.TitleText + " - Error");
                return false;
            }
            else
                this.pictureBox4.Image = ((System.Drawing.Image)
                    (new System.ComponentModel.ComponentResourceManager(typeof(AppForm)).GetObject("pictureBox1.Image")));

            if (this.textBoxBlastSeq.Text == "")
            {
                this.pictureBox3.Image = ((System.Drawing.Image)
                    (new System.ComponentModel.ComponentResourceManager(typeof(AppForm)).GetObject("pictureBox2.Image")));
                MessageBox.Show("Invalid sequence for blast.", this.TitleText + " - Error");
                return false;
            }
            else
                this.pictureBox3.Image = ((System.Drawing.Image)
                    (new System.ComponentModel.ComponentResourceManager(typeof(AppForm)).GetObject("pictureBox1.Image")));

            if (File.Exists(outBlastFilePath))
                File.Delete(outBlastFilePath);
            var t = this.toolStripBlastButton.Text.Split(' ');
            var tt = t[t.Length - 1];

            /*if (tt == "Local")
            else if (tt == "URL")
                bgw.DoWork += bgw_DoWork_LocalBlast;
            else
            {
                MessageBox.Show("Invalid blast source.", "Error");
                return false;
            }*/

            if (!perform)
                return true;

            //Create the loading form, which runs the blast in the background.
            if (tt == "SQL")
                tt = "local " + tt;

            tt = tt.Replace("Local", "local");

            var bgw = new BackgroundWorker();
            bgw.DoWork += bgw_DoWork_LocalBlast;
            bgw.RunWorkerCompleted += bgw_RunWorkerCompleted_LocalBlast;
            this._loadingForm = new AppWorking("Performing " + tt + " blast...", this, bgw);
            this._loadingForm.RunWorker();
            this.Enabled = false;

            return true;
        }
Ejemplo n.º 8
0
        public List<List<string>> GetRowsInTable(string dbName, string tableName, string queryField, string queryValue, AppWorking appW)
        {
            //SELECT * FROM pet WHERE species = 'snake' OR species = 'bird';
            var tr = -1.0;
            if (appW != null)
                tr = this.GetTotalRowsInTable(dbName, tableName) - 1;

            //Get SQL Columns and verify a fasta and sequence columne exist for blasting
            string connection = this._dbStringMap[dbName].GetConnectionString();
            List<List<string>> t = new List<List<string>>();
            t.Add(new List<string>());
            using (var con = new MySqlConnection(connection))
            {
                var x = "";

                if (queryField != null && queryValue != null)
                    x = " WHERE \"" + queryField + "\" = " + queryValue;

                string com = "SELECT * FROM " + tableName + x + ";";
                using (var schemaCommand = new MySqlCommand(com, con))
                {
                    con.Open();
                    using (var reader = schemaCommand.ExecuteReader())
                    {
                        var tc = 0;
                        while (reader.Read())
                        {
                            tc++;
                            for (int i = 0; i < reader.FieldCount; i++)
                            {
                                var ti = reader.GetValue(i);
                                var s = ti.ToString();

                                if (s.ToLower().Contains("system.byte[]"))
                                {
                                    var tb = (byte[])ti;
                                    s = "";
                                    for (int j = 0; j < tb.Length; j++)
                                        s += Convert.ToChar(tb[j]);

                                }

                                bool newLine = false;
                                if (s.Length > 0 && s.Substring(s.Length - 1, 1) == "\r")
                                {
                                    newLine = true;
                                    s = s.Substring(0, s.Length - 1);
                                }

                                t[t.Count - 1].Add(s);

                                if (newLine)
                                    t.Add(new List<string>());
                            }

                            if (appW != null)
                                appW.AddProgressPercent(null, 1.0 / tr);
                        }
                    }
                }
            }

            //var r = new List<string>();
            //if (nameOnly)
                //for (int i = 0; i < Columnnames.Count; i += 6)
                //    r.Add(Columnnames[i]);
            //else
            //    for (int i = 0; i < t.Count; i++)
            //        r.Add(t[i]);

            for (int i = 0; i < t.Count; i++)
            {
                if (t[i].Count == 0)
                {
                    t.RemoveAt(i);
                    i--;
                }
            }

            return t;
        }
Ejemplo n.º 9
0
 public List<List<string>> GetRowsInTable(string dbName, string tableName, AppWorking appW)
 {
     return this.GetRowsInTable(dbName, tableName, null, null, appW);
 }
Ejemplo n.º 10
0
        private static void TestConnection(AppWorking f, string server, string db, string uid, string pwd, bool alertUser, bool addToServers)
        {
            var outpt = f.parent.AppSQL.TestConnection(server, db, uid, pwd, addToServers);

            if (outpt == null && alertUser)
            {
                MessageBox.Show("The connection to the database could not be made with given parameters.\n\n",
                    f.parent.TitleText + " - Test Connection Fail");
                return;
            }

            if (alertUser)
                MessageBox.Show(outpt, f.parent.TitleText + " - Test Connection Success");

            return;
            /*
            var connectionString = "server=" + server + ";" + "database=" +
                db + ";" + "userid=" + uid + ";" + "password="******";" +
                "Connection Timeout=3";

            var sqlConnection = new MySqlConnection(connectionString);
            while (true)
            {
                var os = "";
                try
                {
                    using (sqlConnection)
                    {
                        sqlConnection.Open();
                        os += "User:\t\t" + uid + "\n";
                        if (sqlConnection.Database == "")
                            db = "(none selected)";

                        os += "Database:\t\t" + db + "\n";

                        os += "Server:\t\t" + server + "\n";
                        os += "ServerVersion:\t" + sqlConnection.ServerVersion + "\n";
                    }
                }
                catch (Exception ex)
                {
                    if (alertUser)
                        MessageBox.Show("The connection to the database could not be made.\n\n" + ex.ToString(),
                            f.parent.TitleText + " - Test Connection Fail");
                    break;
                }

                f.tempConnectString = connectionString;

                if (addToServers)
                {
                    if (db != "(none selected)")
                    {
                        if (addToServers)
                            f.parent.AppSQL.AddDatabase(uid, pwd, server, db);

                        if (alertUser)
                            MessageBox.Show("Database added successfully.\n\n" + os, f.parent.TitleText + " - Database Added");
                        f.Close();
                    }
                    else
                    {
                        if (alertUser)
                            MessageBox.Show("Select database to add",f.parent.TitleText);
                    }

                }
                else
                {
                    if (alertUser)
                        MessageBox.Show("User " + uid + " successfully connected to database " + db + " on server " + server + ".\n\n" + os,
                            f.parent.TitleText + " - Test Connection Success");
                }

                break;
            }

            try
            {
                sqlConnection.Close();
            }
            catch (Exception ex)
            {
                if (alertUser)
                    MessageBox.Show("The connection to the database was unable to succesfully close.\n\n" + ex.ToString(), f.Text);
            }

            return;*/
        }