예제 #1
0
        public override async Task <Command> Edit(Command command)
        {
            Command cmd = new Command(command);

            try
            {
                var dto = await SerializerAsync.DeserializeJson <TipoEntradaDto>(command.Json);

                var tipoEntrada = await MyRepository.GetById(cmd.EntityId);

                if (tipoEntrada != null)
                {
                    tipoEntrada.Descricao = dto.Description;
                    cmd.Cmd  = ServerCommands.LogResultOk;
                    cmd.Json = await SerializerAsync.SerializeJson(true);

                    await MyRepository.Save();
                }
                else
                {
                    cmd.Cmd  = ServerCommands.LogResultDeny;
                    cmd.Json = await SerializerAsync.SerializeJson(false);
                }
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError(e);
            }

            return(cmd);
        }
예제 #2
0
        public async Task <Command> Delete(Command command)
        {
            Command cmd = new Command(command);

            try
            {
                var entity = await MyRepository.GetById(cmd.EntityId);

                if (entity != null)
                {
                    entity.IsActive = false;
                    cmd.Cmd         = ServerCommands.LogResultOk;
                    cmd.Json        = await SerializerAsync.SerializeJson(true);

                    await MyRepository.Save();
                }
                else
                {
                    cmd.Cmd  = ServerCommands.LogResultDeny;
                    cmd.Json = await SerializerAsync.SerializeJson(false);
                }
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError(e);
            }

            return(cmd);
        }
예제 #3
0
        public async Task <ActionResult <IEnumerable <TipoSiglaDto> > > GetAll()
        {
            try
            {
                var myUsername = User.Identity.Name;
                if (ZZApiMain.VerifyUserAuthorize(myUsername))
                {
                    if (ZZApiMain.UsersConnections.TryGetValue(myUsername, out var myConn))
                    {
                        var myId = await myConn.Zz.ApiWriteServer(myUsername, new Command { Tela = Tela, Cmd = ServerCommands.GetAll });

                        var responseCommand = await myConn.Zz.GetApiWaitCommand(myId);

                        if (responseCommand != null && responseCommand.Cmd.Equals(ServerCommands.LogResultOk))
                        {
                            return(await SerializerAsync.DeserializeJsonList <TipoSiglaDto>(responseCommand.Json));
                        }
                    }
                }
                return(NotFound());
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError(e);
                return(NotFound());
            }
        }
예제 #4
0
        public async Task <Command> GetByHumanCode(Command command)
        {
            Command cmd = new Command(command);

            try
            {
                var dto = await SerializerAsync.DeserializeJson <EntityDto>(cmd.Json);

                var entity = await MyRepository.GetByHumanCode(dto.Codigo);

                if (entity != null)
                {
                    cmd.Cmd  = ServerCommands.LogResultOk;
                    cmd.Json = await SerializerAsync.SerializeJson(entity.ConvertDto());
                }
                else
                {
                    cmd.Cmd = ServerCommands.LogResultDeny;
                }
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError(e);
            }

            return(cmd);
        }
예제 #5
0
        public async Task <ActionResult <UserDadosDto> > GetByHumanCode(UserDadosDto dto)
        {
            try
            {
                var myUsername = User.Identity.Name;
                if (ZZApiMain.VerifyUserAuthorize(myUsername))
                {
                    if (ZZApiMain.UsersConnections.TryGetValue(myUsername, out var myConn))
                    {
                        var myId = await myConn.Zz.ApiWriteServer(myUsername, new Command { Cmd = ServerCommands.GetById, EntityId = dto.Id, Tela = Tela, Json = await SerializerAsync.SerializeJson(dto) });

                        var responseCommand = await myConn.Zz.GetApiWaitCommand(myId);

                        if (responseCommand != null && responseCommand.Cmd.Equals(ServerCommands.LogResultOk))
                        {
                            return(await SerializerAsync.DeserializeJson <UserDadosDto>(responseCommand.Json));
                        }
                    }
                }
                return(NotFound());
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError(e);
                return(NotFound());
            }
        }
