Exemple #1
0
        public void GetInstanceLogTest()
        {
            ILog log = VehicleTrackingLog.GetInstance();

            Assert.IsNotNull(log);

            ILog newLog = VehicleTrackingLog.GetInstance();

            Assert.AreEqual(log, newLog);
        }
Exemple #2
0
        public void LoadLogs()
        {
            this.log = VehicleTrackingLog.GetInstance();
            List <LogEvent> logs = this.log.FindEvents(le => true);

            foreach (var actualLog in logs)
            {
                ListViewItem lstViewItem = new ListViewItem(
                    new[] { actualLog.Type,
                            actualLog.Date.ToString(),
                            actualLog.User.UserName,
                            actualLog.Content });
                lstViewLogs.Items.Add(lstViewItem);
            }
        }
Exemple #3
0
        public UserLoggedDTO LogIn(LoginDTO loginUser)
        {
            UserLoggedDTO userLoggedDTO = new UserLoggedDTO();

            bool userLoggedIn = false;

            foreach (UserDTO user in TokenContainer.GetContext().LoggedUsers.Values)
            {
                if (user.UserName.Equals(loginUser.UserName))
                {
                    KeyValuePair <Guid, UserDTO> valuePair = TokenContainer.GetContext().LoggedUsers.FirstOrDefault(u => u.Value.Equals(user));
                    UserDTO userDTO = valuePair.Value;
                    userLoggedDTO.FullName = userDTO.Name + " " + userDTO.LastName;
                    userLoggedDTO.Role     = userDTO.Role;
                    userLoggedDTO.Token    = valuePair.Key;
                    userLoggedIn           = true;

                    LogEvent log = new LoginEvent(user);
                    VehicleTrackingLog.GetInstance().WriteEvent(log);
                }
            }

            if (!userLoggedIn)
            {
                UserDTO userDTO = this.userDAO.LogIn(loginUser);

                if (userDTO == null)
                {
                    throw new UserOrPasswordNotFoundException("El nombre de usuario o password no son correctos");
                }
                else
                {
                    Guid token = Guid.NewGuid();
                    TokenContainer.GetContext().LoggedUsers.Add(token, userDTO);
                    userLoggedDTO.Token    = token;
                    userLoggedDTO.FullName = userDTO.Name + " " + userDTO.LastName;
                    userLoggedDTO.Role     = userDTO.Role;

                    LogEvent log = new LoginEvent(userDTO);
                    VehicleTrackingLog.GetInstance().WriteEvent(log);
                }
            }

            return(userLoggedDTO);
        }
Exemple #4
0
        private void LoadVehiclesImportsBtns()
        {
            int count = 0;

            foreach (var item in this.importerService.AllOfType <IVehicleImportOffline>())
            {
                Button button = CreateButton();
                button.Name     = item.Name;
                button.Text     = item.Name;
                button.Location = count == 0 ? new System.Drawing.Point(436, 178) : new System.Drawing.Point(436, 215);
                count++;

                button.Click += (sender, e) =>
                {
                    try
                    {
                        var vehicles         = item.ImportVehicles();
                        var importedVehicles = 0;
                        foreach (var vehicle in vehicles)
                        {
                            vehicleService.AddVehicle(vehicle);
                            importedVehicles++;

                            UserDTO user = new UserDTO();
                            user.UserName = this.userLogged.FullName;
                            LogEvent log = new VehicleImportEvent(user, vehicle);
                            VehicleTrackingLog.GetInstance().WriteEvent(log);
                            this.logs.LoadLogs();
                        }
                        MessageBox.Show("Se han importado " + importedVehicles + " vehículos");
                        this.init();
                    }
                    catch (VehicleNullAttributesException)
                    {
                        MessageBox.Show(
                            "Los vehiculos que se intentan importar no tienen todos los datos",
                            "Error",
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    } catch (VehicleVinDuplicatedException)
                    {
                        MessageBox.Show(
                            "Se encontraron vehículos ya registrados",
                            "Error",
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    catch (JsonReaderException)
                    {
                        MessageBox.Show(
                            "El archivo no tiene un formato de json correcto",
                            "Error",
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    catch (InvalidOperationException)
                    {
                        MessageBox.Show(
                            "El archivo no tiene un formato de xml correcto",
                            "Error",
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    catch (ArgumentException)
                    {
                        // No se hace nada, ya que se cierra el importador de archivos
                    }
                };
                this.Controls.Add(button);
            }
        }