Exemplo n.º 1
0
        public void OnInfoMessage(object sender, SqlInfoMessageEventArgs e)
        {
            MessageToReturn messageToReturn = new MessageToReturn()
            {
                fileName = this.CurrentFile.Name
            };

            if ((int)e.Errors[0].Class != 0)
            {
                this.error = true;
                messageToReturn.message = string.Concat(new object[4]
                {
                    (object)"Falha de Script: ",
                    (object)e.Errors[0].Message,
                    (object)" Linha No:",
                    (object)e.Errors[0].LineNumber
                });
                messageToReturn.messageType = MessageType.Error;
                messageToReturn.fileUid     = this.CurrentFileUid;
            }
            else
            {
                messageToReturn.message     = e.Message;
                messageToReturn.messageType = MessageType.SQLMessage;
                messageToReturn.fileUid     = this.CurrentFileUid;
            }
            this.backgroundScriptWorker.ReportProgress(0, (object)messageToReturn);
        }
Exemplo n.º 2
0
        private void BindMessageToList(MessageToReturn message, Color color)
        {
            CheckBox element = Enumerable.FirstOrDefault <CheckBox>((IEnumerable <CheckBox>)Enumerable.ToList <CheckBox>(
                                                                        Enumerable.OfType <CheckBox>((IEnumerable)this.lstDragDrop.Items)), (Func <CheckBox, bool>)(x => x.Uid == message.fileUid));

            if (element != null)
            {
                element.Content    = (object)message.message;
                element.Foreground = (Brush) new SolidColorBrush(color);
                //element.Background = (Brush)new SolidColorBrush(color);
                element.IsEnabled = false; //Focus();
            }
        }
Exemplo n.º 3
0
        private void WritePassedOrFailedMessageForReportGeneration(MessageToReturn message, bool isPassed)
        {
            if (!this.scriptDetails.Exists((Predicate <ScriptDetails>)(x => x.uid == message.fileUid)))
            {
                List <ScriptDetails> list1          = this.scriptDetails;
                ScriptDetails        scriptDetails1 = new ScriptDetails();
                scriptDetails1.uid       = message.fileUid ?? "";
                scriptDetails1.filename  = message.fileUid == null ? "" : Enumerable.FirstOrDefault <FilePathData>((IEnumerable <FilePathData>) this.sqlRun.filePaths, (Func <FilePathData, bool>)(y => y.uid.ToString() == message.fileUid)).fileName();
                scriptDetails1.timetaken = this.lblTime.Content.ToString();
                scriptDetails1.status    = isPassed ? "Passed" : "Failed";
                ScriptDetails scriptDetails2 = scriptDetails1;
                List <string> list2;
                if (!isPassed)
                {
                    list2 = new List <string>()
                    {
                        message.message
                    }
                }
                ;
                else
                {
                    list2 = new List <string>();
                }
                scriptDetails2.remarks = list2;
                ScriptDetails scriptDetails3 = scriptDetails1;
                list1.Add(scriptDetails3);
            }
            else
            {
                if (message.messageType == MessageType.FailedMessage)
                {
                    return;
                }

                var currentScript = Enumerable.FirstOrDefault <ScriptDetails>((IEnumerable <ScriptDetails>) this.scriptDetails, (Func <ScriptDetails, bool>)(x => x.uid == message.fileUid));
                if (currentScript.remarks == null)
                {
                    currentScript.remarks = new List <string>()
                    {
                        message.message
                    }
                }
                ;
                else
                {
                    currentScript.remarks.Add(message.message);
                }
            }
        }
