void ValidaServicoPostgreSQL()
        {
            //using (telaConfigBD telaConfigBD = new telaConfigBD())
            //{
            string servicoPostgreSQL = "PostgreSQL9.6";

            try
            {
                if (ServicosWindows.StatusServico(servicoPostgreSQL) == false)
                {
                    try
                    {
                        telaConfigBD.TxtInfo.Text      = "Iniciando Serviço...";
                        telaConfigBD.ProgressBar.Value = 97;

                        ServicosWindows.IniciarServico(servicoPostgreSQL);

                        telaConfigBD.ProgressBar.Value = 100;
                        telaConfigBD.TxtInfo.Text      = "Tudo ok!";
                    }
                    catch
                    {
                        telaConfigBD.TxtInfo.Text = "Falha em iniciar serviço\nExecutando pg_restartxlog...";

                        Restartxlog();

                        telaConfigBD.TxtInfo.Text = "Tentando iniciar\nserviço novamente...";

                        ServicosWindows.IniciarServico(servicoPostgreSQL);
                    }
                }
            }
            catch (Exception erro)
            {
                if (erro.Message == "Serviço PostgreSQL9.6 não foi encontrado no computador '.'." && cont < 5)
                {
                    cont++;
                    ValidaServicoPostgreSQL();
                }
                else
                {
                    throw new Exception("Puxa me desculpe, não copnsegui iniciar o serviço do banco de bados,\n" +
                                        "ou talvez esetja demorando para iniciar.\n" +
                                        "Aguarde mais um pouco. Caso o problema persista reinicie o computador. " +
                                        "\n\nErro: " + erro.Message);
                }
            }
            //}
        }
Exemple #2
0
        void ValidaServicoPostgreSQL()
        {
            string servicoPostgreSQL = "PostgreSQL9.6";

            try
            {
                using (Carregando carregando = new Carregando())
                {
                    carregando.lblMensagem.Text = "Iniciando Serviço...";
                    if (ServicosWindows.StatusServico(servicoPostgreSQL) == false)
                    {
                        try
                        {
                            ServicosWindows.IniciarServico(servicoPostgreSQL);
                        }
                        catch
                        {
                            carregando.lblMensagem.Text = "Falha em iniciar serviço\nExecutando pg_restartxlog...";

                            Restartxlog();

                            carregando.lblMensagem.Text = "Tentando iniciar\nserviço novamente...";

                            ServicosWindows.IniciarServico(servicoPostgreSQL);
                        }
                    }
                }
            }
            catch (Exception erro)
            {
                if (erro.Message == "Serviço PostgreSQL9.6 não foi encontrado no computador '.'.")
                {
                    Process.Start(mainPath + "\\Config_BD.exe");
                    Process.GetCurrentProcess().Kill();
                }

                throw new Exception("Puxa me desculpe, o Serviço de Banco de Dados está parado ou ainda está iniciando.\n" +
                                    "Aguarde mais um pouco. Caso o problema persista reinicie o computador. " +
                                    "\n\nErro: " + erro.Message);
            }
        }