Exemplo n.º 1
0
        public void IndexSet_GoodData_Success()
        {
            IEnumerable <IndexSet> indexes = IndexSet.RetrieveIndexData(InstanceName, "master");

            Assert.IsNotNull(indexes);
            Assert.AreNotEqual(0, indexes.Count());
            Assert.AreEqual("master", indexes.ElementAt(0).DatabaseName);
            Assert.AreEqual(InstanceName, indexes.ElementAt(0).ServerName);
        }
Exemplo n.º 2
0
        public void IndexSet_GoodData_ConnectionString_Success()
        {
            string ConnectionString        = String.Format("server={0};database={1};trusted_connection=yes", InstanceName, DatabaseName);
            IEnumerable <IndexSet> indexes = IndexSet.RetrieveIndexData(InstanceName, DatabaseName, ConnectionString);

            Assert.IsNotNull(indexes);
            Assert.AreNotEqual(0, indexes.Count());
            Assert.AreEqual("master", indexes.ElementAt(0).DatabaseName);
            Assert.AreEqual(InstanceName, indexes.ElementAt(0).ServerName);
        }
Exemplo n.º 3
0
        public void IndexSet_BadDatabaseName_Failure()
        {
            try
            {
                IEnumerable <IndexSet> indexes = IndexSet.RetrieveIndexData(InstanceName, BadDatabaseName);
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                Assert.IsTrue(ex.Message.Contains("Cannot open database \"" + BadDatabaseName + "\" requested by the login. The login failed."),
                              "An unexpected SqlException occurred:  " + ex.Message);
                return;
            }
            catch (Exception ex)
            {
                Assert.Fail("Some unexpected exception occurred:  " + ex.Message);
            }

            Assert.Fail("The test should not have gotten this far--it should have caught an exception.  Make sure that BadInstanceName really doesn't exist.");
        }
Exemplo n.º 4
0
        public void IndexSet_BadInstanceName_Failure()
        {
            try
            {
                IEnumerable <IndexSet> indexes = IndexSet.RetrieveIndexData(BadInstanceName, "master");
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                Assert.IsTrue(ex.Message.Contains("A network-related or instance-specific error occurred while establishing a connection to SQL Server."),
                              "An unexpected SqlException occurred:  " + ex.Message);
                return;
            }
            catch (Exception ex)
            {
                Assert.Fail("Some unexpected exception occurred:  " + ex.Message);
            }

            Assert.Fail("The test should not have gotten this far--it should have caught an exception.  Make sure that BadInstanceName really doesn't exist.");
        }
Exemplo n.º 5
0
        private void PopulateGrid(bool ForceRefresh)
        {
            //Show the waiting page.
            SetVisibility(PageToShow.Waiting);

            //Set the async values
            MainWindowValues mwvSetup = LoadMainWindowValues(ForceRefresh);

            System.Windows.Threading.Dispatcher d = this.Dispatcher;

            //Set up a worker
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += delegate(object sender, DoWorkEventArgs e)
            {
                try
                {
                    MainWindowValues mwv = e.Argument as MainWindowValues;

                    if (mwv.ForceRefresh || mwv.DatabaseListingChanged || PrimaryGroup == null || SecondaryGroup == null)
                    {
                        PrimaryGroup   = IndexSet.RetrieveIndexData(mwv.CurrentPrimaryInstanceName, mwv.CurrentPrimaryDatabaseName);
                        SecondaryGroup = IndexSet.RetrieveIndexData(mwv.CurrentSecondaryInstanceName, mwv.CurrentSecondaryDatabaseName);
                        Groups         = IndexGroup.PopulateIndexGroups(PrimaryGroup, SecondaryGroup, mwv.IgnoreMissingTables);
                    }

                    //Now update the display
                    RefreshGridDelegate refresh = new RefreshGridDelegate(RefreshDataGrid);
                    d.BeginInvoke(refresh, mwv, Groups);
                }
                catch (Exception ex)
                {
                    ShowErrorDelegate error = new ShowErrorDelegate(ShowErrorMessage);
                    d.BeginInvoke(error, ex.Message);
                }
            };
            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
            worker.RunWorkerAsync(mwvSetup);
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            Console.CancelKeyPress += delegate { Console.WriteLine(String.Format("{0}Goodbye.{0}", Environment.NewLine)); };

            string PrimaryServerName, SecondaryServerName, PrimaryDatabaseName, SecondaryDatabaseName, OutputFileName;

            if (args.Count() == 5)
            {
                PrimaryServerName     = args[0];
                SecondaryServerName   = args[1];
                PrimaryDatabaseName   = args[2];
                SecondaryDatabaseName = args[3];
                OutputFileName        = args[4];
            }
            else
            {
                if (args.Count() > 0)
                {
                    Console.WriteLine("Invalid argument listing passed.  A valid call looks like:");
                    Console.WriteLine("IndexComparer.exe PrimaryServerName SecondaryServerName PrimaryDatabaseName SecondaryDatabaseName OutputFileName");
                    Console.WriteLine("");
                    Console.WriteLine("");
                }

                #region Console Activity

                do
                {
                    Console.Write("Give the primary server name. ");
                    PrimaryServerName = Console.ReadLine();
                } while (String.IsNullOrWhiteSpace(PrimaryServerName));

                do
                {
                    Console.Write("Give the primary database name. ");
                    PrimaryDatabaseName = Console.ReadLine();
                } while (String.IsNullOrWhiteSpace(PrimaryDatabaseName));

                Console.Write("Give the secondary server name.  If this is the same as the primary server, just hit Enter. ");
                SecondaryServerName = Console.ReadLine();
                if (String.IsNullOrWhiteSpace(SecondaryServerName))
                {
                    SecondaryServerName = PrimaryServerName;
                }

                Console.Write("Give the secondary database name.  If this is the same as the primary database, just hit Enter. ");
                SecondaryDatabaseName = Console.ReadLine();
                if (String.IsNullOrWhiteSpace(SecondaryDatabaseName))
                {
                    SecondaryDatabaseName = PrimaryDatabaseName;
                }

                Console.Write("Tell where you would like the output file to go.  Default: C:\\Temp\\IndexComparisonLog.txt  -- ");
                OutputFileName = Console.ReadLine();
                if (String.IsNullOrWhiteSpace(OutputFileName))
                {
                    OutputFileName = @"C:\Temp\IndexComparisonLog.txt";
                }

                #endregion
            }

            List <IndexSet> PrimaryResults   = IndexSet.RetrieveIndexData(PrimaryServerName, PrimaryDatabaseName);
            List <IndexSet> SecondaryResults = IndexSet.RetrieveIndexData(SecondaryServerName, SecondaryDatabaseName);

            using (System.IO.StreamWriter writer = System.IO.File.CreateText(OutputFileName))
            {
                DataStreamer.StreamFile(true, true, true, writer, PrimaryServerName, PrimaryDatabaseName, SecondaryServerName, SecondaryDatabaseName, PrimaryResults, SecondaryResults);
            }
        }