public static void AddHistoryItemAsync(string historyPath, HistoryItem historyItem) { TaskEx.Run(() => { HistoryManager history = new HistoryManager(historyPath); history.AppendHistoryItem(historyItem); }); }
public bool AppendHistoryItem(HistoryItem historyItem) { try { if (IsValidHistoryItem(historyItem)) { return manager.Append(historyItem); } } catch (Exception e) { DebugHelper.WriteException(e); } return false; }
private void AddHistoryItems(HistoryItem[] historyItems) { UpdateItemCount(historyItems); lvHistory.Items.Clear(); ListViewItem[] listViewItems = new ListViewItem[historyItems.Length]; for (int i = 0; i < historyItems.Length; i++) { HistoryItem hi = historyItems[i]; ListViewItem lvi = listViewItems[i] = new ListViewItem(hi.DateTimeUtc.ToLocalTime().ToString()); lvi.SubItems.Add(hi.Filename); lvi.SubItems.Add(hi.Type); lvi.SubItems.Add(hi.Host); lvi.SubItems.Add(hi.URL); lvi.Tag = hi; } lvHistory.Items.AddRange(listViewItems); lvHistory.FillLastColumn(); lvHistory.Focus(); }
private HistoryItem ParseHistoryItem(XElement element) { HistoryItem hi = new HistoryItem(); foreach (XElement child in element.Elements()) { string name = child.Name.LocalName; switch (name) { case "Filename": hi.Filename = child.Value; break; case "Filepath": hi.Filepath = child.Value; break; case "DateTimeUtc": DateTime dateTime; if (DateTime.TryParse(child.Value, out dateTime)) { hi.DateTimeUtc = dateTime; } break; case "Type": hi.Type = child.Value; break; case "Host": hi.Host = child.Value; break; case "URL": hi.URL = child.Value; break; case "ThumbnailURL": hi.ThumbnailURL = child.Value; break; case "DeletionURL": hi.DeletionURL = child.Value; break; case "ShortenedURL": hi.ShortenedURL = child.Value; break; } } return hi; }
private bool IsValidHistoryItem(HistoryItem historyItem) { return(historyItem != null && !string.IsNullOrEmpty(historyItem.Filename) && historyItem.DateTimeUtc != DateTime.MinValue && (!string.IsNullOrEmpty(historyItem.URL) || !string.IsNullOrEmpty(historyItem.Filepath))); }
private void AddHistoryItems(HistoryItem[] historyItems) { UpdateItemCount(historyItems); lvHistory.Items.Clear(); ListViewItem[] listViewItems = new ListViewItem[historyItems.Length]; for (int i = 0; i < historyItems.Length; i++) { HistoryItem hi = historyItems[i]; ListViewItem lvi = listViewItems[i] = new ListViewItem(hi.DateTimeUtc.ToLocalTime().ToString()); lvi.SubItems.Add(hi.Filename); lvi.SubItems.Add(hi.Type); lvi.SubItems.Add(hi.Host); lvi.SubItems.Add(hi.URL); lvi.Tag = hi; } lvHistory.Items.AddRange(listViewItems); lvHistory.FillLastColumn(); lvHistory.Focus(); }
private void UpdateItemCount(HistoryItem[] historyItems) { StringBuilder status = new StringBuilder(); status.AppendFormat(Resources.HistoryForm_UpdateItemCount_Total___0_, allHistoryItems.Length); if (allHistoryItems.Length > historyItems.Length) { status.AppendFormat(", " + Resources.HistoryForm_UpdateItemCount___Filtered___0_, historyItems.Length); } var types = from hi in historyItems group hi by hi.Type into t let count = t.Count() orderby t.Key select string.Format(", {0}: {1}", t.Key, count); foreach (string type in types) { status.Append(type); } tsslStatus.Text = status.ToString(); }
private HistoryItem[] ApplyFilters(HistoryItem[] historyItems) { IEnumerable<HistoryItem> result = historyItems.AsEnumerable(); if (cbTypeFilter.Checked) { string type = cbTypeFilterSelection.Text; if (!string.IsNullOrEmpty(type)) { result = result.Where(x => !string.IsNullOrEmpty(x.Type) && x.Type == type); } } if (cbHostFilter.Checked) { string host = txtHostFilter.Text; if (!string.IsNullOrEmpty(host)) { result = result.Where(x => !string.IsNullOrEmpty(x.Host) && x.Host.Contains(host, StringComparison.InvariantCultureIgnoreCase)); } } if (cbFilenameFilter.Checked) { string filenameFilter = txtFilenameFilter.Text; if (!string.IsNullOrEmpty(filenameFilter)) { StringComparison rule = GetStringRule(); if (cbFilenameFilterMethod.SelectedIndex == 0) // Contains { result = result.Where(x => x.Filename.Contains(filenameFilter, rule)); } else if (cbFilenameFilterMethod.SelectedIndex == 1) // Starts with { result = result.Where(x => x.Filename.StartsWith(filenameFilter, rule)); } else if (cbFilenameFilterMethod.SelectedIndex == 2) // Ends with { result = result.Where(x => x.Filename.EndsWith(filenameFilter, rule)); } else if (cbFilenameFilterMethod.SelectedIndex == 3) // Exact match { result = result.Where(x => x.Filename.Equals(filenameFilter, rule)); } } } if (cbDateFilter.Checked) { DateTime fromDate = dtpFilterFrom.Value.Date; DateTime toDate = dtpFilterTo.Value.Date; result = from hi in result let date = FastDateTime.ToLocalTime(hi.DateTimeUtc).Date where date >= fromDate && date <= toDate select hi; } return result.ToArray(); }
private bool IsValidHistoryItem(HistoryItem historyItem) { return historyItem != null && !string.IsNullOrEmpty(historyItem.Filename) && historyItem.DateTimeUtc != DateTime.MinValue && (!string.IsNullOrEmpty(historyItem.URL) || !string.IsNullOrEmpty(historyItem.Filepath)); }