Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SqlScript" /> class with a specific script type and a specific order
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="contents">The contents.</param>
 /// <param name="hash">The hash.</param>
 /// <param name="sqlScriptOptions">The script options.</param>
 public SqlScript(string name, string contents, string hash, SqlScriptOptions sqlScriptOptions)
 {
     this.Name             = name;
     this.Contents         = contents;
     this.SqlScriptOptions = sqlScriptOptions ?? new SqlScriptOptions();
     this.Hash             = hash;
 }
Exemple #2
0
        /// <summary>
        /// Create a SqlScript from a file using specified encoding and sql script options
        /// </summary>
        /// <param name="basePath">Root path that was searched</param>
        /// <param name="path">Path to the file</param>
        /// <param name="encoding"></param>
        /// <param name="sqlScriptOptions">The script options</param>
        /// <returns></returns>
        public static SqlScript FromFile(string basePath, string path, Encoding encoding, SqlScriptOptions sqlScriptOptions)
        {
            var fullPath     = Path.GetFullPath(path);
            var fullBasePath = Path.GetFullPath(basePath);

            if (!fullPath.StartsWith(fullBasePath, StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception("The basePath must be a parent of path");
            }

            var filename = fullPath
                           .Substring(fullBasePath.Length)
                           .Replace(Path.DirectorySeparatorChar, '.')
                           .Replace(Path.AltDirectorySeparatorChar, '.')
                           .Trim('.');

            using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                return(FromStream(filename, fileStream, encoding, sqlScriptOptions));
            }
        }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SqlScript"/> class with a specific script type and a specific order
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="contents">The contents.</param>
 /// <param name="sqlScriptOptions">The script options.</param>
 public SqlScript(string name, string contents, SqlScriptOptions sqlScriptOptions)
 {
     Name             = name;
     Contents         = contents;
     SqlScriptOptions = sqlScriptOptions ?? new SqlScriptOptions();
 }
Exemple #4
0
 /// <summary>
 /// Create a SqlScript from a stream using specified encoding and script options
 /// </summary>
 /// <param name="scriptName"></param>
 /// <param name="stream"></param>
 /// <param name="encoding"></param>
 /// <param name="sqlScriptOptions">The script options</param>
 /// <returns></returns>
 public static SqlScript FromStream(string scriptName, Stream stream, Encoding encoding, SqlScriptOptions sqlScriptOptions)
 {
     using (var resourceStreamReader = new StreamReader(stream, encoding, true))
     {
         var c = resourceStreamReader.ReadToEnd();
         return(new SqlScript(scriptName, c, sqlScriptOptions));
     }
 }
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SqlScript"/> class with a specific options - script type and a script order
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="contents">The contents.</param>
 /// <param name="sqlScriptOptions">The script options.</param>
 public SqlScript(string name, string contents, SqlScriptOptions sqlScriptOptions)
 {
     Name             = name ?? throw new ArgumentNullException(nameof(name));
     Contents         = contents;
     SqlScriptOptions = sqlScriptOptions ?? new SqlScriptOptions();
 }
Exemple #6
0
        /// <summary>
        /// Create a <see cref="SqlScript"/> from a stream using specified encoding and script options
        /// </summary>
        /// <param name="scriptName"></param>
        /// <param name="stream"></param>
        /// <param name="encoding"></param>
        /// <param name="sqlScriptOptions">The script options</param>
        /// <returns></returns>
        public static SqlScript FromStream(string scriptName, Stream stream, Encoding encoding, SqlScriptOptions sqlScriptOptions)
        {
            if (encoding == null)
            {
                throw new ArgumentNullException(nameof(encoding));
            }

            using (var resourceStreamReader = new StreamReader(stream, encoding, true))
            {
                var contents = resourceStreamReader.ReadToEnd();
                return(new SqlScript(scriptName, contents, sqlScriptOptions));
            }
        }
Exemple #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LazySqlScript"/> class.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="sqlScriptOptions">The sql script options.</param>
 /// <param name="contentProvider">The delegate which creates the content at execution time.</param>
 public LazySqlScript(string name, SqlScriptOptions sqlScriptOptions, Func <string> contentProvider)
     : base(name, null, sqlScriptOptions)
 {
     this.contentProvider = contentProvider;
 }