Exemple #1
0
        public bool RemoveHistoryItemOld(HistoryItemOld HistoryItemOld)
        {
            lock (thisLock)
            {
                if (HistoryItemOld != null && !string.IsNullOrEmpty(HistoryItemOld.ID) && !string.IsNullOrEmpty(xmlPath) && File.Exists(xmlPath))
                {
                    XmlDocument xml = new XmlDocument();
                    xml.Load(xmlPath);

                    XmlNode rootNode = xml.ChildNodes[1];

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

            return(false);
        }
Exemple #2
0
        public bool AddHistoryItemOld(HistoryItemOld HistoryItemOld)
        {
            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("HistoryItemOlds");
                    }

                    XmlNode rootNode = xml.ChildNodes[1];

                    if (rootNode.Name == "HistoryItemOlds")
                    {
                        HistoryItemOld.ID = Helpers.GetRandomAlphanumeric(12);

                        XmlNode HistoryItemOldNode = rootNode.PrependElement("HistoryItemOld");

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

                        xml.Save(xmlPath);

                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #3
0
        public bool AddHistoryItemOld(HistoryItemOld HistoryItemOld)
        {
            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("HistoryItemOlds");
                    }

                    XmlNode rootNode = xml.ChildNodes[1];

                    if (rootNode.Name == "HistoryItemOlds")
                    {
                        HistoryItemOld.ID = Helpers.GetRandomAlphanumeric(12);

                        XmlNode HistoryItemOldNode = rootNode.PrependElement("HistoryItemOld");

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

                        xml.Save(xmlPath);

                        return true;
                    }
                }
            }

            return false;
        }
Exemple #4
0
        private IEnumerable <HistoryItemOld> ParseHistoryItemOld(XmlNode rootNode)
        {
            foreach (XmlNode historyNode in rootNode.ChildNodes)
            {
                HistoryItemOld hi = new HistoryItemOld();

                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);
            }
        }
Exemple #5
0
        private IEnumerable<HistoryItemOld> ParseHistoryItemOld(XmlNode rootNode)
        {
            foreach (XmlNode historyNode in rootNode.ChildNodes)
            {
                HistoryItemOld hi = new HistoryItemOld();

                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;
            }
        }
Exemple #6
0
        public bool RemoveHistoryItemOld(HistoryItemOld HistoryItemOld)
        {
            lock (thisLock)
            {
                if (HistoryItemOld != null && !string.IsNullOrEmpty(HistoryItemOld.ID) && !string.IsNullOrEmpty(xmlPath) && File.Exists(xmlPath))
                {
                    XmlDocument xml = new XmlDocument();
                    xml.Load(xmlPath);

                    XmlNode rootNode = xml.ChildNodes[1];

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

            return false;
        }