public IEnumerable <object> Sort(string columnName, IEnumerable <object> items) { if (columnName != _activeSortColumn) { items = items.OrderBy(item => item.GetType().GetProperty(columnName).GetValue(item, null)).ToList(); _isSortedAscending = true; _activeSortColumn = columnName; } else { if (_isSortedAscending) { items = items.OrderByDescending(item => item.GetType().GetProperty(columnName).GetValue(item, null)).ToList(); } else { items = items.OrderBy(item => item.GetType().GetProperty(columnName).GetValue(item, null)).ToList(); } _isSortedAscending = !_isSortedAscending; } Sorted?.Invoke(items); return(items); }
/// <summary> /// Reverses the order of the elements in the specified range. /// </summary> /// <param name="index">The zero-based starting index of the range to reverse.</param> /// <param name="count">The number of elements in the range to reverse.</param> /// <exception cref="ArgumentOutOfRangeException">index is less than 0. -or- count is less than 0.</exception> /// <exception cref="ArgumentException">index and count do not denote a valid range of elements in the list.</exception> public void Reverse(int index = 0, int?count = null) { if (!count.HasValue) { slim.EnterWriteLock(); try { list.Reverse(index, list.Count - index); } finally { slim.ExitWriteLock(); } Sorted?.Invoke(this, new EventArgs()); return; } slim.EnterWriteLock(); try { list.Reverse(index, count.Value); } finally { slim.ExitWriteLock(); } Sorted?.Invoke(this, new EventArgs()); }
public void ReOrganize() //sort the task by either duedate or creation date { if (Sorted.Equals("Due Date")) { for (int i = 0; i < Board.Columns.Count; i++) { var tasks = Board.Columns.ElementAt(i).Tasks.ToList(); tasks.Sort((x, y) => DateTime.Compare(x.DueDate, y.DueDate)); Board.Columns.ElementAt(i).Tasks = new ObservableCollection <Model.Task>(tasks. Select((c, j) => tasks[j]).ToList()); } Sorted = "Creation Date"; } else { for (int i = 0; i < Board.Columns.Count; i++) { var tasks = Board.Columns.ElementAt(i).Tasks.ToList(); tasks.Sort((x, y) => DateTime.Compare(x.CreationDate, y.CreationDate)); Board.Columns.ElementAt(i).Tasks = new ObservableCollection <Model.Task>(tasks. Select((c, j) => tasks[j]).ToList()); } Sorted = "Due Date"; } }
/// <summary> /// Sorts the elements in a range of elements in list. /// </summary> /// <param name="index">The zero-based starting index of the range to sort.</param> /// <param name="count">The length of the range to sort.</param> /// <param name="comparer">The optional comparer implementation to use when comparing elements.</param> /// <exception cref="ArgumentOutOfRangeException">index is less than 0. -or- count is less than 0.</exception> /// <exception cref="ArgumentException">index and count do not denote a valid range of elements in the list. -or- The implementation of comparer caused an error during the sort.</exception> /// <exception cref="InvalidOperationException">comparer is null, and the default comparer cannot find implementation.</exception> public void Sort(int index = 0, int?count = null, IComparer <T> comparer = null) { if (!count.HasValue) { slim.EnterWriteLock(); try { list.Sort(index, list.Count - index, comparer); } finally { slim.ExitWriteLock(); } Sorted?.Invoke(this, new EventArgs()); return; } slim.EnterWriteLock(); try { list.Sort(index, count.Value, comparer); } finally { slim.ExitWriteLock(); } Sorted?.Invoke(this, new EventArgs()); }
/// <summary> /// Raises event 'Sorted' /// </summary> protected virtual void OnSorted() { if (Sorted != null) { Sorted.Invoke(this, System.EventArgs.Empty); } }
internal void Freeze() { m_frozen = true; Sorted = m_list.OrderBy(x => x.Order).ToArray(); SortedWritable = Sorted.Where(x => x.CanGetValue).ToArray(); Required = Sorted.Where(x => x.Required).ToArray(); var memoryOffset = 0; for (var i = 0; i < Sorted.Length; i++) { var property = Sorted[i]; property.Index = i; if (property.PropertyType.IsValueType) { property.MemoryOffset = memoryOffset; memoryOffset += property.MemorySize; ValueMemorySize += property.MemorySize; } else { property.MemoryOffset = -1; property.ReferenceIndex = ReferenceCount++; } // Add naming lookup record NameTable.Add(property); } }
public override void Init() { Items.Clear(); for (int i = 0; i < 1000; i++) { Items.Add(rnd.Next(0, 1000)); } Sorted.Clear(); Sorted.AddRange(Items.OrderBy(x => x).ToArray()); }
public void Sort() { Items = Items .OrderBy(item => item.IsEmpty) .ThenByDescending(item => item.IsArmor || item.IsWeapon || item.IsJewelry) .ThenByDescending(item => item.Type?.Type) .ThenBy(item => item.Rarity?.Type) .ThenBy(item => item.Name) .ToList(); Sorted?.Invoke(this); }
public void ReLoad() //update the display board after changes { Board = new Model.Board(Controller, Email, Filter); if (Sorted.Equals("Creation Date")) { for (int i = 0; i < Board.Columns.Count; i++) { var tasks = Board.Columns.ElementAt(i).Tasks.ToList(); tasks.Sort((x, y) => DateTime.Compare(x.DueDate, y.DueDate)); Board.Columns.ElementAt(i).Tasks = new ObservableCollection <Model.Task>(tasks. Select((c, j) => tasks[j]).ToList()); } } }
/// <summary> /// Gets a list of entities ordered by given predicate. /// </summary> /// <param name="order">The column to order by.</param> /// <param name="sort">Sort direction: ASC or DESC</param> /// <param name="pageNum">Page number to select</param> /// <param name="pageSize">Number of rows to select</param> /// <returns></returns> public List <TEntity> GetEntities(Func <TEntity, object> order, Sorted sort, int pageNum, int pageSize) { var query = sort == Sorted.ASC ? _dbContext.Set <TEntity>() .OrderBy(order) .Skip((pageNum - 1) * pageSize) .Take(pageSize) : _dbContext.Set <TEntity>() .OrderByDescending(order) .Skip((pageNum - 1) * pageSize) .Take(pageSize); return(query.ToList()); }
private void buildCommandsList() { Enums = Assembly.GetAssembly(typeof(LimitOrder))?.GetTypes().Where(t => t.IsEnum). ToDictionary(x => x.ToString().Split('.').Last(), x => x); foreach (var item in Enums) { LoggerService.LogTrace(item.ToString()); } LoggerService.LogInfo("Building Commands"); // this will get us the current assembly processAssembly(Assembly.GetAssembly(typeof(CommandService))); // Maintain the sorted command list foreach (var command in Commands) { Sorted.Add(command.Key); } Sorted.Sort(); }
/// <summary> /// Reverses the order of the elements in the specified range. /// </summary> /// <param name="index">The zero-based starting index of the range to reverse.</param> /// <param name="count">The number of elements in the range to reverse.</param> /// <exception cref="ArgumentOutOfRangeException">index is less than 0. -or- count is less than 0.</exception> /// <exception cref="ArgumentException">index and count do not denote a valid range of elements in the list.</exception> public void Reverse(int index = 0, int?count = null) { if (!count.HasValue) { lock (locker) { list.Reverse(index, list.Count - index); } Sorted?.Invoke(this, new EventArgs()); return; } lock (locker) { list.Reverse(index, count.Value); } Sorted?.Invoke(this, new EventArgs()); }
/// <summary> /// Sorts the elements in a range of elements in list. /// </summary> /// <param name="index">The zero-based starting index of the range to sort.</param> /// <param name="count">The length of the range to sort.</param> /// <param name="comparer">The optional comparer implementation to use when comparing elements.</param> /// <exception cref="ArgumentOutOfRangeException">index is less than 0. -or- count is less than 0.</exception> /// <exception cref="ArgumentException">index and count do not denote a valid range of elements in the list. -or- The implementation of comparer caused an error during the sort.</exception> /// <exception cref="InvalidOperationException">comparer is null, and the default comparer cannot find implementation.</exception> public void Sort(int index = 0, int?count = null, IComparer <T> comparer = null) { if (!count.HasValue) { lock (locker) { list.Sort(index, list.Count - index, comparer); } Sorted?.Invoke(this, new EventArgs()); return; } lock (locker) { list.Sort(index, count.Value, comparer); } Sorted?.Invoke(this, new EventArgs()); }
ReplyMarkup GenerateOptionsMarkup(Strings strings) { InlineKeyboardMarkup inline = new InlineKeyboardMarkup { InlineKeyboard = new List <List <InlineKeyboardButton> >() }; if (this.pollType != EPolls.board) { inline.InlineKeyboard.Add(new List <InlineKeyboardButton> { InlineKeyboardButton.Create(String.Format(strings.GetString(Strings.StringsList.optionsPercentageNone), (PercentageBar == PercentageBars.Bars.none).ToCheck()), callbackData: "comm:percentage:none:" + chatId + ":" + pollId), InlineKeyboardButton.Create(PercentageBars.GetIconArray(PercentageBars.Bars.dots).Implode() + " " + (PercentageBar == PercentageBars.Bars.dots).ToCheck(), callbackData: "comm:percentage:dots:" + chatId + ":" + pollId), InlineKeyboardButton.Create(PercentageBars.GetIconArray(PercentageBars.Bars.thumbs).Implode() + " " + (PercentageBar == PercentageBars.Bars.thumbs).ToCheck(), callbackData: "comm:percentage:thumbs:" + chatId + ":" + pollId), }); inline.InlineKeyboard.Add(new List <InlineKeyboardButton> { InlineKeyboardButton.Create(String.Format(strings.GetString(Strings.StringsList.optionsSorted), Sorted.ToCheck()), callbackData: "comm:sorted:" + chatId + ":" + pollId), }); inline.InlineKeyboard.Add(new List <InlineKeyboardButton> { InlineKeyboardButton.Create(String.Format(strings.GetString(Strings.StringsList.optionsAppendable), Appendable.ToCheck()), callbackData: "comm:appendable:" + chatId + ":" + pollId), }); } inline.InlineKeyboard.Add(new List <InlineKeyboardButton> { InlineKeyboardButton.Create(RenderModerationEmoji() + " " + strings.GetString(Strings.StringsList.moderate), callbackData: "comm:moderate:" + chatId + ":" + pollId), }); inline.InlineKeyboard.Add(new List <InlineKeyboardButton> { InlineKeyboardButton.Create(string.Format(strings.GetString(Strings.StringsList.clone), EmojiStore.Clone), callbackData: "comm:clone:" + this.ChatId + ":" + this.PollId) }); inline.InlineKeyboard.Add(new List <InlineKeyboardButton> { InlineKeyboardButton.Create("\ud83d\udcbe " + strings.GetString(Strings.StringsList.done), callbackData: "comm:update:" + chatId + ":" + pollId) }); return(inline); }
protected void OnSorted() { Sorted?.Invoke(this, new EventArgs()); }
/// <summary> /// Raises the Sorted event. /// </summary> /// <param name="e">A SortedEventArgs that contains the event data.</param> protected virtual void OnSorted(SortedEventArgs e) { Sorted?.Invoke(this, e); }
public SortedList(Sorted sorted) { length = 0; HEAD = null; this.sorted = sorted; }
public IEnumerable <TEntity> GetAll(Expression <Func <TEntity, Boolean> > predicate, Func <TEntity, Boolean> orderby, Sorted sorted, int skip, int take) { var context = _context.Set <TEntity>(); var query = sorted == Sorted.DESCENDING ? context.Where(predicate).OrderByDescending(orderby) : context.Where(predicate).OrderBy(orderby); return(query.Skip(skip).Take(take)); }
public static IEnumerable <Disco> OrderDiscos(this IEnumerable <Disco> collection, Sorted sort) { IEnumerable <Disco> discosOrdered = null; switch (sort) { case Sorted.DEFAULT: discosOrdered = collection.OrderByDescending(item => item.IdDisco); break; case Sorted.ASC: discosOrdered = collection.OrderBy(item => item.Interprete.Interprete1); break; case Sorted.DESC: discosOrdered = collection.OrderByDescending(item => item.Interprete.Interprete1); break; case Sorted.DATE: discosOrdered = collection.OrderByDescending(item => item.Agno); break; } return(discosOrdered); }
public SortedList() { length = 0; HEAD = null; sorted = Sorted.ASC; }
public override int GetHashCode() { int hash = 1; if (HasID) { hash ^= ID.GetHashCode(); } if (HasMethod) { hash ^= Method.GetHashCode(); } if (HasPath) { hash ^= Path.GetHashCode(); } if (HasVal) { hash ^= Val.GetHashCode(); } if (HasDir) { hash ^= Dir.GetHashCode(); } if (HasPrevValue) { hash ^= PrevValue.GetHashCode(); } if (HasPrevIndex) { hash ^= PrevIndex.GetHashCode(); } if (HasPrevExist) { hash ^= PrevExist.GetHashCode(); } if (HasExpiration) { hash ^= Expiration.GetHashCode(); } if (HasWait) { hash ^= Wait.GetHashCode(); } if (HasSince) { hash ^= Since.GetHashCode(); } if (HasRecursive) { hash ^= Recursive.GetHashCode(); } if (HasSorted) { hash ^= Sorted.GetHashCode(); } if (HasQuorum) { hash ^= Quorum.GetHashCode(); } if (HasTime) { hash ^= Time.GetHashCode(); } if (HasStream) { hash ^= Stream.GetHashCode(); } if (HasRefresh) { hash ^= Refresh.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public Task <IAsyncEnumerable <TEntity> > GetAllAsync(Expression <Func <TEntity, bool> > predicate, Func <TEntity, bool> orderby, Sorted sorted, int skip, int take) { var context = _context.Set <TEntity>(); var query = sorted == Sorted.DESCENDING ? context.Where(predicate).OrderByDescending(orderby).Skip(skip).Take(take) : context.Where(predicate).OrderBy(orderby).Skip(skip).Take(take); return(Task.FromResult(query.ToAsyncEnumerable())); }
public IEnumerable <T> GetAll(Expression <Func <T, bool> > predicate, Func <T, bool> orderby, Sorted sorted, int skip, int take) { return(_repository.GetAll(predicate, orderby, sorted, skip, take)); }
public async Task <IAsyncEnumerable <T> > GetAllAsync(Expression <Func <T, bool> > predicate, Func <T, bool> orderby, Sorted sorted, int skip, int take) { return(await _repository.GetAllAsync(predicate, orderby, sorted, skip, take)); }
public IEnumerable <TEntity> GetAll(int skip, int take, Func <TEntity, object> orderByPredicate, Expression <Func <TEntity, bool> > filterPredicate, Sorted sort = Sorted.ASC) { var query = sort == Sorted.ASC ? //Sorted is enum InMemory.Set <TEntity>().OrderBy(orderByPredicate).Skip(skip).Take(take) : InMemory.Set <TEntity>().OrderByDescending(orderByPredicate).Skip(skip).Take(take); return(query); }