Exemplo n.º 1
0
        public void AddComment(ExampleComment comment)
        {
            XmlDocument xml = new XmlDocument();

            if (File.Exists(path))
            {
                try
                {
                    xml.Load(path);
                }
                catch (FileNotFoundException)
                {
                    return;
                }
            }

            XmlNode root = xml.SelectSingleNode("example");

            if (root == null)
            {
                return;
            }

            XmlElement elem;
            XmlNode    commentsNode = root.SelectSingleNode("comments");

            if (commentsNode == null)
            {
                elem = xml.CreateElement("comments");
                root.AppendChild(elem);
                commentsNode = root.SelectSingleNode("comments");
            }

            elem = xml.CreateElement("comment");

            XmlAttribute attr = xml.CreateAttribute("name");

            attr.Value = comment.Name;
            elem.Attributes.Append(attr);

            attr       = xml.CreateAttribute("title");
            attr.Value = comment.Title;
            elem.Attributes.Append(attr);

            attr       = xml.CreateAttribute("time");
            attr.Value = DateTime.Now.ToString(new CultureInfo("en-US"));
            elem.Attributes.Append(attr);

            XmlElement message = xml.CreateElement("message");

            message.InnerXml = comment.Message;
            elem.AppendChild(message);

            commentsNode.AppendChild(elem);

            xml.Save(path);
        }
Exemplo n.º 2
0
        public void AddComment(ExampleComment comment)
        {
            XmlDocument xml = new XmlDocument();

            if (File.Exists(path))
            {
                try
                {
                    xml.Load(path);
                }
                catch (FileNotFoundException)
                {
                    return;
                }
            }

            XmlNode root = xml.SelectSingleNode("example");

            if (root == null)
            {
                return;
            }
            
            XmlElement elem;
            XmlNode commentsNode = root.SelectSingleNode("comments");
            if (commentsNode == null)
            {
                elem = xml.CreateElement("comments");
                root.AppendChild(elem);
                commentsNode = root.SelectSingleNode("comments");
            }

            elem = xml.CreateElement("comment");

            XmlAttribute attr = xml.CreateAttribute("name");
            attr.Value = comment.Name;
            elem.Attributes.Append(attr);

            attr = xml.CreateAttribute("title");
            attr.Value = comment.Title;
            elem.Attributes.Append(attr);

            attr = xml.CreateAttribute("time");
            attr.Value = DateTime.Now.ToString(new CultureInfo("en-US"));
            elem.Attributes.Append(attr);

            XmlElement message = xml.CreateElement("message");
            message.InnerXml = comment.Message;
            elem.AppendChild(message);

            commentsNode.AppendChild(elem);

            xml.Save(path);
        }
