コード例 #1
0
        public void Execute(bool isNormalExecution = true)
        {
            try
            {
                bool          blneventerr = false;
                var           _rootpath   = Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), "Resources");
                string        script      = Path.Combine(_rootpath, scriptName + ".ps1");
                string        scriptText  = File.ReadAllText(script);
                StringBuilder sb          = new StringBuilder();
                var           powershell  = new PowerShellHelper();
                var           runspace    = powershell.CreateRunSpace(Application.ExecutablePath, cmbevent.SelectedValue.ToString());
                runspace.Open();
                Pipeline pipeline  = runspace.CreatePipeline();
                Command  myCommand = new Command(scriptText, true);
                if (txtsource.Text.Trim() != string.Empty)
                {
                    var sourceFilter = new CommandParameter(null, txtsource.Text);
                    myCommand.Parameters.Add(sourceFilter);
                }
                else
                {
                    var sourceFilter = new CommandParameter(null, " ");
                    myCommand.Parameters.Add(sourceFilter);
                }
                if (txtmessage.Text.Trim() != string.Empty)
                {
                    var messageFilter = new CommandParameter(null, txtmessage.Text);
                    myCommand.Parameters.Add(messageFilter);
                }
                else
                {
                    var messageFilter = new CommandParameter(null, " ");
                    myCommand.Parameters.Add(messageFilter);
                }

                pipeline.Commands.Add(myCommand);

                Collection <PSObject> results = pipeline.Invoke();
                var errors = pipeline.Error;

                // CSV or Error file Generation code
                var generateCSV = new Csvhelper();
                generateCSV.WriteOutput(Application.ExecutablePath, scriptName, results, pipeline, this.timeStamp, out blneventerr);
                // CSV or Error file Generation code
                if (blneventerr)
                {
                    //MessageBox.Show("Error Occured.for more detail kindly check Event Log!!\r\n", "Error Message");
                    //return;
                }

                runspace.Close();

                Console.WriteLine(sb.ToString());

                //DialogResult dialogResult = MessageBox.Show("Selected event log executed successfully.Do you want to complete?", "Success", MessageBoxButtons.YesNo);
                //if (dialogResult == DialogResult.Yes)
                //{
                //    //do something
                //    Complete objfrm = new Complete();
                //    objfrm.Show();
                //    this.Close();
                //}
                //else if (dialogResult == DialogResult.No)
                //{
                //    EventLog objfrm = new EventLog();
                //    objfrm.Show();
                //    this.Close();
                //}

                if (isNormalExecution)
                {
                    Eventlogs    frmevntlog = new Eventlogs();
                    DialogResult dr         = frmevntlog.ShowDialog(this);
                    if (dr == DialogResult.Cancel)
                    {
                        //frmapplog.Close();
                    }
                    else if (dr == DialogResult.OK)
                    {
                        //textBox1.Text = frm2.getText();
                        //frmapplog.Close();
                        this.Enabled = true;
                        Complete objfrm = new Complete();
                        objfrm.Show();
                        this.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error Occured.for more detail kindly check Event Log!!\r\n" + "\r\n" + ex.Message.ToString(), "Error Message");
            }
        }
コード例 #2
0
        void bgwr_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            var application = new ApplicationInformation();

            application.Execute(false);
            var iisInformation = new IISInformation();

            iisInformation.Execute(false);
            var sqlServerDiagnostics = new SQLServerDiagnostics();

            sqlServerDiagnostics.Execute(false);
            var sqlServer = new SQLServer();

            sqlServer.Execute(false);
            var ssrsConfiguration = new SSRSConfiguration();

            ssrsConfiguration.Execute(false);
            var ssasConfiguration = new SSASConfiguration();

            ssasConfiguration.Execute(false);
            var eventLog = new EventLog();

            eventLog.Execute(false);

            var          frmapplog = new Applicationlogs();
            DialogResult dr        = frmapplog.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                frmapplog.Close();
                var frmiislogs = new IISInformationlogs();
                var iisDialog  = frmiislogs.ShowDialog(this);
                if (iisDialog == DialogResult.OK)
                {
                    frmiislogs.Close();
                    var frmsqlserverdiagnostics    = new SQLServerDiagnosticslogs();
                    var sqlServerDiagnosticsDialog = frmsqlserverdiagnostics.ShowDialog(this);
                    if (sqlServerDiagnosticsDialog == DialogResult.OK)
                    {
                        frmsqlserverdiagnostics.Close();
                        var sqlServerLogs      = new SQLServerlogs();
                        var sqlServerLogDialog = sqlServerLogs.ShowDialog(this);
                        if (sqlServerLogDialog == DialogResult.OK)
                        {
                            sqlServerLogs.Close();
                            var ssrsLogs      = new SSRSConfigurationLogs();
                            var ssrsLogDialog = ssrsLogs.ShowDialog(this);
                            if (ssrsLogDialog == DialogResult.OK)
                            {
                                ssrsLogs.Close();
                                var ssasLogs      = new SSASConfigurationlogs();
                                var ssasLogDialog = ssasLogs.ShowDialog(this);
                                if (ssasLogDialog == DialogResult.OK)
                                {
                                    ssasLogs.Close();
                                    var eventLogs      = new Eventlogs();
                                    var eventLogDialog = eventLogs.ShowDialog(this);
                                    if (eventLogDialog == DialogResult.OK)
                                    {
                                        eventLogs.Close();
                                        this.Show();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            this.Enabled              = true;
            lblprogress.Visible       = false;
            progressBar1.Visible      = false;
            button2.Enabled           = true;
            oneclickexecution.Enabled = true;
            //ResourceInformation rd = new ResourceInformation();
            //rd.Show();
            //this.Close();
        }