/// <summary> /// Creates a new instance of <see cref="CompilerCache"/> from the specified collection of data source wrappers. /// </summary> /// <param name="dataSourceWrappers">A collection of data source wrappers from which to create a cache object.</param> /// <returns>The <see cref="CompilerCache"/> instance that was created.</returns> public static CompilerCache FromDataSourceWrappers(IEnumerable <DataSourceWrapperInfo> dataSourceWrappers) { Contract.Require(dataSourceWrappers, nameof(dataSourceWrappers)); var cache = new CompilerCache(); var types = new HashSet <Type>(); foreach (var dataSourceWrapper in dataSourceWrappers) { if (!cache.hashes.ContainsKey(dataSourceWrapper.DataSourcePath)) { var dataSourceWrapperHash = GenerateHashForXElement(dataSourceWrapper.DataSourceDefinition.Definition); cache.hashes[dataSourceWrapper.DataSourcePath] = dataSourceWrapperHash; } AddTypeReferences(dataSourceWrapper.DataSourceType, types); if (dataSourceWrapper.DependentWrapperInfos != null) { foreach (var dependentWrapper in dataSourceWrapper.DependentWrapperInfos) { AddTypeReferences(dependentWrapper.DataSourceType, types); } } } foreach (var type in types) { var typeHash = GenerateHashForType(type); cache.hashes[type.FullName] = typeHash; } return(cache); }
/// <summary> /// Gets a value indicating whether anything is different between this cache and the specified cache. /// </summary> /// <param name="other">The cache to compare against this cache.</param> /// <returns><see langword="true"/> if this cache is different from the specified cache; otherwise, <see langword="false"/>.</returns> public Boolean IsDifferentFrom(CompilerCache other) { Contract.Require(other, nameof(other)); if (!String.Equals(versionUltraviolet, other.versionUltraviolet, StringComparison.Ordinal) || !String.Equals(versionMscorlib, other.versionMscorlib, StringComparison.Ordinal)) { return(true); } var keys = Enumerable.Union(this.hashes.Keys, other.hashes.Keys).ToList(); foreach (var key in keys) { String hash1, hash2; if (!this.hashes.TryGetValue(key, out hash1)) { return(true); } if (!other.hashes.TryGetValue(key, out hash2)) { return(true); } if (!String.Equals(hash1, hash2, StringComparison.Ordinal)) { return(true); } } return(false); }
/// <summary> /// Creates a new instance of <see cref="CompilerCache"/> from the specified collection of data source wrappers. /// </summary> /// <param name="dataSourceWrappers">A collection of data source wrappers from which to create a cache object.</param> /// <returns>The <see cref="CompilerCache"/> instance that was created.</returns> public static CompilerCache FromDataSourceWrappers(IEnumerable<DataSourceWrapperInfo> dataSourceWrappers) { Contract.Require(dataSourceWrappers, nameof(dataSourceWrappers)); var cache = new CompilerCache(); var types = new HashSet<Type>(); foreach (var dataSourceWrapper in dataSourceWrappers) { if (!cache.hashes.ContainsKey(dataSourceWrapper.DataSourceWrapperName)) { var dataSourceWrapperHash = GenerateHashForXElement(dataSourceWrapper.DataSourceDefinition.Definition); cache.hashes[dataSourceWrapper.DataSourceWrapperName] = dataSourceWrapperHash; } AddTypeReferences(dataSourceWrapper.DataSourceType, types); if (dataSourceWrapper.DependentWrapperInfos != null) { foreach (var dependentWrapper in dataSourceWrapper.DependentWrapperInfos) AddTypeReferences(dependentWrapper.DataSourceType, types); } } foreach (var type in types) { var typeHash = GenerateHashForType(type); cache.hashes[type.FullName] = typeHash; } return cache; }
/// <summary> /// Creates a new instance of <see cref="CompilerCache"/> by loading the contents of the specified file. /// </summary> /// <param name="path">The path to the file to load.</param> /// <returns>The <see cref="CompilerCache"/> instance that was created.</returns> public static CompilerCache FromFile(String path) { Contract.RequireNotEmpty(path, nameof(path)); var cache = new CompilerCache(); var lines = File.ReadAllLines(path); foreach (var line in lines) { if (String.IsNullOrEmpty(line)) { continue; } var components = line.Split((Char[])null, StringSplitOptions.RemoveEmptyEntries); if (components.Length != 2) { throw new InvalidDataException(); } var name = components[0]; var hash = components[1]; cache.hashes[name] = hash; } return(cache); }
/// <summary> /// Creates a new instance of <see cref="CompilerCache"/> from the specified collection of data source wrappers. /// </summary> /// <param name="dataSourceWrappers">A collection of data source wrappers from which to create a cache object.</param> /// <returns>The <see cref="CompilerCache"/> instance that was created.</returns> public static CompilerCache FromDataSourceWrappers(IEnumerable<DataSourceWrapperInfo> dataSourceWrappers) { Contract.Require(dataSourceWrappers, "dataSourceWrappers"); var cache = new CompilerCache(); foreach (var dataSourceWrapper in dataSourceWrappers) { var dataSourceHash = GenerateHashForType(dataSourceWrapper.DataSourceType); cache.hashes[dataSourceWrapper.DataSourceType.FullName] = dataSourceHash; var dataSourceWrapperHash = GenerateHashForXElement(dataSourceWrapper.DataSourceDefinition.Definition); cache.hashes[dataSourceWrapper.DataSourceWrapperName] = dataSourceWrapperHash; } return cache; }
/// <summary> /// Creates a new instance of <see cref="CompilerCache"/> from the specified collection of data source wrappers. /// </summary> /// <param name="dataSourceWrappers">A collection of data source wrappers from which to create a cache object.</param> /// <returns>The <see cref="CompilerCache"/> instance that was created.</returns> public static CompilerCache FromDataSourceWrappers(IEnumerable <DataSourceWrapperInfo> dataSourceWrappers) { Contract.Require(dataSourceWrappers, nameof(dataSourceWrappers)); var cache = new CompilerCache(); foreach (var dataSourceWrapper in dataSourceWrappers) { var dataSourceHash = GenerateHashForType(dataSourceWrapper.DataSourceType); cache.hashes[dataSourceWrapper.DataSourceType.FullName] = dataSourceHash; var dataSourceWrapperHash = GenerateHashForXElement(dataSourceWrapper.DataSourceDefinition.Definition); cache.hashes[dataSourceWrapper.DataSourceWrapperName] = dataSourceWrapperHash; } return(cache); }
/// <summary> /// Creates a new instance of <see cref="CompilerCache"/> by loading the contents of the specified file. /// </summary> /// <param name="path">The path to the file to load.</param> /// <returns>The <see cref="CompilerCache"/> instance that was created.</returns> public static CompilerCache FromFile(String path) { Contract.RequireNotEmpty(path, "path"); var cache = new CompilerCache(); var lines = File.ReadAllLines(path); foreach (var line in lines) { if (String.IsNullOrEmpty(line)) continue; var components = line.Split(' '); if (components.Length != 2) throw new InvalidDataException(); var name = components[0]; var hash = components[1]; cache.hashes[name] = hash; } return cache; }
/// <summary> /// Gets a value indicating whether anything is different between this cache and the specified cache. /// </summary> /// <param name="other">The cache to compare against this cache.</param> /// <returns><c>true</c> if this cache is different from the specified cache; otherwise, <c>false</c>.</returns> public Boolean IsDifferentFrom(CompilerCache other) { Contract.Require(other, "other"); var keys = Enumerable.Union(this.hashes.Keys, other.hashes.Keys).ToList(); foreach (var key in keys) { String hash1, hash2; if (!this.hashes.TryGetValue(key, out hash1)) return true; if (!other.hashes.TryGetValue(key, out hash2)) return true; if (!String.Equals(hash1, hash2, StringComparison.Ordinal)) return true; } return false; }
/// <summary> /// Creates a new instance of <see cref="CompilerCache"/> by loading the contents of the specified file. /// </summary> /// <param name="path">The path to the file to load.</param> /// <returns>The <see cref="CompilerCache"/> instance that was created.</returns> public static CompilerCache FromFile(String path) { Contract.RequireNotEmpty(path, nameof(path)); var cache = new CompilerCache(); var lines = File.ReadAllLines(path); var versionUltraviolet = default(String); var versionMscorlib = default(String); foreach (var line in lines) { if (String.IsNullOrEmpty(line)) continue; if (versionUltraviolet == default(String)) { versionUltraviolet = line; continue; } if (versionMscorlib == default(String)) { versionMscorlib = line; continue; } var components = line.Split((Char[])null, StringSplitOptions.RemoveEmptyEntries); if (components.Length != 2) throw new InvalidDataException(); var name = components[0]; var hash = components[1]; cache.hashes[name] = hash; } cache.versionUltraviolet = versionUltraviolet; cache.versionMscorlib = versionMscorlib; return cache; }
/// <summary> /// Gets a value indicating whether anything is different between this cache and the specified cache. /// </summary> /// <param name="other">The cache to compare against this cache.</param> /// <returns><see langword="true"/> if this cache is different from the specified cache; otherwise, <see langword="false"/>.</returns> public Boolean IsDifferentFrom(CompilerCache other) { Contract.Require(other, nameof(other)); if (!String.Equals(versionUltraviolet, other.versionUltraviolet, StringComparison.Ordinal) || !String.Equals(versionMscorlib, other.versionMscorlib, StringComparison.Ordinal)) { return true; } var keys = Enumerable.Union(this.hashes.Keys, other.hashes.Keys).ToList(); foreach (var key in keys) { String hash1, hash2; if (!this.hashes.TryGetValue(key, out hash1)) return true; if (!other.hashes.TryGetValue(key, out hash2)) return true; if (!String.Equals(hash1, hash2, StringComparison.Ordinal)) return true; } return false; }