Exemplo n.º 3
0
        private void Load()
        {
            this.Description = "No description";
            XmlDocument xml = new XmlDocument();

            if (File.Exists(path))
            {
                try
                {
                    xml.Load(path);
                }
                catch (FileNotFoundException)
                {
                    return;
                } 
            }

            XmlNode root = xml.SelectSingleNode("example");

            if (root == null)
            {
                return;
            }

            XmlAttribute iconCls = root.Attributes["iconCls"];

            if (iconCls != null)
            {
                this.IconCls = iconCls.Value;
            }

            XmlNode desc = root.SelectSingleNode("description");

            if (desc != null)
            {
                this.Description = desc.InnerText;
            }

            XmlNodeList files = root.SelectNodes("include/file");

            if (files != null)
            {
                string url = UIHelpers.PhysicalToAbsolute(path);
                foreach (XmlNode file in files)
                {
                    XmlAttribute urlAttr = file.Attributes["url"];
                    XmlAttribute zipAttr = file.Attributes["zip"];

                    if (includeDescriptors && zipAttr != null && zipAttr.InnerText.ToLower() == "false")
                    {
                        continue;
                    }

                    if (urlAttr != null && !string.IsNullOrEmpty(urlAttr.InnerText))
                    {
                        string fileUrl = urlAttr.InnerText;
                        Uri uri = new Uri(new Uri(url, UriKind.Absolute), fileUrl);
                        this.OuterFiles.Add(HttpContext.Current.Server.MapPath(uri.AbsolutePath));

                        if (includeDescriptors && (fileUrl.EndsWith("ashx.cs") || fileUrl.EndsWith("asmx.cs")))
                        {
                            uri = new Uri(new Uri(url, UriKind.Absolute), fileUrl.Remove(fileUrl.Length - 3, 3));
                            this.OuterFiles.Add(HttpContext.Current.Server.MapPath(uri.AbsolutePath));
                        }
                    }
                }
            }

            XmlNodeList folders = root.SelectNodes("zip-folders/folder");

            if (folders != null)
            {
                string url = UIHelpers.PhysicalToAbsolute(path);
                foreach (XmlNode folder in folders)
                {
                    XmlAttribute urlAttr = folder.Attributes["url"];

                    if (urlAttr != null && !string.IsNullOrEmpty(urlAttr.InnerText))
                    {
                        string folderUrl = urlAttr.InnerText;
                        Uri uri = new Uri(new Uri(url, UriKind.Absolute), folderUrl);
                        this.ZipFolders.Add(HttpContext.Current.Server.MapPath(uri.AbsolutePath));
                    }
                }
            }

            folders = root.SelectNodes("order/folder");

            if (folders != null)
            {
                foreach (XmlNode folder in folders)
                {
                    XmlAttribute urlAttr = folder.Attributes["name"];

                    if (urlAttr != null && !string.IsNullOrEmpty(urlAttr.InnerText))
                    {
                        string folderName = urlAttr.InnerText;
                        this.OrderFolders.Add(folderName.ToLower());
                    }
                }
            }

            folders = root.SelectNodes("new/folder");

            if (folders != null)
            {
                foreach (XmlNode folder in folders)
                {
                    XmlAttribute urlAttr = folder.Attributes["name"];

                    if (urlAttr != null && !string.IsNullOrEmpty(urlAttr.InnerText))
                    {
                        string folderName = urlAttr.InnerText;
                        this.NewFolders.Add(folderName.ToLower());
                    }
                }
            }

            XmlNodeList xmlComments = root.SelectNodes("comments/comment");

            if (xmlComments != null)
            {
                foreach (XmlNode xmlComment in xmlComments)
                {
                    try
                    {
                        ExampleComment comment = new ExampleComment();

                        XmlAttribute attr = xmlComment.Attributes["name"];
                        if (attr != null && !string.IsNullOrEmpty(attr.InnerText))
                        {
                            comment.Name = HttpContext.Current.Server.HtmlEncode(attr.InnerText);
                        }

                        attr = xmlComment.Attributes["title"];
                        if (attr != null && !string.IsNullOrEmpty(attr.InnerText))
                        {
                            comment.Title = HttpContext.Current.Server.HtmlEncode(attr.InnerText);
                        }

                        attr = xmlComment.Attributes["time"];
                        if (attr != null && !string.IsNullOrEmpty(attr.InnerText))
                        {
                            comment.Time = DateTime.Parse(attr.InnerText, new CultureInfo("en-US"));
                        }

                        XmlNode message = xmlComment.SelectSingleNode("message");
                        if (message != null && !string.IsNullOrEmpty(message.InnerText))
                        {
                            comment.Message = HttpContext.Current.Server.HtmlEncode(message.InnerText);
                        }

                        this.Comments.Add(comment);
                    }
                    catch {  }
                }
            }

            XmlNode tagsNode = root.SelectSingleNode("tags");

            if (tagsNode != null)
            {
                this.Tags.AddRange(tagsNode.InnerText.Split(','));
            }
        }
