Esempio n. 1
0
 public ProfileCommandHandler(IDomainRepository domainRepository, IDateTimeProvider dateTimeProvider, IUserService userService, IPlaceFinder placeFinder, IElevationService elevationService)
 {
     _domainRepository = domainRepository;
     _dateTimeProvider = dateTimeProvider;
     _userService      = userService;
     _placeFinder      = placeFinder;
     _elevationService = elevationService;
 }
Esempio n. 2
0
        private ProfilePlace[] CreateProfilePlaces(Guid userId, Track track, IPlaceFinder placeFinder)
        {
            var profilePlaces = new List <ProfilePlace>();

            var places = placeFinder.Find(track.Points, userId);

            foreach (var place in places)
            {
                var placePoints = FindPlacePoints(track.Points, place);

                foreach (var placePoint in placePoints)
                {
                    profilePlaces.Add(new ProfilePlace(place, placePoint, true, false));
                }
            }

            profilePlaces.Sort((x, y) => { return(x.Point.Distance.CompareTo(y.Point.Distance)); });

            ProfilePlace startProfilePlace  = null;
            ProfilePlace finishProfilePlace = null;

            var startPlace = placeFinder.FindClosest(track.FirstPoint, userId);

            if (startPlace != null)
            {
                profilePlaces.RemoveAll(pp => pp.Place.Id == startPlace.Id && pp.Point.Distance < 100);
                startProfilePlace = new ProfilePlace(startPlace, track.FirstPoint, true, true);
            }
            else
            {
                startProfilePlace = new ProfilePlace(new Place(Guid.NewGuid(), userId, "Start", "Local", track.FirstPoint, GeoPolygon.CreateRect(track.FirstPoint, 0.05)), track.FirstPoint, true, true);
            }


            var finishPlace = placeFinder.FindClosest(track.LastPoint, userId);

            if (finishPlace != null)
            {
                profilePlaces.RemoveAll(pp => pp.Place.Id == finishPlace.Id && pp.Point.Distance > track.Length - 100);
                finishProfilePlace = new ProfilePlace(finishPlace, track.LastPoint, true, true);
            }
            else
            {
                finishProfilePlace = new ProfilePlace(new Place(Guid.NewGuid(), userId, "Finish", "Local", track.LastPoint, GeoPolygon.CreateRect(track.LastPoint, 0.05)), track.LastPoint, true, true);
            }

            //var startProfilePlace = profilePlaces.FirstOrDefault(place => place.Point.Distance < 100);

            //if (startProfilePlace != null)
            //{
            //    startProfilePlace.Point.Distance = 0.0;
            //    startProfilePlace.Split = true; ;
            //}
            //else
            //    profilePlaces.Insert(0, new IProfilePlace(new Place(Guid.NewGuid(), userId, "Start", "Local", track.FirstPoint, GeoPolygon.CreateRect(track.FirstPoint, 0.05)), track.FirstPoint, true, true));

            //var finishPlace = profilePlaces.LastOrDefault(place => place.Point.Distance > (track.Length - 100));

            //if (finishPlace != null)
            //{
            //    finishPlace.Point.Distance = track.Length;
            //    finishPlace.Split = true;
            //}
            //else
            //    profilePlaces.Add(new IProfilePlace(new Place(Guid.NewGuid(), userId, "Finish", "Local", track.LastPoint, GeoPolygon.CreateRect(track.LastPoint, 0.05)), track.LastPoint, true, true));


            profilePlaces.Insert(0, startProfilePlace);
            profilePlaces.Add(finishProfilePlace);

            return(profilePlaces.ToArray());
        }
