//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="owner">The owning <see cref="SqlDictionary{TValue}"/> class</param> internal SqlDictionaryEnumerator(SqlDictionary <TValue> owner) { cn = new SqlConnection(owner.connection.ConnectionString); bf = owner.bf; keyFieldName = owner.keyFieldName; valueFieldName = owner.valueFieldName; isReferenceType = owner.isReferenceType; if (owner.groupIdFieldName == null) { cmd = new SqlCommand(String.Format(CultureInfo.InvariantCulture, "Select {0}, {1} From {2}", keyFieldName, valueFieldName, owner.tableName), cn); } else { cmd = new SqlCommand(String.Format(CultureInfo.InvariantCulture, "Select {0}, {1} From {2} " + "Where {3} = '{4}'", keyFieldName, valueFieldName, owner.tableName, owner.groupIdFieldName, owner.groupId), cn); } cn.Open(); this.Reset(); }
//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="component">The build component that owns the dictionary. This is useful for logging /// messages during initialization.</param> /// <param name="configuration">The target dictionary configuration</param> /// <param name="connectionString">The connection string to use</param> /// <param name="groupId">The group ID to use</param> /// <param name="localCacheSize">The local cache size to use</param> /// <param name="reload">True to reload the cache or false to leave it alone. This is used to reload /// project data so that it is always current.</param> /// <returns>A target dictionary instance that uses a simple in-memory /// <see cref="Dictionary{TKey, TValue}"/> instance to store the targets.</returns> public SqlTargetDictionary(BuildComponentCore component, XPathNavigator configuration, string connectionString, string groupId, int localCacheSize, bool reload) : base(component, configuration) { this.connectionString = connectionString; base.DictionaryId = groupId; index = new SqlDictionary <Target>(connectionString, "Targets", "TargetKey", "TargetValue", "GroupId", groupId) { LocalCacheSize = localCacheSize }; int filesToLoad = 0; if (reload) { filesToLoad = Directory.EnumerateFiles(this.DirectoryPath, this.FilePattern, this.Recurse ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly).Count(); } else { foreach (string file in Directory.EnumerateFiles(this.DirectoryPath, this.FilePattern, this.Recurse ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)) { if ((this.NamespaceFileFilter.Count == 0 || this.NamespaceFileFilter.Contains( Path.GetFileName(file))) && !this.ContainsKey("N:" + Path.GetFileNameWithoutExtension(file))) { filesToLoad++; } } } // Loading new targets can take a while so issue a diagnostic message as an alert. The time estimate // is a ballpark figure and depends on the system. if (filesToLoad != 0) { component.WriteMessage(MessageLevel.Diagnostic, "{0} file(s) need to be added to the SQL " + "reflection target cache database. Indexing them will take about {1:N0} minute(s), " + "please be patient. Cache location: {2}", filesToLoad, Math.Ceiling(filesToLoad / 60.0), connectionString); this.LoadTargetDictionary(); } }