Ejemplo n.º 1
0
        public async Task CreateAsync(OperatorActivity entity)
        {
            try
            {
                var operatorActivityClass = _mapper.Map <OperatorActivityClass>(entity);

                await Collection.InsertOneAsync(operatorActivityClass);
            }
            catch (MongoWriteException ex)
            {
                if (ex.IsUniqueViolation())
                {
                    throw Error.UniqueKey(ex);
                }
                throw Error.GenericDb(ex);
            }
            catch (MongoCommandException ex)
            {
                Debug.WriteLine(ex);
                throw Error.GenericDb(ex);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                throw;
            }
        }
        public async Task <Result> Handle(CreateOperatorActivityCommand request, CancellationToken cancellationToken)
        {
            dynamic jObject         = request.OperatorActivities;
            var     activitiesArray = JArray.Parse(jObject.Activities.ToString()) as JArray;
            var     activities      = _jsonService.ToObject <List <OperatorActivityDto> >(activitiesArray);
            var     result          = Result.Ok();

            try
            {
                foreach (var activityDto in activities)
                {
                    var id               = _identifierProvider.Generate();
                    var version          = _versionProvider.Generate();
                    var operatorActivity = new OperatorActivity(id);
                    _mapper.Map(activityDto, operatorActivity);
                    operatorActivity.Version = version;

                    await _operatorActivityWriteRepository.CreateAsync(operatorActivity);

                    result = Result.Ok(id, operatorActivity.Version);
                }
            }
            catch (Exception)
            {
                result = Result.Fail(CustomFailures.CreateOperatorActivityFailure);
            }

            return(result);
        }
Ejemplo n.º 3
0
        public void ConstructorWithOneParameterShouldSuceed()
        {
            //Act
            var operatorActivity = new OperatorActivity(Guid.NewGuid());

            //Assert
            operatorActivity.Should().NotBeNull();
        }
