private void Executor(Selia.Integrador.Adapter.WebService.Config objConfig, Model.Integracao ent, XmlDocument Fila = null)
 {
     try
     {
         var item = ((Model.Interface.WebService)ent.Interface.Item);
         List <Selia.Integrador.Adapter.Util.Mapeamento.Entidade> maps = objConfig.Mapeamentos;
         objConfig.Mapeamentos = new List <Selia.Integrador.Adapter.Util.Mapeamento.Entidade>();
         foreach (Model.Interface.WebService.ParametroWS param in item.Parametros)
         {
             objConfig.Mapeamentos.Add(new Selia.Integrador.Adapter.Util.Mapeamento.Entidade()
             {
                 Para = param.De, Valor = param.Para
             });
         }
         objConfig.DataHoraUltimaExecucao = ent.DataHoraUltimaExecucao;
         Selia.Integrador.Adapter.Resultado objResult = new Selia.Integrador.Adapter.WebService().Executar(objConfig, Fila);
         new BS.Fila().ProcessarFila(objResult, ent, maps);
     }
     catch (Exception ex)
     {
         Model.LogIntegracao entLogIntegracao = new Model.LogIntegracao();
         entLogIntegracao.Conteudo   = ex.Message;
         entLogIntegracao.Integracao = ent;
         entLogIntegracao.Status     = 1;
         new BS.LogIntegracao().Inserir(entLogIntegracao);
         //ServiceLog.LogError(String.Format("Erro: {0} - Message: {1} - StackTrace: {2}", ent.Nome, ex.Message, ex.StackTrace));
     }
 }
            private void ExecutaItemFila(Model.Integracao ent, Model.Fila fila, Selia.Integrador.Adapter.WebService.Config objConfig, List <Selia.Integrador.Adapter.Util.Mapeamento.Entidade> MapeamentoEntrada)
            {
                try
                {
                    Selia.Integrador.Adapter.Resultado objResult = new Selia.Integrador.Adapter.WebService().Executar(objConfig, fila.Conteudo);

                    Model.LogFila entLogFila = new Model.LogFila();

                    if (!string.IsNullOrEmpty(objResult.ParametrosEnvio))
                    {
                        entLogFila.Conteudo = objResult.ParametrosEnvio;
                    }

                    entLogFila.Conteudo         = objResult.ParametrosEnvio;
                    entLogFila.ConteudoFila     = fila.Conteudo;
                    entLogFila.ChavePrimaria    = fila.ChavePrimaria;
                    entLogFila.ChaveSecundaria  = fila.ChaveSecundaria;
                    entLogFila.LogIntegracao.ID = fila.LogIntegracaoID;
                    entLogFila.FilaID           = fila.ID;
                    entLogFila.IntegracaoID     = ent.ID;

                    if (!string.IsNullOrEmpty(objResult.Mensagem))
                    {
                        entLogFila.ConteudoRetorno = objResult.Mensagem;
                    }

                    if (objResult.TipoMensagem == Selia.Integrador.Adapter.Resultado.Tipo.Sucesso)
                    {
                        new BS.Fila().Excluir(fila.ID);
                        if (ent.Destino != null)
                        {
                            new BS.Fila().ProcessarFila(objResult, ent, MapeamentoEntrada);
                        }
                    }
                    else
                    {
                        new BS.Fila().AtualizarStatus(Model.Fila.TipoStatus.Erro, fila.ID);

                        if (!string.IsNullOrEmpty(ent.AcaoReturnoErro))
                        {
                        }
                    }

                    new BS.LogFila().Inserir(entLogFila);
                }
                catch (Exception ex)
                {
                    Model.LogIntegracao entLogIntegracao = new Model.LogIntegracao();
                    entLogIntegracao.Conteudo   = ex.Message;
                    entLogIntegracao.Integracao = ent;
                    entLogIntegracao.Status     = 1;
                    new BS.LogIntegracao().Inserir(entLogIntegracao);
                    //ServiceLog.LogError(String.Format("Erro: {0} - Message: {1} - StackTrace: {2}", ent.Nome, ex.Message, ex.StackTrace));
                }
            }
            public Selia.Integrador.Adapter.WebService.Config PreencherEntWebService(Model.Integracao ent)
            {
                var item = ((Model.Interface.WebService)ent.Interface.Item);

                Selia.Integrador.Adapter.WebService.Config objConfig = new Selia.Integrador.Adapter.WebService.Config();
                objConfig.Url               = item.Url;
                objConfig.Metodo            = item.Metodo;
                objConfig.Login             = item.Login;
                objConfig.Senha             = item.Senha;
                objConfig.ElementoSeparador = ent.ElementoRegistro;
                objConfig.ExecucaoInicial   = ent.AcaoInicial;
                objConfig.ExecucaoFinal     = ent.AcaoFinal;
                objConfig.Action            = item.Action;
                objConfig.ConnectionString  = ent.ConnectionString;

                objConfig.Mapeamentos = MapearParaAdapter(ent.Mapeamento);
                return(objConfig);
            }
            public void Executar(Model.Integracao ent, XmlDocument Fila = null)
            {
                Selia.Integrador.Adapter.WebService.Config objConfig = PreencherEntWebService(ent);

                if (ent.Consumidor)
                {
                    Consumidor(objConfig, ent);
                }
                else
                {
                    Executor(objConfig, ent, Fila);
                }

                if (ent.DestinoID > 0)
                {
                    new Integracao().Executar(ent.DestinoID, true);
                }
            }
            public void Consumidor(Selia.Integrador.Adapter.WebService.Config objConfig, Model.Integracao ent)
            {
                List <Selia.Integrador.Adapter.Util.Mapeamento.Entidade> MapeamentoEntrada = new List <Selia.Integrador.Adapter.Util.Mapeamento.Entidade>();

                if (ent.Destino != null)
                {
                    MapearParaAdapter(ent.Destino.Mapeamento);
                }

                int maxDegreeOfParallelism = ent.NivelParalelismo;

                Parallel.ForEach(ent.Fila, new ParallelOptions()
                {
                    MaxDegreeOfParallelism = maxDegreeOfParallelism
                }, (fila) =>
                {
                    ExecutaItemFila(ent, fila, objConfig, MapeamentoEntrada);
                });
            }