private void AddHistoryItems(HistoryItem[] historyItems)
        {
            UpdateItemCount(historyItems);

            lvHistory.SuspendLayout();
            lvHistory.Items.Clear();

            HistoryItem hi;

            for (int i = 0; i < historyItems.Length; i++)
            {
                hi = historyItems[i];
                ListViewItem lvi = 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.Add(lvi);
            }

            lvHistory.FillLastColumn();
            lvHistory.Focus();
            lvHistory.ResumeLayout(true);
        }
示例#2
0
 public static void AddHistoryItemAsync(string historyPath, HistoryItem historyItem)
 {
     TaskEx.Run(() =>
     {
         HistoryManager history = new HistoryManager(historyPath);
         history.AppendHistoryItem(historyItem);
     });
 }
        public static void AddHistoryItemAsync(string historyPath, HistoryItem historyItem)
        {
            WaitCallback thread = state =>
            {
                HistoryManager history = new HistoryManager(historyPath);
                history.AddHistoryItem(historyItem);
            };

            ThreadPool.QueueUserWorkItem(thread);
        }
        public bool AddHistoryItem(HistoryItem historyItem)
        {
            if (!string.IsNullOrEmpty(xmlPath))
            {
                lock (thisLock)
                {
                    XmlDocument xml = new XmlDocument();

                    if (File.Exists(xmlPath))
                    {
                        xml.Load(xmlPath);
                    }

                    if (xml.ChildNodes.Count == 0)
                    {
                        xml.AppendChild(xml.CreateXmlDeclaration("1.0", "UTF-8", null));
                        xml.AppendElement("HistoryItems");
                    }

                    XmlNode rootNode = xml.ChildNodes[1];

                    if (rootNode.Name == "HistoryItems")
                    {
                        historyItem.ID = ZAppHelper.GetRandomAlphanumeric(12);

                        XmlNode historyItemNode = rootNode.PrependElement("HistoryItem");

                        historyItemNode.AppendElement("ID", historyItem.ID);
                        historyItemNode.AppendElement("Filename", historyItem.Filename);
                        historyItemNode.AppendElement("Filepath", historyItem.Filepath);
                        historyItemNode.AppendElement("DateTimeUtc", historyItem.DateTimeUtc.ToString("o"));
                        historyItemNode.AppendElement("Type", historyItem.Type);
                        historyItemNode.AppendElement("Host", historyItem.Host);
                        historyItemNode.AppendElement("URL", historyItem.URL);
                        historyItemNode.AppendElement("ThumbnailURL", historyItem.ThumbnailURL);
                        historyItemNode.AppendElement("DeletionURL", historyItem.DeletionURL);
                        historyItemNode.AppendElement("ShortenedURL", historyItem.ShortenedURL);

                        xml.Save(xmlPath);

                        return true;
                    }
                }
            }

            return false;
        }
示例#5
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;
        }
示例#6
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();
        }
