Example #1
0
        private void cmbInstanceList_SelectedIndexChanged(object sender, EventArgs e)
        {
            SqlInstances inst = (SqlInstances)this.Tag;
            ComboBox     cb   = (ComboBox)sender;

            inst.InstanceToImport = cb.SelectedItem.ToString();
        }
Example #2
0
        private void fmSelectInstance_Load(object sender, EventArgs e)
        {
            SqlInstances inst = (SqlInstances)this.Tag;

            foreach (String k in inst.InstanceList())
            {
                cmbInstanceList.Items.Add(k);
            }
            cmbInstanceList.SelectedIndex = 0;
            Application.DoEvents();
        }
Example #3
0
        private void DoImport()
        {
            if (CheckAndStop())
            {
                return;
            }
            if (!tlpFiles.Visible)
            {
                this.Height          = 500;
                this.Width           = 850;
                this.FormBorderStyle = FormBorderStyle.Sizable;
                tlpFiles.Visible     = true;
                ssStatus.Visible     = true;
            }

            MainForm.LogMessage("Starting import...");

            if (tsiDropDBBeforeImporting.Checked == true || ImportOptions.IsEnabled("DropDbBeforeImporting"))
            {
                if (Globals.ConsoleMode == false)
                {
                    DialogResult dr = MainForm.LogMessage(String.Format(Properties.Resources.Warning_ToDropDB, Globals.credentialMgr.Database), "Danger", MessageBoxButtons.YesNo);
                    MainForm.LogMessage("dialog result = " + dr.ToString());
                    if (dr == DialogResult.No)
                    {
                        return;
                    }
                    else if (dr == DialogResult.Yes && Globals.credentialMgr.Database.ToLower() != "sqlnexus")
                    {
                        DialogResult reconfirm = MainForm.LogMessage(String.Format("Are you sure you really want to drop database {0}?", Globals.credentialMgr.Database), "Danger", MessageBoxButtons.YesNo);
                        if (DialogResult.No == reconfirm)
                        {
                            return;
                        }
                    }
                }

                SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
                builder.ConnectionString = Globals.credentialMgr.ConnectionString;
                builder.InitialCatalog   = "master";
                SqlConnection conn = new SqlConnection(builder.ConnectionString);
                SqlCommand    cmd  = conn.CreateCommand();
                cmd.CommandText = String.Format(Properties.Resources.CreateDropDB, Globals.credentialMgr.Database);
                try
                {
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
                catch (SqlException sqlex)
                {
                    MainForm.LogMessage("Create Db failed with exception " + sqlex.Message, MessageOptions.Dialog);
                    return;
                }
                finally
                {
                    conn.Close();
                }
            }

            RunScript("SqlNexus_PreProcessing.sql");
            MainForm.LogMessage("Adding Nexus Importer Version" + Globals.credentialMgr.ConnectionString);
            NexusInfo nInfo = new NexusInfo(Globals.credentialMgr.ConnectionString, this.MainForm);

            nInfo.SetAttribute("Nexus Importer Version", Application.ProductVersion);



            int startTicks = Environment.TickCount;

            MainForm.StartStopSpinner(true, MainForm.spnImporter);

            //Switch button/modes to Stop mode
            EnableButtons(false);
            tsbGo.Image = sqlnexus.Properties.Resources.RecordHS1;
            tsbGo.Text  = "Stop";
            Application.DoEvents();

            // Close any open reports based on the data that we're about to overwrite
            fmNexus.singleton.CloseAll();

            string srcPath = Path.GetFullPath(cbPath.Text.Trim().Replace("\"", ""));

            /*
             * string pathFromCmd = Globals.PathsToImport.Dequeue();
             * if (pathFromCmd != null)
             *  srcPath = pathFromCmd;
             * else
             * srcPath=  Path.GetFullPath(cbPath.Text);
             */

            sqlnexus.Properties.Settings.Default.ImportPath = srcPath;
            if (srcPath[srcPath.Length - 1] != '\\')
            {
                srcPath += '\\';
            }
            if (-1 == cbPath.Items.IndexOf(srcPath))
            {
                cbPath.Items.Add(srcPath);
            }
            instances = new SqlInstances(srcPath);

            if (instances.Count > 1 && Globals.QuietMode)
            {
                //get first instance for quiet mode (list already sorted;
                MainForm.LogMessage("quiet mode. Silently select first instance (sorted) for instance: " + instances.InstanceList()[0], MessageOptions.Silent);
                instances.InstanceToImport = instances.InstanceList()[0];
            }
            else if (instances.Count > 1)
            {
                fmSelectInstance chooseInstancefm = new fmSelectInstance();
                chooseInstancefm.Tag = instances;
                chooseInstancefm.ShowDialog();
            }

            DiagConfig config = new DiagConfig(srcPath);

            nInfo.SetAttribute("SQLVersion", config.SQLVersion);
            EnumFiles();

            //AddLabel();
            bool RunScripts = true;
            bool Success    = false;

            CustomXELImporter CI = new CustomXELImporter();

            CI.SQLBaseImport(Globals.credentialMgr.ConnectionString, Globals.credentialMgr.Server,
                             Globals.credentialMgr.WindowsAuth,
                             Globals.credentialMgr.User,
                             Globals.credentialMgr.Password,
                             Globals.credentialMgr.Database, srcPath);


            try
            {
                int j = 0;
                for (int i = 0; i < tlpFiles.Controls.Count; i++)
                {
                    //if (tlpFiles.Controls[i] is LinkLabel)
                    if (tlpFiles.Controls[i] is Label && tlpFiles.Controls[i].Name == "FileNameLabel")
                    {
                        System.Diagnostics.Debug.Assert((null != tlpFiles.Controls[i + 1]) && (null != tlpFiles.Controls[i + 2]));
                        //LinkLabel ll = (LinkLabel)tlpFiles.Controls[i];
                        Label ll = (Label)tlpFiles.Controls[i];
                        currBar       = (ProgressBar)tlpFiles.Controls[i + 1];
                        currBar.Value = 0;
                        currLabel     = (Label)tlpFiles.Controls[i + 2];

                        int ticks = Environment.TickCount;

                        ri = (ll.Tag as INexusImporter);
                        MainForm.LogMessage(ri.Name + " is a INexusImporter");

                        try
                        {
                            ri.Initialize(srcPath + (tlpFiles.Controls[i] as /*LinkLabel*/ Label).Text,
                                          Globals.credentialMgr.ConnectionString,
                                          Globals.credentialMgr.Server,
                                          Globals.credentialMgr.WindowsAuth,
                                          Globals.credentialMgr.User,
                                          Globals.credentialMgr.Password,
                                          Globals.credentialMgr.Database,
                                          MainForm);

                            //Run pre-scripts and cache post scripts for later use
                            if (!PostScripts.ContainsKey(ri.GetType().Name))
                            {
                                PostScripts.Add(ri.GetType().Name, ri.PostScripts);
                                foreach (string s in ri.PreScripts)
                                {
                                    RunScript(s);
                                }
                            }

                            if (!(ri is INexusFileSizeReporter))
                            {
                                currBar.Style = ProgressBarStyle.Marquee;
                            }

                            //Import the data
                            Success = ri.DoImport();



                            if (ri.Name.ToLower().Contains("rowset"))
                            {
                                RunPostScripts();
                            }
                            Globals.IsNexusCoreImporterSuccessful = true;
                            //ll.LinkBehavior = LinkBehavior.HoverUnderline;
                        }
                        catch (Exception ex)
                        {
                            if (ri.Name == "Rowset Importer")
                            {
                                Globals.IsNexusCoreImporterSuccessful = false;
                            }
                            Success = false;
                            Globals.HandleException(ex, this, MainForm);
                        }

                        currBar.Style = ProgressBarStyle.Blocks;
                        string msg;
                        msg = "(Importer:" + ri.Name + ") ";
                        if (ri.Canceled)        // different msg if import was canceled.
                        {
                            RunScripts = false;
                            msg       += "Canceled. (" + (Environment.TickCount - ticks) / 1000 + " sec, ";
                            if (ri is INexusFileImporter)
                            {
                                msg += this.currBar.Value.ToString() + "% complete)";
                            }
                            else
                            {
                                msg += ri.TotalLinesProcessed + " rows inserted)";
                            }
                            MainForm.LogMessage(msg);
                            currLabel.Text = msg;
                            break;
                        }
                        else if (!Success)      // set summary msg if import failed
                        {
                            RunScripts = false;
                            msg       += "Import failed. (" + (Environment.TickCount - ticks) / 1000 + " sec, ";
                            if (ri is INexusFileImporter)
                            {
                                msg += this.currBar.Value.ToString() + "% complete)";
                            }
                            else
                            {
                                msg += ri.TotalLinesProcessed + " rows inserted)";
                            }
                            MainForm.LogMessage(msg);
                            currLabel.Text = msg;
                        }
                        else                                    // different msg if success
                        {
                            currBar.Value = currBar.Maximum;

                            msg += "Done. (" + (Environment.TickCount - ticks) / 1000 + " sec";
                            if (ri is INexusFileImporter)
                            {
                                msg += ", " + ((ri as INexusFileImporter).FileSize / 1000 / 1000) + "MB), ";
                            }
                            else
                            {
                                msg += "), ";
                            }
                            msg += msg = string.Format("{0} lines processed; {1} rows inserted.", ri.TotalLinesProcessed, ri.TotalRowsInserted);
                            MainForm.LogMessage(msg);
                            currLabel.Text = msg;
                        }
                        ri = null;
                        j++;
                    }
                }


                MainForm.LogMessage("RawFileImporter starting");
                RawFileImporter rawfileimporter = new RawFileImporter(Globals.credentialMgr.Server, Globals.credentialMgr.Database, srcPath);
                rawfileimporter.DoImport();
                MainForm.LogMessage("RawFileImporter completed");

                StringBuilder output = new StringBuilder();

                ProcessStartInfo psi = new ProcessStartInfo();
                psi.CreateNoWindow         = true;
                psi.RedirectStandardOutput = true;
                psi.RedirectStandardInput  = true;
                psi.UseShellExecute        = false;
                psi.Arguments = string.Format("{0} {1} \"{2}\"", Globals.credentialMgr.Server, Globals.credentialMgr.Database, srcPath);
                MainForm.LogMessage("PostProcess argument " + psi.Arguments);
                psi.FileName = "PostProcess.cmd";

                Process process = new Process();
                process.StartInfo = psi;

                process.EnableRaisingEvents = true;

                process.OutputDataReceived += new DataReceivedEventHandler
                                              (
                    delegate(object sender, DataReceivedEventArgs e)
                {
                    output.Append(e.Data);
                }
                                              );
                process.Start();
                process.BeginOutputReadLine();
                process.WaitForExit();
                process.CancelOutputRead();

                MainForm.LogMessage("PostProcess output");

                MainForm.LogMessage(output.ToString());
                MainForm.LogMessage("End of  PostProcess output");



                //if (RunScripts)
                //{
                // RunPostScripts();
                //}

                //run post script just once
                RunScript("PerfStatsAnalysis.sql");

                //Refresh reports list in case provider changed it
                MainForm.EnumReports();

                //if (Globals.ReportExportPath != null)
                //  MainForm.ProcessReportQueue();

                MainForm.LogMessage(String.Format("Import complete. Total import time: {0} seconds", (Environment.TickCount - startTicks) / 1000));

                SqlConnection conn = new SqlConnection(Globals.credentialMgr.ConnectionString);
                SqlCommand    cmd  = conn.CreateCommand();
                cmd.CommandText = "select count (distinct runtime) 'NumberOfRuntimes' from tbl_PERF_STATS_SCRIPT_RUNTIMES";
                conn.Open();
                Int32 NumberOfRuntimes = (Int32)cmd.ExecuteScalar();

                conn.Close();

                if (NumberOfRuntimes < 5)
                {
                    MainForm.LogMessage("The data was captured for a very short period of time.  Some reports may fail", MessageOptions.Both);
                }
            }
            catch (Exception ex)
            {
                MainForm.LogMessage("Import failed.");
                Globals.HandleException(ex, this, MainForm);
            }
            finally
            {
                MainForm.StartStopSpinner(false, MainForm.spnImporter);
                tsbGo.Image = sqlnexus.Properties.Resources.PlayHS1;
                tsbGo.Text  = "Import";
                EnableButtons(true);
                this.Cursor = Cursors.Default;
                Application.DoEvents();

                if (Globals.QuietMode == true)
                {
                    Application.Exit();
                }
            }
        }