Esempio n. 3
0
        public static IAggregate Create(Guid id, User user, Guid chartId, string name, Track track, IDateTimeProvider dateTimeProvider, IPlaceFinder placeService, IElevationService elevationService)
        {
            if (id == Guid.Empty)
            {
                throw new ArgumentException("id  can't be empty", "id");
            }

            if (user == null)
            {
                throw new ArgumentException("user can't be empty", "user");
            }

            if (track.Id == Guid.Empty)
            {
                throw new ArgumentException("track.Id can't be empty", "track.Id");
            }


            return(new ProfileAggregate(id, user, chartId, name, track, dateTimeProvider, placeService, elevationService));
        }
Esempio n. 4
0
        public ProfileAggregate(Guid id, User user, Guid chartId, string name, Track track, IDateTimeProvider datetime, IPlaceFinder placeFinder, IElevationService elevationService)
            : this()
        {
            if (!track.HasElevation())
            {
                elevationService.ImportElevationTo(track);
            }

            var profilePlaces = CreateProfilePlaces(user.Id, track, placeFinder);
            var result        = CreateResult(user, track, profilePlaces);
            var legs          = CreateLegs(track, profilePlaces);

            var data = new TrackAnalyzer().Analyze(track);

            RaiseEvent(new ProfileCreated(id, user.Id, chartId, name, datetime.Now, track, data.Ascending, data.Descending, data.HighestPoint, data.LowestPoint, data.Climbs, profilePlaces, legs, result));
        }
Esempio n. 5
0
        private CommandDispatcher CreateCommandDispatcher(IDomainRepository domainRepository, IEventBus eventBus, IDateTimeProvider dateTimeProvider, IUserService userService, IUserLevelService levelService, IPlaceFinder placeFinder, IElevationService elevationService, IEnumerable <Action <ICommand> > preExecutionPipe, IEnumerable <Action <object> > postExecutionPipe)
        {
            var commandDispatcher = new CommandDispatcher(domainRepository, eventBus, preExecutionPipe, postExecutionPipe);

            var userCommandHandler = new UserCommandHandler(domainRepository, dateTimeProvider, levelService);

            commandDispatcher.RegisterHandler <CreateUser>(userCommandHandler);
            commandDispatcher.RegisterHandler <RegisterUserExperience>(userCommandHandler);
            commandDispatcher.RegisterHandler <UpdateUserSettings>(userCommandHandler);
            commandDispatcher.RegisterHandler <FollowUser>(userCommandHandler);
            commandDispatcher.RegisterHandler <UnfollowUser>(userCommandHandler);
            commandDispatcher.RegisterHandler <ClearFollowingUsers>(userCommandHandler);

            var profileCommandHandler = new ProfileCommandHandler(domainRepository, dateTimeProvider, userService, placeFinder, elevationService);

            commandDispatcher.RegisterHandler <CreateProfile>(profileCommandHandler);
            commandDispatcher.RegisterHandler <ChangeChart>(profileCommandHandler);
            commandDispatcher.RegisterHandler <RegisterProfileView>(profileCommandHandler);
            commandDispatcher.RegisterHandler <GiveKudos>(profileCommandHandler);
            commandDispatcher.RegisterHandler <DeleteProfile>(profileCommandHandler);

            return(commandDispatcher);
        }
Esempio n. 6
0
        public DomainEntry(IDomainRepository domainRepository, IEventBus eventBus, IDateTimeProvider dateTimeProvider, IUserService userService, IUserLevelService levelService, IPlaceFinder placeFinder, IElevationService elevationService, IEnumerable <Action <ICommand> > preExecutionPipe = null, IEnumerable <Action <object> > postExecutionPipe = null)
        {
            preExecutionPipe  = preExecutionPipe ?? Enumerable.Empty <Action <ICommand> >();
            postExecutionPipe = CreatePostExecutionPipe(postExecutionPipe);

            _commandDispatcher = CreateCommandDispatcher(domainRepository, eventBus, dateTimeProvider, userService, levelService, placeFinder, elevationService, preExecutionPipe, postExecutionPipe);
            _eventDispatcher   = new EventDispatcher(domainRepository, eventBus);
        }