private void DictionarySort(SortStatus status) { switch (status) { case SortStatus.SortByIdAscend: DefList.ItemsSource = dictionary.OrderBy(i => i.id).ToList(); sortStatus = SortStatus.SortByIdAscend; break; case SortStatus.SortByIdDescend: DefList.ItemsSource = dictionary.OrderByDescending(i => i.id).ToList(); sortStatus = SortStatus.SortByIdDescend; break; case SortStatus.SortByHindiAscend: DefList.ItemsSource = dictionary.OrderBy(i => i.term).ToList(); sortStatus = SortStatus.SortByHindiAscend; break; case SortStatus.SortByHindiDescend: DefList.ItemsSource = dictionary.OrderByDescending(i => i.term).ToList(); sortStatus = SortStatus.SortByHindiDescend; break; case SortStatus.SortByDefAscend: DefList.ItemsSource = dictionary.OrderBy(i => i.definition).ToList(); sortStatus = SortStatus.SortByDefAscend; break; case SortStatus.SortByDefDescend: DefList.ItemsSource = dictionary.OrderByDescending(i => i.definition).ToList(); sortStatus = SortStatus.SortByDefDescend; break; } }
static public void Init() { SortingTimerInit(sortingTime); sortStatus = SortStatus.Stoping; workingStack = null; waitingStackSeqList = new List <StackSeq> { }; outListBox = new List <string> { }; }
private void Write( IFileWriter fileWriter, GroupedItem <T>[] block ) { _Status = SortStatus.Writing; foreach (var item in block) { fileWriter.WriteLine(Serialize(item)); } }
static public void ClearAll() { lock (lockObject) { workingStack = null; waitingStackSeqList.Clear(); outListBox.Clear(); sortStatus = SortStatus.Stoping; SortingTimerStop(); Log.log.Info("Clear all"); } }
/// <summary> /// Indicates whether sorting is enabled for the specified cell. /// </summary> /// <param name="e">The <see cref="Fr.Medit.MedDataGrid.PositionEventArgs"/> instance containing the event data.</param> /// <returns> /// <c>true</c> if is sort enabled for the specified cell; otherwise, <c>false</c>. /// </returns> private bool IsSortEnable(PositionEventArgs e) { if (e.Cell is ICellSortableHeader && doEnableSort) { ICellSortableHeader sortableHeaderCell = (ICellSortableHeader)e.Cell; SortStatus sortStatus = sortableHeaderCell.GetSortStatus(e.Position); return(sortStatus.EnableSort); } else { return(false); } }
/// <summary> /// Indicates if for the specified cell the sort is enabled. /// </summary> /// <param name="e"></param> /// <returns></returns> public bool IsSortEnable(PositionEventArgs e) { if (e.Cell is ICellSortableHeader && m_bEnableSort) { ICellSortableHeader l_tmp = (ICellSortableHeader)e.Cell; SortStatus l_Status = l_tmp.GetSortStatus(e.Position); return(l_Status.EnableSort); } else { return(false); } }
/// <summary> /// Handles the click event on the current cell /// </summary> /// <param name="e">The <see cref="Fr.Medit.MedDataGrid.PositionEventArgs"/> instance containing the event data.</param> public override void OnClick(PositionEventArgs e) { base.OnClick(e); if (IsSortEnable(e) && (resize == null || (resize.IsHeightResizing == false && resize.IsWidthResizing == false))) { ICellSortableHeader sortableHeaderCell = (ICellSortableHeader)e.Cell; SortStatus sortStatus = sortableHeaderCell.GetSortStatus(e.Position); if (sortStatus.EnableSort) { SortColumn(e, sortStatus.Mode != GridSortMode.Ascending, sortStatus.Comparer); } } }
private GroupedItem <T>[] SortBlock(GroupedItem <T>[] block) { _Status = SortStatus.Sorting; if (_sortStrategy.IsSorted(block)) { return(block); } block = _sortStrategy.Sort(block); _BlocksSorted++; return(block); }
private GroupedItem <T>[] MergeBlocks( IFileWriter fileWriter, int blockSize, GroupedItem <T>[] left, GroupedItem <T>[] right ) { _Status = SortStatus.Merging; if (left.Length == 0) { return(right); } if (right.Length == 0) { return(left); } if ( _comparer.Compare(left[0], left[left.Length - 1]) == 0 && _comparer.Compare(right[0], right[right.Length - 1]) == 0 ) { if (_comparer.Compare(left[left.Length - 1], right[0]) <= 0) { Write(fileWriter, right); _BlocksMerged += 2; return(left); } Write(fileWriter, left); _BlocksMerged += 2; return(right); } left = _sortStrategy.Merge(left, right); _BlocksMerged += 2; Write(fileWriter, left.Skip(blockSize).ToArray()); return(left.Take(blockSize).ToArray()); }
private void Init( string inputPath, string outputPath ) { _fileAdapter.CleanSortTrash(inputPath, outputPath); _Watch = new Stopwatch(); _Watch.Start(); _Status = SortStatus.StandBy; _PassesMade = 0; _Done = false; ResetProgressMarkers(); }
/// <summary> /// Draw the image and the displaystring of the specified cell. /// </summary> /// <param name="p_Cell"></param> /// <param name="p_CellPosition"></param> /// <param name="e">Paint arguments</param> /// <param name="p_ClientRectangle">Rectangle position where draw the current cell, relative to the current view,</param> /// <param name="p_Status"></param> protected override void DrawCell_ImageAndText(SourceGrid2.Cells.ICellVirtual p_Cell, Position p_CellPosition, PaintEventArgs e, Rectangle p_ClientRectangle, DrawCellStatus p_Status) { base.DrawCell_ImageAndText(p_Cell, p_CellPosition, e, p_ClientRectangle, p_Status); if (p_Cell is ICellSortableHeader) { ICellSortableHeader l_Header = (ICellSortableHeader)p_Cell; SortStatus l_Status = l_Header.GetSortStatus(p_CellPosition); if (l_Status.Mode == GridSortMode.Ascending) { Utility.PaintImageAndText(e.Graphics, p_ClientRectangle, CommonImages.SortUp, ContentAlignment.MiddleRight, false, null, null, false, Border, Color.Black, null); } else if (l_Status.Mode == GridSortMode.Descending) { Utility.PaintImageAndText(e.Graphics, p_ClientRectangle, CommonImages.SortDown, ContentAlignment.MiddleRight, false, null, null, false, Border, Color.Black, null); } } }
private GroupedItem <T>[] Group( IEnumerable <string> block ) { _Status = SortStatus.Grouping; return (block .AsParallel() .GroupBy(x => x) .Select(g => new GroupedItem <T> { Count = g.Count(), Item = _lineParser.Parse(g.FirstOrDefault()) } ).ToArray()); }
private void WriteUngrouped( IFileWriter fileWriter, GroupedItem <T>[] block ) { _Status = SortStatus.Writing; var unparsed = block .Select(x => new GroupedItem <string> { Count = x.Count, Item = _lineParser.Unparse(x.Item) }); foreach (var item in unparsed) { for (var i = 0; i < item.Count; i++) { fileWriter.WriteLine(item.Item); } } }
public override void OnClick(PositionEventArgs e) { base.OnClick(e); //eseguo il sort solo se non sono attualmente in resize if (IsSortEnable(e) && (m_Resize == null || (m_Resize.IsHeightResizing == false && m_Resize.IsWidthResizing == false))) { ICellSortableHeader l_tmp = (ICellSortableHeader)e.Cell; SortStatus l_Status = l_tmp.GetSortStatus(e.Position); if (l_Status.EnableSort) { if (l_Status.Mode == GridSortMode.Ascending) { SortColumn(e, false, l_Status.Comparer); } else { SortColumn(e, true, l_Status.Comparer); } } } }
/// <summary> /// Obsługa przełączenia sortowania. /// </summary> private void btnSort_Click(object sender, RoutedEventArgs e) { switch (sortStatus) { case SortStatus.NoSort: sortStatus = SortStatus.SortowanieUp; this.iconSort.Kind = MaterialDesignThemes.Wpf.PackIconKind.SortAscending; break; case SortStatus.SortowanieUp: sortStatus = SortStatus.SortowanieDown; this.iconSort.Kind = MaterialDesignThemes.Wpf.PackIconKind.SortDescending; break; case SortStatus.SortowanieDown: sortStatus = SortStatus.NoSort; this.iconSort.Kind = MaterialDesignThemes.Wpf.PackIconKind.Sort; break; default: break; } _ = ShowBrowse(); }
private void RunFileSortTask( string sourcepath, string inputPath, string outputPath, int bufferSize, int blockSize ) { Task.Factory.StartNew(() => { try { SortFile( sourcepath, inputPath, outputPath, bufferSize, blockSize ); } catch (Exception ex) { _progress.Report( new SortProgress { Exception = ex }); _Status = SortStatus.Cleaning; _fileAdapter.CleanSortTrash(inputPath, outputPath); _Done = true; _Status = SortStatus.StandBy; } }); }
static public void Stop() { Log.log.Info("Stop sorting"); sortStatus = SortStatus.Stoping; SortingTimerStop(); }
public NodeSortResult(SolvingNode[] order, SolvingNode[] refs, SortStatus status) { Order = order; Refs = refs; Status = status; }
private void SortFile( string sourcepath, string inputPath, string outputPath, int bufferSize, int blockSize ) { var bufferPath = $"{sourcepath}.{_PassesMade}"; _fileAdapter.Delete(bufferPath); var inputfileFileReader = _fileReader.CreateInstance(); var bufferFileWriter = _fileWriter.CreateInstance(); var outputFileWriter = _fileWriter.CreateInstance(); try { if (_fileAdapter.GetFileInfo(inputPath).Length == 0) { if (_PassesMade > 0) { _Status = SortStatus.Cleaning; _fileAdapter.Delete(inputPath); } _Done = true; return; } _Status = SortStatus.Cleaning; GC.Collect(); inputfileFileReader.BeginRead(inputPath, bufferSize); bufferFileWriter.BeginWrite(bufferPath, bufferSize); outputFileWriter.BeginWrite(outputPath, bufferSize); outputFileWriter.StreamWriter.BaseStream.Position = outputFileWriter.StreamWriter.BaseStream.Length; var output = new GroupedItem <T> [0]; long readLength = 0; long totalLength = inputfileFileReader.StreamReader.BaseStream.Length; _Status = SortStatus.Reading; foreach (var block in inputfileFileReader.ReadBlock(blockSize)) { readLength += block.Sum(x => x.Length + Environment.NewLine.Length); _RowsRed += block.Count(); _RedPercent = (int)(readLength / (double)totalLength * 100); var grouped = new GroupedItem <T> [0]; var sanitized = block.Select(x => Sanitize(x)); if (_PassesMade == 0) { grouped = Group(sanitized); } else { grouped = Deserialize(sanitized); } var sorted = SortBlock(grouped); output = MergeBlocks( bufferFileWriter, blockSize, output, sorted ); _Status = SortStatus.Reading; } WriteUngrouped(outputFileWriter, output); inputfileFileReader.EndRead(); bufferFileWriter.EndWrite(); outputFileWriter.EndWrite(); if (_PassesMade > 0) { _Status = SortStatus.Cleaning; _fileAdapter.Delete(inputPath); } _PassesMade++; ResetProgressMarkers(); RunFileSortTask( sourcepath, bufferPath, outputPath, bufferSize, blockSize ); } finally { inputfileFileReader.EndRead(); bufferFileWriter.EndWrite(); outputFileWriter.EndWrite(); } }
static public void Start() { Log.log.Info("Start sorting"); sortStatus = SortStatus.Working; CheckStackSeq(); }