public virtual void SaveView(SitecoreDriverSettings model) { CopySettings(this.View, model.CxSettings); var mapper = new DriverDataCxSettingsMapper(); mapper.Save(model.CxInfo, model.CxSettings); }
public virtual IEnumerable <IConfigTransformer> GetTransformers(SitecoreDriverSettings driverSettings) { var transformers = new List <IConfigTransformer>() { new MergeSettingsFromFileTransformer("/configuration/connectionStrings", "configSource", driverSettings.CxSettings.WebRootPath), new RemoveElementTransformer("/configuration/sitecore/pipelines/indexing.filterIndex.outbound//processor[@type='Sitecore.ContentSearch.Pipelines.IndexingFilters.ApplyOutboundSecurityFilter, Sitecore.ContentSearch']", false), new RemoveElementTransformer("/configuration/log4net//encoding", true), new AttributeValueTransformer("/configuration/sitecore/configStores/*[starts-with(@arg0, '/App_Config/Security/')]", "arg0", driverSettings.CxSettings.WebRootPath, AttributeValueChangeType.Prepend) }; return(transformers); }
protected virtual XDocument ReadFileFromFileSystem(SitecoreDriverSettings driverSettings, string fileName) { var webRootPath = driverSettings.CxSettings.WebRootPath; if (string.IsNullOrEmpty(webRootPath)) { throw new Exception("No webroot path was specified, or the specified path is invalid"); } var path = Path.Combine(webRootPath, fileName); if (!File.Exists(path)) { throw new Exception(string.Format("The {0} file could not be located at {1}", fileName, path)); } return(XDocument.Load(path)); }
protected virtual void Transform(XDocument document, SitecoreDriverSettings driverSettings) { if (document == null) { return; } var transformers = GetTransformers(driverSettings); if (transformers == null) { return; } foreach (var transformer in transformers) { transformer.Transform(document); } }
public virtual void Save(XDocument document, SitecoreDriverSettings driverSettings) { if (driverSettings == null) { throw new ArgumentNullException("driverSettings"); } var cxInfo = driverSettings.CxInfo; if (cxInfo == null) { throw new NullReferenceException("CxInfo cannot be null"); } if (!File.Exists(cxInfo.AppConfigPath)) { cxInfo.AppConfigPath = Path.GetTempFileName(); } document.Save(cxInfo.AppConfigPath); }
public void Read() { var tmpCxStringsFile = Path.GetTempFileName(); var tmpCxStringsDoc = XDocument.Parse("<aaa></aaa>"); tmpCxStringsDoc.Save(tmpCxStringsFile); var tmpWebConfigFile = Path.GetTempFileName(); var tmpWebConfigDoc = XDocument.Parse((string)this.TestContext.DataRow["fileSystem"]); var csElement = tmpWebConfigDoc.XPathSelectElement("/configuration/connectionStrings"); var attr = csElement.Attribute("configSource"); if (attr != null) { attr.Value = tmpCxStringsFile; } tmpWebConfigDoc.Save(tmpWebConfigFile); var mockCxSettings = new Mock <ISitecoreConnectionSettings>(); mockCxSettings.SetupGet(cxSettings => cxSettings.WebRootPath).Returns(Path.GetDirectoryName(tmpWebConfigFile)); var driverSettings = new SitecoreDriverSettings() { CxSettings = mockCxSettings.Object }; var mockManager = new Mock <ISitecoreConnectionManager>(); var response = new ServerResponse <XElement>(); response.Data = XElement.Parse((string)this.TestContext.DataRow["server"]); mockManager.Setup(m => m.GetSitecoreConfig()).Returns(response); var reader = new Sitecore8AppConfigReader(); var doc = reader.Read(mockManager.Object, driverSettings, tmpWebConfigFile, false); // //Test by re-running the transformers. No changes should be reported. var transformers = reader.GetTransformers(driverSettings); foreach (var transformer in transformers) { Assert.IsFalse(transformer.Transform(doc)); } }
public void SetCxSettingsWithEmptyObjectsForAdvancedSettings() { var mockCxInfo = new Mock <IConnectionInfo>(); var element = XElement.Parse((string)this.TestContext.DataRow["driverData"]); mockCxInfo.SetupGet(cxInfo => cxInfo.DriverData).Returns(element); var cxSettings = new SitecoreConnectionSettings(); var mapper = new DriverDataCxSettingsMapper(); mapper.Read(mockCxInfo.Object, cxSettings); var view = new ConnectionDialog(); view.InitializeComponent(); var driverSettings = new SitecoreDriverSettings() { CxInfo = mockCxInfo.Object, CxSettings = cxSettings, SettingsMapper = new DriverDataCxSettingsMapper() }; view.Model = driverSettings; var controller = new DriverSettingsController(view); controller.LoadView(driverSettings); view.SaveViewToModelCallback = controller.SaveView; // //basic settings view.ClientUrl = "http://localhost"; view.Username = "******"; view.Password = "******"; view.WebRootPath = @"C:\Windows\Temp"; view.ContextDatabaseName = "master"; // //advanced settings view.NamespacesToAdd = new HashSet <string>(); view.SearchResultType = new SelectedType(); view.AppConfigReaderType = new SelectedType(); view.SchemaBuilderType = new SelectedType(); view.DriverInitializerType = new SelectedType(); }
public void SetCxSettingsNull() { var mockCxInfo = new Mock <IConnectionInfo>(); var element = XElement.Parse((string)this.TestContext.DataRow["driverData"]); mockCxInfo.SetupGet(cxInfo => cxInfo.DriverData).Returns(element); var cxSettings = new SitecoreConnectionSettings(); var mapper = new DriverDataCxSettingsMapper(); mapper.Read(mockCxInfo.Object, cxSettings); var view = new ConnectionDialog(); view.InitializeComponent(); var driverSettings = new SitecoreDriverSettings() { CxInfo = mockCxInfo.Object, CxSettings = cxSettings, SettingsMapper = new DriverDataCxSettingsMapper() }; view.Model = driverSettings; var controller = new DriverSettingsController(view); controller.LoadView(driverSettings); view.SaveViewToModelCallback = controller.SaveView; // //basic settings view.ClientUrl = null; view.Username = null; view.Password = null; view.WebRootPath = null; view.ContextDatabaseName = null; // //advanced settings view.NamespacesToAdd = null; view.SearchResultType = null; view.AppConfigReaderType = null; view.SchemaBuilderType = null; view.DriverInitializerType = null; }
public override bool ShowConnectionDialog(IConnectionInfo cxInfo, bool isNewConnection) { var view = new ConnectionDialog(); if (!view.IsInitialized) { view.InitializeComponent(); } try { var settings = GetCxSettings(cxInfo); var driverSettings = new SitecoreDriverSettings() { CxInfo = cxInfo, CxSettings = settings, SettingsMapper = new DriverDataCxSettingsMapper() }; view.Model = driverSettings; var controller = new DriverSettingsController(view); controller.LoadView(driverSettings); view.SaveViewToModelCallback = controller.SaveView; var result = view.ShowDialog(); return(result == true); } catch (Exception ex) { var message = string.Format("An exception was thrown when trying to load the dialog.\n\n" + "You might need to manually edit the connections file located in {0}.\n\n" + "=====================================\n" + "{1}\n{2}", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "LINQPad"), ex.Message, ex.StackTrace); MessageBox.Show(view, message, "Connection Dialog", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } }
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); }
public virtual void LoadView(SitecoreDriverSettings model) { CopySettings(model.CxSettings, this.View); }
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); }