public ObjectScriptHashReportData ProcessHashDifferences(ObjectScriptHashData baseLine, List <ObjectScriptHashData> hashes)
        {
            ObjectScriptHashReportData reportData = new ObjectScriptHashReportData();

            reportData.BaseLineDatabase = baseLine.Database;
            reportData.BaseLineServer   = baseLine.Server;
            reportData.ProcessTime      = DateTime.Now;

            foreach (ObjectScriptHashData data in hashes)
            {
                HashComparison(baseLine.Tables, data.Tables);
                HashComparison(baseLine.StoredProcedures, data.StoredProcedures);
                HashComparison(baseLine.Views, data.Views);
                HashComparison(baseLine.Functions, data.Functions);
                HashComparison(baseLine.KeysAndIndexes, data.KeysAndIndexes);
                HashComparison(baseLine.Logins, data.Logins);
                HashComparison(baseLine.Roles, data.Roles);
                HashComparison(baseLine.Schemas, data.Schemas);
                HashComparison(baseLine.Users, data.Users);

                reportData.DatabaseData.Add(data);
            }

            return(reportData);
        }
        public void CollectHashes()
        {
            if (this.HashCollectionRunnerUpdate != null)
            {
                HashCollectionRunnerUpdate(this, new HashCollectionRunnerUpdateEventArgs(this.serverName, this.databaseName, "Starting"));
            }

            ConnectionData     connData = new ConnectionData(serverName, databaseName);
            ObjectScriptHelper helper   = new ObjectScriptHelper(connData);

            helper.HashScriptingEvent += new ObjectScriptHelper.HashScriptingEventHandler(helper_HashScriptingEvent);
            this.hashData              = helper.GetDatabaseObjectHashes();
            if (hashData != null)
            {
                this.hashData.IsBaseLine = isBaseLine;
            }
            else
            {
                hashData = new ObjectScriptHashData();
            }
            this.hashData.Database = this.databaseName;
            this.hashData.Server   = this.serverName;
        }
        public ObjectScriptHashReportData GetObjectHashes(ref BackgroundWorker bgWorker, string fileName, ReportType reportType, bool runThreaded)
        {
            this.bgWorker = bgWorker;
            int    threadTotal = 0;
            string db;

            bool baseLineSet = false;

            foreach (ServerData srv in multiDbData)
            {
                srv.OverrideSequence.Sort(); //sort so the sequence is in proper order.
                foreach (string sequenceKey in srv.OverrideSequence.Keys)
                {
                    foreach (DatabaseOverride ovr in srv.OverrideSequence[sequenceKey])
                    {
                        db = srv.ServerName + "." + ovr.OverrideDbTarget;
                        if (!dbsSelected.Contains(db))
                        {
                            threadTotal++;
                            lock (HashCollector.SyncObj)
                            {
                                HashCollector.SyncObj.WorkingRunners++;
                            }
                            HashCollectionRunner runner = new HashCollectionRunner(srv.ServerName, ovr.OverrideDbTarget);
                            runner.HashCollectionRunnerUpdate += new HashCollectionRunner.HashCollectionRunnerUpdateEventHandler(runner_HashCollectionRunnerUpdate);
                            if (!baseLineSet) //set the baseline to the first database handled.
                            {
                                runner.IsBaseLine = true;
                                baseLineSet       = true;
                            }

                            runners.Add(runner);
                            if (runThreaded)
                            {
                                System.Threading.ThreadPool.QueueUserWorkItem(ProcessThreadedHashCollection, runner);
                            }
                            else
                            {
                                runner.CollectHashes();
                            }
                        }
                    }
                }
            }

            if (runThreaded)
            {
                int counter = 0;
                while (HashCollector.SyncObj.WorkingRunners > 0)
                {
                    System.Threading.Thread.Sleep(100);
                    counter++;

                    if (bgWorker != null && (counter % 2 == 0))
                    {
                        bgWorker.ReportProgress(HashCollector.SyncObj.WorkingRunners, String.Format("Threads remaining: {0}", HashCollector.SyncObj.WorkingRunners.ToString()));
                    }
                }
            }

            if (bgWorker != null)
            {
                bgWorker.ReportProgress(0, "Collating Results...");
            }

            List <ObjectScriptHashData> hashes   = new List <ObjectScriptHashData>();
            ObjectScriptHashData        baseLine = null;

            foreach (HashCollectionRunner runner in this.runners)
            {
                if (runner.IsBaseLine)
                {
                    baseLine = runner.HashData;
                }
                else
                {
                    hashes.Add(runner.HashData);
                }
            }

            ObjectScriptHashReportData reportData = ProcessHashDifferences(baseLine, hashes);

            GenerateReport(fileName, reportType, reportData);

            hashes.Add(baseLine);

            ObjectScriptHashReportData rawReportData = new ObjectScriptHashReportData();

            rawReportData.ProcessTime  = reportData.ProcessTime;
            rawReportData.DatabaseData = hashes;
            return(rawReportData);
        }