public Task LoadAsync(CancellationToken token = new CancellationToken()) { if (IsLoading) { return(_loadingTask); } timer.Start(); token.Register(() => { ResetState(); _synchronizationContext.Send(SetCount, 0); } ); IsLoading = true; if (_collection != null) { _collection.Clear(); } _synchronizationContext.Send(SetCount, 0); return(_loadingTask = Task.Run(() => { try { _collection = _provider.GetItems(_progress, token); } catch (Exception ex) { OnLoadingError(ex); _synchronizationContext.Send(SetCount, 0); return; } _synchronizationContext.Send(LoadCompleted, _collection.Count); }, token)); }
private List <LogLine> GetLines() { var result = new List <LogLine>(); string[] lines; try { using (var fileStream = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (var streamReader = new StreamReader(fileStream, Encoding.GetEncoding(1251))) { var log = streamReader.ReadToEnd(); lines = log.Split(new[] { Environment.NewLine, "\n" }, StringSplitOptions.None); } } } catch (SystemException ex) { Logger.Error(ex.Message); return(result); } LogLine previousLine = null; int lastIndex = lines.Length - 1; var columnsCount = Mapping.Columns.Count; for (int i = 0; i <= lastIndex; i++) { var line = lines[i]; if (i == lastIndex && string.IsNullOrEmpty(line)) { break; } var items = _itemsProvider.GetItems(line); if (items.Count == columnsCount) { previousLine = new LogLine(i, Mapping, items, previousLine); result.Add(previousLine); } else { if (previousLine != null) { if (!Mapping.IgnoreEmptyLines || !string.IsNullOrEmpty(line)) { previousLine.AppendMessage(line); } } else { previousLine = new LogLine(i, line); result.Add(previousLine); } } } return(result); }
/// <summary> /// Gets the page from the item provider. /// </summary> /// <param name="pageIndex"></param> /// <returns></returns> protected IList <T> FetchPage(int pageIndex) { IList <T> page = new List <T>(); foreach (T item in _itemsProvider.GetItems(pageIndex * PageSize, PageSize)) { page.Add(item); } return(page); }