WriteLog() 공개 정적인 메소드

public static WriteLog ( string msg, bool gravarStackTrace ) : void
msg string
gravarStackTrace bool
리턴 void
예제 #1
0
파일: Auxiliar.cs 프로젝트: tassio1125/Nfe
        /// <summary>
        /// Move arquivos com a extensão informada e que está com erro para uma pasta de xml´s/arquivos com erro configurados no UniNFe.
        /// </summary>
        /// <param name="cArquivo">Nome do arquivo a ser movido para a pasta de XML´s com erro</param>
        /// <param name="ExtensaoArq">Extensão do arquivo que vai ser movido. Ex: .xml</param>
        /// <example>this.MoveArqErro(this.vXmlNfeDadosMsg, ".xml")</example>
        public void MoveArqErro(string Arquivo, string ExtensaoArq)
        {
            int emp = Empresas.FindEmpresaByThread();

            if (File.Exists(Arquivo))
            {
                FileInfo oArquivo = new FileInfo(Arquivo);

                if (!string.IsNullOrEmpty(Empresas.Configuracoes[emp].PastaXmlErro) && Directory.Exists(Empresas.Configuracoes[emp].PastaXmlErro))
                {
                    string vNomeArquivo = Empresas.Configuracoes[emp].PastaXmlErro + "\\" + Functions.ExtrairNomeArq(Arquivo, ExtensaoArq) + ExtensaoArq;

                    Functions.Move(Arquivo, vNomeArquivo);

                    Auxiliar.WriteLog("O arquivo " + Arquivo + " foi movido para " + vNomeArquivo, true);

                    /*
                     * //Deletar o arquivo da pasta de XML com erro se o mesmo existir lá para evitar erros na hora de mover. Wandrey
                     * if (File.Exists(vNomeArquivo))
                     *  this.DeletarArquivo(vNomeArquivo);
                     *
                     * //Mover o arquivo da nota fiscal para a pasta do XML com erro
                     * oArquivo.MoveTo(vNomeArquivo);
                     */
                }
                else
                {
                    //Antes estava deletando o arquivo, agora vou retornar uma mensagem de erro
                    //pois não podemos excluir, pode ser coisa importante. Wandrey 25/02/2011
                    throw new Exception("A pasta de XML´s com erro informada nas configurações não existe, por favor verifique.");
                    //oArquivo.Delete();
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Copia o arquivo para o FTP
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="folderName"></param>
        public void SendFileToFTP(string fileName, string folderName)
        {
            //verifique se o arquivo existe e se o FTP da empresa está configurado e ativo
            if (File.Exists(fileName) && this.FTPIsAlive)
            {
                Thread t = new Thread(new ThreadStart(delegate()
                {
                    string arqDestino = Path.Combine(Path.GetTempPath(), Path.GetFileName(fileName));
                    //Copia o arquivo para a pasta temp
                    FileInfo oArquivo = new FileInfo(fileName);
                    oArquivo.CopyTo(arqDestino, true);

                    FTP ftp = new FTP(this.FTPNomeDoServidor, this.FTPPorta, this.FTPNomeDoUsuario, this.FTPSenha);
                    try
                    {
                        //conecta ao ftp
                        ftp.Connect();
                        //pega a pasta corrente no ftp
                        string vCorrente = ftp.GetWorkingDirectory();
                        //tenta mudar para a pasta de destino
                        if (!ftp.changeDir(folderName))
                        {
                            //como nao foi possivel mudar de pasta, a cria
                            ftp.makeDir(folderName);
                        }
                        //volta para a pasta corrente já que na "makeDir" a pasta se torna ativa na ultima pasta criada
                        ftp.ChangeDir(vCorrente);
                        //transfere o arquivo da pasta temp
                        ftp.OpenUpload(arqDestino, folderName + "/" + Path.GetFileName(fileName), false);
                        while (ftp.DoUpload() > 0)
                        {
                            //Thread.Sleep(1);
                        }
                    }
                    catch (Exception ex)
                    {
                        Auxiliar.WriteLog("Ocorreu um erro ao tentar conectar no FTP: " + ex.Message, false);
                    }
                    finally
                    {
                        if (ftp.IsConnected)
                        {
                            ftp.Disconnect();
                        }

                        //exclui o arquivo transferido da pasta temporaria
                        Functions.DeletarArquivo(arqDestino);
                    }
                    doneThread_FTP(Thread.CurrentThread);
                }));
                this.threads.Add(t);
                t.IsBackground = true;
                //t.Name = name;
                t.Start();
                t.Join();
            }
        }
예제 #3
0
        /// <summary>
        /// Copia o arquivo para o FTP
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="folderName"></param>
        public void SendFileToFTP(string fileName, string folderName)
        {
            //verifique se o arquivo existe e se o FTP da empresa está configurado e ativo
            if (File.Exists(fileName) && this.FTPIsAlive)
            {
                Thread t = new Thread(new ThreadStart(delegate()
                {
                    string arqDestino = Path.Combine(Path.GetTempPath(), Path.GetFileName(fileName));
                    //Copia o arquivo para a pasta temp
                    FileInfo oArquivo = new FileInfo(fileName);
                    oArquivo.CopyTo(arqDestino, true);

                    FTP ftp = new FTP(this.FTPNomeDoServidor, this.FTPPorta, this.FTPNomeDoUsuario, this.FTPSenha);
                    try
                    {
                        //conecta ao ftp
                        ftp.Connect();
                        if (!ftp.IsConnected)
                        {
                            throw new Exception("FTP '" + this.FTPNomeDoServidor + "' não conectado");
                        }

                        ftp.PassiveMode = this.FTPPassivo;

                        //pega a pasta corrente no ftp
                        string vCorrente = ftp.GetWorkingDirectory();

                        //tenta mudar para a pasta de destino
                        if (!ftp.changeDir(folderName))
                        {
                            //como nao foi possivel mudar de pasta, a cria
                            ftp.makeDir(folderName);
                            if (!ftp.changeDir(folderName))
                            {
                                throw new Exception("Pasta '" + folderName + "' criada, mas não foi possível acessá-la");
                            }
                        }
                        //volta para a pasta corrente já que na "makeDir" a pasta se torna ativa na ultima pasta criada
                        ftp.ChangeDir(vCorrente);

                        //transfere o arquivo da pasta temp
                        string remote_filename = folderName + "/" + Path.GetFileName(fileName);
                        ftp.UploadFile(arqDestino, remote_filename, false);

                        if (ftp.GetFileSize(remote_filename) == 0)
                        {
                            throw new Exception("Arquivo '" + remote_filename + "' não encontrado no FTP");
                        }

                        Auxiliar.WriteLog("Arquivo '" + fileName + "' enviado ao FTP com o nome '" + remote_filename + "' com sucesso.", false);
                    }
                    catch (Exception ex)
                    {
                        Auxiliar.WriteLog("Ocorreu um erro ao tentar conectar no FTP: " + ex.Message, false);
                        ///
                        /// gravado o log de ftp aqui, pq o 'chamador' nao o trataria
                        ///
                        new Auxiliar().GravarArqErroERP(Path.ChangeExtension(fileName, ".ftp"), ex.Message);
                    }
                    finally
                    {
                        if (ftp.IsConnected)
                        {
                            ftp.Disconnect();
                        }

                        //exclui o arquivo transferido da pasta temporaria
                        Functions.DeletarArquivo(arqDestino);
                    }
                    doneThread_FTP(Thread.CurrentThread);
                }));
                this.threads.Add(t);
                t.IsBackground = true;
                //t.Name = name;
                t.Start();
                t.Join();
            }
        }