예제 #6
0
        public static async void ReturnLoginRequest(Object[] server, Object[] local)
        {
            var dataJson = SerializerAsync.DeserializeJson <Command>(server[0].ToString()).Result;

            try
            {
                if (dataJson != null)
                {
                    if (dataJson.Cmd.Equals(ServerCommands.LogResultOk))
                    {
                        var username = await SerializerAsync.DeserializeJson <string>(dataJson.Json);

                        if (UsersConnections.TryGetValue(username, out var conn))
                        {
                            await conn.Zz.WriteServer(new Command { Cmd = ServerCommands.IsUser, Json = await SerializerAsync.SerializeJson(username) });
                        }
                    }
                    else if (dataJson.Cmd.Equals(ServerCommands.LogResultDeny))
                    {
                        var username = await SerializerAsync.DeserializeJson <string>(dataJson.Json);
                        await RemoveUserConnection(username);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
예제 #7
0
        public override async Task <Command> GetAll(Command command)
        {
            Command cmd = new Command(command);

            try
            {
                var entities = await MyRepository.Get(null, null, "Endereco");

                var list = entities.ToList();

                if (list.Any())
                {
                    cmd.Cmd = ServerCommands.LogResultOk;
                    var dtos = list.Select(t => t.ConvertDto()).ToList();
                    cmd.Json = await SerializerAsync.SerializeJsonList(dtos);
                }
                else
                {
                    cmd.Cmd = ServerCommands.LogResultDeny;
                }
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError(e);
            }

            return(cmd);
        }
예제 #8
0
        public static async void ReturnLogoutRequest(Object[] server, Object[] local)
        {
            var dataJson = SerializerAsync.DeserializeJson <Command>(server[0].ToString()).Result;

            try
            {
                if (dataJson != null)
                {
                    if (dataJson.Cmd.Equals(ServerCommands.LogResultOk))
                    {
                        var username = await SerializerAsync.DeserializeJson <string>(dataJson.Json);

                        UsersConnections.Remove(username);
                        ConsoleEx.WriteLine("Usuario removido da lista de autorizados com sucesso");
                    }
                    else if (dataJson.Cmd.Equals(ServerCommands.LogResultDeny))
                    {
                        var username = await SerializerAsync.DeserializeJson <string>(dataJson.Json);

                        UsersConnections.Remove(username);
                        ConsoleEx.WriteLine("Deu merda ao remover o usuario da lista de autorizados");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
예제 #9
0
        public static async Task <Command> GetAllStates(Command command)
        {
            Command cmd = new Command(command);

            try
            {
                using (var context = new ZZContext())
                {
                    var rep      = new Repository <Estado>(context);
                    var entities = await rep.Get();

                    var list = entities.ToList();

                    if (list.Any())
                    {
                        cmd.Cmd = ServerCommands.LogResultOk;
                        var dtos = list.Select(t => t.ConvertDto()).ToList();
                        cmd.Json = await SerializerAsync.SerializeJsonList(dtos);
                    }
                    else
                    {
                        cmd.Cmd = ServerCommands.LogResultDeny;
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError(e);
            }

            return(cmd);
        }
예제 #10
0
        public void ReturnServer(Object[] server, Object[] local)
        {
            var dataJson = SerializerAsync.DeserializeJson <Command>(server[0].ToString()).Result;

            try
            {
                if (dataJson != null)
                {
                    if (!dataJson.Cmd.Equals(ServerCommands.Exit))
                    {
                        if (dataJson.Cmd.Equals(ServerCommands.LogResultOk))
                        {
                            ConsoleEx.WriteLine("Uhulll, consegui logar");
                            _expirationTimer =
                                ZZApiMain.SetTimer(
                                    (LoginResultDto.ExpirationDate - LoginResultDto.CreatedDate).TotalMilliseconds,
                                    ExpirationTokenTimer);
                        }
                        else if (dataJson.Cmd.Equals(ServerCommands.LogResultDeny))
                        {
                            ConsoleEx.WriteLine("Algo deu errado");
                            ZZApiMain.RemoveUserConnection(LoginResultDto.Username);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
예제 #11
0
        public override async Task <Command> Add(Command command)
        {
            Command cmd = new Command(command);

            try
            {
                var dto = await SerializerAsync.DeserializeJson <UserPlantaDto>(command.Json);

                if (!string.IsNullOrEmpty(dto.UserId) && dto.PlantaId > 0)
                {
                    var userPlantas = await MyRepository.Get(t => t.PlantaId == dto.PlantaId &&
                                                             t.UserId.Equals(dto.UserId));

                    var userDbSet = Context.Set <UserAccount>();
                    var user      = await userDbSet.FindAsync(dto.UserId);

                    var plantaRep = new Repository <Planta>(Context);
                    var planta    = await plantaRep.GetById(dto.PlantaId);

                    if (userPlantas != null && !userPlantas.Any() && user != null && planta != null)
                    {
                        var entity = new UserPlanta();
                        entity.UpdateEntity(dto);
                        entity.Codigo = dto.UserId + dto.PlantaId + DateTime.Now.ToString();
                        entity.Planta = planta;

                        var insertEntity = await MyRepository.Insert(entity);

                        if (insertEntity != null)
                        {
                            cmd.Cmd  = ServerCommands.LogResultOk;
                            cmd.Json = await SerializerAsync.SerializeJson(true);

                            await MyRepository.Save();

                            cmd.EntityId = entity.Id;
                        }
                        else
                        {
                            cmd.Cmd = ServerCommands.RepeatedHumanCode;
                            ConsoleEx.WriteLine(ServerCommands.RepeatedHumanCode);
                        }
                    }
                    else
                    {
                        cmd.Cmd = ServerCommands.LogResultDeny;
                    }
                }
                else
                {
                    cmd.Cmd = ServerCommands.LogResultDeny;
                }
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError(e);
            }

            return(cmd);
        }
예제 #12
0
 private void ExpirationTokenTimer(Object source, ElapsedEventArgs e)
 {
     Zz.WriteServer(new Command {
         Cmd = ServerCommands.Logout, Json = SerializerAsync.SerializeJson("Token expired").Result
     });
     ZZApiMain.RemoveUserConnection(LoginResultDto.Username);
 }
예제 #13
0
        public override async Task <Command> Add(Command command)
        {
            Command cmd = new Command(command);

            try
            {
                var dto = await SerializerAsync.DeserializeJson <ServicoDto>(command.Json);

                var servicos = await MyRepository.Get(t => t.Codigo.Equals(dto.Codigo));

                if (servicos != null && !servicos.Any())
                {
                    var unidadeMedidaRep = new Repository <UnidadeMedida>(Context);
                    var unidadeMedida    = await unidadeMedidaRep.GetById(dto.UnidadeMedidaId);

                    var tipoServicoRep = new Repository <TipoServico>(Context);
                    var tipoServico    = await tipoServicoRep.GetById(dto.TipoServicoId);

                    var centroCustoRep = new Repository <CentroCustoSintetico>(Context);
                    var centroCusto    = await centroCustoRep.GetById(dto.CentroCustoId);

                    if (unidadeMedida != null && tipoServico != null && centroCusto != null)
                    {
                        var entity = new Servico();
                        entity.UpdateEntity(dto);
                        entity.UnidadeMedida = unidadeMedida;
                        entity.TipoServico   = tipoServico;
                        entity.CentroCusto   = centroCusto;

                        var insertEntity = await MyRepository.Insert(entity);

                        if (insertEntity != null)
                        {
                            cmd.Cmd  = ServerCommands.LogResultOk;
                            cmd.Json = await SerializerAsync.SerializeJson(true);

                            await MyRepository.Save();

                            cmd.EntityId = entity.Id;
                        }
                        else
                        {
                            cmd.Cmd = ServerCommands.RepeatedHumanCode;
                            ConsoleEx.WriteLine(ServerCommands.RepeatedHumanCode);
                        }
                    }
                }
                else
                {
                    cmd.Cmd = ServerCommands.LogResultDeny;
                }
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError(e);
            }

            return(cmd);
        }
예제 #14
0
        public static async Task <Command> GetAddress(Command command)
        {
            Command cmd = new Command(command);

            try
            {
                using (var context = new ZZContext())
                {
                    var dto = await SerializerAsync.DeserializeJson <EnderecoDto>(cmd.Json);

                    var rep       = new Repository <Endereco>(context);
                    var enderecos = await rep.Get(e => e.Logradouro.Equals(dto.Logradouro) && e.Numero == dto.Numero);

                    var endList = enderecos.ToList();
                    if (endList.Any())
                    {
                        cmd.Cmd = ServerCommands.LogResultOk;
                        var dtosEnd = endList.Select(e => e.ConvertDto()).ToList();
                        cmd.Json = await SerializerAsync.SerializeJsonList(dtosEnd);
                    }
                    else
                    {
                        var addressList = await SearchAddressAsync(dto.Estado, dto.Cidade, dto.Logradouro,
                                                                   CancellationToken.None);

                        var viaCepResults = addressList.ToList();
                        if (viaCepResults.Any())
                        {
                            cmd.Cmd = ServerCommands.LogResultOk;
                            var dtos = viaCepResults.Select(d => new EnderecoDto
                            {
                                Cep         = d.ZipCode,
                                Bairro      = d.Neighborhood,
                                Cidade      = d.City,
                                Estado      = d.StateInitials,
                                Logradouro  = d.Street,
                                Complemento = d.Complement,
                                Ibge        = d.IBGECode,
                                GIACode     = d.GIACode,
                                Numero      = dto.Numero,
                                Codigo      = d.IBGECode.ToString() + d.GIACode.ToString() + d.ZipCode + dto.Numero.ToString()
                            });
                            cmd.Json = await SerializerAsync.SerializeJsonList(dtos.ToList());
                        }
                        else
                        {
                            cmd.Cmd = ServerCommands.LogResultDeny;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError(e);
            }

            return(cmd);
        }
예제 #15
0
        public static async Task <Command> GetAddressByZipCode(Command command)
        {
            Command cmd = new Command(command);

            try
            {
                using (var context = new ZZContext())
                {
                    var dto = await SerializerAsync.DeserializeJson <EnderecoDto>(cmd.Json);

                    var rep       = new Repository <Endereco>(context);
                    var enderecos = await rep.Get(e => e.Cep.Equals(dto.Cep) && e.Numero == dto.Numero);


                    if (enderecos != null && enderecos.Any())
                    {
                        var endList = enderecos.FirstOrDefault();
                        cmd.Cmd = ServerCommands.LogResultOk;
                        var dtosEnd = endList.ConvertDto();
                        cmd.Json = await SerializerAsync.SerializeJson(dtosEnd);
                    }
                    else
                    {
                        var address = await SearchAddressAsync(dto.Cep, CancellationToken.None);

                        if (address != null)
                        {
                            cmd.Cmd = ServerCommands.LogResultOk;
                            var entity = new EnderecoDto
                            {
                                Cep         = address.ZipCode,
                                Bairro      = address.Neighborhood,
                                Cidade      = address.City,
                                Estado      = address.StateInitials,
                                Logradouro  = address.Street,
                                Complemento = address.Complement,
                                Ibge        = address.IBGECode,
                                GIACode     = address.GIACode,
                                Numero      = dto.Numero,
                                Codigo      = address.IBGECode.ToString() + address.GIACode.ToString() + address.ZipCode + dto.Numero.ToString()
                            };
                            cmd.Json = await SerializerAsync.SerializeJson(entity);
                        }
                        else
                        {
                            cmd.Cmd = ServerCommands.LogResultDeny;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError(e);
            }

            return(cmd);
        }
예제 #16
0
        public static async Task <Command> UpdateEstados(Command command)
        {
            Command cmd = new Command(command);

            try
            {
                using (var context = new ZZContext())
                {
                    var rep      = new Repository <Estado>(context);
                    var entities = await rep.Get();

                    var list     = entities.ToList();
                    var ibgeList = await SearchEstadoAsync();

                    if (list.Any() && ibgeList.Any())
                    {
                        foreach (var estado in ibgeList)
                        {
                            if (list.Exists(e => e.Ibge == estado.Ibge))
                            {
                                var est = list.Find(e => e.Ibge == estado.Ibge);
                                est.Ibge      = estado.Ibge;
                                est.Descricao = estado.Descricao;
                                est.Sigla     = estado.Sigla;
                            }
                        }
                        await rep.InsertList(list);

                        await rep.Save();

                        cmd.Cmd = ServerCommands.LogResultOk;
                        var dtos = list.Select(t => t.ConvertDto()).ToList();
                        cmd.Json = await SerializerAsync.SerializeJsonList(dtos);
                    }
                    else if (ibgeList.Any())
                    {
                        await rep.InsertList(ibgeList);

                        await rep.Save();

                        cmd.Cmd = ServerCommands.LogResultOk;
                        var dtos = ibgeList.Select(t => t.ConvertDto()).ToList();
                        cmd.Json = await SerializerAsync.SerializeJsonList(dtos);
                    }
                    else
                    {
                        cmd.Cmd = ServerCommands.LogResultDeny;
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError(e);
            }

            return(cmd);
        }
예제 #17
0
 public static async Task RemoveUserConnection(string username)
 {
     var del = new DelegateAction {
         act = ReturnLogoutRequest
     };
     var cmd = new Command {
         Cmd = ServerCommands.RemoveClientAuthorized, Json = await SerializerAsync.SerializeJson(username)
     };
     await Zz.WriteServer(del, cmd);
 }
예제 #18
0
        public async Task <string> ApiWriteServer(string username, Command cmd)
        {
            cmd.Id = username + await GetCommandId();

            cmd.IsWait = true;

            var cmdSend = await SerializerAsync.SerializeJson(cmd);

            _bufferWrite.Enqueue(cmdSend);
            return(cmd.Id);
        }
예제 #19
0
        /// <summary>
        /// Envia para o client um Command com id, comando e json
        /// </summary>
        /// <param name="cmd">Command que contem id, comando e json</param>
        /// <returns></returns>
        public async Task WriteServer(Command cmd)
        {
            if (string.IsNullOrEmpty(cmd.Id))
            {
                cmd.Id = ServerCommands.BroadCastId;
            }

            var cmdSend = await SerializerAsync.SerializeJson(cmd);

            _bufferWrite.Enqueue(cmdSend);
        }
예제 #20
0
        public override async Task <Command> Edit(Command command)
        {
            Command cmd = new Command(command);

            try
            {
                var dto = await SerializerAsync.DeserializeJson <ServicoDto>(command.Json);

                var servico = await MyRepository.GetById(cmd.EntityId);

                if (servico != null)
                {
                    servico.UpdateEntity(dto);
                    var unidadeMedidaRep = new Repository <UnidadeMedida>(Context);
                    var unidadeMedida    = await unidadeMedidaRep.GetById(dto.UnidadeMedidaId);

                    if (unidadeMedida != null)
                    {
                        servico.UnidadeMedida = unidadeMedida;
                    }
                    var tipoServicoRep = new Repository <TipoServico>(Context);
                    var tipoServico    = await tipoServicoRep.GetById(dto.TipoServicoId);

                    if (tipoServico != null)
                    {
                        servico.TipoServico = tipoServico;
                    }

                    var centroCustoRep = new Repository <CentroCustoSintetico>(Context);
                    var centroCusto    = await centroCustoRep.GetById(dto.CentroCustoId);

                    if (centroCusto != null)
                    {
                        servico.CentroCusto = centroCusto;
                    }

                    cmd.Cmd  = ServerCommands.LogResultOk;
                    cmd.Json = await SerializerAsync.SerializeJson(true);

                    await MyRepository.Save();
                }
                else
                {
                    cmd.Cmd  = ServerCommands.LogResultDeny;
                    cmd.Json = await SerializerAsync.SerializeJson(false);
                }
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError(e);
            }

            return(cmd);
        }
예제 #21
0
        public override async Task <Command> Add(Command command)
        {
            Command cmd = new Command(command);

            try
            {
                var dto = await SerializerAsync.DeserializeJson <TabelaDto>(command.Json);

                var tabelas = await MyRepository.Get(t => t.ServicoId == dto.ServicoId && t.Descricao.Equals(dto.Description));

                if (tabelas != null && !tabelas.Any())
                {
                    var servicoRep = new Repository <Servico>(Context);
                    var servico    = await servicoRep.GetById(dto.ServicoId);

                    if (servico != null)
                    {
                        var entity = new TabelaCusto();
                        entity.UpdateEntity(dto);
                        entity.DataTabela = DateTime.Now;
                        entity.Servico    = servico;

                        var insertEntity = await MyRepository.Insert(entity);

                        if (insertEntity != null)
                        {
                            cmd.Cmd  = ServerCommands.LogResultOk;
                            cmd.Json = await SerializerAsync.SerializeJson(true);

                            await MyRepository.Save();

                            cmd.EntityId = entity.Id;
                        }
                        else
                        {
                            cmd.Cmd = ServerCommands.RepeatedHumanCode;
                            ConsoleEx.WriteLine(ServerCommands.RepeatedHumanCode);
                        }
                    }
                }
                else
                {
                    cmd.Cmd = ServerCommands.LogResultDeny;
                }
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError(e);
            }

            return(cmd);
        }
예제 #22
0
        public static async Task AddUserConnection(LoginResultDto loginResult)
        {
            var del = new DelegateAction {
                act = ReturnLoginRequest
            };
            var cmd = new Command {
                Cmd = ServerCommands.AddClientAuthorized, Json = await SerializerAsync.SerializeJson(loginResult.Username)
            };
            await Zz.WriteServer(del, cmd);

            var conn = new ConnectionManager(loginResult);

            UsersConnections.Add(loginResult.Username, conn);
        }
예제 #23
0
        public async Task WriteServer(string id, long playerId, string command, string json)
        {
            if (string.IsNullOrEmpty(id))
            {
                id = ServerCommands.BroadCastId;
            }

            var cmd = new Command {
                Id = id, EntityId = playerId, Cmd = command, Json = json
            };

            var cmdSend = await SerializerAsync.SerializeJson(cmd);

            _bufferWrite.Enqueue(cmdSend);
        }
예제 #24
0
        public async Task WriteServer(DelegateAction del, Command cmd)
        {
            if (string.IsNullOrEmpty(cmd.Id))
            {
                cmd.Id = await GetCommandId();
            }
            var cmdSend = await SerializerAsync.SerializeJson(cmd);

            if (!_srvsCmdsBuffer.ContainsKey(cmd.Id))
            {
                _srvsCmdsBuffer.Add(cmd.Id, del);
            }

            _bufferWrite.Enqueue(cmdSend);
        }
예제 #25
0
        /// <summary>
        /// Searches the asynchronous.
        /// </summary>
        /// <param name="zipCode">The zip code.</param>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public static async Task <ViaCEPResult> SearchAddressAsync(String zipCode, CancellationToken token)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(BaseUrl);
                var response = await client.GetAsync($"/ws/{zipCode}/json", token).ConfigureAwait(false);

                response.EnsureSuccessStatusCode();
                var jsonContent = await response.Content.ReadAsStringAsync();

                var json = await SerializerAsync.DeserializeJson <ViaCEPResult>(jsonContent);

                json.ZipCode = new String(json.ZipCode.Where(Char.IsDigit).ToArray());
                return(json);
            }
        }
예제 #26
0
        public override async Task <Command> Edit(Command command)
        {
            Command cmd = new Command(command);

            try
            {
                cmd.Cmd  = ServerCommands.LogResultDeny;
                cmd.Json = await SerializerAsync.SerializeJson(false);
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError(e);
            }

            return(cmd);
        }
예제 #27
0
        public void ProcessLogin(Object[] server, Object[] local)
        {
            var dataJson = SerializerAsync.DeserializeJson <Command>(server[0].ToString()).Result;

            try
            {
                if (dataJson != null)
                {
                    if (!dataJson.Cmd.Equals(ServerCommands.Exit))
                    {
                        if (dataJson.Cmd.Equals(ServerCommands.IsController))
                        {
                            ConsoleEx.WriteLine("Oi Controller fofo *3* ");
                            _client = new ControllerClient();
                            MyId    = ServerCommands.IsController;
                            _client.Login(this, connection);
                        }
                        else if (dataJson.Cmd.Equals(ServerCommands.IsUser))
                        {
                            if (Server.VerifyUserAuthorization(
                                    SerializerAsync.DeserializeJson <string>(dataJson.Json).Result, this))
                            {
                                ConsoleEx.WriteLine("Oi Cli fofo *3* ");
                                MyId    = SerializerAsync.DeserializeJson <string>(dataJson.Json).Result;
                                _client = new UserClient();
                                _client.Login(this, connection);
                            }
                            else
                            {
                                ConsoleEx.WriteLine("Cliente não autorizado");
                                connection.WriteServer("", 542, ServerCommands.LogResultDeny, "");
                            }
                        }
                        else
                        {
                            _client.Command(dataJson);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleEx.WriteLine("Erro na criação do client : " + " | " + _client + " | " +
                                    dataJson + " | " + e.Message);
            }
        }
예제 #28
0
        /// <summary>
        /// Converte um array de object recebido como entrada de um DelegateAction em Command
        /// </summary>
        /// <param name="s"></param>
        /// <returns><typeparam name="dataJson"></typeparam></returns>
        public static async Task <Command> ObjectToCommand(Object[] s)
        {
            try
            {
                var     data     = s[0].ToString();
                Command dataJson = new Command();

                dataJson = await SerializerAsync.DeserializeJson <Command>(data);

                return(dataJson);
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError(e);
                return(null);
            }
        }
예제 #29
0
        public override async Task Command(Command command)
        {
            try
            {
                if (Manager != null && Connection != null)
                {
                    if (command.Cmd != null)
                    {
                        if (command.Cmd.Equals(ServerCommands.AddClientAuthorized))
                        {
                            if (Manager.Server.AddAuthorizedUser(
                                    await SerializerAsync.DeserializeJson <string>(command.Json)))
                            {
                                command.Cmd = ServerCommands.LogResultOk;
                            }
                            else
                            {
                                command.Cmd = ServerCommands.LogResultDeny;
                            }

                            await Connection.WriteServer(command);
                        }
                        else if (command.Cmd.Equals(ServerCommands.RemoveClientAuthorized))
                        {
                            if (Manager.Server.RemoveAuthorizedUser(
                                    await SerializerAsync.DeserializeJson <string>(command.Json)))
                            {
                                command.Cmd = ServerCommands.LogResultOk;
                            }
                            else
                            {
                                command.Cmd = ServerCommands.LogResultDeny;
                            }

                            await Connection.WriteServer(command);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError("Erro ao receber command do controller ", e);
                throw;
            }
        }
예제 #30
0
        public override async Task <Command> Add(Command command)
        {
            Command cmd = new Command(command);

            try
            {
                var dto = await SerializerAsync.DeserializeJson <TipoEntradaDto>(command.Json);

                var tipos = await MyRepository.Get(t => t.Descricao.Equals(dto.Description));

                if (tipos != null && !tipos.Any())
                {
                    var entity = new TipoEntrada();
                    entity.UpdateEntity(dto);
                    var insertEntity = await MyRepository.Insert(entity);

                    if (insertEntity != null)
                    {
                        cmd.Cmd  = ServerCommands.LogResultOk;
                        cmd.Json = await SerializerAsync.SerializeJson(true);

                        await MyRepository.Save();

                        cmd.EntityId = entity.Id;
                    }
                    else
                    {
                        cmd.Cmd = ServerCommands.RepeatedHumanCode;
                        ConsoleEx.WriteLine(ServerCommands.RepeatedHumanCode);
                    }
                }
                else
                {
                    cmd.Cmd = ServerCommands.LogResultDeny;
                }
            }
            catch (Exception e)
            {
                ConsoleEx.WriteError(e);
            }

            return(cmd);
        }