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;
        }
Exemple #3
0
        public bool AppendHistoryItem(HistoryItem historyItem)
        {
            try
            {
                if (historyItem != null && !string.IsNullOrEmpty(historyItem.Filename) && historyItem.DateTimeUtc != DateTime.MinValue &&
                    (!string.IsNullOrEmpty(historyItem.URL) || !string.IsNullOrEmpty(historyItem.Filepath)))
                {
                    return Manager.Append(historyItem);
                }
            }
            catch (Exception e)
            {
                DebugHelper.WriteException(e);
            }

            return false;
        }
Exemple #4
0
        private IEnumerable <HistoryItem> GetHistoryItems()
        {
            if (history == null)
            {
                history = new HistoryManager(HistoryPath);
            }

            List <HistoryItem> historyItems         = history.GetHistoryItems();
            List <HistoryItem> filteredHistoryItems = new List <HistoryItem>();

            Regex regex = null;

            if (!string.IsNullOrEmpty(SearchText))
            {
                string pattern = Regex.Escape(SearchText).Replace("\\?", ".").Replace("\\*", ".*");
                regex = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
            }

            for (int i = historyItems.Count - 1; i >= 0; i--)
            {
                HistoryItem hi = historyItems[i];

                if (!string.IsNullOrEmpty(hi.Filepath) && Helpers.IsImageFile(hi.Filepath) &&
                    (regex == null || regex.IsMatch(hi.Filename)) &&
                    (!Settings.FilterMissingFiles || File.Exists(hi.Filepath)))
                {
                    filteredHistoryItems.Add(hi);

                    if (Settings.MaxItemCount > 0 && filteredHistoryItems.Count >= Settings.MaxItemCount)
                    {
                        break;
                    }
                }
            }

            UpdateTitle(historyItems.Count, filteredHistoryItems.Count);

            return(filteredHistoryItems);
        }
Exemple #5
0
        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 bool IsValidHistoryItem(HistoryItem historyItem)
 {
     return historyItem != null && !string.IsNullOrEmpty(historyItem.Filename) && historyItem.DateTimeUtc != DateTime.MinValue &&
         (!string.IsNullOrEmpty(historyItem.URL) || !string.IsNullOrEmpty(historyItem.Filepath));
 }
Exemple #7
0
        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.DateTime = 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;
        }
Exemple #8
0
 private bool IsValidHistoryItem(HistoryItem historyItem)
 {
     return(historyItem != null && !string.IsNullOrEmpty(historyItem.Filename) && historyItem.DateTime != DateTime.MinValue &&
            (!string.IsNullOrEmpty(historyItem.URL) || !string.IsNullOrEmpty(historyItem.Filepath)));
 }
 public bool AppendHistoryItem(HistoryItem historyItem)
 {
     return(AppendHistoryItems(new HistoryItem[] { historyItem }));
 }
Exemple #10
0
        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();
        }
Exemple #11
0
        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();
        }
Exemple #12
0
        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.IndexOf(host, StringComparison.InvariantCultureIgnoreCase) >= 0);
                }
            }

            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.IndexOf(filenameFilter, rule) >= 0);
                    }
                    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();
        }
Exemple #13
0
        private void UpdateTitle(HistoryItem[] historyItems = null)
        {
            string title = defaultTitle;

            if (historyItems != null)
            {
                StringBuilder status = new StringBuilder();

                status.Append(" (");
                status.AppendFormat(Resources.HistoryForm_UpdateItemCount_Total___0_, allHistoryItems.Length.ToString("N0"));

                if (allHistoryItems.Length > historyItems.Length)
                {
                    status.AppendFormat(" - " + Resources.HistoryForm_UpdateItemCount___Filtered___0_, historyItems.Length.ToString("N0"));
                }

                var types = from hi in historyItems
                            group hi by hi.Type
                            into t
                            let count = t.Count()
                            select string.Format(" - {0}: {1:N0}", t.Key, count);

                foreach (string type in types)
                {
                    status.Append(type);
                }

                status.Append(")");
                title += status.ToString();
            }

            Text = title;
        }
Exemple #14
0
        private HistoryItem[] ApplyFilters(HistoryItem[] historyItems)
        {
            if (!cbTypeFilter.Checked && !cbHostFilter.Checked && !cbFilenameFilter.Checked && !cbDateFilter.Checked)
            {
                return 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.Equals(type, StringComparison.InvariantCultureIgnoreCase));
                }
            }

            if (cbHostFilter.Checked)
            {
                string host = cbHostFilterSelection.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 filenameRule = StringComparison.CurrentCultureIgnoreCase;

                    switch (cbFilenameFilterMethod.SelectedIndex)
                    {
                        default:
                        case 0: // Contains
                            result = result.Where(x => x.Filename.Contains(filenameFilter, filenameRule));
                            break;
                        case 1: // Starts with
                            result = result.Where(x => x.Filename.StartsWith(filenameFilter, filenameRule));
                            break;
                        case 2: // Ends with
                            result = result.Where(x => x.Filename.EndsWith(filenameFilter, filenameRule));
                            break;
                        case 3: // Exact match
                            result = result.Where(x => x.Filename.Equals(filenameFilter, filenameRule));
                            break;
                    }
                }
            }

            if (cbDateFilter.Checked)
            {
                DateTime fromDate = dtpFilterFrom.Value.Date;
                DateTime toDate = dtpFilterTo.Value.Date;

                result = result.Where(x => x.DateTime.Date >= fromDate && x.DateTime.Date <= toDate);
            }

            return result.ToArray();
        }
Exemple #15
0
        private void AddHistoryItems(HistoryItem[] historyItems)
        {
            UpdateTitle(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();

                if (hi.Type.Equals("Image", StringComparison.InvariantCultureIgnoreCase))
                {
                    lvi.ImageIndex = 0;
                }
                else if (hi.Type.Equals("Text", StringComparison.InvariantCultureIgnoreCase))
                {
                    lvi.ImageIndex = 1;
                }
                else if (hi.Type.Equals("File", StringComparison.InvariantCultureIgnoreCase))
                {
                    lvi.ImageIndex = 2;
                }
                else
                {
                    lvi.ImageIndex = 3;
                }

                lvi.SubItems.Add(hi.DateTime.ToString());
                lvi.SubItems.Add(hi.Filename);
                lvi.SubItems.Add(hi.URL);
                lvi.Tag = hi;
            }

            lvHistory.Items.AddRange(listViewItems);
            lvHistory.FillLastColumn();
            lvHistory.Focus();
        }
Exemple #16
0
 public HistoryItemInfoForm(HistoryItem hi)
 {
     InitializeComponent();
     ShareXResources.ApplyTheme(this);
     pgHistoryItem.SelectedObject = hi;
 }