Exemplo n.º 4
0
        private void Load()
        {
            this.Description = "No description";
            XmlDocument xml = new XmlDocument();

            if (File.Exists(path))
            {
                try
                {
                    xml.Load(path);
                }
                catch (FileNotFoundException)
                {
                    return;
                }
            }

            XmlNode root = xml.SelectSingleNode("example");

            if (root == null)
            {
                return;
            }

            XmlAttribute iconCls = root.Attributes["iconCls"];

            if (iconCls != null)
            {
                this.IconCls = iconCls.Value;
            }

            XmlNode desc = root.SelectSingleNode("description");

            if (desc != null)
            {
                this.Description = desc.InnerText;
            }

            XmlNodeList files = root.SelectNodes("include/file");

            if (files != null)
            {
                string url = UIHelpers.PhysicalToAbsolute(path);
                foreach (XmlNode file in files)
                {
                    XmlAttribute urlAttr = file.Attributes["url"];
                    XmlAttribute zipAttr = file.Attributes["zip"];

                    if (includeDescriptors && zipAttr != null && zipAttr.InnerText.ToLower() == "false")
                    {
                        continue;
                    }

                    if (urlAttr != null && !string.IsNullOrEmpty(urlAttr.InnerText))
                    {
                        string fileUrl = urlAttr.InnerText;
                        Uri    uri     = new Uri(new Uri(url, UriKind.Absolute), fileUrl);
                        this.OuterFiles.Add(HttpContext.Current.Server.MapPath(uri.AbsolutePath));

                        if (includeDescriptors && (fileUrl.EndsWith("ashx.cs") || fileUrl.EndsWith("asmx.cs")))
                        {
                            uri = new Uri(new Uri(url, UriKind.Absolute), fileUrl.Remove(fileUrl.Length - 3, 3));
                            this.OuterFiles.Add(HttpContext.Current.Server.MapPath(uri.AbsolutePath));
                        }
                    }
                }
            }

            XmlNodeList folders = root.SelectNodes("zip-folders/folder");

            if (folders != null)
            {
                string url = UIHelpers.PhysicalToAbsolute(path);

                foreach (XmlNode folder in folders)
                {
                    XmlAttribute urlAttr = folder.Attributes["url"];

                    if (urlAttr != null && !string.IsNullOrEmpty(urlAttr.InnerText))
                    {
                        string folderUrl = urlAttr.InnerText;
                        Uri    uri       = new Uri(new Uri(url, UriKind.Absolute), folderUrl);
                        this.ZipFolders.Add(HttpContext.Current.Server.MapPath(uri.AbsolutePath));
                    }
                }
            }

            folders = root.SelectNodes("order/folder");

            if (folders != null)
            {
                foreach (XmlNode folder in folders)
                {
                    XmlAttribute urlAttr = folder.Attributes["name"];

                    if (urlAttr != null && !string.IsNullOrEmpty(urlAttr.InnerText))
                    {
                        string folderName = urlAttr.InnerText;
                        this.OrderFolders.Add(folderName.ToLower());
                    }
                }
            }

            // This will match only new items for the current version a.b.c.
            folders = root.SelectNodes("new[@version = \"" + ExtNetVersion.WithBuild + "\"]/folder");

            if (folders != null)
            {
                foreach (XmlNode folder in folders)
                {
                    XmlAttribute urlAttr = folder.Attributes["name"];

                    if (urlAttr != null && !string.IsNullOrEmpty(urlAttr.InnerText))
                    {
                        string folderName = urlAttr.InnerText;
                        this.NewFolders.Add(folderName.ToLower());
                    }
                }
            }

            // This will match only new items for the current version a.b.c.
            folders = root.SelectNodes("updated[@version = \"" + ExtNetVersion.WithBuild + "\"]/folder");

            if (folders != null)
            {
                foreach (XmlNode folder in folders)
                {
                    XmlAttribute urlAttr = folder.Attributes["name"];

                    if (urlAttr != null && !string.IsNullOrEmpty(urlAttr.InnerText))
                    {
                        string folderName = urlAttr.InnerText;
                        this.UpdFolders.Add(folderName.ToLower());
                    }
                }
            }
            XmlNodeList xmlComments = root.SelectNodes("comments/comment");

            if (xmlComments != null)
            {
                foreach (XmlNode xmlComment in xmlComments)
                {
                    try
                    {
                        ExampleComment comment = new ExampleComment();

                        XmlAttribute attr = xmlComment.Attributes["name"];
                        if (attr != null && !string.IsNullOrEmpty(attr.InnerText))
                        {
                            comment.Name = HttpContext.Current.Server.HtmlEncode(attr.InnerText);
                        }

                        attr = xmlComment.Attributes["title"];
                        if (attr != null && !string.IsNullOrEmpty(attr.InnerText))
                        {
                            comment.Title = HttpContext.Current.Server.HtmlEncode(attr.InnerText);
                        }

                        attr = xmlComment.Attributes["time"];
                        if (attr != null && !string.IsNullOrEmpty(attr.InnerText))
                        {
                            comment.Time = DateTime.Parse(attr.InnerText, new CultureInfo("en-US"));
                        }

                        XmlNode message = xmlComment.SelectSingleNode("message");
                        if (message != null && !string.IsNullOrEmpty(message.InnerText))
                        {
                            comment.Message = HttpContext.Current.Server.HtmlEncode(message.InnerText);
                        }

                        this.Comments.Add(comment);
                    }
                    catch {  }
                }
            }

            XmlNode tagsNode = root.SelectSingleNode("tags");

            if (tagsNode != null)
            {
                this.Tags.AddRange(tagsNode.InnerText.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
            }
        }