protected virtual void CopySettings(ISitecoreConnectionSettings from, ISitecoreConnectionSettings to) { // //basic settings to.ClientUrl = from.ClientUrl; to.Username = from.Username; to.Password = from.Password; to.WebRootPath = from.WebRootPath; to.ContextDatabaseName = from.ContextDatabaseName; // //advanced settings to.NamespacesToAdd = (from.NamespacesToAdd == null) ? null : new HashSet <string>(from.NamespacesToAdd.Select(ns => ns).ToList()); to.SearchResultType = (from.SearchResultType == null) ? null : new SelectedType(from.SearchResultType.GetSelectedType()) { GetValidTypesDelegate = DefaultValuesForCxSettings.Current.GetValidTypesForSearchResultItem }; to.AppConfigReaderType = (from.AppConfigReaderType == null) ? null : new SelectedType(from.AppConfigReaderType.GetSelectedType()) { GetValidTypesDelegate = DefaultValuesForCxSettings.Current.GetValidTypesForAppConfigReaderType }; to.SchemaBuilderType = (from.SchemaBuilderType == null) ? null : new SelectedType(from.SchemaBuilderType.GetSelectedType()) { GetValidTypesDelegate = DefaultValuesForCxSettings.Current.GetValidTypesForSchemaBuilderType }; to.DriverInitializerType = (from.DriverInitializerType == null) ? null : new SelectedType(from.DriverInitializerType.GetSelectedType()) { GetValidTypesDelegate = DefaultValuesForCxSettings.Current.GetValidTypesForDriverInitializerType }; }
public virtual bool AreEqual(ISitecoreConnectionSettings cxSettings1, ISitecoreConnectionSettings cxSettings2) { if (cxSettings1 == cxSettings2) { return true; } if (cxSettings1 == null || cxSettings2 == null) { return false; } if (cxSettings1.Equals(cxSettings2)) { return true; } return (GetHashCodeFor(cxSettings1) == GetHashCodeFor(cxSettings2)); }
protected virtual int GetHashCodeFor(ISitecoreConnectionSettings cxSettings) { if (cxSettings == null) { return(0); } unchecked { var hash = GetHashCodeFor(cxSettings.ClientUrl); hash = hash * GetHashCodeFor(cxSettings.ClientUrl); hash = hash * GetHashCodeFor(cxSettings.Username); hash = hash * GetHashCodeFor(cxSettings.Password); hash = hash * GetHashCodeFor(cxSettings.WebRootPath); hash = hash * GetHashCodeFor(cxSettings.ContextDatabaseName); if (cxSettings.NamespacesToAdd != null) { foreach (var ns in cxSettings.NamespacesToAdd) { hash = hash * GetHashCodeFor(ns); } } hash = hash * GetHashCodeFor(cxSettings.SearchResultType); hash = hash * GetHashCodeFor(cxSettings.AppConfigReaderType); hash = hash * GetHashCodeFor(cxSettings.SchemaBuilderType); hash = hash * GetHashCodeFor(cxSettings.DriverInitializerType); return(hash); } }
protected virtual int GetHashCodeFor(ISitecoreConnectionSettings cxSettings) { if (cxSettings == null) { return 0; } unchecked { var hash = GetHashCodeFor(cxSettings.ClientUrl); hash = hash * GetHashCodeFor(cxSettings.ClientUrl); hash = hash * GetHashCodeFor(cxSettings.Username); hash = hash * GetHashCodeFor(cxSettings.Password); hash = hash * GetHashCodeFor(cxSettings.WebRootPath); hash = hash * GetHashCodeFor(cxSettings.ContextDatabaseName); if (cxSettings.NamespacesToAdd != null) { foreach (var ns in cxSettings.NamespacesToAdd) { hash = hash * GetHashCodeFor(ns); } } hash = hash * GetHashCodeFor(cxSettings.SearchResultType); hash = hash * GetHashCodeFor(cxSettings.AppConfigReaderType); hash = hash * GetHashCodeFor(cxSettings.SchemaBuilderType); hash = hash * GetHashCodeFor(cxSettings.DriverInitializerType); return hash; } }
public DriverSettingsController(ISitecoreConnectionSettings view) { if (view == null) { throw new ArgumentNullException("view"); } this.View = view; }
public virtual HashSet<string> GetAssemblyLocations(ISitecoreConnectionSettings settings) { var locations = new HashSet<string>(); var directories = GetAssemblyDirectories(settings); foreach (var directory in directories) { locations.UnionWith(Directory.GetFiles(directory, "*.dll")); } RemoveNonAssemblyLocations(locations); return locations; }
public virtual HashSet <string> GetAssemblyLocations(ISitecoreConnectionSettings settings) { var locations = new HashSet <string>(); var directories = GetAssemblyDirectories(settings); foreach (var directory in directories) { locations.UnionWith(Directory.GetFiles(directory, "*.dll")); } RemoveNonAssemblyLocations(locations); return(locations); }
/// <summary> /// This method reads default values for the following properties: /// * ContextDatabaseName /// * NamespacesToAdd /// * SearchResultType /// * AppConfigReaderType /// * SchemaBuilderType /// * DriverInitializerType /// </summary> /// <param name="cxInfo"></param> /// <param name="cxSettings"></param> public virtual void Read(IConnectionInfo cxInfo, ISitecoreConnectionSettings cxSettings) { if (cxInfo == null) { throw new ArgumentNullException("cxInfo"); } if (cxSettings == null) { throw new ArgumentNullException("cxSettings"); } var element = cxInfo.DriverData; if (element == null) { throw new NullReferenceException("DriverData on the IConnectionInfo object is null"); } cxSettings.ClientUrl = GetStringFromAttribute(element, KEY_CLIENT_URL); cxSettings.Username = GetStringFromAttribute(element, KEY_USERNAME); cxSettings.Password = GetStringFromAttribute(element, KEY_PASSWORD); cxSettings.WebRootPath = GetStringFromAttribute(element, KEY_WEB_ROOT_PATH); cxSettings.ContextDatabaseName = GetStringFromAttribute(element, KEY_CONTEXT_DB, DefaultValuesForCxSettings.Current.ContextDatabaseName); cxSettings.NamespacesToAdd = GetHashSetFromElement(element, KEY_NAMESPACES_TO_ADD, DefaultValuesForCxSettings.Current.NamespacesToAdd); var paths = GetHashSetFromElement(element, "paths"); if (paths == null) { paths = new HashSet <string>(); } var path = (string.IsNullOrEmpty(cxSettings.WebRootPath)) ? null : Path.Combine(cxSettings.WebRootPath, "bin"); if (!paths.Contains(path)) { paths.Add(path); } using (var context = new AssemblyLoadingContext(paths)) { // cxSettings.SearchResultType = GetSelectedTypeFromElement(element, KEY_SEARCH_RESULT_TYPE, DefaultValuesForCxSettings.Current.SearchResultItemType); cxSettings.SearchResultType.GetValidTypesDelegate = DefaultValuesForCxSettings.Current.GetValidTypesForSearchResultItem; // cxSettings.AppConfigReaderType = GetSelectedTypeFromElement(element, KEY_APP_CONFIG_READER_TYPE, DefaultValuesForCxSettings.Current.AppConfigReaderType); cxSettings.AppConfigReaderType.GetValidTypesDelegate = DefaultValuesForCxSettings.Current.GetValidTypesForAppConfigReaderType; // cxSettings.SchemaBuilderType = GetSelectedTypeFromElement(element, KEY_SCHEMA_BUILDER_TYPE, DefaultValuesForCxSettings.Current.SchemaBuilderType); cxSettings.SchemaBuilderType.GetValidTypesDelegate = DefaultValuesForCxSettings.Current.GetValidTypesForSchemaBuilderType; // cxSettings.DriverInitializerType = GetSelectedTypeFromElement(element, KEY_DRIVER_INITIALIZER_TYPE, DefaultValuesForCxSettings.Current.DriverInitializerType); cxSettings.DriverInitializerType.GetValidTypesDelegate = DefaultValuesForCxSettings.Current.GetValidTypesForDriverInitializerType; } }
public virtual HashSet<string> GetAssemblyDirectories(ISitecoreConnectionSettings settings) { var paths = new HashSet<string>(); if (!string.IsNullOrEmpty(settings.WebRootPath)) { paths.Add(Path.Combine(settings.WebRootPath, "bin")); } AddAssemblyPath(settings.SearchResultType, paths); AddAssemblyPath(settings.AppConfigReaderType, paths); AddAssemblyPath(settings.SchemaBuilderType, paths); AddAssemblyPath(settings.DriverInitializerType, paths); return paths; }
/// <summary> /// This method sets the default values for the following properties: /// * ContextDatabaseName /// * NamespacesToAdd /// * SearchResultType /// * AppConfigReaderType /// * SchemaBuilderType /// * DriverInitializerType /// </summary> /// <param name="cxInfo"></param> /// <param name="cxSettings"></param> public virtual void Save(IConnectionInfo cxInfo, ISitecoreConnectionSettings cxSettings) { if (cxInfo == null) { throw new ArgumentNullException("cxInfo"); } if (cxSettings == null) { throw new ArgumentNullException("cxSettings"); } var element = cxInfo.DriverData; if (element == null) { throw new NullReferenceException("DriverData on the IConnectionInfo object is null"); } SetAttribute(element, KEY_CLIENT_URL, cxSettings.ClientUrl); SetAttribute(element, KEY_USERNAME, cxSettings.Username); SetAttribute(element, KEY_PASSWORD, cxSettings.Password); SetAttribute(element, KEY_WEB_ROOT_PATH, cxSettings.WebRootPath); SetAttribute(element, KEY_CONTEXT_DB, cxSettings.ContextDatabaseName, DefaultValuesForCxSettings.Current.ContextDatabaseName); SetElement(element, KEY_NAMESPACES_TO_ADD, "namespace", cxSettings.NamespacesToAdd, DefaultValuesForCxSettings.Current.NamespacesToAdd); // // var paths = new List <string>(); AddAssemblyPathToList(cxSettings.SearchResultType, paths); AddAssemblyPathToList(cxSettings.AppConfigReaderType, paths); AddAssemblyPathToList(cxSettings.SchemaBuilderType, paths); AddAssemblyPathToList(cxSettings.DriverInitializerType, paths); var thisAssemblyPath = Path.GetDirectoryName(this.GetType().Assembly.Location); if (paths.Contains(thisAssemblyPath)) { paths.Remove(thisAssemblyPath); } var path = (string.IsNullOrEmpty(cxSettings.WebRootPath)) ? null : Path.Combine(cxSettings.WebRootPath, "bin"); if (paths.Contains(path)) { paths.Remove(path); } SetElement(element, "paths", "path", paths); // // SetElement(element, KEY_SEARCH_RESULT_TYPE, cxSettings.SearchResultType, DefaultValuesForCxSettings.Current.SearchResultItemType); SetElement(element, KEY_APP_CONFIG_READER_TYPE, cxSettings.AppConfigReaderType, DefaultValuesForCxSettings.Current.AppConfigReaderType); SetElement(element, KEY_SCHEMA_BUILDER_TYPE, cxSettings.SchemaBuilderType, DefaultValuesForCxSettings.Current.SchemaBuilderType); SetElement(element, KEY_DRIVER_INITIALIZER_TYPE, cxSettings.DriverInitializerType, DefaultValuesForCxSettings.Current.DriverInitializerType); }
public virtual HashSet <string> GetAssemblyDirectories(ISitecoreConnectionSettings settings) { var paths = new HashSet <string>(); if (!string.IsNullOrEmpty(settings.WebRootPath)) { paths.Add(Path.Combine(settings.WebRootPath, "bin")); } AddAssemblyPath(settings.SearchResultType, paths); AddAssemblyPath(settings.AppConfigReaderType, paths); AddAssemblyPath(settings.SchemaBuilderType, paths); AddAssemblyPath(settings.DriverInitializerType, paths); return(paths); }
public SitecoreConnectionManager(ISitecoreConnectionSettings model, CookieAwareWebClient client) { if (model == null) { throw new ArgumentNullException("model"); } this.Model = model; if (client == null) { client = new CookieAwareWebClient(null); } this.Client = client; this.BaseUrl = new Uri(model.ClientUrl, UriKind.Absolute); this.LoginUrl = new Uri(this.BaseUrl + "/admin/login.aspx"); this.GetConfigUrl = new Uri(this.BaseUrl + "/admin/showconfig.aspx"); this.GetVersionUrl = new Uri(this.BaseUrl + "/shell/sitecore.version.xml"); }
protected virtual void AddConstructorCode(CodeConstructor constructor, ISitecoreConnectionSettings settings) { var contextDb = settings.ContextDatabaseName; if (string.IsNullOrEmpty(contextDb)) { contextDb = "master"; } var targetObject = new CodeTypeReferenceExpression(new CodeTypeReference("Sitecore.Data.Database")); var right = new CodeMethodInvokeExpression(targetObject, "GetDatabase", new CodeExpression[] { new CodePrimitiveExpression(contextDb) }); var expression3 = new CodeTypeReferenceExpression(new CodeTypeReference("Sitecore.Context")); var left = new CodePropertyReferenceExpression(expression3, "Database"); var statement = new CodeAssignStatement(left, right); constructor.Statements.Add(statement); }
public virtual bool AreEqual(ISitecoreConnectionSettings cxSettings1, ISitecoreConnectionSettings cxSettings2) { if (cxSettings1 == cxSettings2) { return(true); } if (cxSettings1 == null || cxSettings2 == null) { return(false); } if (cxSettings1.Equals(cxSettings2)) { return(true); } return(GetHashCodeFor(cxSettings1) == GetHashCodeFor(cxSettings2)); }
public SitecoreConnectionManager(ISitecoreConnectionSettings model, CookieAwareWebClient client) { if (model == null) { throw new ArgumentNullException("model"); } this.Model = model; if (client == null) { client = new CookieAwareWebClient(null); } this.Client = client; this.BaseUrl = new Uri(model.ClientUrl, UriKind.Absolute); this.LoginUrl = new Uri(this.BaseUrl + "/admin/login.aspx"); this.GetConfigUrl = new Uri(this.BaseUrl + "/admin/showconfig.aspx"); this.GetVersionUrl = new Uri(this.BaseUrl + "/shell/sitecore.version.xml"); }
protected virtual IQueryable <string> GetAssemblyFilesToReference(ISitecoreConnectionSettings settings) { var list = new List <Assembly> { Assembly.Load(new AssemblyName("Sitecore.ContentSearch")), Assembly.Load(new AssemblyName("Sitecore.ContentSearch.Linq")), typeof(IQueryable).Assembly }; var selectedType = settings.SearchResultType.GetSelectedType(); if (selectedType != null) { list.Add(selectedType.Assembly); } var assemblies = new HashSet <Assembly>(); foreach (var assembly in list) { this.AddAssemblyFiles(assembly, assemblies); } return(from a in assemblies.AsQueryable <Assembly>() select a.Location); }
protected virtual string GetDragText(ExplorerItem item, ISitecoreConnectionSettings settings) { var builder = new StringBuilder(); builder.AppendLine(string.Format("var index = ContentSearchManager.GetIndex(\"{0}\");", item.Text)); builder.AppendLine("using (var context = index.CreateSearchContext())"); builder.AppendLine("{"); var type = settings.SearchResultType.GetSelectedType(); var typeName = settings.NamespacesToAdd.Contains(type.Namespace) ? type.Name : type.FullName; builder.AppendLine(string.Format("\tcontext.GetQueryable<{0}>()", typeName)); var whereClauses = new HashSet <string>(); var selectAssignments = new HashSet <string>(); var nameProperty = GetPropertyNameForLinqExpression(type, "_name"); var languageProperty = GetPropertyNameForLinqExpression(type, "_language"); var itemIdProperty = GetPropertyNameForLinqExpression(type, "_group"); if (!string.IsNullOrEmpty(nameProperty)) { whereClauses.Add(string.Format("item.{0} == \"Home\"", nameProperty)); selectAssignments.Add(string.Format("Name = item.{0}", nameProperty)); } if (!string.IsNullOrEmpty(languageProperty)) { whereClauses.Add(string.Format("item.{0} == \"en\"", languageProperty)); } if (!string.IsNullOrEmpty(itemIdProperty)) { selectAssignments.Add(string.Format("Id = item.{0}.ToString()", itemIdProperty)); } foreach (var clause in whereClauses) { builder.AppendFormat("\t\t.Where(item => {0})\n", clause); } builder.AppendFormat("\t\t\t\t.Select(item => new {{{0}}} )\n", string.Join(", ", selectAssignments.ToArray())); builder.AppendLine("\t\t\t\t\t.Dump();"); builder.AppendLine("}"); return(builder.ToString()); }
public SitecoreConnectionManager(ISitecoreConnectionSettings model) : this(model, null) { }
protected virtual string GetDragText(ExplorerItem item, ISitecoreConnectionSettings settings) { var builder = new StringBuilder(); builder.AppendLine(string.Format("var index = ContentSearchManager.GetIndex(\"{0}\");", item.Text)); builder.AppendLine("using (var context = index.CreateSearchContext())"); builder.AppendLine("{"); var type = settings.SearchResultType.GetSelectedType(); var typeName = settings.NamespacesToAdd.Contains(type.Namespace) ? type.Name : type.FullName; builder.AppendLine(string.Format("\tcontext.GetQueryable<{0}>()", typeName)); var whereClauses = new HashSet<string>(); var selectAssignments = new HashSet<string>(); var nameProperty = GetPropertyNameForLinqExpression(type, "_name"); var languageProperty = GetPropertyNameForLinqExpression(type, "_language"); var itemIdProperty = GetPropertyNameForLinqExpression(type, "_group"); if (! string.IsNullOrEmpty(nameProperty)) { whereClauses.Add(string.Format("item.{0} == \"Home\"", nameProperty)); selectAssignments.Add(string.Format("Name = item.{0}", nameProperty)); } if (! string.IsNullOrEmpty(languageProperty)) { whereClauses.Add(string.Format("item.{0} == \"en\"", languageProperty)); } if (! string.IsNullOrEmpty(itemIdProperty)) { selectAssignments.Add(string.Format("Id = item.{0}.ToString()", itemIdProperty)); } foreach (var clause in whereClauses) { builder.AppendFormat("\t\t.Where(item => {0})\n", clause); } builder.AppendFormat("\t\t\t\t.Select(item => new {{{0}}} )\n", string.Join(", ", selectAssignments.ToArray())); builder.AppendLine("\t\t\t\t\t.Dump();"); builder.AppendLine("}"); return builder.ToString(); }
protected virtual IQueryable<string> GetAssemblyFilesToReference(ISitecoreConnectionSettings settings) { var list = new List<Assembly> { Assembly.Load(new AssemblyName("Sitecore.ContentSearch")), Assembly.Load(new AssemblyName("Sitecore.ContentSearch.Linq")), typeof(IQueryable).Assembly }; var selectedType = settings.SearchResultType.GetSelectedType(); if (selectedType != null) { list.Add(selectedType.Assembly); } var assemblies = new HashSet<Assembly>(); foreach (var assembly in list) { this.AddAssemblyFiles(assembly, assemblies); } return (from a in assemblies.AsQueryable<Assembly>() select a.Location); }
protected virtual void AddConstructorCode(CodeConstructor constructor, ISitecoreConnectionSettings settings) { var contextDb = settings.ContextDatabaseName; if (string.IsNullOrEmpty(contextDb)) { contextDb = "master"; } var targetObject = new CodeTypeReferenceExpression(new CodeTypeReference("Sitecore.Data.Database")); var right = new CodeMethodInvokeExpression(targetObject, "GetDatabase", new CodeExpression[] { new CodePrimitiveExpression(contextDb) }); var expression3 = new CodeTypeReferenceExpression(new CodeTypeReference("Sitecore.Context")); var left = new CodePropertyReferenceExpression(expression3, "Database"); var statement = new CodeAssignStatement(left, right); constructor.Statements.Add(statement); }
public SitecoreConnectionManager(ISitecoreConnectionSettings model) : this(model, null) { }