Exemple #1
0
        /**
         * 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
        }
Exemple #2
0
        /**
         * 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);
                }
            }
        }
Exemple #3
0
 private void viewDocument(ECMFolderService.documentDto doc)
 {
     if (doc != null)
     {
         //LOG.imprimeLog(System.DateTime.Now + " ========= Exibindo documento: " + doc.documentId + " - " + doc.version + " = " + doc.documentDescription);
         SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer();
         string url = ecmURL;
         if (!url.EndsWith("/"))
         {
             url = url + "/";
         }
         url = url + "documentviewer?WDNrDocto=" + doc.documentId + "&WDNrVersao=" + doc.version;
         //LOG.imprimeLog(System.DateTime.Now + " ========= URL: " + url);
         ie.Navigate(url);
         ie.ToolBar = 0;
         ie.AddressBar = false;
         ie.Visible = true;
     }
     else
     {
         LOG.imprimeLog(System.DateTime.Now + " ========= Lascou!!! Nao achou o documento!!");
     }
 }
Exemple #4
0
        private ECMFolderService.documentDto findCreateLastFolderInPath(ECMFolderService.documentDto startFolder, String basePath)
        {
            LOG.imprimeLog(System.DateTime.Now + " =========== findCreateLastFolderInPath - 1 - basePath: " + basePath);
            string[] folders = parseFolder(basePath);
            ECMFolderService.documentDto result = startFolder;
            int ini = 0;
            if (startFolder == null)
            {
                LOG.imprimeLog(System.DateTime.Now + " =========== findCreateLastFolderInPath - 2");
                startFolder = getRootFolder(folders[0]);
                ini = 1;
            }
            LOG.imprimeLog(System.DateTime.Now + " =========== findCreateLastFolderInPath - 3 - ini: " + ini);
            if (startFolder == null)
            {
                LOG.imprimeLog(System.DateTime.Now + " =========== findCreateLastFolderInPath - 4: Lascou, nao achou o ROOT folder!");
                return null;
            }
            LOG.imprimeLog(System.DateTime.Now + " =========== findCreateLastFolderInPath - 5 - root folder: " + startFolder.documentId + " = " + startFolder.documentDescription);

            for (int i = ini; i < folders.Length; i++)
            {
                LOG.imprimeLog(System.DateTime.Now + " =========== findCreateLastFolderInPath - 6 - tratando folder: " + folders[i]);
                ECMFolderService.documentDto folder = null;
                ECMFolderService.documentDto[] fdocs = folderService.getSubFolders(this.ecmLogin, this.ecmPassword, this.ecmCompany, result.documentId, this.ecmUser);
                for (int j = 0; j < fdocs.Length; j++)
                {
                    if (fdocs[j].documentDescription.Equals(folders[i]))
                    {
                        folder = fdocs[j];
                        LOG.imprimeLog(System.DateTime.Now + " =========== findCreateLastFolderInPath - 7 - Folder encontrado: " + folder.documentId + "=" + folder.documentDescription);
                        break;
                    }
                }
                if (folder == null)
                {
                    folder = createFolder(folders[i], result.documentId);
                    LOG.imprimeLog(System.DateTime.Now + " =========== findCreateLastFolderInPath - 8 - Folder criado: " + folder.documentId + "=" + folder.documentDescription);
                }
                result = folder;
            }
            //LOG.imprimeLog(System.DateTime.Now + " =========== findCreateLastFolderInPath - 9 - result: " + result);
            return result;
        }