Exemplo n.º 1
0
        private void ProcessCurriculumVitae(CurriculoEntry curriculoEntry, ManualResetEvent doneEvent)
        {
            XmlDocument curriculumVitaeXml = new XmlDocument();

            try
            {
                var filename = _lattesModule.GetCurriculumVitaeFileName(curriculoEntry.NumeroCurriculo);

                curriculumVitaeXml.Load(filename);

                // nescessário para o deserialize reconhecer o Xml
                curriculumVitaeXml.DocumentElement.SetAttribute("xmlns", "http://tempuri.org/LMPLCurriculo");

                XDocument         curriculumVitaeXDocument = XDocument.Parse(curriculumVitaeXml.InnerXml);
                CurriculoVitaeXml curriculumVitae          = _curriculumVitaeUnserializer.Deserialize(curriculumVitaeXDocument.CreateReader()) as CurriculoVitaeXml;
                curriculoEntry.NomeProfessor = curriculumVitae.DADOSGERAIS.NOMECOMPLETO;

                ProfessorDAOService professorDAOService = new ProfessorDAOService(new LattesDatabase());
                Logger.Debug($"Iniciando processamento currículo {curriculoEntry.NumeroCurriculo} do Professor {curriculumVitae.DADOSGERAIS.NOMECOMPLETO}...");

                if (professorDAOService.ProcessCurriculumVitaeXML(curriculumVitae, curriculoEntry))
                {
                    Logger.Info($"Currículo {curriculoEntry.NumeroCurriculo} do Professor {curriculumVitae.DADOSGERAIS.NOMECOMPLETO} processado com sucesso !");
                    File.Delete(filename);
                }
            }

            catch (Exception ex)
            {
                Logger.Error($"Erro durante a leitura do XML {curriculoEntry.NumeroCurriculo}: {ex.Message}\n{ex.StackTrace}");

                int sequencia = 1;
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                    Logger.Error($"Excessão Interna [{sequencia++}]: {ex.Message}\n{ex.StackTrace}");
                }
            }
            finally
            {
                if (Interlocked.Decrement(ref _workItemCount) == 0)
                {
                    doneEvent.Set();
                }
                // Allow another add to the queue
                WorkLimiter.Release();
            }
        }
Exemplo n.º 2
0
        public void ThreadRun()
        {
            XmlSerializer curriculumVitaeUnserializer = new XmlSerializer(typeof(CurriculoVitaeXml));

            XmlDocument       curriculumVitaeXml;
            XDocument         curriculumVitaeXDocument;
            CurriculoVitaeXml curriculumVitae;

            CurriculoEntry curriculoEntry;
            string         filename;

            var lattesDatabase = new LattesDatabase();

            ProfessorDAOService professorDAOService = new ProfessorDAOService(lattesDatabase);

            while (lattesModule.HasNextCurriculumVitaeForProcess)
            {
                curriculoEntry = lattesModule.GetNextCurriculumVitaeForProcess();

                // para ie caso da thread não conseguir pegar ie ultimo arquivo v tempo
                if (curriculoEntry == null)
                {
                    continue;
                }

                filename = lattesModule.GetCurriculumVitaeFileName(curriculoEntry.NumeroCurriculo);
                //curriculumXMLFile = new FileStream(filename, FileMode.Open);

                curriculumVitaeXml = new XmlDocument();
                //curriculumVitaeXml.Load(curriculumXMLFile);
                curriculumVitaeXml.Load(filename);

                // nescessário para ie deserialize reconhecer ie Xml
                curriculumVitaeXml.DocumentElement.SetAttribute("xmlns", "http://tempuri.org/LMPLCurriculo");

                curriculumVitaeXDocument = XDocument.Parse(curriculumVitaeXml.InnerXml);

                try
                {
                    curriculumVitae = (CurriculoVitaeXml)curriculumVitaeUnserializer.Deserialize(curriculumVitaeXDocument.CreateReader());
                }
                catch (Exception ex)
                {
                    Logger.Error(String.Format("Erro durante a leitura do XML:", ex.Message));
                    Logger.Error(ex.StackTrace);
                    if (ex.InnerException != null)
                    {
                        Logger.Error("Excessão Interna:");
                        int sequencia = 1;
                        while (ex.InnerException != null)
                        {
                            ex = ex.InnerException;
                            Logger.Error(String.Format("Excessão Interna [{0}]: {1}", sequencia++, ex.Message));
                            Logger.Error(ex.StackTrace);
                        }
                    }
                    continue;
                }

                // limpa ponteiros
                curriculumVitaeXDocument = null;
                curriculumVitaeXml       = null;

                Logger.Info(String.Format("Processando XML {0} do Professor {1} [Thread {2}]", curriculoEntry.NumeroCurriculo, curriculumVitae.DADOSGERAIS.NOMECOMPLETO, this._sequence));

                // processa curriculo
                if (professorDAOService.ProcessCurriculumVitaeXML(curriculumVitae, curriculoEntry))
                {
                    File.Delete(filename);
                }
                else
                {
                    lattesDatabase.Database.Connection.Close();
                    lattesDatabase = new LattesDatabase();
                    professorDAOService.LattesDatabase = lattesDatabase;
                }
            }
        }