Example #1
0
        /// <summary>
        /// Twitter não tem troca de token.
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public PerfilAccessToken TrocarToken(string json)
        {
            var accessToken = DeserializadorHelper.Deserializar <twitter.AccessToken>(json);

            var perfilToken = new comum_dto.PerfilAccessToken
            {
                Token  = accessToken.oauth_token,
                Secret = accessToken.oauth_token_secret
            };

            perfilToken.Json = SerializadorHelper.Serializar(perfilToken);

            return(perfilToken);
        }
        /// <summary>
        /// Twitch não tem troca de token.
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public PerfilAccessToken TrocarToken(string json)
        {
            var accessToken = DeserializadorHelper.Deserializar <twitch.AccessToken>(json);

            var perfilToken = new comum_dto.PerfilAccessToken
            {
                Token   = accessToken.access_token,
                Refresh = accessToken.refresh_token,
                Tipo    = accessToken.token_type
            };

            perfilToken.Json = SerializadorHelper.Serializar(perfilToken);

            return(perfilToken);
        }
Example #3
0
        /// <summary>
        /// youtube não tem troca de token.
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public PerfilAccessToken TrocarToken(string json)
        {
            var accessToken = DeserializadorHelper.Deserializar <youtube.AccessToken>(json);

            var expires_in = 0;

            int.TryParse(accessToken.expires_in, out expires_in);

            var perfilToken = new comum_dto.PerfilAccessToken
            {
                Token     = accessToken.access_token,
                Expiracao = DateTimeHelper.Now().AddSeconds(expires_in),
                Tipo      = accessToken.token_type
            };

            perfilToken.Json = SerializadorHelper.Serializar(perfilToken);

            return(perfilToken);
        }
Example #4
0
        static void Main(string[] args)
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile(
                path: "appsettings.json",
                optional: false,
                reloadOnChange: true)
                                .Build();

            var serviceProvider = new ServiceCollection()
                                  .AddSingleton <IConfiguration>(configuration)
                                  .AddTransient <DapperHelper>()
                                  .AddTransient <EnfileiradorClient>()
                                  .AddTransient <eventos.Repositorio>()
                                  .AddTransient <eventos.Servico>()
                                  .AddTransient <pontuacao.Repositorio>()
                                  .AddTransient <pontuacao.Servico>()
                                  .AddTransient <saldo.Repositorio>()
                                  .AddTransient <saldo.Servico>()
                                  .AddTransient <Repositorio>()
                                  .AddTransient <Servico>()
                                  .BuildServiceProvider();

            var enfileiradorClient = serviceProvider.GetService <EnfileiradorClient>();

            var servico = serviceProvider.GetService <Servico>();

            var filaConfig = enfileiradorClient.Consolidador();

            var factory = new ConnectionFactory()
            {
                HostName = filaConfig.HostName
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    var filaDeclarada = channel.QueueDeclare(queue: filaConfig.Nome,
                                                             durable: filaConfig.Durable,
                                                             exclusive: filaConfig.Exclusive,
                                                             autoDelete: filaConfig.AutoDelete,
                                                             arguments: null);

                    var consumer = new EventingBasicConsumer(channel);

                    channel.BasicConsume(queue: filaConfig.Nome,
                                         autoAck: filaConfig.AutoAck,
                                         consumer: consumer);

                    consumer.Received += (model, ea) =>
                    {
                        var body = ea.Body;
                        var json = Encoding.UTF8.GetString(body.ToArray());

                        var ponto = DeserializadorHelper.Deserializar <coredto.Ponto>(json);

                        try
                        {
                            Console.WriteLine("--------------------------------------------");
                            Console.WriteLine("Evento: {0}", ponto.EventoId);
                            Console.WriteLine("Empresa: {0}", ponto.EmpresaId);
                            Console.WriteLine("UsuarioId: {0}", ponto.UsuarioId);
                            Console.WriteLine("Post: {0}", ponto.PostId);
                            Console.WriteLine("Data: {0}", DateTimeHelper.Now());

                            servico.Processar(ponto);

                            Console.WriteLine("Processou");

                            if (!filaConfig.AutoAck)
                            {
                                channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                            }
                        }
                        catch (Exception ex)
                        {
                            servico.Rollback(ponto);

                            Console.WriteLine("*************************************************************");
                            Console.WriteLine("Erro");
                            Console.WriteLine(ex.Message);
                            Console.WriteLine("*************************************************************");
                        }
                    };

                    Console.WriteLine("Consolidador aguardando...");
                    Console.ReadLine();
                }
        }
