/// <summary>
        /// this function finds the matching url and delete from the record
        /// </summary>
        /// <param name="SiteInfo">contains all the info of the website to be deleted</param>
        public void DeleteSite(ManageSitesModel siteInfo)
        {
            try
            {
                rwLock.EnterWriteLock();
                //File path string
                string Internal = System.Web.Hosting.HostingEnvironment.MapPath("~/App/XML/InternalURLs.xml");

                //Loading the xml file into the xdocument object
                XDocument xdocemie = XDocument.Load(Internal);
                string    domainUrl = null; bool isDomain = false;
                if (siteInfo.FullURL.IndexOf('/') == -1)
                {
                    isDomain = true;
                }
                //get the list of all the domain info added into the xml file
                var list = xdocemie.Descendants("domain").ToList();
                //Remove  the websites which is matching with the info in the siteInfo object
                foreach (var domain in list)
                {
                    if (domain.Attribute("FullURL") != null && siteInfo != null)
                    {
                        if (domain.Attribute("FullURL").Value.Contains(siteInfo.FullURL))
                        {
                            if (domain.Attribute("FullURL").Value.Equals(siteInfo.FullURL))
                            {
                                domain.Remove();
                                if (!isDomain)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                if (domain.Attribute("FullURL").Value.IndexOf('/') != -1)
                                {
                                    domainUrl = domain.Attribute("FullURL").Value.Substring(0, domain.Attribute("FullURL").Value.IndexOf('/'));
                                }
                                else
                                {
                                    continue;
                                }
                                if (domainUrl.Equals(siteInfo.FullURL))
                                {
                                    domain.Remove();
                                }
                            }
                        }
                    }
                }
                xdocemie.Save(Internal);
                //Incereasing the version of the emie website list by 1
                DataSet ds = new DataSet();
                ds.ReadXml(Internal);
                ds.Tables[0].Rows[0]["version"] = (Convert.ToInt32(ds.Tables[0].Rows[0]["version"].ToString()) + 1).ToString();
                ds.WriteXml(Internal);
                rwLock.ExitWriteLock();
            }
            catch (Exception) { throw; }
        }
        /// <summary>
        /// This function returns all the URL related information to be sent to UI to display
        /// the data on the page load
        /// </summary>
        /// <returns>URL's info in Json format</returns>
        public JsonResult GetSiteInfo()
        {
            string Internal = System.Web.Hosting.HostingEnvironment.MapPath("~/App/XML/InternalURLs.xml");
            List <ManageSitesModel> list = new List <ManageSitesModel>(); //int i = 0;

            try
            {
                rwLock.EnterReadLock();
                //load the xml in XDocument object
                XDocument doc = XDocument.Load(Internal);
                //selecting the related information from the XML file
                var    excludeAttribute  = doc.Descendants("domain").Attributes("OpenInIE").ToList();
                var    LastModifiedBy    = doc.Descendants("emie").Elements("domain").Attributes("LastModifiedBy").ToList();
                var    Notes             = doc.Descendants("emie").Elements("domain").Attributes("Notes").ToList();
                var    docModeAttribute  = doc.Descendants("domain").Attributes("docMode").ToList();
                var    parentIdAttribute = doc.Descendants("domain").Attributes("parentId").ToList();
                var    FullURL           = doc.Descendants("emie").Elements("domain").Attributes("FullURL").ToList();
                string version           = doc.Root.Attribute("version").Value;
                //Inserting the data into ManageSitesModel object and adding into the list
                for (int k = 0; k < excludeAttribute.Count; k++)
                {
                    ManageSitesModel site = new ManageSitesModel();
                    //if the exclude is true means openInIE is false
                    site.OpenIn         = (excludeAttribute[k].Value);
                    site.LastModifiedBy = LastModifiedBy[k].Value;
                    site.NotesAboutURL  = Notes[k].Value;
                    site.DomainDocMode  = docModeAttribute[k].Value;
                    site.FullURL        = FullURL[k].Value;
                    site.EmieVersion    = version;
                    site.ParentId       = parentIdAttribute[k].Value == "null" ? null : parentIdAttribute[k].Value;
                    list.Add(site);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
            JsonResult json = new JsonResult(); json.MaxJsonLength = int.MaxValue; json.Data = list;

            return(json);
        }
        /// <summary>
        /// this function is for EMIE Tool it will update the informations of the existing urls into the xml file
        /// </summary>
        /// <param name="info">contains all the data need to be updated</param>
        #region UpdateXMLData
        public void UpdateXMLData(ManageSitesModel newInfo)
        {
            try
            {
                rwLock.EnterWriteLock();

                using (DataSet ds = new DataSet())
                {
                    string Internal = System.Web.Hosting.HostingEnvironment.MapPath("~/App/XML/InternalURLs.xml");
                    ds.ReadXml(Internal);

                    if (newInfo.NotesAboutURL == null)
                    {
                        newInfo.NotesAboutURL = "";
                    }
                    //updating the information when the URL has a subdomain and we need to modify their parentId as well
                    if (newInfo.FullURL.IndexOf('/') != -1)
                    {
                        for (int i = 0; i < ds.Tables[2].Rows.Count; i++)
                        {
                            //Modifying the subdomain url informations
                            if (ds.Tables[2].Rows[i]["FullURL"].ToString().Equals(newInfo.FullURL))
                            {
                                ds.Tables[2].Rows[i]["FullURL"]        = newInfo.FullURL;
                                ds.Tables[2].Rows[i]["LastModifiedBy"] = newInfo.LastModifiedBy;
                                ds.Tables[2].Rows[i]["Notes"]          = newInfo.NotesAboutURL;
                                ds.Tables[2].Rows[i]["docMode"]        = newInfo.SubDocMode;
                                ds.Tables[2].Rows[i]["OpenInIE"]       = newInfo.OpenInForSubdomain;
                                for (int k = 0; k < ds.Tables[2].Rows.Count; k++)
                                {
                                    //Modifying the parent information as well
                                    if (ds.Tables[2].Rows[i]["parentId"].ToString().Equals(ds.Tables[2].Rows[k]["FullURL"].ToString()))
                                    {
                                        ds.Tables[2].Rows[k]["LastModifiedBy"] = newInfo.LastModifiedBy;
                                        ds.Tables[2].Rows[k]["FullURL"]        = newInfo.DomainURL;
                                        ds.Tables[2].Rows[k]["Notes"]          = newInfo.NotesAboutURL;
                                        ds.Tables[2].Rows[k]["docMode"]        = newInfo.DomainDocMode;
                                        ds.Tables[2].Rows[k]["OpenInIE"]       = newInfo.OpenIn;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        //if the url has no subdomain part means we don't have to modify the parent information so only modifying the domain info
                        for (int i = 0; i < ds.Tables[2].Rows.Count; i++)
                        {
                            if (ds.Tables[2].Rows[i]["FullURL"].ToString().Equals(newInfo.FullURL))
                            {
                                ds.Tables[2].Rows[i]["LastModifiedBy"] = newInfo.LastModifiedBy;
                                ds.Tables[2].Rows[i]["FullURL"]        = newInfo.DomainURL;
                                ds.Tables[2].Rows[i]["Notes"]          = newInfo.NotesAboutURL;
                                ds.Tables[2].Rows[i]["docMode"]        = newInfo.DomainDocMode;
                                ds.Tables[2].Rows[i]["OpenInIE"]       = newInfo.OpenIn;
                                break;
                            }
                        }
                    }
                    ds.Tables[0].Rows[0]["version"] = (Convert.ToInt32(ds.Tables[0].Rows[0]["version"].ToString()) + 1).ToString();
                    ds.WriteXml(Internal);
                }
                rwLock.ExitWriteLock();
            }
            catch (Exception)
            {
                throw;
            }
        }