Beispiel #1
0
        protected void btnImport_Click(object sender, EventArgs e)
        {
            var contentType = FileUpload.PostedFile.ContentType;

            if (contentType == "application/xml" || contentType == "text/xml")
            {
                try
                {
                    string fileName = Path.Combine(Server.MapPath("UploadDocuments"), Guid.NewGuid().ToString() + ".xml");
                    FileUpload.PostedFile.SaveAs(fileName);
                    XDocument Xdoc = XDocument.Load(fileName);

                    model.Details    = XDocumentHelper.DescendantElement(Xdoc, "me");
                    model.Education  = XDocumentHelper.DescendantElement(Xdoc, "education");
                    model.Employment = XDocumentHelper.DescendantElement(Xdoc, "employment");

                    DetailsTextBox.Text    = model.Details;
                    EducationTextBox.Text  = model.Education;
                    EmploymentTextBox.Text = model.Employment;
                }
                catch (Exception)
                {
                    throw;
                }
            }
            else
            {
                lblMessage.Text = "Please upload a CV in xlm format. The type should be application/xml or text/xml ";
            }
        }
            private void interfaceXDocument()
            {
                Console.WriteLine("Writing XML > Write using XDocument Class");
                Console.WriteLine("===========");
                Console.WriteLine("1. Simple Writing Verbose");
                Console.WriteLine("2. Simple Writing");
                Console.WriteLine("3. Writing Attributes");
                Console.WriteLine("4. No Formatting");
                Console.Write("Select: ");
                var input = Console.ReadLine();

                switch (input)
                {
                case "1":
                    XDocumentHelper.GetInstance().SimpleWritingVerbose();
                    break;

                case "2":
                    XDocumentHelper.GetInstance().SimpleWriting();
                    break;

                case "3":
                    XDocumentHelper.GetInstance().WritingAttributes();
                    break;

                case "4":
                    XDocumentHelper.GetInstance().NoFormatting();
                    break;
                }
            }
Beispiel #3
0
 /// <summary>
 /// Updates the attribute with name key of element el.
 /// </summary>
 /// <param name='el'>
 /// the tag's XElement instance
 /// </param>
 /// <param name='key'>
 /// Key.
 /// </param>
 /// <param name='value'>
 /// The new value of the attribute
 /// </param>
 public void UpdateAttribute(XElement el, string key, string value)
 {
     UpdateAttribute(
         XDocumentHelper.GetAttributeCI(el.Attributes, key),
         value
         );
 }
Beispiel #4
0
        private void EnsureDocumentSettingsExists(Models.Settings settings)
        {
            if (SettingsExists() && XDocumentHelper.CanBeLoaded(ConfigurationPath))
            {
                return;
            }

            Save(settings);
        }
