Пример #1
0
        /// <summary>
        /// Creates textboxes with labels
        /// TODO: textboxes are not copy-pastable, not even selectable
        /// </summary>
        /// <param name="element">Module element</param>
        /// <returns></returns>
        public bool SetContent(HtmlAgilityPack.HtmlNode element)
        {
            // Save element (<div class='modulecontainer'><module ....)
            this.activeElem = element;

            // Create module
            module = CXMLParser.Instance.GetModuleFromNode(element.FirstChild);

            // Clear Properties
            tableLayoutPanel1.Controls.Clear();
            tableLayoutPanel1.RowStyles.Clear();
            textboxList.Clear();

            // Create row for each setup_ property in moduleSetup class
            int row = 0;
            foreach (HtmlAgilityPack.HtmlAttribute attribute in element.FirstChild.Attributes)
            {
                if (attribute.Name.Length > 6 && attribute.Name.StartsWith("setup_"))
                {

                    tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 30));

                    Label label = new Label();
                    label.Text = attribute.Name.Substring(6);
                    tableLayoutPanel1.Controls.Add(label, 0, row);

                    TextBox textbox = new TextBox();
                    textbox.Width = 200;
                    textbox.Name = attribute.Name;
                    textbox.Text = attribute.Value;
                    textbox.KeyDown += new KeyEventHandler(textbox_KeyDown);
                    textboxList.Add(textbox);
                    tableLayoutPanel1.Controls.Add(textbox, 1, row++);
                }
            }

            this.Text = element.FirstChild.Attributes["name"].Value + " properties";
            return true;
        }
Пример #2
0
        /// <summary>
        /// Creates XML string from instance of module
        /// </summary>
        /// <param name="module">Module</param>
        /// <returns>XML Node of module</returns>
        public HtmlNode GetNodeFromModule(AModule module)
        {
            Type moduleType = module.GetType();
            Type setupType = module.setup.GetType();

            // Create root node
            String moduleName = (String)moduleType.GetField("name", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy).GetValue(null);

            HtmlDocument htmlDoc = new HtmlDocument();
            HtmlNode node = htmlDoc.CreateElement("module");

            // Save all setup_* members to attributes
            MemberInfo[] setupMembers = setupType.GetMember("setup_*", BindingFlags.Public | BindingFlags.Instance);
            foreach (MemberInfo setupMember in setupMembers)
            {
                HtmlAttribute attribute = htmlDoc.CreateAttribute(setupMember.Name);
                attribute.Value = (String)setupType.InvokeMember(setupMember.Name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty, null, module.setup, null);
                node.Attributes.Append(attribute);
            }

            // Save name(type) of module
            HtmlAttribute nameAttr = htmlDoc.CreateAttribute("name");
            nameAttr.Value = moduleName;
            node.Attributes.Append(nameAttr);

            // Save position as attr
            Rectangle location = (Rectangle)setupType.GetField("location", BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy).GetValue(module.setup);
            HtmlAttribute locationAttr = htmlDoc.CreateAttribute("location");
            RectangleConverter converter = new RectangleConverter();
            locationAttr.Value = converter.ConvertToString(location);
            node.Attributes.Append(locationAttr);

            return node;
        }