Exemple #1
0
        protected override void OnStart(string[] args)
        {
            ImprimeCabecalhoLog();

            // código do serviço começa aqui!
            try
            {
                _log.Debug("Inicializando Parametros...");
                _parameters = new Parameters(_log);

                _log.Debug("Inicializando Consumidor...");
                _controllerGatewaySMS = new ControllerGatewayNoticias(_parameters);

                _log.Debug("Inicializando Socket Server...");
                _serverSocket = new SocketServer(_log, _parameters, _controllerGatewaySMS);

                if (!_serverSocket.Start())
                {
                    Stop();
                }
            }
            catch (Exception ex)
            {
                _log.Debug("Exception: " + ex.Message);
            }
        }
Exemple #2
0
        public SocketServer(ILog log, Parameters parameters, ControllerGatewayNoticias controllerGatewaySMS)
        {
            _log                  = log;
            _parameters           = parameters;
            _listSocket           = new List <BufferSocketServer>();
            _controllerGatewaySMS = controllerGatewaySMS;

            _serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        }
Exemple #3
0
        public static string LeTextoNoticia(ILog log, IList <KeyValuePair <string, string> > paramList, ControllerGatewayNoticias controllerGatewaySMS)
        {
            try
            {
                var callbackFunction = paramList.FirstOrDefault(t => t.Key == "callback").Value ?? "";
                var id_noticia       = paramList.FirstOrDefault(t => t.Key == "id_noticia").Value ?? "";

                // Testa se recebeu o id_noticia em branco
                if (id_noticia == "")
                {
                    return(HttpHelper.AddHttpHeaderRequests(false, "Seleção de uma nóticia é obrigatória na leitura.", callbackFunction));
                }

                var lista = controllerGatewaySMS.LetextoNoticia(id_noticia);

                return(HttpHelper.AddHttpHeader(JsonConvert.SerializeObject(lista, Formatting.Indented),
                                                lista.Count));
            }
            catch (Exception ex)
            {
                log.Error("Exceção: " + ex);
                return(HttpHelper.AddHttpHeader("[]", 0));
            }
        }
Exemple #4
0
        public static string ListaAutores(ILog log, IList <KeyValuePair <string, string> > paramList, ControllerGatewayNoticias controllerGatewaySMS)
        {
            try
            {
                var lista = controllerGatewaySMS.ListaAutores();

                return(HttpHelper.AddHttpHeader(JsonConvert.SerializeObject(lista, Formatting.Indented),
                                                lista.Count));
            }
            catch (Exception ex)
            {
                log.Error("Exceção: " + ex);
                return(HttpHelper.AddHttpHeader("[]", 0));
            }
        }
Exemple #5
0
        public static string ListaNoticiasFiltro(ILog log, IList <KeyValuePair <string, string> > paramList, ControllerGatewayNoticias controllerGatewaySMS)
        {
            try
            {
                var callbackFunction = paramList.FirstOrDefault(t => t.Key == "callback").Value ?? "";
                var filtro           = paramList.FirstOrDefault(t => t.Key == "filtro").Value ?? "";

                // Testa se recebeu filtro em branco
                if (filtro == "")
                {
                    return(HttpHelper.AddHttpHeaderRequests(false, "Nenhum dado de filtro foi passado.", callbackFunction));
                }

                var lista = controllerGatewaySMS.ListaNoticiasFiltro(filtro);

                return(HttpHelper.AddHttpHeader(JsonConvert.SerializeObject(lista, Formatting.Indented),
                                                lista.Count));
            }
            catch (Exception ex)
            {
                log.Error("Exceção: " + ex);
                return(HttpHelper.AddHttpHeader("[]", 0));
            }
        }
