Exemple #1
0
 private void _queueTxt()
 {
     while (_isRunning)
     {
         try
         {
             TOArqTxt fileName = null;
             if (_cqFilesTxt.TryDequeue(out fileName))
             {
                 this._processTxt(fileName);
             }
             else
             {
                 lock (_syncTxt)
                     Monitor.Wait(_syncTxt, 300);
             }
         }
         catch { }
     }
 }
Exemple #2
0
        private void _processTxt(TOArqTxt toTxt)
        {
            try
            {
                ColdFilesSplitter splitter = new ColdFilesSplitter();
                bool bSplit = false;

                switch (toTxt.Config.Type)
                {
                case TypeWatcher.COLD_BTC:
                    bSplit = splitter.SplitArquivoBTC(toTxt);
                    break;

                case TypeWatcher.COLD_LIQ:
                    bSplit = splitter.SplitArquivoLiquidacoes(toTxt);
                    break;

                case TypeWatcher.COLD_POS_CLI:
                    bSplit = splitter.SplitArquivoPosicaoCliente(toTxt);
                    break;

                case TypeWatcher.COLD_CUST:
                    bSplit = splitter.SplitArquivoCustodia(toTxt);
                    break;

                case TypeWatcher.COLD_MARG:
                    bSplit = splitter.SplitArquivoMargem(toTxt);
                    break;

                case TypeWatcher.COLD_GART:
                    bSplit = splitter.SplitArquivoGarantias(toTxt);
                    break;

                case TypeWatcher.COLD_TERMO:
                    bSplit = splitter.SplitArquivoTermo(toTxt);
                    break;

                case TypeWatcher.COLD_DIVIDENDO:
                    bSplit = splitter.SplitArquivoDividendo(toTxt);
                    break;

                default: break;
                }

                if (!bSplit)
                {
                    logger.Warn("*** Erro ao fragmentar arquivo: " + toTxt.FileName);
                    logger.Warn("Config.ClientIdCheck ...: " + toTxt.Config.ClientIdCheck);
                    logger.Warn("Config.Exchange ........: " + toTxt.Config.Exchange);
                    logger.Warn("Config.ExtensionFilter..: " + toTxt.Config.ExtensionFilter);
                    logger.Warn("Config.FileType.........: " + toTxt.Config.FileType);
                    logger.Warn("Config.NameType ........: " + toTxt.Config.NameType);
                    logger.Warn("Config.PathBkp .........: " + toTxt.Config.PathBkp);
                    logger.Warn("Config.PathProcessed ...: " + toTxt.Config.PathProcessed);
                    logger.Warn("Config.PathWatcher .....: " + toTxt.Config.PathWatcher);
                    logger.Warn("Config.SubjectEmail ....: " + toTxt.Config.SubjectEmail);
                    logger.Warn("Config.TemplateFile ....: " + toTxt.Config.TemplateFile);
                    logger.Warn("Config.TimeToRefresh ...: " + toTxt.Config.TimeToRefresh);
                    logger.Warn("Config.Type ............: " + toTxt.Config.Type);
                    logger.Warn("*** End of report *** ");
                }
            }
            catch (Exception ex)
            {
                logger.Error("Problemas no processamento do arquivo txt: " + ex.Message, ex);
            }
        }
Exemple #3
0
 public void AddTxtFile(TOArqTxt file)
 {
     _cqFilesTxt.Enqueue(file);
     lock (_syncTxt)
         Monitor.Pulse(_syncTxt);
 }
Exemple #4
0
        private void _moveFile(string fileName)
        {
            try
            {
                if (_isFileReady(fileName))
                {
                    string pathBkp = this.Config.PathBkp + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd");

                    if (!Directory.Exists(pathBkp))
                    {
                        Directory.CreateDirectory(pathBkp);
                    }

                    string onlyFileName = fileName.Substring(fileName.LastIndexOf(Path.DirectorySeparatorChar) + 1);

                    string fileBkp = pathBkp + Path.DirectorySeparatorChar + onlyFileName;

                    if (!File.Exists(fileBkp))
                    {
                        File.Move(fileName, fileBkp);
                        switch (this.Config.FileType)
                        {
                        case FileTypes.PDF:
                            TOArqPdf toPdf = new TOArqPdf();
                            toPdf.FileName = fileBkp;
                            toPdf.Config   = this.Config;
                            PdfManager.Instance.AddPdfFile(toPdf);
                            break;

                        case FileTypes.TXT:
                            TOArqTxt toTxt = new TOArqTxt();
                            toTxt.FileName = fileBkp;
                            toTxt.Config   = this.Config;
                            TxtManager.Instance.AddTxtFile(toTxt);
                            break;
                        }
                    }
                    else
                    {
                        string ext         = fileName.Substring(fileName.LastIndexOf('.'), fileName.Length - fileName.LastIndexOf('.'));
                        string newext      = DateTime.Now.ToString(".yyyy-MM-dd-HH-mm-ss-fff") + ext;
                        string newFileName = fileBkp.Substring(0, fileBkp.LastIndexOf('.')) + newext;
                        File.Move(fileName, newFileName);

                        switch (this.Config.FileType)
                        {
                        case FileTypes.PDF:
                            TOArqPdf toPdf = new TOArqPdf();
                            toPdf.FileName = newFileName;
                            toPdf.Config   = this.Config;
                            PdfManager.Instance.AddPdfFile(toPdf);
                            break;

                        case FileTypes.TXT:
                            TOArqTxt toTxt = new TOArqTxt();
                            toTxt.FileName = newFileName;
                            toTxt.Config   = this.Config;
                            TxtManager.Instance.AddTxtFile(toTxt);
                            break;
                        }
                    }
                }
                else
                {
                    logger.Debug("File not ready: " + fileName);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Erro ao mover o arquivo: " + ex.Message, ex);
            }
        }