Exemplo n.º 4
0
        //
        public void backgroundScriptWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            MessageToReturn message = (MessageToReturn)e.UserState;

            if (message.messageType == MessageType.SQLMessage)
            {
                this.messagesListBox.Items.Insert(0, (object)message.message);
            }
            else if (message.messageType == MessageType.Error)
            {
                ItemCollection items       = this.messagesListBox.Items;
                int            insertIndex = 0;
                TextBlock      textBlock1  = new TextBlock();
                textBlock1.Width      = 730.0;
                textBlock1.Text       = message.message;
                textBlock1.Foreground = (Brush) new SolidColorBrush(Colors.Red);
                TextBlock textBlock2 = textBlock1;
                items.Insert(insertIndex, (object)textBlock2);
                this.WritePassedOrFailedMessageForReportGeneration(message, false);
            }
            else if (message.messageType == MessageType.DataBaseConnectionFailure)
            {
                ItemCollection items       = this.messagesListBox.Items;
                int            insertIndex = 0;
                TextBlock      textBlock1  = new TextBlock();
                textBlock1.Width      = 730.0;
                textBlock1.Text       = message.message;
                textBlock1.Foreground = (Brush) new SolidColorBrush(Colors.Red);
                TextBlock textBlock2 = textBlock1;
                items.Insert(insertIndex, (object)textBlock2);
                this.WritePassedOrFailedMessageForReportGeneration(message, false);
                this.btnRunScript.Content = (object)((object)BtnType.Iniciar).ToString();
            }
            else if (message.messageType == MessageType.PassMessage)
            {
                this.BindMessageToList(message, Colors.DarkGreen);
                this.WritePassedOrFailedMessageForReportGeneration(message, true);
                this.lblTime.Content = (object)"00:00:00";
            }
            else if (message.messageType == MessageType.FailedMessage)
            {
                this.BindMessageToList(message, Colors.Red);
                this.WritePassedOrFailedMessageForReportGeneration(message, false);
                this.lblTime.Content = (object)"00:00:00";
                bool?isChecked = this.optionWindow.cbContinueOnError.IsChecked;
                if ((isChecked.HasValue ? new bool?(!isChecked.GetValueOrDefault()) : new bool?()).Value)
                {
                    this.sqlRun.Timer.Stop();
                    this.lblTime.Content      = (object)"00:00:00";
                    this.btnClear.IsEnabled   = true;
                    this.btnRunScript.Content = (object)((object)BtnType.Continuar).ToString();
                }
                else
                {
                    this.sqlRun.error = false;
                }
                if (this.optionWindow.cbOpenScript.IsChecked.HasValue && this.optionWindow.cbOpenScript.IsChecked.Value)
                {
                    if (!this.sqlRun.fileOpened)
                    {
                        var currentScript = Enumerable.FirstOrDefault <FilePathData>((IEnumerable <FilePathData>) this.sqlRun.filePaths, (Func <FilePathData, bool>)(y => y.uid.ToString() == message.fileUid));
                        //try
                        //{
                        //var file = @"C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe";
                        // http://stackoverflow.com/questions/4624113/how-to-process-start-with-impersonated-domain-user
                        //var sspw = new System.Security.SecureString();
                        //foreach (var c in optionWindow.tbPassword.Password.ToCharArray()) sspw.AppendChar(c);
                        //var proc = new Process();
                        //proc.StartInfo.UseShellExecute = false;
                        ////proc.StartInfo.WorkingDirectory = Path.GetDirectoryName(file);
                        //proc.StartInfo.FileName = "Ssms.exe"; // Path.GetFileName(file);
                        //proc.StartInfo.Arguments = currentScript.fullFileName;
                        //proc.StartInfo.Domain = optionWindow.tbServerName.Text;
                        //proc.StartInfo.UserName = optionWindow.tbUserName.Text;
                        //proc.StartInfo.Password = sspw;

                        // http://stackoverflow.com/questions/4422084/impersonating-in-net-c-opening-a-file-via-process-start
                        //proc.StartInfo.LoadUserProfile = true;
                        //proc.Start();

                        //System.Security.SecureString password = new System.Security.SecureString();
                        //foreach (char c in optionWindow.tbPassword.Password.ToCharArray())
                        //{
                        //   password.AppendChar(c);
                        //}
                        //System.Diagnostics.ProcessStartInfo procInfo = new System.Diagnostics.ProcessStartInfo();
                        //procInfo.Arguments = " -file_name " + currentScript.fullFileName; //"/netonly";
                        //procInfo.FileName = "Ssms.exe";// @"C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe"; ;
                        //procInfo.Domain = optionWindow.tbServerName.Text;
                        //procInfo.Verb = "runas";
                        //procInfo.UserName = optionWindow.tbUserName.Text;
                        //procInfo.Password = password;
                        //procInfo.UseShellExecute = false;
                        //System.Diagnostics.Process.Start(procInfo);

                        //Process.Start("Ssms.exe", " -nosplash" +
                        //   " -S " + optionWindow.tbServerName.Text +
                        //   " -D " + optionWindow.cbBancoDeDados.SelectedValue.ToString() +
                        //   (string.IsNullOrEmpty(optionWindow.tbUserName.Text) ? " -U " + optionWindow.tbUserName.Text + " -P " + optionWindow.tbPassword.Password : "******") +
                        //   " -file_name " + currentScript.fullFileName);
                        //}
                        //catch
                        //{
                        Process.Start("notepad.exe", currentScript.fullFileName);
                        //}
                        this.sqlRun.fileOpened = true;
                    }
                }
                this.sqlRun.continueWait = false;
            }
            else if (message.messageType == MessageType.Running)
            {
                this.BindMessageToList(message, Colors.Orange);
            }
            if (!this.sqlRun.finished)
            {
                return;
            }
            this.btnRunScript.Content = (object)((object)BtnType.Reiniciar).ToString();
            this.btnClear.IsEnabled   = true;
            this.sqlRun.finished      = false;
        }