Exemple #6
0
        public static string ExcluiNoticia(ILog log, IList <KeyValuePair <string, string> > paramList, ControllerGatewayNoticias controllerGatewaySMS)
        {
            var id_noticia       = paramList.FirstOrDefault(t => t.Key == "id_noticia").Value ?? "0";
            var callbackFunction = paramList.FirstOrDefault(t => t.Key == "callback").Value ?? "";

            try
            {
                // Testa se recebeu o id_noticia em branco
                if (id_noticia == "")
                {
                    return(HttpHelper.AddHttpHeaderRequests(false, "Seleção de uma nóticia é obrigatória na exclusão.", callbackFunction));
                }

                if (controllerGatewaySMS.ExecutaComando($"delete from noticias where id_noticia = {id_noticia};"))
                {
                    return(HttpHelper.AddHttpHeaderLista("ServicoNoticias", "[{}]", callbackFunction, true, "Noticia excluída com sucesso"));
                }
                else
                {
                    return(HttpHelper.AddHttpHeaderLista("ServicoMensageria", "[{}]", callbackFunction, false, "Falha no comando de excluir campanha. Tente novamente."));
                }
            }
            catch (Exception ex)
            {
                log.Error("Exceção: " + ex);
                return(HttpHelper.AddHttpHeaderLista("ServicoMensageria", "[{}]", callbackFunction, false, "Falha no comando de excluir campanha."));
            }
        }
Exemple #7
0
        public static string ListaNoticias(ILog log, IList <KeyValuePair <string, string> > paramList, ControllerGatewayNoticias controllerGatewaySMS)
        {
            try
            {
                var filtro = paramList.FirstOrDefault(t => t.Key == "filtro").Value ?? "";

                // Verifica se recebeu o parâmetro filtro neste caso roda o metodo com o filtro
                if (filtro == "")
                {
                    var lista = controllerGatewaySMS.ListaNoticias();

                    return(HttpHelper.AddHttpHeader(JsonConvert.SerializeObject(lista, Formatting.Indented),
                                                    lista.Count));
                }
                else
                {
                    var lista = controllerGatewaySMS.ListaNoticiasFiltro(filtro);

                    return(HttpHelper.AddHttpHeader(JsonConvert.SerializeObject(lista, Formatting.Indented),
                                                    lista.Count));
                }
            }
            catch (Exception ex)
            {
                log.Error("Exceção: " + ex);
                return(HttpHelper.AddHttpHeader("[]", 0));
            }
        }
Exemple #8
0
        public static string CriaNoticia(ILog log, IList <KeyValuePair <string, string> > paramList, ControllerGatewayNoticias controllerGatewaySMS)
        {
            var callbackFunction = paramList.FirstOrDefault(t => t.Key == "callback").Value ?? "";

            try
            {
                var autor  = paramList.FirstOrDefault(t => t.Key == "autor").Value ?? "";
                var titulo = paramList.FirstOrDefault(t => t.Key == "titulo").Value ?? "";
                var texto  = paramList.FirstOrDefault(t => t.Key == "texto").Value ?? "";

                // Testa id do autor em branco não enviado (nome não selecionado)
                if (autor == "")
                {
                    return(HttpHelper.AddHttpHeaderRequests(false, "Nome do autor da notícia é obrigatório.", callbackFunction));
                }

                // Testa título da notícia em branco
                if (titulo == "")
                {
                    return(HttpHelper.AddHttpHeaderRequests(false, "Título da notícia é obrigatório.", callbackFunction));
                }

                // Testa texto da notícia em branco
                if (texto == "")
                {
                    return(HttpHelper.AddHttpHeaderRequests(false, "Texto da notícia é obrigatório.", callbackFunction));
                }

                if (!controllerGatewaySMS.CriaNoticia(titulo, autor, texto))
                {
                    return(HttpHelper.AddHttpHeaderRequests(false, "Falha ao criar a notícia.", callbackFunction));
                }
                return(HttpHelper.AddHttpHeaderRequests(true, "Sucesso na criação da noticia", callbackFunction));
            }
            catch (Exception ex)
            {
                log.Error("Exceção: " + ex);
                return(HttpHelper.AddHttpHeaderRequests(false, "Falha no comando de criar noticia", callbackFunction));
            }
        }
Exemple #9
0
        // Validação do usuário não implementada (qualquer usuário e senha será permitido entrar)
        public static string ValidaUsuario(ILog log, IList <KeyValuePair <string, string> > paramList, ControllerGatewayNoticias controllerGatewaySMS)
        {
            var callbackFunction = paramList.FirstOrDefault(t => t.Key == "callback").Value ?? "";

            try
            {
                return(HttpHelper.AddHttpHeaderRequests(true, "true|0|0", callbackFunction));
            }
            catch (Exception ex)
            {
                log.Error("Exceção: " + ex);
                return(HttpHelper.AddHttpHeaderLista("ServicoMensageria", "[{}]", callbackFunction, false, "Identificação invalida"));
            }
        }