예제 #1
0
        private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            if (!(sender is BackgroundWorker))
            {
                return;
            }

            BackgroundWorker bg = (BackgroundWorker)sender;

            if (!(e.Argument is List <IScriptPolicy>))
            {
                bg.ReportProgress(0, "Error running. Policies not selected");
                return;
            }
            List <IScriptPolicy> selectedPolices = (List <IScriptPolicy>)e.Argument;

            string message, fileName, script, targetDatabase;
            bool   passed;

            foreach (SqlSyncBuildData.ScriptRow row in this.buildData.Script)
            {
                fileName = Path.Combine(this.projectFilePath + row.FileName);
                if (File.Exists(fileName))
                {
                    script         = File.ReadAllText(fileName);
                    targetDatabase = row.Database;
                    for (int i = 0; i < selectedPolices.Count; i++)
                    {
                        passed  = false;
                        message = string.Empty;

                        if (selectedPolices[i] is CommentHeaderPolicy)
                        {
                            ((CommentHeaderPolicy)selectedPolices[i]).DayThreshold = 40;
                        }

                        Violation tmp = PolicyHelper.ValidateScriptAgainstPolicy(script, targetDatabase, selectedPolices[i]);

                        if (tmp == null)
                        {
                            passed = true;
                        }
                        else
                        {
                            message = tmp.Message;
                        }

                        PolicyMessage msg = new PolicyMessage(row.FileName, selectedPolices[i].ShortDescription, passed, message, row);
                        bg.ReportProgress(0, msg);
                    }
                }
            }
        }
예제 #2
0
        private void bgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            if (e.UserState is PolicyMessage)
            {
                PolicyMessage msg = (PolicyMessage)e.UserState;

                string changeDate = (msg.ScriptRow.DateModified == DateTime.MinValue) ? msg.ScriptRow.DateAdded.ToString() : msg.ScriptRow.DateModified.ToString();

                ListViewItem item = new ListViewItem(new string[] { msg.ScriptName, changeDate, msg.PolicyType, msg.Passed.ToString(), msg.Message });
                item.Tag = msg.ScriptRow;
                lstResults.Items.Insert(0, item);
            }
        }