コード例 #1
0
 private static void AddAllReferences(TypedDatabaseObject objectToSearch, IDictionary<TypedDatabaseObject, GraphNode> dependencyGraph, ISet<TypedDatabaseObject> set, Func<TypedDatabaseObject, bool> excludeFromSet)
 {
     var references = dependencyGraph[objectToSearch].ReferencedBy;
     var toAdd = references.Where(x => !set.Contains(x) && !excludeFromSet(x));
     foreach (var r in toAdd)
     {
         set.Add(r);
         AddAllReferences(r, dependencyGraph, set, excludeFromSet);
     }
 }
コード例 #2
0
        private static void AddAllReferences(TypedDatabaseObject objectToSearch, IDictionary <TypedDatabaseObject, GraphNode> dependencyGraph, ISet <TypedDatabaseObject> set, Func <TypedDatabaseObject, bool> excludeFromSet)
        {
            var references = dependencyGraph[objectToSearch].ReferencedBy;
            var toAdd      = references.Where(x => !set.Contains(x) && !excludeFromSet(x));

            foreach (var r in toAdd)
            {
                set.Add(r);
                AddAllReferences(r, dependencyGraph, set, excludeFromSet);
            }
        }
コード例 #3
0
        /// <summary>
        /// Retrieves the build script corresponding to the given database object identifier.
        /// </summary>
        /// <param name="dbObject">The database object for which a build script is desired.</param>
        /// <returns>A build script.</returns>
        public virtual async Task <ScriptFile> GetScriptAsync(TypedDatabaseObject dbObject)
        {
            if (!string.Equals(dbObject.ServerName, ServerName, StringComparison.InvariantCultureIgnoreCase) ||
                !string.Equals(dbObject.DatabaseName, DatabaseName, StringComparison.InvariantCultureIgnoreCase))
            {
                return(new ScriptFile(dbObject, new MissingScriptFileError(dbObject)));
            }
            var file = FileSystem.FileInfo.FromFileName(Path.Combine(ScriptDirectory.FullName, dbObject.SchemaName, dbObject.ObjectType.ToString(), dbObject.ObjectName + ".sql"));

            return(await GetScriptAsync(file));
        }
コード例 #4
0
        /// <summary>
        /// Retrieves the script file for the given database object identifier, if and only if the
        /// database object belongs to this script repository.
        /// </summary>
        /// <param name="dbObject">The database object for which a script file is desired.</param>
        /// <returns>A file descriptor for the script.</returns>
        public FileInfoBase GetScriptFile(TypedDatabaseObject dbObject)
        {
            if (!string.Equals(dbObject.ServerName, ServerName, StringComparison.InvariantCultureIgnoreCase) ||
                !string.Equals(dbObject.DatabaseName, DatabaseName, StringComparison.InvariantCultureIgnoreCase))
            {
                throw new ArgumentException("The given database object identifier does not belong to the database for which this script repository builds.", "dbObject");
            }
            var file = FileSystem.FileInfo.FromFileName(Path.Combine(ScriptDirectory.FullName, dbObject.SchemaName, dbObject.ObjectType.ToString(), dbObject.ObjectName + ".sql"));

            return(file);
        }
コード例 #5
0
        /// <summary>
        /// Retrieves the build script contained in the given file.
        /// </summary>
        /// <param name="file">The file containing a build script</param>
        /// <returns>A build script.</returns>
        protected async Task <ScriptFile> GetScriptAsync(FileInfoBase file)
        {
            // Parse file name and path
            var typeName   = file.Directory.Name;
            var schemaName = file.Directory.Parent.Name;
            var fileName   = Path.GetFileNameWithoutExtension(file.FullName);

            if (!_objectTypes.ContainsKey(typeName))
            {
                return(new ScriptFile(new DatabaseObject(ServerName, DatabaseName, schemaName.TrimObjectName(), fileName.TrimObjectName()), new UnexpectedObjectTypeError(typeName)));
            }
            var objectType = _objectTypes[typeName];
            var dbObject   = new TypedDatabaseObject(ServerName, DatabaseName, schemaName.TrimObjectName(), fileName.TrimObjectName(), objectType);

            // Read file contents
            string content;

            try
            {
                using (var fileInputStream = file.OpenRead())
                {
                    using (var fileReader = new StreamReader(fileInputStream))
                    {
                        content = await fileReader.ReadToEndAsync();
                    }
                }
            }
            catch (DirectoryNotFoundException)
            {
                return(new ScriptFile(dbObject, GetDropScript(dbObject), _sqlParser));
            }
            catch (FileNotFoundException)
            {
                return(new ScriptFile(dbObject, GetDropScript(dbObject), _sqlParser));
            }

            // Parse script file
            var script = new ScriptFile(dbObject, content, _sqlParser);

            return(script);
        }
コード例 #6
0
 public MissingScriptFileError(TypedDatabaseObject dbObject)
 {
     DatabaseObject = dbObject;
 }
