Beispiel #1
0
        void Atualizacao(object sender, EventArgs e)
        {
            if (ConexaoDTOBindingSource.List.Count <= 0)
            {
                MessageBox.Show("Nenhuma conexão foi estabelecida. Acesse o módulo de \"Manutenção de Conexões\" para configurar uma nova conexão.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            string connectionstring = "host=" + ((ConexoesDTO)ConexaoDTOBindingSource.Current).Servidor + ";Port=" + ((ConexoesDTO)ConexaoDTOBindingSource.Current).Porta + ";Database=" + ((ConexoesDTO)ConexaoDTOBindingSource.Current).Banco + ";User="******";Password="******";Unicode=False;Protocol=2";
            string versaoAtual;

            versaoAtual = new VersaoBO().VersaoAtual(connectionstring);
            if (!File.Exists(Global.DriveRede + @"\Sistemas\MechTech\Atualizacao.exe"))
            {
                MessageBox.Show("O módulo de atualização não foi localizado.\nEntre em contato com o suporte técnico.", "Arquivo não encontrado", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }
            Process.Start(string.Format(Global.DriveRede + @"\Sistemas\MechTech\Atualizacao.exe"), connectionstring + " " + versaoAtual + " " + Global.DriveRede);
            Application.Exit();
        }
Beispiel #2
0
        private bool ProcurarAtualizacoesNovo(BackgroundWorker status)
        {
            if (Global.DriveRede == string.Empty)
            {
                if (!File.Exists(AppPath + "\\CpArqM.xml"))
                {
                    Notify(status, 21);
                    MessageBox.Show("O arquivo 'CpArqM.xml' não pode ser localizado. Impossível prosseguir.", "Arquivo não encontrado", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
            }

            try
            {
                if (Global.DriveRede == string.Empty) //1ª FASE DO MIRROR
                {
                    DataSet DS = new DataSet();
                    DS.ReadXml("CpArqM.xml");

                    string origem         = string.Empty;
                    string destino        = string.Empty;
                    string arquivo        = string.Empty;
                    string hashfileserver = string.Empty;
                    string hashfilelocal  = string.Empty;

                    atualizacoes.Clear();
                    foreach (DataRow row in DS.Tables[0].Rows)
                    {
                        try
                        {
                            origem  = Path.GetPathRoot(AppPath).Substring(0, 2) + row["origem"].ToString();
                            destino = row["destino"].ToString().Replace("C:", Global.LocalPath);
                            arquivo = row["arquivo"].ToString();

                            //ARQUIVOS DO SERVIDOR
                            string[] filesserver = Directory.GetFiles(origem, arquivo);
                            foreach (string fileserver in filesserver)
                            {
                                arquivo = Path.GetFileName(fileserver);
                                //COMPARAR ARQUIVOS DO SERVIDOR/ARQUIVOS LOCAIS
                                if (!File.Exists(destino + Path.GetFileName(fileserver)))
                                {
                                    atualizacoes.Add(new CpArq(origem, destino, Path.GetFileName(fileserver)));
                                }
                                else
                                {
                                    hashfileserver = Global.CalculaFileHash(Path.GetFullPath(fileserver));
                                    hashfilelocal  = Global.CalculaFileHash(destino + Path.GetFileName(fileserver));

                                    if (hashfileserver != hashfilelocal)
                                    {
                                        atualizacoes.Add(new CpArq(origem, destino, Path.GetFileName(fileserver)));
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            atualizacoes.Add(new CpArq(origem, destino, arquivo));
                        }
                    }
                }
                else //2º FASE DO MIRROR
                {
                    Global.ConnectionStringPg = "host=" + ((ConexoesDTO)ConexaoDTOBindingSource.Current).Servidor +
                                                ";Port=" + ((ConexoesDTO)ConexaoDTOBindingSource.Current).Porta + ";Database="
                                                + ((ConexoesDTO)ConexaoDTOBindingSource.Current).Banco + ";User="******";Password="******";Unicode=False;Protocol=2";

                    string origem         = string.Empty;
                    string destino        = string.Empty;
                    string arquivo        = string.Empty;
                    string hashfileserver = string.Empty;
                    string hashfilelocal  = string.Empty;

                    atualizacoes.Clear();
                    List <CpArqDbDTO> lista = new VersaoBO().GetCpArqDb(Global.ConnectionStringPg);

                    foreach (CpArqDbDTO item in lista)
                    {
                        try
                        {
                            origem  = Global.DriveRede + item.Path;
                            destino = Global.LocalPath + item.Path;
                            arquivo = item.Arquivo;

                            if (!File.Exists(destino + item.Arquivo))
                            {
                                atualizacoes.Add(new CpArq(origem, destino, item.Arquivo));
                            }
                            else if (item.Hash.Trim() == string.Empty)
                            {
                                hashfileserver = Global.CalculaFileHash(origem + item.Arquivo);
                                hashfilelocal  = Global.CalculaFileHash(destino + item.Arquivo);

                                if (hashfileserver != hashfilelocal)
                                {
                                    atualizacoes.Add(new CpArq(origem, destino, item.Arquivo));
                                }
                            }
                            else
                            {
                                hashfileserver = item.Hash;
                                hashfilelocal  = string.Empty;

                                if (destino.Substring(0, 2) != @"\\" || destino.ToUpper().IndexOf(@"$RGG\C$") == 0)
                                {
                                    hashfilelocal = Global.CalculaFileHash(destino + item.Arquivo);
                                }

                                if (hashfileserver.Trim() == string.Empty || hashfilelocal.Trim() == string.Empty || hashfileserver != hashfilelocal)
                                {
                                    atualizacoes.Add(new CpArq(origem, destino, item.Arquivo));
                                }
                            }
                        }
                        catch
                        {
                            atualizacoes.Add(new CpArq(origem, destino, arquivo));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Notify(status, 21);
                MessageBox.Show("Não foi possível efetuar a operação.\n\n" +
                                "Motivo: " + ex.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return(false);
            }

            return(true);
        }