Example #1
0
        private Boolean ProcessPrintLogFile(String fileName, PrintLogSender printLogSender)
        {
            // Informações de trace são enviadas ao listener através de NotifyListener()
            // O listener grava essas informações em log de arquivo
            CSVReader reader = new CSVReader(fileName, listener);

            NotifyListener("Fazendo a leitura do CSV.");
            DataTable fullTable = reader.Read();
            int       rowCount  = fullTable.Rows.Count;

            // Verifica se existem registros no CSV
            if (rowCount < 1)
            {
                NotifyListener("CSV inválido. Nenhum registro encontrado.");
                return(false);
            }

            // Informa a quantidade de registros no CSV e uma amostra de seu conteúdo
            NotifyListener("Quantidade de registros no CSV - " + rowCount);
            String sampleData = fullTable.Rows[0]["Time"].ToString() + " - " +
                                fullTable.Rows[0]["Document Name"].ToString();

            NotifyListener("Amostra dos dados - " + sampleData);

            // Gera uma view do log com uma faixa de horário
            String    startHour            = DateTime.Now.AddHours(-1).ToString("yyyy-MM-dd HH:mm:ss");
            String    endHour              = DateTime.Now.AddHours(+1).ToString("yyyy-MM-dd HH:mm:ss");
            String    rowFilter            = "Time > '" + startHour + "' AND Time < '" + endHour + "'";
            DataView  view                 = new DataView(fullTable, rowFilter, null, DataViewRowState.Added);
            DataTable printedDocumentTable = view.ToTable();

            // Cria arquivo que armazenará resumo dos trabalhos de impressão
            DateTime?      fileDate = PrintLogFile.GetDate(fileName);
            PrintLogDigest digest   = new PrintLogDigest();

            digest.Create(fileDate);

            PrintedDocument printedDocument;

            foreach (DataRow row in printedDocumentTable.Rows)
            {
                printedDocument             = new PrintedDocument();
                printedDocument.tenantId    = tenantId;
                printedDocument.jobTime     = DateTime.Parse(row["Time"].ToString());
                printedDocument.userName    = row["User"].ToString();
                printedDocument.printerName = row["Printer"].ToString();
                printedDocument.name        = row["Document Name"].ToString();
                printedDocument.pageCount   = int.Parse(row["Pages"].ToString());
                printedDocument.copyCount   = int.Parse(row["Copies"].ToString());
                printedDocument.duplex      = ConvertToBool(row["Duplex"].ToString());
                printedDocument.color       = !ConvertToBool(row["Grayscale"].ToString());

                printLogSender.AddPrintedDocument(printedDocument);
                digest.AddToDigest(printedDocument, row["Language"].ToString(), row["Size"].ToString());
            }

            return(true);
        }
Example #2
0
        public Boolean SendPrintJobs(String logDirectories)
        {
            Boolean        success        = true;
            DateTime       today          = DateTime.Now.Date;
            PrintLogSender printLogSender = new PrintLogSender(serviceUrl, listener);

            String[] directoryArray = logDirectories.Split(new Char[] { ';' });
            foreach (String directory in directoryArray)
            {
                DirectoryInfo logDir   = new DirectoryInfo(directory);
                String        fileName = null;
                if (logDir.Exists)
                {
                    fileName = PrintLogFile.MountName(directory, today.Day, today.Month, today.Year);
                    FileInfo logFile = new FileInfo(fileName);
                    if (!logFile.Exists)
                    {
                        fileName = null;
                    }
                }

                // Se o arquivo existe, processa seu conteúdo
                if (!String.IsNullOrEmpty(fileName))
                {
                    // Informa dados do arquivo
                    NotifyListener("Arquivo - fileName = " + fileName);

                    if (!ProcessPrintLogFile(fileName, printLogSender))
                    {
                        success = false; // Falha ao processar o arquivo .CSV
                    }
                }
            }

            if (!printLogSender.FinishSending())
            {
                success = false; // Falha ao enviar algum pacote de logs
            }
            return(success);
        }