Example #5
0
        static void Main(string[] args)
        {
            var serviceProvider = new ServiceCollection()
                                  .AddSingleton <EnfileiradorClient>()
                                  .AddTransient <TriadorService <Evento> >()
                                  .AddScoped(typeof(coreinterfaces.triador.IRegistradorEventoTriagem <EventoPing>), typeof(pingtriador.Registrador))
                                  .AddScoped(typeof(coreinterfaces.triador.IValidadorDeEvento <Evento>), typeof(Validador))
                                  .AddScoped(typeof(coreinterfaces.triador.IAvaliadorDeEvento <EventoPing>), typeof(pingtriador.Avaliador))
                                  .AddScoped(typeof(coreinterfaces.triador.IIdentificadorUsuario <Evento>), typeof(IdentificadorUsuario))
                                  .AddScoped(typeof(coreinterfaces.triador.ITriador <Evento>), typeof(Triador))
                                  .AddTransient <PerfilClient>()
                                  .AddTransient <registrador.Client>()
                                  .BuildServiceProvider();

            var triadorService = serviceProvider.GetService <TriadorService <Evento> >();

            var enfileiradorClient = serviceProvider.GetService <EnfileiradorClient>();

            var filaConfig = enfileiradorClient.TriadorTwitch();

            var factory = new ConnectionFactory()
            {
                HostName = filaConfig.HostName
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    var filaDeclarada = channel.QueueDeclare(queue: filaConfig.Nome,
                                                             durable: filaConfig.Durable,
                                                             exclusive: filaConfig.Exclusive,
                                                             autoDelete: filaConfig.AutoDelete,
                                                             arguments: null);

                    var consumer = new EventingBasicConsumer(channel);

                    channel.BasicConsume(queue: filaConfig.Nome,
                                         autoAck: filaConfig.AutoAck,
                                         consumer: consumer);

                    consumer.Received += (model, ea) =>
                    {
                        try
                        {
                            var json = Encoding.UTF8.GetString(ea.Body.ToArray());

                            var envelope = DeserializadorHelper.Deserializar <EnvelopeEvento <Evento> >(json);

                            Console.WriteLine("--------------------------------------------");
                            Console.WriteLine("Empresa: {0}", envelope.EmpresaId);
                            Console.WriteLine("DataEvento: {0}", envelope.DataEvento);
                            Console.WriteLine("Data: {0}", DateTimeHelper.Now());

                            Console.WriteLine("Atual: {0}", envelope.Evento.Ping.Atual);
                            Console.WriteLine("Ultimo: {0}", envelope.Evento.Ping.Ultimo);
                            Console.WriteLine("FrequenciaMinutos: {0}", envelope.Evento.Ping.FrequenciaMinutos);
                            Console.WriteLine("ToleranciaSegundos: {0}", envelope.Evento.Ping.ToleranciaSegundos);
                            Console.WriteLine("PausaMilissegundos: {0}", envelope.Evento.Ping.PausaMilissegundos);
                            Console.WriteLine("TotalSeconds: {0}", (envelope.Evento.Ping.Atual - envelope.Evento.Ping.Ultimo).TotalSeconds);

                            triadorService.ProcessarEnvelope(envelope);

                            Console.WriteLine("Processou");

                            if (!filaConfig.AutoAck)
                            {
                                channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                            }
                        }
                        catch (EventoInvalidoException eventoInvalidoException)
                        {
                            //##TODO logar
                            Console.WriteLine("*************************************************************");
                            Console.WriteLine("Evento inválido");
                            Console.WriteLine(DateTimeHelper.Now());
                            Console.WriteLine(Encoding.UTF8.GetString(ea.Body.ToArray()));
                            Console.WriteLine("*************************************************************");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("*************************************************************");
                            Console.WriteLine("Erro");
                            Console.WriteLine(ex.Message);
                            Console.WriteLine("*************************************************************");
                        }
                    };

                    Console.WriteLine("Triador Twitch aguardando...");
                    Console.ReadLine();
                }
        }