Ejemplo n.º 4
0
        public void ConstructorWithoutParametersShouldSucceed()
        {
            //Act
            var operatorActivity = new OperatorActivity();

            //Assert
            operatorActivity.Should().NotBeNull();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets aggregate operator activities for the current timespan.
        /// </summary>
        /// <param name="desde"></param>
        /// <param name="hasta"></param>
        /// <param name="distrito"></param>
        /// <param name="planta"></param>
        /// <param name="ids"></param>
        /// <param name="km"></param>
        /// <returns></returns>
        public IEnumerable <OperatorActivity> GetOperatorActivities(DateTime desde, DateTime hasta, Int32 distrito, Int32 planta, List <Int32> ids, Double km)
        {
            OperatorActivity oa = null;

            DetachedCriteria dc = GetDatamartDetachedCriteria().FilterBeginBetween(desde, hasta).CreateAlias("Employee", "ch", JoinType.InnerJoin);

            if (distrito != -1)
            {
                dc.Add(Restrictions.Or(Restrictions.IsNull("ch.Empresa"), Restrictions.Eq("ch.Empresa.Id", distrito)));
            }

            if (planta != -1)
            {
                dc.Add(Restrictions.Or(Restrictions.IsNull("ch.Linea"), Restrictions.Eq("ch.Linea.Id", distrito)));
            }

            if (ids.Count <= SQLParameterLimit)
            {
                dc.Add(Restrictions.In("ch.Id", ids));
            }

            ProjectionList pl = Projections.ProjectionList();

            pl.Add(Projections.Sum <Datamart>(dm => dm.StoppedHours).WithAlias(() => oa.StoppedHours));
            pl.Add(Projections.Sum <Datamart>(dm => dm.MovementHours).WithAlias(() => oa.MovementHours));
            pl.Add(Projections.Sum <Datamart>(dm => dm.InfractionMinutes).WithAlias(() => oa.InfractionsMinutes));
            pl.Add(Projections.Sum <Datamart>(dm => dm.Infractions).WithAlias(() => oa.Infractions));
            IProjection kilometersProjection = Projections.Sum <Datamart>(dm => dm.Kilometers).WithAlias(() => oa.Kilometers);

            pl.Add(kilometersProjection);
            pl.Add(Projections.Max <Datamart>(dm => dm.MaxSpeed).WithAlias(() => oa.MaxSpeed));
            pl.Add(Projections.Group <Datamart>(dm => dm.Employee.Id).WithAlias(() => oa.OperatorId));

            ICriteria crit = GetDatamartCriteria(0, dc, pl, null, typeof(OperatorActivity));

            crit.Add(Restrictions.Ge(kilometersProjection, km));

            IList <OperatorActivity> results = crit.List <OperatorActivity>();

            var empleadoDAO = new EmpleadoDAO();

            foreach (OperatorActivity r in results)
            {
                Empleado empleado = empleadoDAO.FindById(r.OperatorId);
                r.Operator = empleado.Entidad != null ? empleado.Entidad.Descripcion : null;
            }

            foreach (OperatorActivity r in results.Where(filteredResult => filteredResult.Kilometers > 0 && filteredResult.MovementHours > 0))
            {
                r.AverageSpeed = Convert.ToInt32(r.Kilometers / r.MovementHours);
            }

            IEnumerable <OperatorActivity> result = (ids.Count > SQLParameterLimit ? results.Where(r => ids.Contains(r.OperatorId)) : results);

            return(result);
        }
Ejemplo n.º 6
0
 public OperatorActivityVo(OperatorActivity t)
 {
     Operator          = t.Operator;
     VelocidadMaxima   = t.MaxSpeed;
     VelocidadPromedio = t.AverageSpeed;
     Infracciones      = t.Infractions;
     Recorrido         = t.Kilometers;
     HorasActivo       = String.Format("Días:{0} - Horas {1}:{2}:{3}", t.Movement.Days, t.Movement.Hours, t.Movement.Minutes, t.Movement.Seconds);
     HorasDetenido     = String.Format("Días:{0} - Horas {1}:{2}:{3}", t.Stopped.Days, t.Stopped.Hours, t.Stopped.Minutes, t.Stopped.Seconds);
     HorasInfraccion   = String.Format("Días:{0} - Horas {1}:{2}:{3}", t.InfractionsTime.Days, t.InfractionsTime.Hours, t.InfractionsTime.Minutes, t.InfractionsTime.Seconds);
 }
Ejemplo n.º 7
0
        public void SetOperatorNameShouldSucceed()
        {
            //Arrange
            var operatorLogin    = "******";
            var operatorActivity = new OperatorActivity();

            //Act
            operatorActivity.SetOperatorLogin(operatorLogin);

            //Assert
            operatorActivity.OperatorLogin.Should().Be(operatorLogin);
        }
Ejemplo n.º 8
0
        public void SetCreatedShouldSucceed()
        {
            //Arrange
            var created          = DateTime.Now;
            var operatorActivity = new OperatorActivity();

            //Act
            operatorActivity.SetCreated(created);

            //Assert
            operatorActivity.Created.Should().Be(created);
        }
Ejemplo n.º 9
0
        public void SetNameShouldSucceed()
        {
            //Arrange
            var name             = "Step name";
            var operatorActivity = new OperatorActivity();

            //Act
            operatorActivity.SetName(name);

            //Assert
            operatorActivity.Name.Should().Be(name);
        }
Ejemplo n.º 10
0
        public void SetTitleShouldSucceed()
        {
            //Act
            var title            = "Validate licence plate";
            var operatorActivity = new OperatorActivity();

            //Act
            operatorActivity.SetTitle(title);

            //Assert
            operatorActivity.Title.Should().Be(title);
        }
Ejemplo n.º 11
0
        public void SetTypeShouldSucceed()
        {
            //Act
            var blockType        = BlockType.Checklist;
            var operatorActivity = new OperatorActivity();

            //Act
            operatorActivity.SetType(blockType);

            //Assert
            operatorActivity.Type.Should().Be(blockType);
        }
Ejemplo n.º 12
0
        public void SetWorkOrderIdShouldSucceed()
        {
            //Arrange
            var workOrderId      = Guid.NewGuid();
            var operatorActivity = new OperatorActivity();

            //Act
            operatorActivity.SetWorkOrderId(workOrderId);

            //Assert
            operatorActivity.WorkOrderId.Should().Be(workOrderId);
        }
        public async Task CreateShouldSucceed()
        {
            //Arrange
            var id = Guid.NewGuid();
            var operatorActivity = new OperatorActivity(id);

            operatorActivity.SetType(BlockType.Instruction);

            //Act
            await _repository.CreateAsync(operatorActivity);

            //Assert
            var activities = RepositoryHelper.ForOperatorActivity.GetOperatorActivities();

            activities.Should().HaveCount(1);
        }
Ejemplo n.º 14
0
            public static OperatorActivity CreateOperatorActivity(Guid id)
            {
                var config = new MapperConfiguration(cfg =>
                {
                    cfg.AddProfile <DomainToClassProfile>();
                    cfg.AddProfile <ClassToDomainProfile>();
                });
                var mapper           = new Mapper(config);
                var odataProvider    = new Mock <IOperatorActivityOdataProvider>().Object;
                var writeRepository  = new OperatorActivityWriteRepository(new DataContext(new PersistenceConfiguration(RepositoryTestsHelper.ConnectionString)), mapper);
                var readRepository   = new OperatorActivityReadRepository(new DataContext(new PersistenceConfiguration(RepositoryTestsHelper.ConnectionString)), odataProvider, mapper);
                var operatorActivity = new OperatorActivity(id);

                operatorActivity.SetType(BlockType.Instruction);

                writeRepository.CreateAsync(operatorActivity).GetAwaiter().GetResult();

                return(operatorActivity);
            }
Ejemplo n.º 15
0
 public Task UpdateAsync(OperatorActivity entity)
 {
     throw new NotImplementedException();
 }