Beispiel #5
0
        /// <summary>
        /// Sets an attribtue value in the source code editor to the provided value string.
        /// </summary>
        /// <param name='el'>
        /// the tag's XElement instance
        /// </param>
        /// <param name='key'>
        /// Name of the attribute
        /// </param>
        /// <param name='value'>
        /// The string of the new value.
        /// </param>
        public void SetAttribtue(XElement el, string key, string value)
        {
            XAttribute attr = XDocumentHelper.GetAttributeCI(el.Attributes, key);

            if (attr == null)
            {
                InsertAttribute(el, key, value);
            }
            else if (attr.Value != value)
            {
                UpdateAttribute(attr, value);
            }
        }
        void DocumentOutlineSelectionChanged(MonoDevelop.Xml.StateEngine.XNode selNode)
        {
            if (selNode == null)
            {
                return;                 // not what we are looking for
            }
            XElement el = selNode as XElement;

            if (el == null)
            {
                return;                 // not a XML tag node
            }
            bool   isRunAtServer = false;
            string id            = string.Empty;

            //XName runatName = new XName ("runat");
            //XName idName = new XName ("id");

            foreach (XAttribute attr in el.Attributes)
            {
                if (XDocumentHelper.IsXNameEqualCI(attr.Name, "runat"))
                {
                    if (attr.Value == "server")
                    {
                        isRunAtServer = true;
                    }
                    else
                    {
                        break;
                    }
                }
                else if (XDocumentHelper.IsXNameEqualCI(attr.Name, "id"))
                {
                    id = attr.Value;
                }
            }

            if (isRunAtServer && (id != string.Empty) && (host != null))
            {
                // TODO: Add a unique field to editable nodes. the id of the node is not guaranteed to be the component's Site.Name
                IComponent selected = host.DesignerHost.GetComponent(id);

                if (selected != null)
                {
                    //var properties = TypeDescriptor.GetProperties (selected) as PropertyDescriptorCollection;

                    var selServ = host.Services.GetService(typeof(ISelectionService)) as ISelectionService;
                    selServ.SetSelectedComponents(new IComponent[] { selected });
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Persist the container's controls list matches the tag's attributes' state
        /// </summary>
        public void PersistControls()
        {
            var doc = Parse();

            foreach (XNode node in doc.XDocument.RootElement.AllDescendentElements)
            {
                if (!(node is XElement))
                {
                    continue;
                }

                var element = node as XElement;

                if (element.Name.HasPrefix || XDocumentHelper.IsRunAtServer(element))
                {
                    string id = XDocumentHelper.GetAttributeValueCI(element.Attributes, "id");

                    bool       checkDefaults;
                    IComponent comp = host.GetComponent(id);
                    if (comp == null)
                    {
                        // the tag does not have a matching component in the
                        // container so create one
                        comp = ProcessControl(element);

                        if (comp == null)
                        {
                            continue;
                        }

                        // assuming that we have an id already from the initial controls parse
                        host.Container.Add(comp, id);

                        // no need to check for defaults as we have a new component
                        checkDefaults = false;
                    }
                    else
                    {
                        // check if the tag's attributes and the component's attributes match
                        checkDefaults = true;
                    }

                    ProcessControlProperties(element, comp, checkDefaults);
                }
            }
        }
            private void interfaceXDocument()
            {
                Console.WriteLine();
                Console.WriteLine("Reading XML > Read using XDocument Class");
                Console.WriteLine("========================================");
                Console.WriteLine("1. Simple Processing");
                Console.WriteLine("2. Read Employee Nodes");
                Console.WriteLine("3. Read All Nodes");
                Console.WriteLine("4. Load XML");
                Console.WriteLine("5. Get Attributes");
                Console.WriteLine("6. Find by Attribute");
                var input = Console.ReadLine();

                switch (input)
                {
                case "1":
                    XDocumentHelper.GetInstance().UsingSimpleProcessing();
                    break;

                case "2":
                    XDocumentHelper.GetInstance().ReadEmployeeNodes();
                    break;

                case "3":
                    XDocumentHelper.GetInstance().ReadAllNodes();
                    break;

                case "4":
                    XDocumentHelper.GetInstance().LoadXml();
                    break;

                case "5":
                    XDocumentHelper.GetInstance().GetAttributes();
                    break;

                case "6":
                    XDocumentHelper.GetInstance().FindByAttribute();
                    break;
                }
            }
Beispiel #9
0
        /// <summary>
        /// Gets the control tag's XElement instance.
        /// </summary>
        /// <returns>
        /// The control tag.
        /// </returns>
        /// <param name='container'>
        /// The Xelement that contains the control's XElement instance
        /// </param>
        /// <param name='id'>
        /// Identifier of the control.
        /// </param>
        XElement GetControlTag(XElement container, string id)
        {
            XElement controlTag = null;

            foreach (XNode node in container.Nodes)
            {
                if (controlTag != null)
                {
                    break;
                }
                if (node is XElement)
                {
                    XElement el     = node as XElement;
                    string   currId = XDocumentHelper.GetAttributeValueCI(el.Attributes, "id");
                    if (XDocumentHelper.IsRunAtServer(el) && (string.Compare(currId, id, true) == 0))
                    {
                        controlTag = el;
                        break;
                    }
                    controlTag = GetControlTag(el, id);
                }
            }
            return(controlTag);
        }
Beispiel #10
0
        /// <summary>
        /// Gets the type of the html control.
        /// </summary>
        /// <returns>
        /// The html control type.
        /// </returns>
        /// <param name='el'>
        /// The supposed html control's tag XElement
        /// </param>
        private Type GetHtmlControlType(XElement el)
        {
            // query the htmlControlTags dict for the type
            string nameLowered = el.Name.Name.ToLower();

            if (!htmlControlTags.ContainsKey(nameLowered))
            {
                return(null);
            }

            Type compType = htmlControlTags[nameLowered];

            // for the input tag we have different types depending on the type attribute
            // so in the dict its type is marked with null
            if (compType == null)
            {
                string typeAttr = XDocumentHelper.GetAttributeValueCI(el.Attributes, "type");
                // get the Type depending on the type attribute
                switch (typeAttr.ToLower())
                {
                case "button":
                    compType = typeof(HtmlInputButton);
                    break;

                case "checkbox":
                    compType = typeof(HtmlInputCheckBox);
                    break;

                case "file":
                    compType = typeof(HtmlInputFile);
                    break;

                case "hidden":
                    compType = typeof(HtmlInputHidden);
                    break;

                case "image":
                    compType = typeof(HtmlInputImage);
                    break;

                case "password":
                    compType = typeof(HtmlInputPassword);
                    break;

                case "radio":
                    compType = typeof(HtmlInputRadioButton);
                    break;

                case "reset":
                    compType = typeof(HtmlInputReset);
                    break;

                case "submit":
                    compType = typeof(HtmlInputSubmit);
                    break;

                case "text":
                    compType = typeof(HtmlInputText);
                    break;
                }
            }

            return(compType);
        }
Beispiel #11
0
        /// <summary>
        /// Checks the document for control tags, creates components and adds the to the IContainer.
        /// Adds an id attributes to tags that are server controls but doesn't have an id attribute.
        /// </summary>
        void ParseControls()
        {
            // no need to serialize the document, if we add just an id attribute to a control
            suppressSerialization = true;

            // if an id tag was added the document changes
            // so we parse the document each time it does
            do
            {
                // get a fresh new AspNetParsedDocument
                var doc = Parse();

                // go through all the nodes of the document
                foreach (XNode node in doc.XDocument.RootElement.AllDescendentElements)
                {
                    // if a node is not a XElement, no need to check if it's a control
                    if (!(node is XElement))
                    {
                        continue;
                    }

                    var element = node as XElement;

                    // the controls have a tag prefix or runat="server" attribute
                    if (element.Name.HasPrefix || XDocumentHelper.IsRunAtServer(element))
                    {
                        string id = XDocumentHelper.GetAttributeValueCI(element.Attributes, "id");

                        // check the DesignContainer if a component for that node already exists
                        if (host.GetComponent(id) == null)
                        {
                            // create a component of type depending of the element
                            IComponent comp = ProcessControl(element);

                            if (comp == null)
                            {
                                continue;
                            }

                            // add id to the component, for later recognition if it has no ID attribute
                            if (String.IsNullOrEmpty(id))
                            {
                                var nameServ = host.GetService(typeof(INameCreationService)) as INameCreationService;
                                if (nameServ == null)
                                {
                                    throw new Exception("Could not obtain INameCreationService from the DesignerHost.");
                                }

                                // insert the attribute to the element
                                host.AspNetSerializer.SetAttribtue(element, "id", nameServ.CreateName(host.Container, comp.GetType()));
                                updateEditorContent.WaitOne();                                  // wait until the changes have been applied to the document
                                break;
                            }

                            // we have a control component, add it to the container
                            this.host.Container.Add(comp, id);
                            // and parse its attributes for component properties
                            ProcessControlProperties(element, comp);
                        }
                    }
                }
            } while (txtDocDirty);

            suppressSerialization = false;
        }
Beispiel #12
0
 /// <summary>
 /// Removes an attribute with name "key" from XElement "el" in the source code editor
 /// </summary>
 /// <param name='el'>
 /// the tag's XElement instance
 /// </param>
 /// <param name='key'>
 /// Name of the attribute
 /// </param>
 public void RemoveAttribute(XElement el, string key)
 {
     document.RemoveText(
         XDocumentHelper.GetAttributeCI(el.Attributes, key).Region
         );
 }
Beispiel #13
0
        /// <summary>
        /// Serializes a XNode to a HTML tag. This is a recursive method.
        /// </summary>
        /// <param name='node'>
        /// Node.
        /// </param>
        /// <param name='sb'>
        /// A string builder instance.
        /// </param>
        void SerializeNode(XNode node, StringBuilder sb)
        {
            prevTagLocation = node.Region.End;

            var element = node as XElement;

            if (element == null)
            {
                return;
            }

            string id = XDocumentHelper.GetAttributeValueCI(element.Attributes, "id");

            // Controls are runat="server" and have unique id in the Container
            if (element.Name.HasPrefix || XDocumentHelper.IsRunAtServer(element))
            {
                IComponent component = host.GetComponent(id);

                // HTML controls, doesn't need special rendering
                var control = component as Control;

                // genarete placeholder
                if (control != null)
                {
                    StringWriter   strWriter = new StringWriter();
                    HtmlTextWriter writer    = new HtmlTextWriter(strWriter);
                    control.RenderControl(writer);
                    writer.Close();
                    strWriter.Flush();
                    sb.Append(strWriter.ToString());
                    strWriter.Close();
                    if (!element.IsSelfClosing)
                    {
                        prevTagLocation = element.ClosingTag.Region.End;
                    }
                    return;
                }
            }

            // strip script tags
            if (element.Name.Name.ToLower() == "script")
            {
                return;
            }

            // the node is a html element
            sb.AppendFormat("<{0}", element.Name.FullName);

            // print the attributes
            foreach (MonoDevelop.Xml.StateEngine.XAttribute attr in element.Attributes)
            {
                string name = attr.Name.Name.ToLower();
                // strip runat and on* event attributes
                if ((name != "runat") && (name.Substring(0, 2).ToLower() != "on"))
                {
                    sb.AppendFormat(" {0}=\"{1}\"", attr.Name.FullName, attr.Value);
                }
            }

            if (element.IsSelfClosing)
            {
                sb.Append(" />");
            }
            else
            {
                sb.Append(">");

                // we are currentyl on the head tag
                // add designer content - js and css
                if (element.Name.Name.ToLower() == "head")
                {
                    sb.Append(designerContext);
                }

                if (element.Name.Name.ToLower() == "body")
                {
                    GetDesignerInitParams(sb);
                }

                // serializing the childnodes if any
                foreach (MonoDevelop.Xml.StateEngine.XNode nd in element.Nodes)
                {
                    // get the text before the openning tag of the child element
                    sb.Append(document.GetTextFromEditor(prevTagLocation, nd.Region.Begin));
                    // and the element itself
                    SerializeNode(nd, sb);
                }

                // printing the text after the closing tag of the child elements
                int lastChildEndLine   = element.Region.EndLine;
                int lastChildEndColumn = element.Region.EndColumn;

                // if the element have 1+ children
                if (element.LastChild != null)
                {
                    var lastChild = element.LastChild as MonoDevelop.Xml.StateEngine.XElement;
                    // the last child is an XML tag
                    if (lastChild != null)
                    {
                        // the tag is selfclosing
                        if (lastChild.IsSelfClosing)
                        {
                            lastChildEndLine   = lastChild.Region.EndLine;
                            lastChildEndColumn = lastChild.Region.EndColumn;
                            // the tag is not selfclosing and has a closing tag
                        }
                        else if (lastChild.ClosingTag != null)
                        {
                            lastChildEndLine   = lastChild.ClosingTag.Region.EndLine;
                            lastChildEndColumn = lastChild.ClosingTag.Region.EndColumn;
                        }
                        else
                        {
                            // TODO: the element is not closed. Warn the user
                        }
                        // the last child is not a XML element. Probably AspNet tag. TODO: find the end location of that tag
                    }
                    else
                    {
                        lastChildEndLine = element.LastChild.Region.EndLine;
                        lastChildEndLine = element.LastChild.Region.EndLine;
                    }
                }

                if (element.ClosingTag != null)
                {
                    sb.Append(document.GetTextFromEditor(new TextLocation(lastChildEndLine, lastChildEndColumn), element.ClosingTag.Region.Begin));
                    prevTagLocation = element.ClosingTag.Region.End;
                }
                else
                {
                    // TODO: the element is not closed. Warn the user
                }

                sb.AppendFormat("</{0}>", element.Name.FullName);
            }
        }