Example #6
0
        static void Main(string[] args)
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile(
                path: "appsettings.json",
                optional: false,
                reloadOnChange: true)
                                .Build();

            var serviceProvider = new ServiceCollection()
                                  .AddSingleton <IConfiguration>(configuration)
                                  .AddTransient <DapperHelper>()
                                  .AddTransient <EnfileiradorClient>()
                                  .AddTransient <pontuacao.Repositorio>()
                                  .AddTransient <pontuacao.Servico>()
                                  .AddTransient <nivel.Servico>()
                                  .AddTransient <nivel.Regras>()
                                  .AddTransient <nivel.Repositorio>()
                                  .AddTransient <nivel.FronteiroServico>()
                                  .AddTransient <classificacao.Servico>()
                                  .AddTransient <classificacao.Repositorio>()
                                  .AddTransient <transacao.Saldo>()
                                  .AddTransient <transacao.Debito>()
                                  .AddTransient <transacao.Repositorio>()
                                  .AddTransient <usuario.Servico>()
                                  .AddTransient <usuario.Repositorio>()
                                  .BuildServiceProvider();

            var enfileiradorClient   = serviceProvider.GetService <EnfileiradorClient>();
            var classificacaoService = serviceProvider.GetService <classificacao.Servico>();

            var filaConfig = enfileiradorClient.Classificador();

            var factory = new ConnectionFactory()
            {
                HostName = filaConfig.HostName
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    var filaDeclarada = channel.QueueDeclare(queue: filaConfig.Nome,
                                                             durable: filaConfig.Durable,
                                                             exclusive: filaConfig.Exclusive,
                                                             autoDelete: filaConfig.AutoDelete,
                                                             arguments: null);

                    var consumer = new EventingBasicConsumer(channel);

                    channel.BasicConsume(queue: filaConfig.Nome,
                                         autoAck: filaConfig.AutoAck,
                                         consumer: consumer);

                    consumer.Received += (model, ea) =>
                    {
                        try
                        {
                            var body = ea.Body;
                            var json = Encoding.UTF8.GetString(body.ToArray());

                            var usuarioParaProcessar = DeserializadorHelper.Deserializar <dto.UsuarioParaProcessar>(json);

                            Console.WriteLine("--------------------------------------------");
                            Console.WriteLine("UsuarioId: {0}", usuarioParaProcessar.UsuarioId);
                            Console.WriteLine("Tentariva: {0}", usuarioParaProcessar.Tentativa);
                            Console.WriteLine("Data: {0}", DateTimeHelper.Now());

                            classificacaoService.Processar(usuarioParaProcessar);

                            Console.WriteLine("Processou");

                            if (!filaConfig.AutoAck)
                            {
                                channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.ForegroundColor = ConsoleColor.White;
                            Console.BackgroundColor = ConsoleColor.Red;

                            Console.WriteLine("");
                            Console.WriteLine("* Erro                                     *");
                            Console.ResetColor();
                            Console.WriteLine(DateTimeHelper.Now());
                            Console.WriteLine(ex.Message);
                        }
                    };

                    Console.ForegroundColor = ConsoleColor.White;
                    Console.BackgroundColor = ConsoleColor.DarkBlue;

                    Console.WriteLine("Classificador processador aguardando...");
                    Console.ResetColor();
                    Console.ReadLine();
                }
        }
Example #7
0
 public comum_dto.PerfilAccessToken Parse(string json)
 {
     return(DeserializadorHelper.Deserializar <comum_dto.PerfilAccessToken>(json));
 }
Example #8
0
        static void Main(string[] args)
        {
            var serviceProvider = new ServiceCollection()
                                  .AddSingleton <EnfileiradorClient>()
                                  .AddTransient <TriadorService>()
                                  .AddTransient <TriadorService <twitterdto.eventos.EventoReacao> >()
                                  .AddScoped(typeof(coreinterfaces.triador.IRegistradorEventoTriagem <twitterdto.eventos.EventoReacao>), typeof(reacaotriador.Registrador))
                                  .AddScoped(typeof(coreinterfaces.IRegistradorEventosConsultas <twitterdto.eventos.EventoReacao>), typeof(reacaotriador.Registrador))
                                  .AddScoped(typeof(coreinterfaces.triador.IAvaliadorDeEvento <twitterdto.eventos.EventoReacao>), typeof(reacaotriador.Avaliador))
                                  .AddScoped(typeof(coreinterfaces.triador.IValidadorDeEvento <twitterdto.eventos.EventoReacao>), typeof(reacaotriador.Validador))
                                  .AddScoped(typeof(coreinterfaces.triador.IIdentificadorUsuario <twitterdto.eventos.EventoReacao>), typeof(reacaotriador.IdentificadorUsuario))
                                  .AddScoped(typeof(coreinterfaces.triador.ITriador <twitterdto.eventos.EventoReacao>), typeof(reacaotriador.Triador))
                                  .AddTransient <PerfilClient>()
                                  .AddTransient <registrador.Client>()
                                  .BuildServiceProvider();

            var triadorTwitterService = serviceProvider.GetService <TriadorService>();

            var enfileiradorClient = serviceProvider.GetService <EnfileiradorClient>();

            var filaConfig = enfileiradorClient.TriadorTwitter();

            var factory = new ConnectionFactory()
            {
                HostName = filaConfig.HostName
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    var filaDeclarada = channel.QueueDeclare(queue: filaConfig.Nome,
                                                             durable: filaConfig.Durable,
                                                             exclusive: filaConfig.Exclusive,
                                                             autoDelete: filaConfig.AutoDelete,
                                                             arguments: null);

                    var consumer = new EventingBasicConsumer(channel);

                    channel.BasicConsume(queue: filaConfig.Nome,
                                         autoAck: filaConfig.AutoAck,
                                         consumer: consumer);

                    consumer.Received += (model, ea) =>
                    {
                        try
                        {
                            var json = Encoding.UTF8.GetString(ea.Body.ToArray());

                            var envelope = DeserializadorHelper.Deserializar <comum_dto.EnvelopeEvento <twitterdto.eventos.Evento> >(json);

                            Console.WriteLine("--------------------------------------------");
                            Console.WriteLine("Empresa: {0}", envelope.EmpresaId);
                            Console.WriteLine("DataEvento: {0}", envelope.DataEvento);
                            Console.WriteLine("Data: {0}", DateTimeHelper.Now());

                            triadorTwitterService.ProcessarEnvelope(envelope);

                            Console.WriteLine("Processou");

                            if (!filaConfig.AutoAck)
                            {
                                channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                            }
                        }
                        catch (EventoInvalidoException eventoInvalidoException)
                        {
                            //##TODO logar
                            Console.WriteLine("*************************************************************");
                            Console.WriteLine("Evento inválido");
                            Console.WriteLine(DateTimeHelper.Now());
                            Console.WriteLine(Encoding.UTF8.GetString(ea.Body.ToArray()));
                            Console.WriteLine("*************************************************************");
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("*************************************************************");
                            Console.WriteLine("Erro");
                            Console.WriteLine(ex.Message);
                            Console.WriteLine("*************************************************************");
                        }
                    };

                    Console.ForegroundColor = ConsoleColor.Black;
                    Console.BackgroundColor = ConsoleColor.DarkGreen;

                    Console.WriteLine("*************************************************");
                    Console.WriteLine($"Triador Twitter aguardando - {DateTimeHelper.Now()}");
                    Console.WriteLine("*************************************************");
                    Console.WriteLine("");
                    Console.ResetColor();

                    Console.ReadLine();
                }
        }
