void LongRunningOperationManager_DoWork(object sender, DoWorkEventArgs e)
        {
            LongRunningOperationManager.StartNextStep();
            for (int i = 0; i < 100; i++)
            {
                LongRunningOperationManager.ReportProgress(i + 1);
                Thread.Sleep(100);

                //if (LongRunningOperationManager.CancellationPending)
                //{
                //    e.Cancel = true;
                //    return;
                //}
            }


            LongRunningOperationManager.StartNextStep();
            for (int i = 0; i < 100; i++)
            {
                LongRunningOperationManager.ReportProgress(i + 1);
                Thread.Sleep(50);

                if (LongRunningOperationManager.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
            }
            //LongRunningOperationManager.ReportProgress(100);

            LongRunningOperationManager.StartNextStep();
            for (int i = 0; i < 100; i++)
            {
                LongRunningOperationManager.ReportProgress(i + 1);
                Thread.Sleep(20);

                if (LongRunningOperationManager.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
            }
        }
        private void lrom_DoWorkConnectToSqlServer(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            Dictionary <int, SqlConnection> pool = (Dictionary <int, SqlConnection>)e.Argument;
            List <int> succServerObjects         = new List <int>();
            int        counter = 0;

            LongRunningOperationManager.StartNextStep();

            foreach (var c in pool)
            {
                counter++;

                LongRunningOperationManager.ReportProgress(counter / pool.Count);
                SqlConnection conn = c.Value;


                if (conn.State == System.Data.ConnectionState.Open)
                {
                    succServerObjects.Add(c.Key);
                }
                else
                {
                    try
                    {
                        conn.Open();
                        succServerObjects.Add(c.Key);
                    }
                    catch (Exception ex)
                    {
                        MyOutput.NewMessage(EOutputMessageType.ERROR, ex.Message, true);
                    }
                }
            }

            e.Result = succServerObjects.ToArray();
        }
예제 #3
0
        private void LongRunningOperationManager_DoWorkExecQuery(object sender, DoWorkEventArgs e)
        {
            LongRunningOperationManager.StartNextStep();
            LongRunningOperationManager.ReportProgress(-1);

            MyOutput.NewMessage(EOutputMessageType.PROGRESS, string.Format("Reading data from {0}... ", this._mySqlObject.ObjectNameFull));

            DateTime dt = DateTime.Now;

            string query = string.Format("SELECT TOP 1000 * FROM [{0}].[{1}] WITH (NOLOCK)", _mySqlObject.SchemaName, _mySqlObject.ObjectName);

            _mySqlServer.ConnectionPool.GetConnection(_mySqlObject.ServerObjectId).ChangeDatabase(_mySqlObject.DatabaseName);
            cmd                = (SqlCommand)_mySqlServer.ConnectionPool.GetConnection(_mySqlObject.ServerObjectId).CreateCommand();
            cmd.CommandText    = query;
            cmd.CommandTimeout = UserSettings.Default.CommandTimeout;
            cmd.CommandType    = CommandType.Text;

            SqlDataReader rdr = null;

            try
            {
                rdr = cmd.ExecuteReader(CommandBehavior.SingleResult);
            }
            catch (Exception ex1)
            {
                if (!LongRunningOperationManager.CancellationPending)
                {
                    MyOutput.AppendToLastMessage(EOutputMessageType.ERROR, string.Format("{0}", ex1.Message));
                    MessageBox.Show(ex1.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MyOutput.AppendToLastMessage(EOutputMessageType.WARNING, string.Format("Done. Cancelled by user."), (DateTime.Now - dt).TotalSeconds);
                }
            }

            if (rdr == null)
            {
                e.Cancel = true;
                return;
            }

            DataTable dataTable = new DataTable();

            dataTable.Load(rdr);
            rdr.Close();

            // Get all byte columns
            List <DataColumn> byteColumns = dataTable.Columns.Cast <DataColumn>().Where(dc => dc.DataType == typeof(byte[])).ToList();

            foreach (DataColumn dc in byteColumns)
            {
                int    colOrdinal = dc.Ordinal;
                string colName    = String.Format("{0} (Hex)", dc.ColumnName);

                DataColumn tmpCol = new DataColumn(colName, typeof(String));
                dataTable.Columns.Add(tmpCol);
                foreach (DataRow row in dataTable.Rows)
                {
                    row[tmpCol] = byteArrayToHexString((byte[])row[dc]);
                }
                dataTable.Columns.Remove(dc);
                dataTable.Columns[colName].SetOrdinal(colOrdinal);
            }

            e.Result = dataTable;

            MyOutput.AppendToLastMessage(EOutputMessageType.INFORMATION, string.Format("Done. Loaded {0} rows.", dataTable.Rows.Count), (DateTime.Now - dt).TotalSeconds);
        }
예제 #4
0
        void lrom_DoWorkViewDependencies(object sender, DoWorkEventArgs e)
        {
            BwObject bwo = (BwObject)e.Argument;

            LongRunningOperationManager.StartNextStep();
            mySqlServer1.Load(bwo.IsForceReload);
            //inMemoryDatabase1.Load(bwo.CheckedDatabases, bwo.IsForceReload);

            //
            if (LongRunningOperationManager.CancellationPending)
            {
                e.Cancel = true;
                return;
            }
            //
            LongRunningOperationManager.StartNextStep();
            DependencyBrowserDockForm dbdf = new DependencyBrowserDockForm(ref mySqlServer1, bwo.SearchObjectFullDescription, bwo.ObjectTypes, bwo.IsTopDownDiscovery, this._windowId++);

            dbdf.LoadDependencies(bwo.ObjectName, bwo.ObjectTypes, bwo.IsTopDownDiscovery, bwo.MatchMethod, bwo.IsForceReload, bwo.SearchDatabases);

            //
            if (LongRunningOperationManager.CancellationPending)
            {
                e.Cancel = true;
                return;
            }
            //
            LongRunningOperationManager.StartNextStep();
            dbdf.DrawObjects();



            if (dbdf.RecommendedDatabases.Count > 0)
            {
                var v1 = dbdf.RecommendedDatabases.Select(d => d.Value.ToString().ToUpper()).ToArray();
                var v2 = mySqlServer1.SqlDatabases.Select(d => d.ToString().ToUpper()).ToArray();
                var v3 = v1.Except(v2);

                if (v3 != null && v3.Any())
                {
                    var v4 = from rd in dbdf.RecommendedDatabases.AsEnumerable()
                             where v3.Contains(rd.Value.ToString().ToUpper())
                             select rd;

                    new InvalidDatabaseReferencesForm(v4.ToArray()).ShowDialog();
                }


                MySqlDatabase[] recommendedDatabasesWithAllAttributesSet =
                    dbdf.RecommendedDatabases.Select(
                        db =>
                        //this.DatabaseBrowserDockForm.AllDatabases.First(
                        mySqlServer1.SqlDatabases.FirstOrDefault(
                            db1 =>
                            db1.ServerObjectName.Equals(db.Value.ServerObjectName, StringComparison.InvariantCultureIgnoreCase) &&
                            db1.DatabaseName.Equals(db.Value.DatabaseName, StringComparison.InvariantCultureIgnoreCase)))
                    .Where(db => db != null).ToArray();

                string missingDbs     = string.Join(", ", recommendedDatabasesWithAllAttributesSet.Select(db => "[" + db.DatabaseName + "]").Distinct());
                string missingDbsText = string.Format("Results might be incomplete! Include database{0} " + missingDbs + " to get more accurate results.", (recommendedDatabasesWithAllAttributesSet.Length == 1) ? string.Empty : "s");
                dbdf.SetInfo(missingDbsText, Resources.StatusAnnotations_Warning_16xLG_color);

                var f = new RecommendedDatabasesForm(recommendedDatabasesWithAllAttributesSet);
                if (f.ShowDialog() == DialogResult.OK)
                {
                    e.Result = new DependencyBackgroundWorkerResult {
                        ResultType = EResultType.RERUN, ResultObject = f.CheckedRecommendedDatabases
                    };
                }
                else
                {
                    e.Result = new DependencyBackgroundWorkerResult {
                        ResultType = EResultType.SHOW_RESULTS, ResultObject = dbdf
                    };
                }
            }
            else
            {
                e.Result = new DependencyBackgroundWorkerResult {
                    ResultType = EResultType.SHOW_RESULTS, ResultObject = dbdf
                }
            };
        }

        void lrom_ViewDependenciesCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                return;
            }

            if (e.Result.GetType().IsAssignableFrom(typeof(DependencyBackgroundWorkerResult)))
            {
                var res = ((DependencyBackgroundWorkerResult)e.Result);

                if (res.ResultType == EResultType.SHOW_RESULTS)
                {
                    var d = ((DependencyBrowserDockForm)res.ResultObject);
                    if (d.AreDependenciesInitialized)
                    {
                        d.Show(this.dockPanel, DockState.Document);
                        d.AutoResizeColumns();
                    }
                }
                else if (res.ResultType == EResultType.RERUN)
                {
                    MySqlDatabase[] checkedRecommendedDatabases = new MySqlDatabase[((List <MySqlDatabase>)res.ResultObject).Count];
                    ((List <MySqlDatabase>)res.ResultObject).CopyTo(checkedRecommendedDatabases);

                    this.DatabaseBrowserDockForm.CheckDatabases(checkedRecommendedDatabases.Select(db => mySqlServer1.SqlDatabases.First(db1 => db1.ServerObjectName.Equals(db.ServerObjectName, StringComparison.InvariantCultureIgnoreCase) && db1.DatabaseName.Equals(db.DatabaseName, StringComparison.InvariantCultureIgnoreCase))).ToArray());
                }
            }

            /*
             * if (d.RecommendedDatabases.Count > 0)
             * {
             *  var recommendedDatabasesCleaned =
             *      d.RecommendedDatabases.Select(
             *          db =>
             *              this.DatabaseBrowserDockForm.AllDatabases.First(
             *                  db1 =>
             *                      db1.ServerName.Equals(db.ServerName, StringComparison.InvariantCultureIgnoreCase) &&
             *                      db1.DatabaseName.Equals(db.DatabaseName, StringComparison.InvariantCultureIgnoreCase)))
             *          .ToArray();
             *
             *  string missingDbs = string.Join(", ", recommendedDatabasesCleaned.Select(db => "[" + db.DatabaseName + "]").Distinct());
             *  string missingDbsText = string.Format("Results might be incomplete! Include database{0} " + missingDbs + " to get more accurate results.", (recommendedDatabasesCleaned.Length == 1) ? string.Empty : "s");
             *  d.SetInfo(missingDbsText, Resources.StatusAnnotations_Warning_16xLG_color);
             *
             *  var f = new RecommendedDatabasesForm(recommendedDatabasesCleaned);
             *  if (f.ShowDialog() == DialogResult.OK)
             *  {
             *      this.DatabaseBrowserDockForm.CheckDatabases(f.CheckedRecommendedDatabases.Select(db => this.DatabaseBrowserDockForm.AllDatabases.First(db1 => db1.ServerName.Equals(db.ServerName, StringComparison.InvariantCultureIgnoreCase) && db1.DatabaseName.Equals(db.DatabaseName, StringComparison.InvariantCultureIgnoreCase))).ToArray());
             *
             *      d.Close();
             *      //newDependencyCheck(sender, e);
             *  }
             * }
             * */
        }