コード例 #7
0
 private static string GetDropScript(TypedDatabaseObject dbObject)
 {
     return(string.Format("DROP {0} [{1}].[{2}]", dbObject.ObjectType, dbObject.SchemaName, dbObject.ObjectName));
 }
コード例 #8
0
 public GraphNode(TypedDatabaseObject value)
 {
     Value        = value;
     Dependencies = new HashSet <TypedDatabaseObject>(new TypedDatabaseObjectComparer());
     ReferencedBy = new HashSet <TypedDatabaseObject>(new TypedDatabaseObjectComparer());
 }
コード例 #9
0
ファイル: GraphNode.cs プロジェクト: Zocdoc/ZocBuild.Database
 public GraphNode(TypedDatabaseObject value)
 {
     Value = value;
     Dependencies = new HashSet<TypedDatabaseObject>(new TypedDatabaseObjectComparer());
     ReferencedBy = new HashSet<TypedDatabaseObject>(new TypedDatabaseObjectComparer());
 }
 private static string GetDropScript(TypedDatabaseObject dbObject)
 {
     return string.Format("DROP {0} [{1}].[{2}]", dbObject.ObjectType, dbObject.SchemaName, dbObject.ObjectName);
 }
        /// <summary>
        /// Retrieves the build script contained in the given file.
        /// </summary>
        /// <param name="file">The file containing a build script</param>
        /// <returns>A build script.</returns>
        protected async Task<ScriptFile> GetScriptAsync(FileInfo file)
        {
            // Parse file name and path
            var typeName = file.Directory.Name;
            var schemaName = file.Directory.Parent.Name;
            var fileName = Path.GetFileNameWithoutExtension(file.FullName);
            if(!objectTypes.ContainsKey(typeName))
            {
                return new ScriptFile(new DatabaseObject(ServerName, DatabaseName, schemaName.TrimObjectName(), fileName.TrimObjectName()), new UnexpectedObjectTypeError(typeName));
            }
            var objectType = objectTypes[typeName];
            var dbObject = new TypedDatabaseObject(ServerName, DatabaseName, schemaName.TrimObjectName(), fileName.TrimObjectName(), objectType);

            // Read file contents
            string content;
            try
            {
                using (var fileInputStream = file.OpenRead())
                {
                    using (var fileReader = new StreamReader(fileInputStream))
                    {
                        content = await fileReader.ReadToEndAsync();
                    }
                }
            }
            catch (Exception)
            {
                return new ScriptFile(dbObject, GetDropScript(dbObject), sqlParser);
            }

            // Parse script file
            var script = new ScriptFile(dbObject, content, sqlParser);

            return script;
        }
 /// <summary>
 /// Retrieves the build script corresponding to the given database object identifier.
 /// </summary>
 /// <param name="dbObject">The database object for which a build script is desired.</param>
 /// <returns>A build script.</returns>
 public virtual async Task<ScriptFile> GetScriptAsync(TypedDatabaseObject dbObject)
 {
     if (!string.Equals(dbObject.ServerName, ServerName, StringComparison.InvariantCultureIgnoreCase)
         || !string.Equals(dbObject.DatabaseName, DatabaseName, StringComparison.InvariantCultureIgnoreCase))
     {
         return new ScriptFile(dbObject, new MissingScriptFileError(dbObject));
     }
     var file = new FileInfo(Path.Combine(ScriptDirectory.FullName, dbObject.SchemaName, dbObject.ObjectType.ToString(), dbObject.ObjectName + ".sql"));
     return await GetScriptAsync(file);
 }
コード例 #13
0
 /// <summary>
 /// Retrieves the script file for the given database object identifier, if and only if the 
 /// database object belongs to this script repository.
 /// </summary>
 /// <param name="dbObject">The database object for which a script file is desired.</param>
 /// <returns>A file descriptor for the script.</returns>
 public FileInfoBase GetScriptFile(TypedDatabaseObject dbObject)
 {
     if (!string.Equals(dbObject.ServerName, ServerName, StringComparison.InvariantCultureIgnoreCase)
         || !string.Equals(dbObject.DatabaseName, DatabaseName, StringComparison.InvariantCultureIgnoreCase))
     {
         throw new ArgumentException("The given database object identifier does not belong to the database for which this script repository builds.", "dbObject");
     }
     var file = FileSystem.FileInfo.FromFileName(Path.Combine(ScriptDirectory.FullName, dbObject.SchemaName, dbObject.ObjectType.ToString(), dbObject.ObjectName + ".sql"));
     return file;
 }
コード例 #14
0
 /// <summary>
 /// Creates an instance of a missing script file error object.
 /// </summary>
 /// <param name="dbObject">The object that was expected and not found.</param>
 public MissingScriptFileError(TypedDatabaseObject dbObject)
 {
     DatabaseObject = dbObject;
 }