public void TestPathsSinAtributos() { var paths = PathAccessor .GetPaths(typeof(Sql2Sql.Test.ComplexTypes.Cliente2)) .Paths .OrderBy(x => x.Key) ; var expected = new string[] { "Dir_Calle", "Dir_Colonia", "Dir_Numero", "Nombre", }; var actual = paths.Select(x => x.Key).ToList(); CollectionAssert.AreEqual(expected, actual); }
public void TestPaths() { var paths = PathAccessor .GetPaths(typeof(Test.ComplexTypes.Empresa)) .Paths .OrderBy(x => x.Key) ; var expected = new string[] { "Datos_Rfc", "Datos_Tipo", "Destacado", "FechaMod", "IdCuenta", "IdRegistro", "Nombre" }; var actual = paths.Select(x => x.Key).ToList(); CollectionAssert.AreEqual(expected, actual); }
/// <summary> /// Create a mapping between a type and a list of columns. /// </summary> /// <param name="prefix">Only look into columns with this prefix</param> public static ValueMapping CreateMapping(Type type, string prefix, IReadOnlyList <string> columns, IReadOnlyList <Type> chain) { if (chain.Contains(type)) { //Recursive type: return(new NullMapping(type)); } //True if this mapping is for the top type var topLevel = !chain.Any(); chain = chain.Concat(new[] { type }).ToList(); if (PathAccessor.IsSimpleType(type)) { var ixs = columns .Select((x, i) => (x, i)) .Where(x => PrefixMatchesColumnName(prefix, x.x)) .Select(X => (int?)X.i) .ToList(); if (ixs.Count > 1) { var ixsStr = string.Join(", ", ixs); throw new ArgumentException($"Multiple columns '{ixsStr}' matches name '{prefix}'"); } var ix = ixs.SingleOrDefault(); if (ix == null) { return(new NullMapping(type)); } return(new SingularMapping(type, ix.Value)); } if (IsBlacklistedType(type)) { return(new NullMapping(type)); } if (!topLevel && IsEntityType(type)) { //Entity properties are not resolved return(new NullMapping(type)); } var constructors = type.GetConstructors(); if (!constructors.Any()) { return(new NullMapping(type)); } //Selects the first constructor with the most number of arguments that have a non-null mapping var(cons, consMap) = PickConstructor(constructors, prefix, columns, chain); if (consMap == null) { return(new NullMapping(type)); } var props = type.GetProperties().Where(x => x.GetSetMethod() != null); var propMap = MapProperties(props, prefix, columns, chain); //Remove property mapping of repeated constructor columns: var propMapFiltered = propMap .Where(x => !consMap.Any(cs => cs.Columns.SequenceEqual(x.Value.Columns))) .ToDictionary(x => x.Key, x => x.Value); return(new CtorMapping(cons, consMap, propMapFiltered)); }
private void UpdatePlatformVelocities() { var deltaTime = GetDeltaTime(); // move along path Entities.ForEach( (Entity entity, DynamicBuffer <PathPosition> pathPositions, ref PhysicsVelocity velocity, ref FixTranslation translation, ref MovingPlatformState state, in MoveSpeed moveSpeed, in MovingPlatformSettings settings) => { if (pathPositions.Length == 0) { velocity.Linear = fix2.zero; return; } if (HasComponent <Signal>(entity)) { Signal signal = GetComponent <Signal>(entity); if (!signal.Value) { velocity.Linear = fix2.zero; return; } } if (state.RemainingWaitTime > TimeValue.Zero) { velocity.Linear = fix2.zero; state.RemainingWaitTime -= deltaTime.GetValue(state.RemainingWaitTime.Type); return; } var pathAccessor = new PathAccessor(pathPositions, settings.MoveMode == PlatformMoveMode.Yoyo); fix actualMoveSpeed = moveSpeed.Value; if (settings.SlowDownNearNodes) { // If the platform is near the past or next node, clamp speed to smaller value fix nodeDist = sqrt(sqrt(min( lengthsq(translation.Value - pathAccessor[state.NextStep - 1]), lengthsq(translation.Value - pathAccessor[state.NextStep])))); fix maximumSpeed = MovingPlatformSettings.SLOW_DOWN_MINIMUM_SPEED + (nodeDist * MovingPlatformSettings.SLOW_DOWN_FACTOR_INV); actualMoveSpeed = min(maximumSpeed, moveSpeed.Value); } fix moveDist = actualMoveSpeed * deltaTime.Seconds.Value; fix2 a = translation.Value; fix2 b = translation.Value; fix2 v = fix2(0); fix vLength = 0; bool incrementStep = false; int beginIndex = state.NextStep % pathAccessor.Length; while (moveDist > vLength) { moveDist -= vLength; a = b; if (incrementStep) { state.NextStep++; if (beginIndex == state.NextStep % pathAccessor.Length) // if we've done a full loop, stop here. This prevents infinite while loops. { break; } if (settings.MoveMode == PlatformMoveMode.LoopTeleport && pathAccessor.IsStart(state.NextStep)) { a = pathAccessor[state.NextStep]; translation.Value = pathAccessor[state.NextStep]; state.NextStep++; } if (settings.PauseOnNodesDuration > TimeValue.Zero) { state.RemainingWaitTime = settings.PauseOnNodesDuration; } } incrementStep = true; b = pathAccessor[state.NextStep]; v = b - a; vLength = length(v); } fix2 dir = (vLength == 0 ? fix2(0) : (v / vLength)); fix2 targetPosition = a + (dir * min(moveDist, vLength)); fix2 targetVelocity = (targetPosition - translation.Value) / deltaTime.Seconds.Value; velocity.Linear = targetVelocity; }).Run();