コード例 #1
0
ファイル: ECM.cs プロジェクト: Javanei/clientes
        /**
         * Faz o upload de um arquivo para o ECM.
         */
        private void uploadECMDocument(ECMFolderService.documentDto folder, string filePath)
        {
            //TODO: Tratar para mandar pro ECM apenas os desenhos que devem ser impressos.
            string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1);

            //TODO: ECMFolderService.documentDto exist = getECMChild(fileName, folder);
            ECMFolderService.documentDto exist = getECMChild(fileName, folder.documentId);

            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            byte[] filebytes = new byte[fs.Length];
            fs.Read(filebytes, 0, Convert.ToInt32(fs.Length));
            fs.Close();
            fs.Dispose();

            //string base64String = System.Convert.ToBase64String(filebytes, 0, filebytes.Length);
            //System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
            //Byte[] bytesMessage = UTF8.GetBytes(base64String);

            ECMDocService.attachment[] attach = new ECMDocService.attachment[1];
            attach[0] = new ECMDocService.attachment();
            attach[0].editing = false;
            attach[0].attach = false;
            attach[0].filecontent = filebytes;
            attach[0].fileName = fileName;
            attach[0].fileSize = filebytes.Length;
            attach[0].principal = true;

            if (exist == null)
            {
                // Arquivo novo, cria.
                LOG.imprimeLog(System.DateTime.Now + " ======= Criando um novo arquivo no Fluig: " + fileName);
                docService.createSimpleDocument(ecmLogin, ecmPassword, ecmCompany, folder.documentId, ecmUser, fileName, attach);
            }
            else
            {
                // Arquivo existente, atualiza.
                LOG.imprimeLog(System.DateTime.Now + " ======= Atualizando um arquivo no Fluig: " + fileName);
                docService.updateSimpleDocument(ecmLogin, ecmPassword, ecmCompany, exist.documentId, ecmUser, fileName, attach);
                LOG.imprimeLog(System.DateTime.Now + " ======= Arquivo atualizado no Fluig: " + fileName);
            }

            //docService.getActiveDocument(ecmUser, ecmPassword, ecmCompany, 1, ecmUser);
            // 2013-05-30: Por algum motivo, as vezes não está encontrando o documento e gerando erro.
            //             Faz uma pausa e tenta novamente quando isso ocorrer.
            try
            {
                docService.getActiveDocument(ecmUser, ecmPassword, ecmCompany, 1, ecmUser);
            }
            catch (Exception ex)
            {
                LOG.imprimeLog(System.DateTime.Now + " Error : uploadECMDocument() : Falhou obtendo documento ativo. Tenta novamente");
                LOG.imprimeLog(System.DateTime.Now + " Error=" + ex.Message);
                LOG.imprimeLog("Empresa: " + ecmCompany + ", Usuario: " + ecmUser);
                LOG.imprimeLog("StackTrace: " + ex.StackTrace);
                pause();
                try
                {
                    docService.getActiveDocument(ecmUser, ecmPassword, ecmCompany, 1, ecmUser);
                }
                catch (Exception ex1)
                {
                    LOG.imprimeLog(System.DateTime.Now + " Error: uploadECMDocument() : Falhou de novo, agora lascou!!");
                    LOG.imprimeLog(System.DateTime.Now + " Error=" + ex1.Message);
                    Program.sendMail("ERRO Conversao desenho", "O Fluig falhou, nao foi possivel fazer upload de um arquivo: " + filePath);
                    throw new Exception("Nao conseguiu fazer upload para o Fluig do arquivo '" + filePath + "' [uploadECMDocument()]");
                }
            }
            // FIM
        }
コード例 #2
0
ファイル: ECM.cs プロジェクト: Javanei/clientes
        /**
         * Faz o upload de um arquivo para o ECM.
         */
        private void uploadDocument(ECMFolderService.documentDto folder, string filePath)
        {
            string fileName = filePath.Substring(filePath.LastIndexOf("\\") + 1);
            //string decodedFileName = decodeFileName(fileName);
            ECMFolderService.documentDto exist = getDocument(fileName, folder.documentId);

            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            byte[] filebytes = new byte[fs.Length];
            fs.Read(filebytes, 0, Convert.ToInt32(fs.Length));

            //string base64String = System.Convert.ToBase64String(filebytes, 0, filebytes.Length);
            //System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
            //Byte[] bytesMessage = UTF8.GetBytes(base64String);

            ECMDocService.attachment[] attach = new ECMDocService.attachment[1];
            attach[0] = new ECMDocService.attachment();
            attach[0].editing = false;
            attach[0].attach = false;
            attach[0].filecontent = filebytes;
            attach[0].fileName = fileName;
            attach[0].fileSize = filebytes.Length;
            attach[0].principal = true;

            if (exist == null)
            {
                // Arquivo novo, cria.
                LOG.imprimeLog(System.DateTime.Now + " ========= Criando um novo arquivo no ECM: " + fileName);
                docService.createSimpleDocument(this.ecmLogin, this.ecmPassword, this.ecmCompany, folder.documentId, this.ecmUser, fileName, attach);
            }
            else
            {
                // Arquivo existente, atualiza.
                LOG.imprimeLog(System.DateTime.Now + " ========= Atualizando um arquivo no ECM: " + fileName);
                docService.updateSimpleDocument(this.ecmLogin, this.ecmPassword, this.ecmCompany, exist.documentId, this.ecmUser, fileName, attach);
                //LOG.imprimeLog(System.DateTime.Now + " ========= Arquivo atualizado no ECM: " + fileName);
            }

            try
            {
                docService.getActiveDocument(this.ecmLogin, this.ecmPassword, this.ecmCompany, 1, this.ecmUser);
            }
            catch (Exception ex)
            {
                LOG.imprimeLog(System.DateTime.Now + " Error : uploadDocument() : Falhou obtendo documento ativo. Tenta novamente");
                LOG.imprimeLog(System.DateTime.Now + " Error=" + ex.Message);
                LOG.imprimeLog("Empresa: " + ecmCompany + ", Usuario: " + ecmUser);
                LOG.imprimeLog("StackTrace: " + ex.StackTrace);
                pause();
                try
                {
                    docService.getActiveDocument(ecmUser, ecmPassword, ecmCompany, 1, ecmUser);
                }
                catch (Exception ex1)
                {
                    LOG.imprimeLog(System.DateTime.Now + " Error: uploadDocument() : Falhou de novo, agora lascou!!");
                    LOG.imprimeLog(System.DateTime.Now + " Error=" + ex1.Message);
                }
            }
        }