internal World(ModData modData, Map map, OrderManager orderManager, WorldType type) { Type = type; OrderManager = orderManager; orderGenerator = new UnitOrderGenerator(); Map = map; Timestep = orderManager.LobbyInfo.GlobalSettings.Timestep; SharedRandom = new MersenneTwister(orderManager.LobbyInfo.GlobalSettings.RandomSeed); LocalRandom = new MersenneTwister(); ModelCache = modData.ModelSequenceLoader.CacheModels(map, modData, map.Rules.ModelSequences); var worldActorType = type == WorldType.Editor ? "EditorWorld" : "World"; WorldActor = CreateActor(worldActorType, new TypeDictionary()); ActorMap = WorldActor.Trait <IActorMap>(); ScreenMap = WorldActor.Trait <ScreenMap>(); Selection = WorldActor.Trait <ISelection>(); // Reset mask LongBitSet <PlayerBitMask> .Reset(); // Add players foreach (var cmp in WorldActor.TraitsImplementing <ICreatePlayers>()) { cmp.CreatePlayers(this); } // Set defaults for any unset stances foreach (var p in Players) { if (!p.Spectating) { AllPlayersMask = AllPlayersMask.Union(p.PlayerMask); } foreach (var q in Players) { SetUpPlayerMask(p, q); if (!p.Stances.ContainsKey(q)) { p.Stances[q] = Stance.Neutral; } } } Game.Sound.SoundVolumeModifier = 1.0f; gameInfo = new GameInformation { Mod = Game.ModData.Manifest.Id, Version = Game.ModData.Manifest.Metadata.Version, MapUid = Map.Uid, MapTitle = Map.Title }; RulesContainTemporaryBlocker = map.Rules.Actors.Any(a => a.Value.HasTraitInfo <ITemporaryBlockerInfo>()); }
internal World(ModData modData, Map map, OrderManager orderManager, WorldT type) { Type = type; OrderManager = orderManager; orderGenerator = new UnitOrderGenerator(); Map = map; Timestep = orderManager.LobbyInfo.GlobalSettings.Timestep; SharedRandom = new MersenneTwister(orderManager.LobbyInfo.GlobalSettings.RandomSeed); ModelCache = modData.ModelSequenceLoader.CachModels(map, modData, map.Rules.ModelSequences); var worldActorT = type == WorldT.Editor ? "EditorWorld" : "World"; WorldActor = CreateActor(worldActorT, new TypeDictionary()); ActorMap = WorldActor.Trait <IActorMap>(); ScreenMap = WorldActor.Trait <ScreenMap>(); //Add players foreach (var cmp in WorldActor.TraitsImplementing <ICreatePlayers>()) { cmp.CreatePlayers(this); } //Set defaults for any unset stances foreach (var p in Players) { foreach (var q in Players) { if (!p.Stances.ContainsKey(q)) { p.Stances[q] = Stance.Neutral; } } } }
public UsersController(IUserServices userServices, IAccountServices accountServices, ICategoryServices categoryServices, ITransactionServices transactionServices, IBudgetServices budgetServices, IHttpContextProvider context, ISiteConfiguration config, ICryptoProvider crypto, IUrlHelper urlHelper, IModelCache cache, ICachingHelpers cachingHelpers, ISessionServices sessionServices) : base(userServices, accountServices, categoryServices, transactionServices, budgetServices, context, config, urlHelper, cache, cachingHelpers) { _crypto = crypto; _sessionServices = sessionServices; }
public bool TryGetModelCache <TModel>(out IModelCache model) { var result = typeModelMap.TryGetValue(typeof(TModel).GetTypeData(), out ModelCache modelCache); model = modelCache; return(result); }
public RabbitMqSendTransport(IModelCache modelCache, SendSettings sendSettings, params ExchangeBindingSettings[] exchangeBindings) { _observers = new SendObservable(); _sendSettings = sendSettings; _modelCache = modelCache; _filter = new PrepareSendExchangeFilter(_sendSettings, exchangeBindings); }
public RabbitMqSendTransport(IModelCache modelCache, IFilter <ModelContext> preSendFilter, string exchange) { _observers = new SendObservable(); _modelCache = modelCache; _filter = preSendFilter; _exchange = exchange; }
public MetaService( IMetaRepository metaRepository, IModelLoader modelLoader, IModelCache cache) { _metaRepository = metaRepository.NotNull(nameof(metaRepository)); _modelLoader = modelLoader.NotNull(nameof(modelLoader)); _cache = cache.NotNull(nameof(cache)); }
/// <summary> /// /// </summary> /// <param name="renderData"></param> /// <param name="cache"></param> /// <param name="t"></param> /// <param name="lightDirection"></param> /// <param name="ambientLight"></param> /// <param name="diffuseLight"></param> /// <param name="colorPaletteTextureMidIndex"></param> /// <param name="normalsPaletteTextureMidIndex"></param> void Render(ModelRenderData renderData, IModelCache cache, float[] t, float[] lightDirection, float[] ambientLight, float[] diffuseLight, float colorPaletteTextureMidIndex, float normalsPaletteTextureMidIndex) { shader.SetTexture("DiffuseTexture", renderData.Sheet.GetTexture()); shader.SetVec("PaletteRows", colorPaletteTextureMidIndex, normalsPaletteTextureMidIndex); shader.SetMatrix("TransformMatrix", t); shader.SetVec("LightDirection", lightDirection, 4); shader.SetVec("AmbientLight", ambientLight, 3); shader.SetVec("DiffuseLight", diffuseLight, 3); shader.Render(() => renderer.DrawBatch(cache.VertexBuffer, renderData.Start, renderData.Count, PrimitiveType.TriangleList)); }
public GenericSearchModelBinder(IListConfiguration configuration, IModelActivator modelActivator, IModelPropertyActivator modelPropertyActivator, IModelCache modelCache, IModelBinder fallbackModelBinder) { this.configuration = configuration; this.modelActivator = modelActivator; this.modelPropertyActivator = modelPropertyActivator; this.modelCache = modelCache; this.fallbackModelBinder = fallbackModelBinder; }
internal World(ModData modData, Map map, OrderManager orderManager, WorldType type) { Type = type; OrderManager = orderManager; orderGenerator = new UnitOrderGenerator(); Map = map; Timestep = orderManager.LobbyInfo.GlobalSettings.Timestep; SharedRandom = new MersenneTwister(orderManager.LobbyInfo.GlobalSettings.RandomSeed); ModelCache = modData.ModelSequenceLoader.CacheModels(map, modData, map.Rules.ModelSequences); var worldActorType = type == WorldType.Editor ? "EditorWorld" : "World"; WorldActor = CreateActor(worldActorType, new TypeDictionary()); ActorMap = WorldActor.Trait <IActorMap>(); ScreenMap = WorldActor.Trait <ScreenMap>(); // Add players foreach (var cmp in WorldActor.TraitsImplementing <ICreatePlayers>()) { cmp.CreatePlayers(this); } // Set defaults for any unset stances foreach (var p in Players) { foreach (var q in Players) { if (!p.Stances.ContainsKey(q)) { p.Stances[q] = Stance.Neutral; } } } Game.Sound.SoundVolumeModifier = 1.0f; gameInfo = new GameInformation { Mod = Game.ModData.Manifest.Id, Version = Game.ModData.Manifest.Metadata.Version, MapUid = Map.Uid, MapTitle = Map.Title }; }
internal World(ModData modData, Map map, OrderManager orderManager, WorldType type) { Type = type; OrderManager = orderManager; orderGenerator = new UnitOrderGenerator(); Map = map; Timestep = orderManager.LobbyInfo.GlobalSettings.Timestep; SharedRandom = new MersenneTwister(orderManager.LobbyInfo.GlobalSettings.RandomSeed); LocalRandom = new MersenneTwister(); ModelCache = modData.ModelSequenceLoader.CacheModels(map, modData, map.Rules.ModelSequences); var worldActorType = type == WorldType.Editor ? "EditorWorld" : "World"; WorldActor = CreateActor(worldActorType, new TypeDictionary()); ActorMap = WorldActor.Trait <IActorMap>(); ScreenMap = WorldActor.Trait <ScreenMap>(); Selection = WorldActor.Trait <ISelection>(); OrderValidators = WorldActor.TraitsImplementing <IValidateOrder>().ToArray(); LongBitSet <PlayerBitMask> .Reset(); // Create an isolated RNG to simplify synchronization between client and server player faction/spawn assignments var playerRandom = new MersenneTwister(orderManager.LobbyInfo.GlobalSettings.RandomSeed); foreach (var cmp in WorldActor.TraitsImplementing <ICreatePlayers>()) { cmp.CreatePlayers(this, playerRandom); } Game.Sound.SoundVolumeModifier = 1.0f; gameInfo = new GameInformation { Mod = Game.ModData.Manifest.Id, Version = Game.ModData.Manifest.Metadata.Version, MapUid = Map.Uid, MapTitle = Map.Title }; RulesContainTemporaryBlocker = map.Rules.Actors.Any(a => a.Value.HasTraitInfo <ITemporaryBlockerInfo>()); gameSettings = Game.Settings.Game; }
public BaseController(IUserServices userServices, IAccountServices accountServices, ICategoryServices categoryServices, ITransactionServices transactionServices, IBudgetServices budgetServices, IHttpContextProvider context, ISiteConfiguration config, IUrlHelper urlHelper, IModelCache cache, ICachingHelpers cachingHelpers) { _userServices = userServices; _accountServices = accountServices; _categoryServices = categoryServices; _transactionServices = transactionServices; _budgetServices = budgetServices; _context = context; _config = config; _url = urlHelper; _cache = cache; _cachingHelpers = cachingHelpers; }
public CachingTransactionServices(ITransactionServices nonCachingTransactionServices, IModelCache cache, ICachingHelpers helpers) : base(cache, helpers) { _transactionServices = nonCachingTransactionServices; }
public ModelMapperProfile(IModelCache modelCache) { ModelCache = modelCache; CreateMap <MappableDTO, MappableModel>() .BeforeMap((src, dest) => dest?.InitReset()) .ForMember(dest => dest.LastUpdate, opt => opt.MapFrom((src, trg) => DateTime.Now)) .ForMember(dest => dest.IsExpired, opt => opt.MapFrom((src, trg) => false)) .AfterMap((src, dest) => dest?.ResetChangedState()) .IncludeAllDerived(); // Mapping Season data CreateMap <SeasonDataDTO, SeasonModel>() .EqualityComparison((src, dest) => src.SeasonId == dest.SeasonId) .ConstructUsing(source => ModelCache.PutOrGetModel(new SeasonModel(source.SeasonId))) .AfterMap((src, dest) => { CurrentSchedules = null; dest.InitReset(); }) .ReverseMap(); CreateMap <SeasonInfoDTO, SeasonModel>() .EqualityComparison((src, dest) => src.SeasonId == dest.SeasonId) .ConstructUsing(source => ModelCache.PutOrGetModel(new SeasonModel(source.SeasonId))) .AfterMap((src, dest) => { dest.InitReset(); }) .ReverseMap(); // Mapping League member data CreateMap <LeagueMemberDataDTO, LeagueMember>() .ConstructUsing(source => (source != null) ? ModelCache.PutOrGetModel(new LeagueMember(source.MemberId.GetValueOrDefault())) : null) .ReverseMap(); CreateMap <LeagueMemberInfoDTO, LeagueMember>() .ConvertUsing(source => (source != null) ? ModelCache.PutOrGetModel(new LeagueMember(source.MemberId.GetValueOrDefault())) : null); //.ConstructUsing(source => new LeagueMember(source.MemberId)); CreateMap <LeagueMember, LeagueMemberInfoDTO>(); CreateMap <TeamDataDTO, TeamModel>() .ConstructUsing(source => (source != null) ? ModelCache.PutOrGetModel(new TeamModel() { TeamId = source.TeamId }) : null) .ForMember(dest => dest.Members, opt => opt.MapFrom((src, dest, members) => { return(new ObservableCollection <LeagueMember>(src.MemberIds.Select(x => ModelCache.PutOrGetModel(new LeagueMember(x))))); })) .ReverseMap() .ForMember(dest => dest.MemberIds, opt => opt.MapFrom((src, dest, members) => { return(src.Members.Select(x => x.MemberId.GetValueOrDefault()).ToArray()); })); // Mapping incident data CreateMap <IncidentReviewDataDTO, IncidentReviewModel>() .ConstructUsing(source => ModelCache.PutOrGetModel(new IncidentReviewModel(source.ReviewId))) .EqualityComparison((src, dest) => src.ReviewId == dest.ReviewId) .IncludeBase <IncidentReviewInfoDTO, IncidentReviewInfo>() .AfterMap((src, dest) => { dest.InitReset(); }) .ReverseMap() .IncludeBase <IncidentReviewInfo, IncidentReviewInfoDTO>(); CreateMap <IncidentReviewInfoDTO, IncidentReviewInfo>() //.ConstructUsing(source => new IncidentReviewInfo() { ReviewId = source.ReviewId }) .ConstructUsing(source => Test(source)) .EqualityComparison((src, dest) => src.ReviewId == dest.ReviewId) .ForMember(dest => dest.Author, opt => opt.MapFrom((src, dest, author) => { if (dest.Author != null && dest.Author.UserId == src.AuthorUserId) { return(dest.Author); } return(LeagueContext.UserManager.GetUserModel(src.AuthorUserId)); })) .AfterMap((src, dest) => { dest.InitReset(); }) .ReverseMap() .ForMember(dest => dest.AuthorUserId, opt => opt.MapFrom(src => src.Author != null ? src.Author.UserId : null)); // Mapping comment data CreateMap <ReviewCommentDataDTO, ReviewCommentModel>() .ConstructUsing(source => ModelCache.PutOrGetModel(new ReviewCommentModel(source.CommentId.GetValueOrDefault(), source.AuthorName))) .AfterMap((src, dest) => { dest.InitReset(); }) .IncludeAllDerived() .ReverseMap(); CreateMap <CommentDataDTO, CommentModel>() .ConstructUsing(source => ModelCache.PutOrGetModel(new CommentModel(source.CommentId.GetValueOrDefault(), source.AuthorName))) .AfterMap((src, dest) => { dest.InitReset(); }) .IncludeAllDerived() .ReverseMap(); CreateMap <CommentInfoDTO, CommentInfo>() //.ConstructUsing(source => ModelCache.PutOrGetModel(new CommentBase(source.CommentId.GetValueOrDefault(), source.AuthorName))) .ConstructUsing(source => new CommentInfo(source.CommentId, source.AuthorName)) .ForMember(dest => dest.Author, opt => opt.MapFrom((src, dest, author) => { if (dest.Author != null && dest.Author.UserId == src.AuthorUserId) { return(dest.Author); } return(LeagueContext.UserManager.GetUserModel(src.AuthorUserId)); })) .AfterMap((src, dest) => { dest.InitReset(); }) .IncludeAllDerived() .ReverseMap() .ForMember(dest => dest.AuthorUserId, opt => opt.MapFrom(src => src.Author != null ? src.Author.UserId : null)) .ForMember(dest => dest.AuthorName, opt => opt.MapFrom(src => src.Author != null ? src.Author.UserName : src.AuthorName)); //.IncludeAllDerived(); // Mapping schedule data CreateMap <ScheduleDataDTO, ScheduleModel>() .BeforeMap((src, dest) => { if (CurrentSchedules == null) { CurrentSchedules = new ScheduleModel[0]; } //CurrentSessions = dest?.Sessions; }) //.ForMember(dest => dest.Season, opt => opt.Ignore()) .EqualityComparison((src, dest) => src.ScheduleId == dest.ScheduleId) .ConstructUsing(source => ModelCache.PutOrGetModel(new ScheduleModel(source.ScheduleId))) .AfterMap((src, dest) => { dest.InitReset(); CurrentSessions = null; SortObservableCollection(dest.Sessions, x => x.Date); int i = 1; foreach (var race in dest.Sessions.Where(x => x.SessionType == SessionType.Race).Cast <RaceSessionModel>()) { race.RaceId = i; i++; } }) .ReverseMap(); //CreateMap<ScheduleInfoDTO, ScheduleModel>() // .EqualityComparison((src, dest) => src.ScheduleId == dest.ScheduleId) // .ConstructUsing(source => new ScheduleModel(source.ScheduleId)) // .AfterMap((src, dest) => // { // dest.InitReset(); // }) // .ReverseMap() // .As<ScheduleDataDTO>(); CreateMap <ScheduleInfoDTO, ScheduleInfo>() .EqualityComparison((src, dest) => src.ScheduleId == dest.ScheduleId) .ReverseMap() .IncludeAllDerived(); // Mapping session data CreateMap <SessionDataDTO, SessionModel>() .BeforeMap((src, dest) => { if (CurrentSessions == null) { CurrentSessions = new SessionModel[0]; } }) //.ForMember(dest => dest.Season, opt => opt.Ignore()) //.ForMember(dest => dest.Schedule, opt => opt.Ignore()) //.ForMember(dest => dest.Location, opt => opt.MapFrom(src => src.LocationId)) .EqualityComparison((src, dest) => src.SessionId == dest.SessionId) //.ConstructUsing(source => (source.SessionType == SessionType.Race) ? new RaceSessionModel(source.SessionId) : new SessionModel(source.SessionId, source.SessionType)) .ConstructUsing(source => ModelCache.PutOrGetModel(new SessionModel(source.SessionId, source.SessionType))) .AfterMap((src, dest) => { dest.InitReset(); }) .Include <RaceSessionDataDTO, RaceSessionModel>(); CreateMap <RaceSessionDataDTO, RaceSessionModel>() .BeforeMap((src, dest) => { if (CurrentSessions == null) { CurrentSessions = new SessionModel[0]; } }) //.ForMember(dest => dest.Season, opt => opt.Ignore()) //.ForMember(dest => dest.Schedule, opt => opt.Ignore()) //.ForMember(dest => dest.Location, opt => opt.MapFrom(src => src.LocationId)) .EqualityComparison((src, dest) => src.SessionId == dest.SessionId) .ConstructUsing(source => ModelCache.PutOrGetModel(new RaceSessionModel(source.SessionId, source.RaceId))) .AfterMap((src, dest) => { dest.InitReset(); }); CreateMap <SessionModel, SessionDataDTO>() //.ForMember(dest => dest.LocationId, opt => opt.MapFrom(source => source.Location)) .Include <RaceSessionModel, RaceSessionDataDTO>(); CreateMap <RaceSessionModel, RaceSessionDataDTO>(); //.ForMember(dest => dest.LocationId, opt => opt.MapFrom(source => source.Location)); CreateMap <SessionInfoDTO, SessionInfo>() //.BeforeMap((src, dest) => //{ // if (CurrentSessions == null) // { // CurrentSessions = new SessionInfo[0]; // } //}) .ConstructUsing(source => new SessionInfo(source.SessionId, source.SessionType)) .ReverseMap(); // Mapping result data CreateMap <ResultDataDTO, ResultModel>() .ConstructUsing(source => ModelCache.PutOrGetModel(new ResultModel(source.ResultId.GetValueOrDefault()))) .EqualityComparison((src, dest) => src.ResultId == dest.ResultId) .ReverseMap(); CreateMap <ResultInfoDTO, ResultInfo>() .ConstructUsing(source => new ResultInfo(source.ResultId.GetValueOrDefault())) .ReverseMap() .Include <ResultModel, ResultDataDTO>(); CreateMap <ResultRowDataDTO, ResultRowModel>() .ConstructUsing(source => ModelCache.PutOrGetModel(new ResultRowModel(source.ResultRowId))) .ForMember(dest => dest.Location, opt => opt.MapFrom((src, trg) => LeagueContext.Locations.FirstOrDefault(x => x.LocationId == src.LocationId))) .EqualityComparison((src, dest) => src.ResultRowId == dest.ResultRowId) .ReverseMap(); CreateMap <ScoringDataDTO, ScoringModel>() .ConstructUsing(source => ModelCache.PutOrGetModel(new ScoringModel(source.ScoringId))) .EqualityComparison((src, dest) => src.ScoringId == dest.ScoringId) .ForMember(dest => dest.BasePoints, opt => opt.MapFrom((src, dest, result) => { if (src.BasePoints == null || src.BasePoints == "" || src.BasePoints == " ") { return(new ObservableCollection <ScoringModel.BasePointsValue>()); } string[] pointString = src.BasePoints.Split(' '); ObservableCollection <ScoringModel.BasePointsValue> pairs = new ObservableCollection <ScoringModel.BasePointsValue>(); for (int i = 0; i < pointString.Count(); i++) { pairs.Add(new ScoringModel.BasePointsValue(i + 1, int.Parse(pointString[i]))); } return(pairs); })) .ForMember(dest => dest.BonusPoints, opt => opt.MapFrom((src, dest, result) => { if (src.BonusPoints == null || src.BonusPoints == "" || src.BonusPoints == " ") { return(new ObservableCollection <ScoringModel.BonusPointsValue>()); } string[] pointString = src.BonusPoints.Split(' '); ObservableCollection <ScoringModel.BonusPointsValue> pairs = new ObservableCollection <ScoringModel.BonusPointsValue>(); for (int i = 0; i < pointString.Count(); i++) { var stringPair = pointString[i].Split(':'); pairs.Add(new ScoringModel.BonusPointsValue(stringPair.First(), int.Parse(stringPair.Last()))); } return(pairs); })) .ForMember(dest => dest.IncPenaltyPoints, opt => opt.Ignore()) .ReverseMap() .ForMember(dest => dest.BasePoints, opt => opt.MapFrom(src => (src.BasePoints.Count > 0) ? src.BasePoints.Select(x => x.Value.ToString()).Aggregate((x, y) => x + " " + y) : "")) .ForMember(dest => dest.BonusPoints, opt => opt.MapFrom(src => (src.BonusPoints.Count > 0) ? src.BonusPoints.Select(x => x.Key + ":" + x.Value.ToString()).Aggregate((x, y) => x + " " + y) : "")) .ForMember(dest => dest.IncPenaltyPoints, opt => opt.Ignore()); CreateMap <ScoringInfoDTO, ScoringModel>() .ConstructUsing(source => ModelCache.PutOrGetModel(new ScoringModel(source.ScoringId))) .EqualityComparison((src, dest) => src.ScoringId == dest.ScoringId) .ForAllMembers(opt => opt.Ignore()); CreateMap <ScoringModel, ScoringInfoDTO>(); CreateMap <ScoringInfoDTO, ScoringInfo>() .ConstructUsing(source => new ScoringInfo(source.ScoringId)) .EqualityComparison((src, dest) => src.ScoringId == dest.ScoringId) .ReverseMap(); CreateMap <ScoringTableDataDTO, ScoringTableModel>() .ConstructUsing(source => ModelCache.PutOrGetModel(new ScoringTableModel() { ScoringTableId = source.ScoringTableId })) .EqualityComparison((src, dest) => src.ScoringTableId == dest.ScoringTableId) .ForMember(dest => dest.Scorings, opt => opt.MapFrom((src, dest, result, context) => { List <double> factors = new List <double>(); bool success = true; if (src.ScoringFactors != null) { var factorStrings = src.ScoringFactors.Replace(',', '.').Split(';'); foreach (var factorString in factorStrings) { if (double.TryParse(factorString, System.Globalization.NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out double factor)) { factors.Add(factor); } else { success = false; break; } } } if (factors.Count() == 0 || success == false) { factors = src.Scorings.Select(x => (double)1).ToList(); } var mapper = context.Mapper; var destMultiScorings = src.Scorings.Select((x, i) => new MyKeyValuePair <ScoringInfo, double>(mapper.Map <ScoringModel>(x), factors.ElementAt(i))); return(new ObservableCollection <MyKeyValuePair <ScoringInfo, double> >(destMultiScorings)); })) .ReverseMap() .ForMember(dest => dest.ScoringFactors, opt => opt.MapFrom((src, dest, factors) => { if (src.Scorings?.Count > 0) { return(src.Scorings.Select(x => x.Value.ToString()).Aggregate((x, y) => x + ";" + y)); } return(null); })) .ForMember(dest => dest.Scorings, opt => opt.MapFrom((src, dest, scorings) => { if (src.Scorings?.Count > 0) { return(src.Scorings.Select(x => x.Key).ToArray()); } return(new ScoringInfo[0]); })); CreateMap <ScoredResultRowDataDTO, ScoredResultRowModel>() //.ConstructUsing(source => ModelCache.PutOrGetModel(new ScoredResultRowModel() { ScoredResultRowId = source.ScoredResultRowId})) .ConstructUsing(source => new ScoredResultRowModel() { ScoredResultRowId = source.ScoredResultRowId }) .ForMember(dest => dest.Location, opt => opt.MapFrom((src, trg) => LeagueContext.Locations.FirstOrDefault(x => x.LocationId == src.LocationId))) .EqualityComparison((src, dest) => src.ScoredResultRowId == dest.ScoredResultRowId) .IncludeBase <ResultRowDataDTO, ResultRowModel>(); //.EqualityComparison((src, dest) => src.ScoredResultRowId == dest.ScoredResultRowId) CreateMap <ScoredResultDataDTO, ScoredResultModel>() .ConstructUsing(source => ModelCache.PutOrGetModel(new ScoredResultModel() { Scoring = new ScoringInfo(source.Scoring.ScoringId), ResultId = source.ResultId })) .EqualityComparison((src, dest) => src.Session.SessionId == dest.Session.SessionId && src.Scoring.ScoringId == dest.Scoring.ScoringId) .Include <ScoredTeamResultDataDTO, ScoredTeamResultModel>() //.AfterMap((src, dest) => dest.FinalResults = new ObservableCollection<ScoredResultRowModel>(dest.FinalResults.OrderBy(x => x.FinalPosition))) //.ForMember(dest => dest.FinalResults, opt => opt.MapFrom(src => src.ScoredResults)) ; CreateMap <ScoredTeamResultDataDTO, ScoredTeamResultModel>() .ConstructUsing(source => ModelCache.PutOrGetModel(new ScoredTeamResultModel() { Scoring = new ScoringInfo(source.Scoring.ScoringId), ResultId = source.ResultId })) .EqualityComparison((src, dest) => src.Session.SessionId == dest.Session.SessionId && src.Scoring.ScoringId == dest.Scoring.ScoringId) .ForMember(dest => dest.TeamResults, opt => opt.MapFrom((src, trg) => src.TeamResults.OrderBy(x => x.FinalPosition))); CreateMap <ScoredTeamResultRowDataDTO, ScoredTeamResultRowModel>() .ConstructUsing(source => new ScoredTeamResultRowModel() { ScoredResultRowId = source.ScoredResultRowId }) .EqualityComparison((src, dest) => src.ScoredResultRowId == dest.ScoredResultRowId) .ForMember(dest => dest.Team, opt => opt.MapFrom((src, dst) => { return(modelCache.PutOrGetModel(new TeamModel() { TeamId = src.TeamId })); })); CreateMap <StandingsDataDTO, StandingsModel>() .ConstructUsing(source => ModelCache.PutOrGetModel(new StandingsModel() { ScoringTableId = source.ScoringTableId, SessionId = source.SessionId })) .EqualityComparison((src, dest) => src.ScoringTableId == dest.ScoringTableId) .Include <TeamStandingsDataDTO, TeamStandingsModel>(); CreateMap <StandingsRowDataDTO, StandingsRowModel>() //.ConstructUsing(source => ModelCache.PutOrGetModel(new StandingsRowModel() { Scoring = new ScoringInfo(source.Scoring.ScoringId), Member = new LeagueMember(source.Member.MemberId) })) .ConstructUsing(source => new StandingsRowModel()) .EqualityComparison((src, dest) => src.Member.MemberId == dest.Member.MemberId) .Include <TeamStandingsRowDataDTO, TeamStandingsRowModel>(); CreateMap <TeamStandingsDataDTO, TeamStandingsModel>() .ConstructUsing(source => modelCache.PutOrGetModel(new TeamStandingsModel() { ScoringTableId = source.ScoringTableId, SessionId = source.SessionId })) .EqualityComparison((src, dest) => src.ScoringTableId == dest.ScoringTableId); CreateMap <TeamStandingsRowDataDTO, TeamStandingsRowModel>() .ConstructUsing(source => new TeamStandingsRowModel()) .ForMember(dest => dest.Team, opt => opt.MapFrom((src, dst) => { return(modelCache.PutOrGetModel(new TeamModel() { TeamId = src.TeamId })); })) .EqualityComparison((src, dest) => src.TeamId == dest.Team.TeamId); CreateMap <AddPenaltyDTO, AddPenaltyModel>() .ConstructUsing(source => ModelCache.PutOrGetModel(new AddPenaltyModel(source.ScoredResultRowId))) .EqualityComparison((src, dest) => src.ScoredResultRowId == dest.ScoredResultRowId) .ReverseMap(); //CreateMap<LeagueUserDTO, UserModel>() // .ConstructUsing(source => ModelCache.PutOrGetModel(new UserModel(source.AdminId))) // .EqualityComparison((src, dest) => src.AdminId == dest.UserId); CreateMap <UserDTO, UserModel>() .ConstructUsing(src => ModelCache.PutOrGetModel(new UserModel(src.UserId))); //.ForMember(dest => dest.Admin, opt => opt.MapFrom(src => src)); CreateMap <UserModel, UserDTO>(); CreateMap <ReviewVoteDataDTO, ReviewVoteModel>() .ConstructUsing(src => new ReviewVoteModel() { ReviewVoteId = src.ReviewVoteId }) .EqualityComparison((src, dest) => src.ReviewVoteId == dest.ReviewVoteId) .ForMember(dest => dest.VoteCategory, opt => opt .MapFrom(src => src.VoteCategoryId != null ? ModelCache.PutOrGetModel(new VoteCategoryModel() { CatId = src.VoteCategoryId.Value }) : null)) .ReverseMap() .ForMember(dest => dest.VoteCategoryId, opt => opt.MapFrom(src => src.VoteCategory != null ? src.VoteCategory.CatId : (long?)null)); //.ForMember(dest => dest.AdminId, opt => opt.MapFrom(src => (src.Admin != null) ? (int?)src.Admin.AdminId : null)) //.ForMember(dest => dest.IsOwner, opt => opt.MapFrom(src => (src.Admin != null) ? (bool?)src.Admin.IsOwner : null)) //.ForMember(dest => dest.LeagueName, opt => opt.MapFrom(src => (src.Admin != null) ? src.Admin.LeagueName : null)) //.ForMember(dest => dest.Rights, opt => opt.MapFrom(src => (src.Admin != null) ? src.Admin.Rights : 0)); //CreateMap<UserDTO, AdminModel>() // .ConstructUsing(src => (LeagueContext.CurrentUser.Admin.AdminId == src.AdminId) ? LeagueContext.CurrentUser.Admin : new AdminModel((src.AdminId == null) ? 0 : (int)src.AdminId)); CreateMap <TimeSpan, LapTime>() .ConvertUsing <LapTimeConverter>(); CreateMap <TimeSpan, LapInterval>() .ConvertUsing <LapIntervalConverter>(); CreateMap <LapTime, TimeSpan>() .ConvertUsing <LapTimeConverter>(); CreateMap <LapInterval, TimeSpan>() .ConvertUsing <LapIntervalConverter>(); CreateMap <VoteCategoryDTO, VoteCategoryModel>() .ConstructUsing(src => ModelCache.PutOrGetModel(new VoteCategoryModel() { CatId = src.CatId })) .EqualityComparison((src, dest) => src.CatId == dest.CatId) .ReverseMap(); CreateMap <CustomIncidentDTO, CustomIncidentModel>() .ConstructUsing(src => ModelCache.PutOrGetModel(new CustomIncidentModel() { IncidentId = src.IncidentId })) .EqualityComparison((src, dest) => src.IncidentId == dest.IncidentId) .ReverseMap(); CreateMap <ReviewPenaltyDTO, ReviewPenaltyModel>() .ConstructUsing(src => ModelCache.PutOrGetModel(new ReviewPenaltyModel() { ResultRowId = src.ResultRowId, ReviewId = src.ReviewId })) .EqualityComparison((src, dest) => src.ResultRowId == dest.ResultRowId && src.ReviewId == dest.ReviewId) .ReverseMap(); CreateMap <ResultsFilterOptionDTO, ResultsFilterOptionModel>() .ConstructUsing(src => ModelCache.PutOrGetModel(new ResultsFilterOptionModel(src.ResultsFilterId, src.ScoringId))) .EqualityComparison((src, dest) => src.ResultsFilterId == dest.ResultsFilterId) .ForMember(dest => dest.FilterValues, opt => opt.MapFrom((src, dest, destMember, context) => { var targetColumnProperty = typeof(ResultRowModel).GetNestedPropertyInfo(dest.ColumnPropertyName); var sourceColumnProperty = typeof(ResultRowDataDTO).GetNestedPropertyInfo(src.ColumnPropertyName); var targetPropertyType = targetColumnProperty.PropertyType; var sourcePropertyType = sourceColumnProperty.PropertyType; return(new ObservableCollection <FilterValueModel>(src.FilterValues? .Select(x => new FilterValueModel(targetPropertyType, targetPropertyType.Equals(sourcePropertyType) == false ? context.Mapper.Map(x, sourcePropertyType, targetPropertyType) : x)) ?? new FilterValueModel[0])); })) .ReverseMap() .ForMember(dest => dest.FilterValues, opt => opt.MapFrom((src, dest, destMember, context) => { var targetColumnProperty = typeof(ResultRowDataDTO).GetNestedPropertyInfo(dest.ColumnPropertyName); var sourceColumnProperty = typeof(ResultRowModel).GetNestedPropertyInfo(src.ColumnPropertyName); var targetPropertyType = targetColumnProperty.PropertyType; var sourcePropertyType = sourceColumnProperty.PropertyType; return(src.FilterValues? .Select(x => targetPropertyType.Equals(sourcePropertyType) == false ? context.Mapper.Map(x.Value, sourcePropertyType, targetPropertyType) : x.Value) .ToArray() ?? new object[0]); })); }
public ModelManager(IModelCache modelCache, IModelDataProvider modelDataProvider, IConfigurationProvider mapperConfiguration) { ModelCache = modelCache; ModelDataProvider = modelDataProvider; MapperConfiguration = mapperConfiguration as MapperConfiguration; }
public LeagueMember GetLeagueMember(long?memberId, IModelCache modelCache) { return(memberId != null?modelCache.PutOrGetModel(new LeagueMember(memberId)) : null); }
public CachingBudgetServices(IBudgetServices nonCachingBudgetServices, IModelCache cache, ICachingHelpers helpers) : base(cache, helpers) { _budgetServices = nonCachingBudgetServices; }
public CachingTagServices(ITagServices nonCachingTagServices, IModelCache cache, ICacheConfigurationInfo config) { _tagServices = nonCachingTagServices; _cache = cache; _config = config; }
public ModelMapperProfile(IModelCache modelCache) { CreateMap <MappableDTO, MappableModel>() .BeforeMap((src, dest) => dest?.InitReset()) .ForMember(dest => dest.LastUpdate, opt => opt.MapFrom((src, trg) => DateTime.Now)) .ForMember(dest => dest.IsExpired, opt => opt.MapFrom((src, trg) => false)) .AfterMap((src, dest) => dest?.ResetChangedState()) .IncludeAllDerived(); // Mapping Season data CreateMap <SeasonDataDTO, SeasonModel>() .EqualityComparison((src, dest) => src.SeasonId == dest.SeasonId) .ConstructUsing(source => modelCache.PutOrGetModel(new SeasonModel(source.SeasonId))) .ForMember(dest => dest.Schedules, opt => opt.UseDestinationValue()) .ForMember(dest => dest.Scorings, opt => opt.UseDestinationValue()) .ForMember(dest => dest.ScoringTables, opt => opt.UseDestinationValue()) .ForMember(dest => dest.SeasonStatisticSets, opt => opt.MapFrom(src => src.SeasonStatisticSetIds.Select(x => new StatisticSetInfo() { Id = x }))) .AfterMap((src, dest) => { CurrentSchedules = null; dest.InitReset(); }) .ReverseMap(); CreateMap <SeasonInfoDTO, SeasonModel>() .EqualityComparison((src, dest) => src.SeasonId == dest.SeasonId) .ConstructUsing(source => modelCache.PutOrGetModel(new SeasonModel(source.SeasonId))) .AfterMap((src, dest) => { dest.InitReset(); }) .ReverseMap(); // Mapping League member data CreateMap <LeagueMemberDataDTO, LeagueMember>() .ConstructUsing(source => (source != null) ? modelCache.PutOrGetModel(new LeagueMember(source.MemberId.GetValueOrDefault())) : null) .ReverseMap(); CreateMap <LeagueMemberInfoDTO, LeagueMember>() .ConvertUsing(source => (source != null) ? modelCache.PutOrGetModel(new LeagueMember(source.MemberId.GetValueOrDefault())) : null); //.ConstructUsing(source => new LeagueMember(source.MemberId)); CreateMap <LeagueMember, LeagueMemberInfoDTO>(); CreateMap <TeamDataDTO, TeamModel>() .ConstructUsing(source => (source != null) ? modelCache.PutOrGetModel(new TeamModel() { TeamId = source.TeamId }) : null) //.ForMember(dest => dest.Members, opt => opt.MapFrom((src, dest, members) => //{ // return new ObservableCollection<LeagueMember>(src.MemberIds.Select(x => ModelCache.PutOrGetModel(new LeagueMember(x)))); //})) .ForMember(dest => dest.Members, opt => opt.MapFrom(src => src.MemberIds)) .ForMember(dest => dest.Members, opt => opt.UseDestinationValue()) .ReverseMap() .ForMember(dest => dest.MemberIds, opt => opt.MapFrom((TeamModel src, TeamDataDTO dest, long[] members) => { return(src.Members.Select(x => x.MemberId.GetValueOrDefault()).ToArray()); })); CreateMap <long, LeagueMember>() .ConvertUsing((src, dest) => GetLeagueMember(src, modelCache)); // Mapping incident data CreateMap <IncidentReviewDataDTO, IncidentReviewModel>() .ConstructUsing(source => modelCache.PutOrGetModel(new IncidentReviewModel(source.ReviewId))) .ForMember(dest => dest.InvolvedMembers, opt => opt.MapFrom(src => src.InvolvedMemberIds.Select(x => GetLeagueMember(x, modelCache)))) .ForMember(dest => dest.InvolvedMembers, opt => opt.UseDestinationValue()) .ForMember(dest => dest.Comments, opt => opt.UseDestinationValue()) .ForMember(dest => dest.AcceptedReviewVotes, opt => opt.UseDestinationValue()) .EqualityComparison((src, dest) => src.ReviewId == dest.ReviewId) .IncludeBase <IncidentReviewInfoDTO, IncidentReviewInfo>() .AfterMap((src, dest) => { dest.InitReset(); }) .ReverseMap() .ForMember(dest => dest.InvolvedMemberIds, opt => opt.MapFrom(src => src.InvolvedMembers.Select(x => x.MemberId))) .IncludeBase <IncidentReviewInfo, IncidentReviewInfoDTO>(); CreateMap <IncidentReviewInfoDTO, IncidentReviewInfo>() //.ConstructUsing(source => new IncidentReviewInfo() { ReviewId = source.ReviewId }) .ConstructUsing(source => Test(source)) .EqualityComparison((src, dest) => src.ReviewId == dest.ReviewId) .ForMember(dest => dest.Author, opt => opt.MapFrom((src, dest, author) => { if (dest.Author != null && dest.Author.UserId == src.AuthorUserId) { return(dest.Author); } return(LeagueContext.UserManager.GetUserModel(src.AuthorUserId)); })) .AfterMap((src, dest) => { dest.InitReset(); }) .ReverseMap() .ForMember(dest => dest.AuthorUserId, opt => opt.MapFrom(src => src.Author != null ? src.Author.UserId : null)); // Mapping comment data CreateMap <ReviewCommentDataDTO, ReviewCommentModel>() .ConstructUsing(source => modelCache.PutOrGetModel(new ReviewCommentModel(source.CommentId.GetValueOrDefault(), source.AuthorName))) .EqualityComparison((src, dest) => src.CommentId == dest.CommentId) .ForMember(dest => dest.CommentReviewVotes, opt => opt.UseDestinationValue()) .ForMember(dest => dest.Replies, opt => opt.UseDestinationValue()) .AfterMap((src, dest) => { dest.InitReset(); }) .IncludeAllDerived() .ReverseMap(); CreateMap <CommentDataDTO, CommentModel>() .ConstructUsing(source => modelCache.PutOrGetModel(new CommentModel(source.CommentId.GetValueOrDefault(), source.AuthorName))) .EqualityComparison((src, dest) => src.CommentId == dest.CommentId) .ForMember(dest => dest.Replies, opt => opt.UseDestinationValue()) .AfterMap((src, dest) => { dest.InitReset(); }) .IncludeAllDerived() .ReverseMap(); CreateMap <CommentInfoDTO, CommentInfo>() //.ConstructUsing(source => ModelCache.PutOrGetModel(new CommentBase(source.CommentId.GetValueOrDefault(), source.AuthorName))) .ConstructUsing(source => new CommentInfo(source.CommentId, source.AuthorName)) .EqualityComparison((src, dest) => src.CommentId == dest.CommentId) .ForMember(dest => dest.Author, opt => opt.MapFrom((src, dest, author) => { if (dest.Author != null && dest.Author.UserId == src.AuthorUserId) { return(dest.Author); } return(LeagueContext.UserManager.GetUserModel(src.AuthorUserId)); })) .AfterMap((src, dest) => { dest.InitReset(); }) .IncludeAllDerived() .ReverseMap() .ForMember(dest => dest.AuthorUserId, opt => opt.MapFrom(src => src.Author != null ? src.Author.UserId : null)) .ForMember(dest => dest.AuthorName, opt => opt.MapFrom(src => src.Author != null ? src.Author.UserName : src.AuthorName)); //.IncludeAllDerived(); // Mapping schedule data CreateMap <ScheduleDataDTO, ScheduleModel>() .BeforeMap((src, dest) => { if (CurrentSchedules == null) { CurrentSchedules = new ScheduleModel[0]; } //CurrentSessions = dest?.Sessions; }) //.ForMember(dest => dest.Season, opt => opt.Ignore()) .EqualityComparison((src, dest) => src.ScheduleId == dest.ScheduleId) .ForMember(dest => dest.Sessions, opt => opt.UseDestinationValue()) .ConstructUsing(source => modelCache.PutOrGetModel(new ScheduleModel(source.ScheduleId))) //.ForMember(dest => dest.Sessions, opt => opt.MapFrom((src, dest, target, context) => context.Mapper.Map(src.Sessions, dest.Sessions))) .AfterMap((src, dest) => { dest.InitReset(); CurrentSessions = null; SortObservableCollection(dest.Sessions, x => x.Date); int i = 1; foreach (var race in dest.Sessions.Where(x => x.SessionType == SessionType.Race || x.SessionType == SessionType.HeatEvent).OfType <RaceSessionModel>()) { race.RaceId = i; i++; } }) .ReverseMap(); CreateMap <ScheduleInfoDTO, ScheduleInfo>() .EqualityComparison((src, dest) => src.ScheduleId == dest.ScheduleId) .ReverseMap() .IncludeAllDerived(); // Mapping session data CreateMap <SessionDataDTO, SessionModel>() .BeforeMap((src, dest) => { if (CurrentSessions == null) { CurrentSessions = new SessionModel[0]; } }) .EqualityComparison((src, dest) => src.SessionId == dest.SessionId) //.ConstructUsing(source => (source.SessionType == SessionType.Race) ? new RaceSessionModel(source.SessionId) : new SessionModel(source.SessionId, source.SessionType)) .ConstructUsing(source => modelCache.PutOrGetModel(new SessionModel(source.SessionId, source.SessionType))) .ForMember(dest => dest.ParentSession, opt => opt.MapFrom(src => src.ParentSessionId != null ? modelCache.GetModel <SessionModel>(src.ParentSessionId.Value) : null)) .ForMember(dest => dest.SessionResult, opt => opt.MapFrom(src => src.SessionResultId != null ? new ResultInfo(src.SessionResultId) : null)) .ForMember(dest => dest.Reviews, opt => opt.MapFrom(src => src.ReviewIds.Select(x => new IncidentReviewInfo() { ReviewId = x }))) .ForMember(dest => dest.Reviews, opt => opt.UseDestinationValue()) .AfterMap((src, dest) => { dest.InitReset(); }) .Include <RaceSessionDataDTO, RaceSessionModel>(); CreateMap <RaceSessionDataDTO, RaceSessionModel>() .BeforeMap((src, dest) => { if (CurrentSessions == null) { CurrentSessions = new SessionModel[0]; } }) .EqualityComparison((src, dest) => src.SessionId == dest.SessionId) .ForMember(dest => dest.Reviews, opt => opt.UseDestinationValue()) .ConstructUsing(source => modelCache.PutOrGetModel(new RaceSessionModel(source.SessionId, source.RaceId))) //.ForMember(dest => dest.Reviews, opt => opt.UseDestinationValue()) .AfterMap((src, dest) => { dest.InitReset(); }); CreateMap <SessionModel, SessionDataDTO>() //.ForMember(dest => dest.LocationId, opt => opt.MapFrom(source => source.Location)) .ForMember(dest => dest.SessionResultId, opt => opt.MapFrom(src => src.SessionResult != null ? src.SessionResult.ResultId : null)) .ForMember(dest => dest.ReviewIds, opt => opt.MapFrom(src => src.Reviews.Select(x => x.ReviewId.GetValueOrDefault()))) .Include <RaceSessionModel, RaceSessionDataDTO>(); CreateMap <RaceSessionModel, RaceSessionDataDTO>(); //.ForMember(dest => dest.LocationId, opt => opt.MapFrom(source => source.Location)); CreateMap <SessionInfoDTO, SessionInfo>() .ConstructUsing(source => new SessionInfo(source.SessionId, source.SessionType)) .ReverseMap(); //Mapping result data CreateMap <ResultDataDTO, ResultModel>() .ConstructUsing(source => modelCache.PutOrGetModel(new ResultModel(source.ResultId.GetValueOrDefault()))) .EqualityComparison((src, dest) => src.ResultId == dest.ResultId) .ForMember(dest => dest.Session, opt => opt.MapFrom(src => new SessionInfo(src.SessionId, SessionType.Undefined))) .ForMember(dest => dest.RawResults, opt => opt.UseDestinationValue()) .ForMember(dest => dest.Reviews, opt => opt.MapFrom(src => src.ReviewIds.Select(x => new IncidentReviewInfo() { ReviewId = x }))) .ForMember(dest => dest.Reviews, opt => opt.UseDestinationValue()) .ReverseMap() .ForMember(dest => dest.SessionId, opt => opt.MapFrom(src => src.Session.SessionId)) .ForMember(dest => dest.ReviewIds, opt => opt.MapFrom(src => src.Reviews.Select(x => x.ReviewId.GetValueOrDefault()))); CreateMap <SimSessionDetailsDTO, SimSessionDetails>() .ReverseMap(); CreateMap <ResultInfoDTO, ResultInfo>() .ConstructUsing(source => new ResultInfo(source.ResultId.GetValueOrDefault())) .ReverseMap() .Include <ResultModel, ResultDataDTO>(); CreateMap <ResultRowDataDTO, ResultRowModel>() .ConstructUsing(source => modelCache.PutOrGetModel(new ResultRowModel(source.ResultRowId))) .ForMember(dest => dest.Member, opt => opt.MapFrom(src => GetLeagueMember(src.MemberId, modelCache))) .ForMember(dest => dest.Team, opt => opt.MapFrom(src => src.TeamId != null ? modelCache.PutOrGetModel(new TeamModel() { TeamId = src.TeamId.GetValueOrDefault() }) : null)) .ForMember(dest => dest.Location, opt => opt.MapFrom((src, trg) => LeagueContext.Locations.FirstOrDefault(x => x.LocationId == src.LocationId))) .EqualityComparison((src, dest) => src.ResultRowId == dest.ResultRowId) .ReverseMap() .ForMember(dest => dest.MemberId, opt => opt.MapFrom(src => src.Member.MemberId)) .ForMember(dest => dest.LocationId, opt => opt.MapFrom(src => src.Location != null ? src.Location.LocationId : null)) .ForMember(dest => dest.TeamId, opt => opt.MapFrom(src => src.Team != null ? src.Team.TeamId : (long?)null)); CreateMap <ScoringDataDTO, ScoringModel>() .ConstructUsing(source => modelCache.PutOrGetModel(new ScoringModel(source.ScoringId))) .EqualityComparison((src, dest) => src.ScoringId == dest.ScoringId) .ForMember(dest => dest.ConnectedSchedule, opt => opt.MapFrom(src => src.ConnectedScheduleId != null ? new ScheduleInfo(src.ConnectedScheduleId) : null)) .ForMember(dest => dest.Sessions, opt => opt.MapFrom(src => src.SessionIds.Select(x => modelCache.PutOrGetModel(new SessionModel(x, SessionType.Undefined))))) .ForMember(dest => dest.ExtScoringSource, opt => opt.MapFrom(src => src.ExtScoringSourceId != null ? new ScoringInfo(src.ExtScoringSourceId) : null)) .ForMember(dest => dest.AccumulateScoring, opt => opt.MapFrom(src => src.AccumulateResults != AccumulateResultsOption.None ? true : false)) .ForMember(dest => dest.BasePoints, opt => opt.MapFrom((src, dest, result) => { ObservableCollection <ScoringModel.BasePointsValue> pairs = new ObservableCollection <ScoringModel.BasePointsValue>(); pairs.Clear(); if (src.BasePoints == null || src.BasePoints == "" || src.BasePoints == " ") { return(pairs); } string[] pointString = src.BasePoints.Split(' '); for (int i = 0; i < pointString.Count(); i++) { pairs.Add(new ScoringModel.BasePointsValue(i + 1, int.Parse(pointString[i]))); } return(pairs); })) .ForMember(dest => dest.BasePoints, opt => opt.UseDestinationValue()) .ForMember(dest => dest.BonusPoints, opt => opt.MapFrom((src, dest, result) => { ObservableCollection <ScoringModel.BonusPointsValue> pairs = new ObservableCollection <ScoringModel.BonusPointsValue>(); pairs.Clear(); if (src.BonusPoints == null || src.BonusPoints == "" || src.BonusPoints == " ") { return(pairs); } string[] pointString = src.BonusPoints.Split(' '); for (int i = 0; i < pointString.Count(); i++) { var stringPair = pointString[i].Split(':'); pairs.Add(new ScoringModel.BonusPointsValue(stringPair.First(), int.Parse(stringPair.Last()))); } return(pairs); })) .ForMember(dest => dest.ScoringWeights, opt => opt.MapFrom(src => src.SubSessionScoringIds .Select(x => modelCache.PutOrGetModel(new ScoringModel() { ScoringId = x })) .Zip(src.ScoringWeights, (scoring, weight) => new MyKeyValuePair <ScoringModel, double>(scoring, weight)))) .ForMember(dest => dest.BonusPoints, opt => opt.UseDestinationValue()) .ForMember(dest => dest.Sessions, opt => opt.UseDestinationValue()) .ForMember(dest => dest.Standings, opt => opt.UseDestinationValue()) .ForMember(dest => dest.ResultsFilterOptionIds, opt => opt.UseDestinationValue()) .ForMember(dest => dest.ScoringWeights, opt => opt.UseDestinationValue()) .ForMember(dest => dest.IncPenaltyPoints, opt => opt.Ignore()) .ForMember(dest => dest.SubSessionScorings, opt => opt .MapFrom((src => src.SubSessionScoringIds .Select(x => modelCache.PutOrGetModel(new ScoringModel() { ScoringId = x })) )) ) .ForMember(dest => dest.SubSessionScorings, opt => opt.UseDestinationValue()) .ForMember(dest => dest.ParentScoring, opt => opt.MapFrom(src => src.ParentScoringId != null ? modelCache.PutOrGetModel(new ScoringModel() { ScoringId = src.ParentScoringId }) : null)) .ReverseMap() .ForMember(dest => dest.ConnectedScheduleId, opt => opt.MapFrom(src => src.ConnectedSchedule != null ? src.ConnectedSchedule.ScheduleId : null)) .ForMember(dest => dest.SessionIds, opt => opt.MapFrom(src => src.Sessions.Select(x => x.SessionId))) .ForMember(dest => dest.ExtScoringSourceId, opt => opt.MapFrom(src => src.ExtScoringSource != null ? src.ExtScoringSource.ScoringId : null)) .ForMember(dest => dest.BasePoints, opt => opt.MapFrom(src => (src.BasePoints.Count > 0) ? src.BasePoints.Select(x => x.Value.ToString()).Aggregate((x, y) => x + " " + y) : "")) .ForMember(dest => dest.BonusPoints, opt => opt.MapFrom(src => (src.BonusPoints.Count > 0) ? src.BonusPoints.Select(x => x.Key + ":" + x.Value.ToString()).Aggregate((x, y) => x + " " + y) : "")) .ForMember(dest => dest.AccumulateResults, opt => opt.MapFrom(src => src.AccumulateScoring == true ? src.AccumulateResults : AccumulateResultsOption.None)) .ForMember(dest => dest.SubSessionScoringIds, opt => opt.MapFrom(src => src.SubSessionScorings.Select(x => x.ScoringId))) .ForMember(dest => dest.ScoringWeights, opt => opt.MapFrom(src => src.SubSessionScorings .Select(x => src.ScoringWeights.Any(y => y.Key == x) ? src.ScoringWeights.SingleOrDefault(y => y.Key == x).Value : 0))) .ForMember(dest => dest.IncPenaltyPoints, opt => opt.Ignore()); CreateMap <ScoringInfoDTO, ScoringModel>() .ConstructUsing(source => modelCache.PutOrGetModel(new ScoringModel(source.ScoringId))) .EqualityComparison((src, dest) => src.ScoringId == dest.ScoringId) .ForAllMembers(opt => opt.Ignore()); CreateMap <ScoringModel, ScoringInfoDTO>(); CreateMap <ScoringInfoDTO, ScoringInfo>() .ConstructUsing(source => new ScoringInfo(source.ScoringId)) .EqualityComparison((src, dest) => src.ScoringId == dest.ScoringId) .ReverseMap(); CreateMap <ScoringTableDataDTO, ScoringTableModel>() .ConstructUsing(source => modelCache.PutOrGetModel(new ScoringTableModel() { ScoringTableId = source.ScoringTableId })) .EqualityComparison((src, dest) => src.ScoringTableId == dest.ScoringTableId) .ForMember(dest => dest.Sessions, opt => opt.MapFrom(src => src.SessionIds.Select(x => new SessionInfo(x, SessionType.Undefined)))) .ForMember(dest => dest.Scorings, opt => opt.MapFrom((src, dest, result, context) => { List <double> factors = new List <double>(); bool success = true; if (src.ScoringFactors != null) { var factorStrings = src.ScoringFactors.Replace(',', '.').Split(';'); foreach (var factorString in factorStrings) { if (double.TryParse(factorString, System.Globalization.NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out double factor)) { factors.Add(factor); } else { success = false; break; } } } if (factors.Count() == 0 || success == false) { factors = src.ScoringIds.Select(x => (double)1).ToList(); } var mapper = context.Mapper; //var destMultiScorings = src.Scorings.Select((x, i) => new MyKeyValuePair<ScoringInfo, double>(mapper.Map<ScoringModel>(x), factors.ElementAt(i))); var destMultiScorings = src.ScoringIds.Select((x, i) => new MyKeyValuePair <ScoringInfo, double>(mapper.Map <ScoringInfo>(modelCache.PutOrGetModel(new ScoringInfo(x))), factors.ElementAt(i))); return(new ObservableCollection <MyKeyValuePair <ScoringInfo, double> >(destMultiScorings)); })) .ForMember(dest => dest.Scorings, opt => opt.UseDestinationValue()) .ReverseMap() .ForMember(dest => dest.SessionIds, opt => opt.MapFrom(src => src.Sessions.Select(x => x.SessionId))) .ForMember(dest => dest.ScoringFactors, opt => opt.MapFrom((src, dest, factors) => { if (src.Scorings?.Count > 0) { return(src.Scorings.Select(x => x.Value.ToString()).Aggregate((x, y) => x + ";" + y)); } return(null); })) .ForMember(dest => dest.ScoringIds, opt => opt.MapFrom((src, dest, scoringIds) => { if (src.Scorings?.Count > 0) { return(src.Scorings.Select(x => x.Key.ScoringId.GetValueOrDefault()).Where(x => x != default).ToArray()); } return(new long[0]); })); CreateMap <ScoredResultRowDataDTO, ScoredResultRowModel>() //.ConstructUsing(source => ModelCache.PutOrGetModel(new ScoredResultRowModel() { ScoredResultRowId = source.ScoredResultRowId})) .ConstructUsing(source => new ScoredResultRowModel() { ScoredResultRowId = source.ScoredResultRowId }) .ForMember(dest => dest.Location, opt => opt.MapFrom((src, trg) => LeagueContext.Locations.FirstOrDefault(x => x.LocationId == src.LocationId))) .EqualityComparison((src, dest) => src.ScoredResultRowId == dest.ScoredResultRowId) .IncludeBase <ResultRowDataDTO, ResultRowModel>(); //.EqualityComparison((src, dest) => src.ScoredResultRowId == dest.ScoredResultRowId) CreateMap <ScoredResultDataDTO, ScoredResultModel>() .ConstructUsing(source => modelCache.PutOrGetModel(new ScoredResultModel() { Scoring = new ScoringInfo(source.ScoringId), ResultId = source.ResultId })) .EqualityComparison((src, dest) => src.SessionId == dest.Session.SessionId && src.ScoringId == dest.Scoring.ScoringId) .ForMember(dest => dest.Scoring, opt => opt.MapFrom(src => new ScoringInfo(src.ScoringId))) .ForMember(dest => dest.FinalResults, opt => opt.MapFrom(src => src.FinalResults.OrderBy(x => x.FinalPosition))) .ForMember(dest => dest.FinalResults, opt => opt.UseDestinationValue()) .ForMember(dest => dest.HardChargers, opt => opt.MapFrom(src => src.HardChargerMemberIds.Select(x => GetLeagueMember(x, modelCache)))) .ForMember(dest => dest.CleanestDrivers, opt => opt.MapFrom(src => src.CleanesDriverMemberIds.Select(x => GetLeagueMember(x, modelCache)))) .ForMember(dest => dest.HardChargers, opt => opt.UseDestinationValue()) .ForMember(dest => dest.CleanestDrivers, opt => opt.UseDestinationValue()) .ForMember(dest => dest.FastestLapDriver, opt => opt.MapFrom(src => src.FastestLapDriverId)) .Include <ScoredTeamResultDataDTO, ScoredTeamResultModel>(); CreateMap <ScoredTeamResultDataDTO, ScoredTeamResultModel>() .ConstructUsing(source => modelCache.PutOrGetModel(new ScoredTeamResultModel() { Scoring = new ScoringInfo(source.ScoringId), ResultId = source.ResultId })) .EqualityComparison((src, dest) => src.SessionId == dest.Session.SessionId && src.ScoringId == dest.Scoring.ScoringId) .ForMember(dest => dest.FinalResults, opt => opt.MapFrom(src => src.FinalResults.OrderBy(x => x.FinalPosition))) .ForMember(dest => dest.FinalResults, opt => opt.UseDestinationValue()) .ForMember(dest => dest.TeamResults, opt => opt.MapFrom((src, trg) => src.TeamResults.OrderBy(x => x.FinalPosition))) .ForMember(dest => dest.TeamResults, opt => opt.UseDestinationValue()) .IncludeBase <ScoredResultDataDTO, ScoredResultModel>(); CreateMap <ScoredTeamResultRowDataDTO, ScoredTeamResultRowModel>() .ConstructUsing(source => new ScoredTeamResultRowModel() { ScoredResultRowId = source.ScoredResultRowId }) .EqualityComparison((src, dest) => src.ScoredResultRowId == dest.ScoredResultRowId) .ForMember(dest => dest.ScoredResultRows, opt => opt.UseDestinationValue()) .ForMember(dest => dest.Team, opt => opt.MapFrom((src, dst) => { return(modelCache.PutOrGetModel(new TeamModel() { TeamId = src.TeamId })); })); CreateMap <StandingsDataDTO, StandingsModel>() .ConstructUsing(source => modelCache.PutOrGetModel(new StandingsModel() { ScoringTableId = source.ScoringTableId, SessionId = source.SessionId })) .EqualityComparison((src, dest) => src.ScoringTableId == dest.ScoringTableId) .ForMember(dest => dest.MostWinsDriver, opt => opt.MapFrom(src => GetLeagueMember(src.MostWinsDriverId, modelCache))) .ForMember(dest => dest.MostPolesDriver, opt => opt.MapFrom(src => GetLeagueMember(src.MostPolesDriverId, modelCache))) .ForMember(dest => dest.CleanestDriver, opt => opt.MapFrom(src => GetLeagueMember(src.CleanestDriverId, modelCache))) .ForMember(dest => dest.MostPenaltiesDriver, opt => opt.MapFrom(src => GetLeagueMember(src.MostPenaltiesDriverId, modelCache))) .ForMember(dest => dest.StandingsRows, opt => opt.UseDestinationValue()) .Include <TeamStandingsDataDTO, TeamStandingsModel>(); CreateMap <StandingsRowDataDTO, StandingsRowModel>() //.ConstructUsing(source => ModelCache.PutOrGetModel(new StandingsRowModel() { Scoring = new ScoringInfo(source.Scoring.ScoringId), Member = new LeagueMember(source.Member.MemberId) })) .ConstructUsing(source => new StandingsRowModel()) .ForMember(dest => dest.Member, opt => opt.MapFrom(src => GetLeagueMember(src.MemberId, modelCache))) .ForMember(dest => dest.DriverResults, opt => opt.MapFrom(src => src.DriverResults.OrderBy(x => x.Date))) .ForMember(dest => dest.Team, opt => opt.MapFrom(src => src.TeamId != null ? modelCache.PutOrGetModel(new TeamModel() { TeamId = src.TeamId.Value }) : null)) .EqualityComparison((src, dest) => src.MemberId == dest.Member.MemberId) .Include <TeamStandingsRowDataDTO, TeamStandingsRowModel>(); CreateMap <TeamStandingsDataDTO, TeamStandingsModel>() .ConstructUsing(source => modelCache.PutOrGetModel(new TeamStandingsModel() { ScoringTableId = source.ScoringTableId, SessionId = source.SessionId })) .EqualityComparison((src, dest) => src.ScoringTableId == dest.ScoringTableId) .ForMember(dest => dest.StandingsRows, opt => opt.UseDestinationValue()); CreateMap <TeamStandingsRowDataDTO, TeamStandingsRowModel>() .ConstructUsing(source => new TeamStandingsRowModel()) .ForMember(dest => dest.Team, opt => opt.MapFrom((src, dst) => { return(modelCache.PutOrGetModel(new TeamModel() { TeamId = src.TeamId })); })) .ForMember(dest => dest.DriverStandingsRows, opt => opt.MapFrom(src => src.DriverStandingsRows.OrderBy(x => - x.TotalPoints).ThenBy(x => - x.PenaltyPoints))) .ForMember(dest => dest.DriverStandingsRows, opt => opt.UseDestinationValue()) .EqualityComparison((src, dest) => src.TeamId == dest.Team.TeamId); CreateMap <AddPenaltyDTO, AddPenaltyModel>() .ConstructUsing(source => modelCache.PutOrGetModel(new AddPenaltyModel(source.ScoredResultRowId))) .EqualityComparison((src, dest) => src.ScoredResultRowId == dest.ScoredResultRowId) .ReverseMap(); //CreateMap<LeagueUserDTO, UserModel>() // .ConstructUsing(source => ModelCache.PutOrGetModel(new UserModel(source.AdminId))) // .EqualityComparison((src, dest) => src.AdminId == dest.UserId); CreateMap <UserDTO, UserModel>() .ConstructUsing(src => modelCache.PutOrGetModel(new UserModel(src.UserId))); //.ForMember(dest => dest.Admin, opt => opt.MapFrom(src => src)); CreateMap <UserModel, UserDTO>(); CreateMap <ReviewVoteDataDTO, ReviewVoteModel>() .ConstructUsing(src => new ReviewVoteModel() { ReviewVoteId = src.ReviewVoteId }) .EqualityComparison((src, dest) => src.ReviewVoteId == dest.ReviewVoteId) .ForMember(dest => dest.MemberAtFault, opt => opt.MapFrom(src => GetLeagueMember(src.MemberAtFaultId, modelCache))) .ForMember(dest => dest.VoteCategory, opt => opt .MapFrom(src => src.VoteCategoryId != null ? modelCache.PutOrGetModel(new VoteCategoryModel() { CatId = src.VoteCategoryId.Value }) : null)) .ReverseMap() .ForMember(dest => dest.MemberAtFaultId, opt => opt.MapFrom(src => src.MemberAtFault != null ? src.MemberAtFault.MemberId : null)) .ForMember(dest => dest.VoteCategoryId, opt => opt.MapFrom(src => src.VoteCategory != null ? src.VoteCategory.CatId : (long?)null)); CreateMap <TimeSpan, LapTime>() .ConvertUsing <LapTimeConverter>(); CreateMap <TimeSpan, LapInterval>() .ConvertUsing <LapIntervalConverter>(); CreateMap <LapTime, TimeSpan>() .ConvertUsing <LapTimeConverter>(); CreateMap <LapInterval, TimeSpan>() .ConvertUsing <LapIntervalConverter>(); CreateMap <VoteCategoryDTO, VoteCategoryModel>() .ConstructUsing(src => modelCache.PutOrGetModel(new VoteCategoryModel() { CatId = src.CatId })) .EqualityComparison((src, dest) => src.CatId == dest.CatId) .ReverseMap(); CreateMap <CustomIncidentDTO, CustomIncidentModel>() .ConstructUsing(src => modelCache.PutOrGetModel(new CustomIncidentModel() { IncidentId = src.IncidentId })) .EqualityComparison((src, dest) => src.IncidentId == dest.IncidentId) .ReverseMap(); CreateMap <ReviewPenaltyDTO, ReviewPenaltyModel>() .ConstructUsing(src => modelCache.PutOrGetModel(new ReviewPenaltyModel() { ResultRowId = src.ResultRowId, ReviewId = src.ReviewId })) .EqualityComparison((src, dest) => src.ResultRowId == dest.ResultRowId && src.ReviewId == dest.ReviewId) .ReverseMap(); CreateMap <ResultsFilterOptionDTO, ResultsFilterOptionModel>() .ConstructUsing(src => modelCache.PutOrGetModel(new ResultsFilterOptionModel(src.ResultsFilterId, src.ScoringId))) .EqualityComparison((src, dest) => src.ResultsFilterId == dest.ResultsFilterId) .ForMember(dest => dest.FilterValues, opt => opt.MapFrom((src, dest, destMember, context) => { var targetColumnProperty = typeof(ResultRowModel).GetNestedPropertyInfo(dest.ColumnPropertyName); var sourceColumnProperty = typeof(ResultRowDataDTO).GetNestedPropertyInfo(src.ColumnPropertyName); var targetPropertyType = targetColumnProperty.PropertyType; var sourcePropertyType = sourceColumnProperty.PropertyType; return(new ObservableCollection <FilterValueModel>(src.FilterValues? .Select(x => new FilterValueModel(targetPropertyType, Convert.ChangeType(x, targetPropertyType))) ?? new FilterValueModel[0])); })) .ForMember(dest => dest.FilterValues, opt => opt.UseDestinationValue()) .ReverseMap() .ForMember(dest => dest.FilterValues, opt => opt.MapFrom((src, dest, destMember, context) => { var targetColumnProperty = typeof(ResultRowDataDTO).GetNestedPropertyInfo(dest.ColumnPropertyName); var sourceColumnProperty = typeof(ResultRowModel).GetNestedPropertyInfo(src.ColumnPropertyName); var targetPropertyType = targetColumnProperty.PropertyType; var sourcePropertyType = sourceColumnProperty.PropertyType; return(src.FilterValues? .Select(x => Convert.ChangeType(x.Value, targetPropertyType)) .ToArray() ?? new object[0]); })); CreateMap <LeagueDTO, LeagueModel>(); #region statistic mapping CreateMap <StatisticSetDTO, StatisticSetInfo>(); CreateMap <StatisticSetDTO, StatisticSetModel>() .ConstructUsing(src => modelCache.PutOrGetModel(new StatisticSetModel() { Id = src.Id })) .EqualityComparison((src, dest) => src.Id == dest.Id) .Include <SeasonStatisticSetDTO, SeasonStatisticSetModel>() .Include <LeagueStatisticSetDTO, LeagueStatisticSetModel>() .Include <ImportedStatisticSetDTO, ImportedStatisticSetModel>() .ReverseMap() .IncludeAllDerived(); CreateMap <SeasonStatisticSetDTO, SeasonStatisticSetModel>() .ConstructUsing(src => modelCache.PutOrGetModel(new SeasonStatisticSetModel() { Id = src.Id })) .ForMember(dest => dest.Season, opt => opt.MapFrom(src => modelCache.PutOrGetModel(new SeasonModel() { SeasonId = src.SeasonId }))) .ForMember(dest => dest.ScoringTable, opt => opt.MapFrom(src => src.ScoringTableId.HasValue && src.ScoringTableId != 0 ? modelCache.PutOrGetModel(new ScoringTableModel() { ScoringTableId = src.ScoringTableId.Value }) : null)) .EqualityComparison((src, dest) => src.Id == dest.Id) .ReverseMap() .ForMember(dest => dest.ScoringTableId, opt => opt.MapFrom(src => src != null ? src.ScoringTable.ScoringTableId : (long?)null)) .ForMember(dest => dest.SeasonId, opt => opt.MapFrom(src => src.Season.SeasonId)); CreateMap <LeagueStatisticSetDTO, LeagueStatisticSetModel>() .ConstructUsing(src => modelCache.PutOrGetModel(new LeagueStatisticSetModel() { Id = src.Id })) .ForMember(dest => dest.StatisticSets, opt => opt.MapFrom(src => src.SeasonStatisticSetIds.Select(x => modelCache.GetModel <StatisticSetModel>(x) ?? new StatisticSetModel() { Id = x }))) .EqualityComparison((src, dest) => src.Id == dest.Id) .ReverseMap() .ForMember(dest => dest.SeasonStatisticSetIds, opt => opt.MapFrom(src => src.StatisticSets.Select(x => x.Id))); CreateMap <ImportedStatisticSetDTO, ImportedStatisticSetModel>() .ConstructUsing(src => modelCache.PutOrGetModel(new ImportedStatisticSetModel() { Id = src.Id })) .EqualityComparison((src, dest) => src.Id == dest.Id) .ReverseMap(); CreateMap <DriverStatisticDTO, DriverStatisticModel>() .ConstructUsing(src => modelCache.PutOrGetModel(new DriverStatisticModel() { StatisticSetId = src.StatisticSetId })) .EqualityComparison((src, dest) => src.StatisticSetId == dest.StatisticSetId) .ReverseMap(); CreateMap <DriverStatisticRowDTO, DriverStatisticRowModel>() .EqualityComparison((src, dest) => src.StatisticSetId == dest.StatisticSetId && src.MemberId == dest.MemberId) .ForMember(dest => dest.LeagueMember, opt => opt.MapFrom(src => GetLeagueMember(src.MemberId, modelCache))) .ReverseMap(); #endregion }
public EntryController(IEntryServices entryServices, ICommentServices commentServices, ITagServices tagServices, IConfigurationInfo config, IModelCache cache) : base(entryServices, commentServices, config) { _tagServices = tagServices; _cache = cache; }
public RequestModelProvider(IModelCache modelCache) => this.modelCache = modelCache;
public void RegisterDataModel( ) { IModelCache model = reflector.Register <Customer>(); Assert.IsNotNull(model); }
public CachingUserServices(IUserServices nonCachingUserServices, IModelCache cache, ICachingHelpers helpers) : base(cache, helpers) { _userServices = nonCachingUserServices; }
public CachingAccountServices(IAccountServices nonCachingAccountServices, IModelCache cache, ICachingHelpers helpers) : base(cache, helpers) { _accountServices = nonCachingAccountServices; }