Example #9
0
        static void Main(string[] args)
        {
            Configuracoes();

            var enfileiradorClient = new EnfileiradorClient();

            var servico = serviceProvider.GetService <services.Servico>();

            var filaConfig = enfileiradorClient.Avatar();

            var factory = new ConnectionFactory()
            {
                HostName = filaConfig.HostName
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    var filaDeclarada = channel.QueueDeclare(queue: filaConfig.Nome,
                                                             durable: filaConfig.Durable,
                                                             exclusive: filaConfig.Exclusive,
                                                             autoDelete: filaConfig.AutoDelete,
                                                             arguments: null);

                    var consumer = new EventingBasicConsumer(channel);

                    channel.BasicConsume(queue: filaConfig.Nome,
                                         autoAck: filaConfig.AutoAck,
                                         consumer: consumer);

                    consumer.Received += (model, ea) =>
                    {
                        try
                        {
                            var body = ea.Body;
                            var json = Encoding.UTF8.GetString(body.ToArray());

                            var avatarParaProcessar = DeserializadorHelper.Deserializar <dto.AvatarParaProcessar>(json);

                            Console.WriteLine("--------------------------------------------");
                            Console.WriteLine("UsuarioId: {0}", avatarParaProcessar.UsuarioId);
                            Console.WriteLine("EmpresaId: {0}", avatarParaProcessar.EmpresaId);
                            Console.WriteLine("Imagem: {0}", avatarParaProcessar.Avatar.Imagem);
                            Console.WriteLine("Caminho: {0}", avatarParaProcessar.Caminho);
                            Console.WriteLine("Data: {0}", DateTimeHelper.Now());

                            servico.Processar(avatarParaProcessar);

                            Console.WriteLine("Processou");

                            if (!filaConfig.AutoAck)
                            {
                                channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                            }
                        }
                        catch (Exception ex)
                        {
                            //channel.BasicNack(ea.DeliveryTag, false, true);

                            Console.WriteLine("*************************************************************");
                            Console.WriteLine("Erro");
                            Console.WriteLine(ex.Message);
                            Console.WriteLine("*************************************************************");
                        }
                    };

                    var foregroundColor = Console.ForegroundColor;
                    var backgroundColor = Console.BackgroundColor;

                    Console.ForegroundColor = ConsoleColor.Black;
                    Console.BackgroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("------------------------------------------");
                    Console.WriteLine($"* Avatar aguardando - {DateTimeHelper.Now()}");
                    Console.WriteLine("------------------------------------------");
                    Console.WriteLine("");

                    Console.ForegroundColor = foregroundColor;
                    Console.BackgroundColor = backgroundColor;

                    Console.ReadLine();
                }
        }