Beispiel #1
0
        //------------------------------------------------------------------
        public bool UpdateSite(SiteEntity site)
        {
            bool        res       = false;
            XmlNodeList nodesList = XmlDoc.SelectNodes("/sites/Site[@ID='" + site.ID + "']");

            if (nodesList.Count == 1)
            {
                XmlElement oldSiteNode = (XmlElement)nodesList[0];
                oldSiteNode.Attributes.RemoveAll();
                PopulateXmlNodeFromSite(site, oldSiteNode);
                XmlDoc.Save(sitesConfigpath);
                res = true;
            }
            return(res);
        }
Beispiel #2
0
        public bool AddSite(SiteEntity site)
        {
            bool        res      = false;
            XmlNodeList nodeList = XmlDoc.SelectNodes("/sites/Site[@ID='" + site.ID + "']");

            if (nodeList.Count == 0)
            {
                //-----------------------------------------------------------------
                XmlElement xmlNewSite = XmlDoc.CreateElement("Site");
                xmlNewSite = PopulateXmlNodeFromSite(site, xmlNewSite);
                XmlNode commonParent = XmlDoc.SelectSingleNode("/Sites");
                commonParent.AppendChild(xmlNewSite);
                XmlDoc.Save(sitesConfigpath);
                ////-----------------------------------------------------------------
                res = true;
            }
            return(res);
        }
Beispiel #3
0
        //-----------------------------------------------------------------
        #region -----------------PopulateSiteFromXmlNode-----------------
        //-----------------------------------------------------------------
        private SiteEntity PopulateSiteFromXmlNode(XmlNode node)
        {
            SiteEntity site = new SiteEntity();

            /****************************************************/
            //find all the public properties of list Type using reflection
            PropertyInfo[] piT = typeof(SiteEntity).GetProperties();
            // Get the Type object corresponding to MyClass.
            Type         myType = typeof(SiteEntity);
            PropertyInfo myPropInfo;
            string       exceptions = "";

            foreach (XmlAttribute attr in node.Attributes)
            {
                try
                {
                    myPropInfo = myType.GetProperty(attr.Name);
                    if (myPropInfo.CanWrite)
                    {
                        if (myPropInfo.PropertyType.BaseType == typeof(System.Enum))
                        {
                            //int intVal = Convert.ToInt32(attr.Value);
                            myPropInfo.SetValue(site, Enum.Parse(myPropInfo.PropertyType, attr.Value), null);
                            //Enum.Parse(typeof(myPropInfo.), "FirstName");
                        }
                        else
                        {
                            myPropInfo.SetValue(site, Convert.ChangeType(attr.Value, myPropInfo.PropertyType), null);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(attr.Name);
                }
            }
            return(site);
        }