/// <summary> /// Returns a path segment enumerator starting with the specified <see cref="UserPartition"/>. /// </summary> /// <param name="partition">Starting <see cref="UserPartition"/> of the enumerator</param> /// <returns>An <see cref="IEnumerable{IPathSegment}"/> instance.</returns> /// <remarks> /// <para>Each <see cref="IPathSegment"/> of the enumerator will be a <see cref="PartitionPathSegment"/> /// instance wrapping a <see cref="UserPartition"/>. /// </para> /// <para> /// The enumerator will start at the user partition specified by <paramref name="partition"/>. /// </para> /// </remarks> /// <example> /// This code example enumerates over all the user partition starting with a given starting partition. /// <code> /// foreach (IPathSegment seg in path.GetEnumeratorFrom(startingPartition) { /// PartitionPathSegment partitionSeg = (PartitionPathSegment)seg; /// Debug.WriteLine("user parition id: + " + partitionSeg.UserPartition.PartitionID.ToString()); /// Debug.WriteLine("start: " + seg.Start.ToString() + ", end: " + seg.End.ToString()); /// } /// </code> /// </example> public IEnumerable <IPathSegment> GetEnumeratorFrom(UserPartition partition) { // enumerate over the first segment IConnectWaypoints parent = partition.ParentPartition; for (int i = parent.UserPartitions.IndexOf(partition); i < parent.UserPartitions.Count; i++) { yield return(GetPathSegment(parent.UserPartitions[i])); } }
/// <summary> /// Returns the index of the specified segment. /// </summary> /// <param name="item">Segment to look for.</param> /// <returns> /// Zero-based index of segment if found, -1 if not found. /// </returns> public int IndexOf(IPathSegment item) { PartitionPathSegment laneSeg = item as PartitionPathSegment; if (laneSeg == null) { return(-1); } UserPartition partition = laneSeg.UserPartition; return(partition.ParentPartition.UserPartitions.IndexOf(partition)); }
/// <summary> /// Returns a path segment enumerator starting after the specified <see cref="UserPartition"/>. /// </summary> /// <param name="partition">Starting <see cref="UserPartition"/> of the enumerator</param> /// <returns>An <see cref="IEnumerable{IPathSegment}"/> instance.</returns> /// <remarks> /// <para>Each <see cref="IPathSegment"/> of the enumerator will be a <see cref="PartitionPathSegment"/> /// instance wrapping a <see cref="UserPartition"/>. /// </para> /// <para> /// The enumerator will start after the user partition specified by <paramref name="partition"/>. /// </para> /// </remarks> /// <example> /// This code example enumerates over all the user partitions after a given starting partition. /// <code> /// foreach (IPathSegment seg in path.GetEnumeratorAfter(startingPartition) { /// PartitionPathSegment partitionSeg = (PartitionPathSegment)seg; /// Debug.WriteLine("user parition id: + " + partitionSeg.UserPartition.PartitionID.ToString()); /// Debug.WriteLine("start: " + seg.Start.ToString() + ", end: " + seg.End.ToString()); /// } /// </code> /// </example> public IEnumerable <IPathSegment> GetEnumeratorAfter(UserPartition partition) { bool first = true; foreach (IPathSegment seg in GetEnumeratorFrom(partition)) { if (first) { first = false; } else { yield return(seg); } } }
/// <summary> /// Gets the segment at the specified index. /// </summary> /// <param name="index">The zero-based index of the element to get or set.</param> /// <returns>The element at the specified index.</returns> /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is not a valid index in the list.</exception> /// <exception cref="NotSupportedException">Throw when attempting to set the property.</exception> public IPathSegment this[int index] { get { foreach (LanePartition lanePartition in lane.LanePartitions) { if (lanePartition.UserPartitions.Count >= index) { index -= lanePartition.UserPartitions.Count; } else { UserPartition userPartition = lanePartition.UserPartitions[index]; return(GetPathSegment(userPartition)); } } throw new ArgumentOutOfRangeException(); } set { throw new NotSupportedException(); } }
/// <summary> /// Returns the index of the specified segment. /// </summary> /// <param name="item">Segment to look for.</param> /// <returns> /// Zero-based index of segment if found, -1 if not found. /// </returns> public int IndexOf(IPathSegment item) { PartitionPathSegment laneSeg = item as PartitionPathSegment; if (laneSeg == null) { return(-1); } UserPartition partition = laneSeg.UserPartition; LanePartition lanePartition = partition.ParentPartition as LanePartition; Debug.Assert(lanePartition.Lane.Equals(lane)); int index = partition.ParentPartition.UserPartitions.IndexOf(partition); int laneIndex = lanePartition.Lane.LanePartitions.IndexOf(lanePartition); while (--laneIndex > 0) { index += lane.LanePartitions[laneIndex].UserPartitions.Count; } return(index); }
/// <summary> /// Returns a path segment enumerator starting with the specified <see cref="UserPartition"/>. /// </summary> /// <param name="partition">Starting <see cref="UserPartition"/> of the enumerator</param> /// <returns>An <see cref="IEnumerable{IPathSegment}"/> instance.</returns> /// <remarks> /// <para>Each <see cref="IPathSegment"/> of the enumerator will be a <see cref="PartitionPathSegment"/> /// instance wrapping a <see cref="UserPartition"/>. /// </para> /// <para> /// The enumerator will start at the user partition specified by <paramref name="partition"/>. /// </para> /// </remarks> /// <example> /// This code example enumerates over all the user partition starting with a given starting partition. /// <code> /// foreach (IPathSegment seg in path.GetEnumeratorFrom(startingPartition) { /// PartitionPathSegment partitionSeg = (PartitionPathSegment)seg; /// Debug.WriteLine("user parition id: + " + partitionSeg.UserPartition.PartitionID.ToString()); /// Debug.WriteLine("start: " + seg.Start.ToString() + ", end: " + seg.End.ToString()); /// } /// </code> /// </example> public IEnumerable <IPathSegment> GetEnumeratorFrom(UserPartition partition) { // enumerate over the first segment LanePartition lanePartition = partition.ParentPartition as LanePartition; if (lanePartition == null) { throw new InvalidOperationException(); } for (int i = lanePartition.UserPartitions.IndexOf(partition); i < lanePartition.UserPartitions.Count; i++) { yield return(GetPathSegment(lanePartition.UserPartitions[i])); } // enumerate over the later lane partitions for (int i = lane.LanePartitions.IndexOf(lanePartition) + 1; i < lane.LanePartitions.Count; i++) { foreach (UserPartition userPartition in lane.LanePartitions[i].UserPartitions) { yield return(GetPathSegment(userPartition)); } } }
public static User CreateInstance(string userName, string mobile, string email, string password, string nickName, string operatedBy, UserPartition partition = UserPartition.JianPing, UserChannel channel = UserChannel.JianPingApp) { var now = DateTime.Now; return(new User { Mobile = mobile, Channel = channel, CreatedBy = operatedBy, CreatedOn = now, Email = email, NickName = nickName, Partition = partition, Password = SecretProvider.EncryptToMD5(password), UpdatedBy = operatedBy, UpdatedOn = now, UserName = userName, IsSuspend = false }); }
/// <summary> /// Returns a <see cref="PartitionPathSegment"/> instance constructed from the given <see cref="UserPartition"/>. /// </summary> /// <param name="partition"><see cref="UserPartition"/> instance to construct the segment with</param> /// <returns><see cref="PartitionPathSegment"/> instance referencing <paramref name="partition"/>.</returns> private PartitionPathSegment GetPathSegment(UserPartition partition) { return(new PartitionPathSegment(partition.InitialWaypoint.Position, partition.FinalWaypoint.Position, partition)); }
internal PartitionPathSegment(Coordinates start, Coordinates end, UserPartition partition) : base(start, end) { this.partition = partition; }