示例#7
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 void UpdateItemCount(HistoryItem[] historyItems)
        {
            StringBuilder status = new StringBuilder();

            status.Append("Total: " + allHistoryItems.Length);

            if (allHistoryItems.Length > historyItems.Length)
            {
                status.Append(", Filtered: " + 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;

                result = result.Where(x => x.Type == type);
            }

            if (cbHostFilter.Checked)
            {
                string host = txtHostFilter.Text;

                result = result.Where(x => x.Host.IndexOf(host, StringComparison.InvariantCultureIgnoreCase) >= 0);
            }

            string filenameFilter = txtFilenameFilter.Text;
            if (cbFilenameFilter.Checked && !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) // 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();
        }
示例#10
0
        private IEnumerable <HistoryItem> ParseHistoryItem(XmlNode rootNode)
        {
            foreach (XmlNode historyNode in rootNode.ChildNodes)
            {
                HistoryItem hi = new HistoryItem();

                foreach (XmlNode node in historyNode.ChildNodes)
                {
                    if (node == null || string.IsNullOrEmpty(node.InnerText))
                    {
                        continue;
                    }

                    switch (node.Name)
                    {
                    case "ID":
                        hi.ID = node.InnerText;
                        break;

                    case "Filename":
                        hi.Filename = node.InnerText;
                        break;

                    case "Filepath":
                        hi.Filepath = node.InnerText;
                        break;

                    case "DateTimeUtc":
                        hi.DateTimeUtc = DateTime.Parse(node.InnerText);
                        break;

                    case "Type":
                        hi.Type = node.InnerText;
                        break;

                    case "Host":
                        hi.Host = node.InnerText;
                        break;

                    case "URL":
                        hi.URL = node.InnerText;
                        break;

                    case "ThumbnailURL":
                        hi.ThumbnailURL = node.InnerText;
                        break;

                    case "DeletionURL":
                        hi.DeletionURL = node.InnerText;
                        break;

                    case "ShortenedURL":
                        hi.ShortenedURL = node.InnerText;
                        break;
                    }
                }

                hi.Node = historyNode;

                yield return(hi);
            }
        }
        public bool RemoveHistoryItem(HistoryItem historyItem)
        {
            xml.RemoveHistoryItem(historyItem);

            return false;
        }
示例#12
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.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 IEnumerable<HistoryItem> ParseHistoryItem(XmlNode rootNode)
        {
            foreach (XmlNode historyNode in rootNode.ChildNodes)
            {
                HistoryItem hi = new HistoryItem();

                foreach (XmlNode node in historyNode.ChildNodes)
                {
                    if (node == null || string.IsNullOrEmpty(node.InnerText)) continue;

                    switch (node.Name)
                    {
                        case "ID":
                            hi.ID = node.InnerText;
                            break;
                        case "Filename":
                            hi.Filename = node.InnerText;
                            break;
                        case "Filepath":
                            hi.Filepath = node.InnerText;
                            break;
                        case "DateTimeUtc":
                            hi.DateTimeUtc = DateTime.Parse(node.InnerText);
                            break;
                        case "Type":
                            hi.Type = node.InnerText;
                            break;
                        case "Host":
                            hi.Host = node.InnerText;
                            break;
                        case "URL":
                            hi.URL = node.InnerText;
                            break;
                        case "ThumbnailURL":
                            hi.ThumbnailURL = node.InnerText;
                            break;
                        case "DeletionURL":
                            hi.DeletionURL = node.InnerText;
                            break;
                        case "ShortenedURL":
                            hi.ShortenedURL = node.InnerText;
                            break;
                    }
                }

                hi.Node = historyNode;

                yield return hi;
            }
        }
        public bool RemoveHistoryItem(HistoryItem historyItem)
        {
            lock (thisLock)
            {
                if (historyItem != null && !string.IsNullOrEmpty(historyItem.ID) && !string.IsNullOrEmpty(xmlPath) && File.Exists(xmlPath))
                {
                    XmlDocument xml = new XmlDocument();
                    xml.Load(xmlPath);

                    XmlNode rootNode = xml.ChildNodes[1];

                    if (rootNode.Name == "HistoryItems" && rootNode.ChildNodes != null && rootNode.ChildNodes.Count > 0)
                    {
                        foreach (HistoryItem hi in ParseHistoryItem(rootNode))
                        {
                            if (hi.ID == historyItem.ID)
                            {
                                rootNode.RemoveChild(hi.Node);
                                xml.Save(xmlPath);
                                return true;
                            }
                        }
                    }
                }
            }

            return false;
        }
        public HistoryItem GenerateHistoryItem(UploadResult ur)
        {
            var hi = new HistoryItem
                         {
                             DateTimeUtc = EndTime,
                             DeletionURL = ur.DeletionURL,
                             ThumbnailURL = ur.ThumbnailURL,
                             ShortenedURL = ur.ShortenedURL,
                             URL = ur.URL,
                             Filename = Info.FileName,
                             Filepath = Info.LocalFilePath,
                             Host = ur.Host,
                             Type = Job1.GetDescription()
                         };

            return hi;
        }
        public bool RemoveHistoryItem(HistoryItem historyItem)
        {
            xml.RemoveHistoryItem(historyItem);

            return(false);
        }