public virtual XDocument Read(ISitecoreConnectionManager cxManager, SitecoreDriverSettings driverSettings, string fileName, bool save)
        {
            if (cxManager == null)
            {
                throw new ArgumentNullException("cxManager");
            }
            if (driverSettings == null)
            {
                throw new ArgumentNullException("driverSettings");
            }
            if (driverSettings.CxSettings == null)
            {
                throw new NullReferenceException("CxSettings cannot be null");
            }
            var config = this.ReadConfigFromSitecore(cxManager, driverSettings, fileName);

            this.Transform(config, driverSettings);
            if (save)
            {
                this.Save(config, driverSettings);
            }
            return(config);
        }
        protected virtual XDocument ReadConfigFromSitecore(ISitecoreConnectionManager cxManager, SitecoreDriverSettings driverSettings, string fileName)
        {
            var fsConfig = this.ReadFileFromFileSystem(driverSettings, fileName);
            var response = cxManager.GetSitecoreConfig();

            if (response == null)
            {
                throw new Exception("Connection manager returned a null response.");
            }
            var webScRootElement = response.Data;

            if (webScRootElement == null)
            {
                throw new Exception("Connection manager returned a null Sitecore config.");
            }
            var fsScRootElement = fsConfig.XPathSelectElement("/configuration/sitecore");

            if (fsScRootElement == null)
            {
                throw new Exception("Unable to locate the element /configuration/sitecore in web.config");
            }
            fsScRootElement.ReplaceWith(webScRootElement);
            return(fsConfig);
        }