Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the LogMarshal using the specified <see cref="Logging.ILog"/> to perform the actual logging.
 /// </summary>
 /// <param name="log">The hosted <see cref="Logging.ILog"/>.</param>
 /// <param name="logSettings">The log settings.</param>
 public LogMarshal(Logging.ILog log,
                   LogControllerSettings logSettings)
     : this()
 {
     _ActualLog   = log ?? throw new ArgumentNullException(nameof(log));
     _LogSettings = logSettings ?? throw new ArgumentNullException(nameof(logSettings));
 }
Esempio n. 2
0
        public static string[] Deploy(Arguments.IDeployArguments deployArguments, Logging.ILog log = null)
        {
            if (log == null)
            {
                log = new Logging.NoLogging();
            }

            if (System.IO.File.Exists(deployArguments.ArtifactFile))
            {
                string packageFile = deployArguments.ArtifactFile;//System.IO.Path.Combine(deployArguments.ArtifactFolder, PackageTask.PackageFile);
                if (System.IO.File.Exists(packageFile))
                {
                    string tempFolder = System.IO.Path.GetTempPath();
                    string newFolder  = System.Guid.NewGuid().ToString();
                    string ourFolder  = System.IO.Path.Combine(tempFolder, newFolder);
                    System.IO.Directory.CreateDirectory(ourFolder);
                    ICSharpCode.SharpZipLib.Zip.FastZip fz = new FastZip();

                    fz.ExtractZip(packageFile, ourFolder, null);

                    Arguments.BuildArguments ba = new BuildArguments();
                    ba.ConnectionString  = deployArguments.ConnectionString;
                    ba.DbProviderFactory = deployArguments.DbProviderFactory;
                    ba.ScriptProcessor   = deployArguments.ScriptProcessor;
                    ba.VersionParser     = deployArguments.VersionParser;
                    ba.DryRun            = false;
                    ba.BreakOnError      = true;
                    ba.MaximumVersion    = "99999.99999.99999";
                    ba.MinimumVersion    = "0.0.0";
                    ba.Recurse           = true;
                    ba.ScriptPath        = ourFolder;
                    ba.ScriptPattern     = "*.*";
                    ba.Transactional     = true;


                    return(BuildTask.Build(ba, log));
                }
            }

            return(null);
        }
Esempio n. 3
0
 /// <summary>
 /// Instantiates a new <see cref="LogController"/>.
 /// </summary>
 /// <param name="log">The <see cref="Logging.ILog"/>-based logger used to write the actual logs.</param>
 /// <param name="logArchiveFileStore">A <see cref="FileStorage.IFileStore"/> when log archives will be created.</param>
 /// <param name="archiveFilenameFactory">A <see cref="IArchiveFilenameFactory"/> used to create archive log file names.</param>
 /// <param name="logControllerSettings">Settings to control the actions of the <see cref="ILogController"/>.</param>
 public LogController(Logging.ILog log,
                      FileStorage.IFileStore logArchiveFileStore,
                      IArchiveFilenameFactory archiveFilenameFactory,
                      LogControllerSettings logControllerSettings)
     : this()
 {
     if (log == null)
     {
         throw new ArgumentNullException(nameof(log));
     }
     // **** turn OFF auto-truncation if it is the known interface:{Logging.ITruncatable}
     if (log is Logging.ITruncatable)
     {
         (log as Logging.ITruncatable).AutoTruncateEnabled = false;
     }
     //
     _Log                    = log;
     Settings                = logControllerSettings ?? throw new ArgumentNullException(nameof(logControllerSettings));
     _LogArchiveFileStore    = logArchiveFileStore ?? throw new ArgumentNullException(nameof(logArchiveFileStore));
     _ArchiveFilenameFactory = archiveFilenameFactory ?? throw new ArgumentNullException(nameof(archiveFilenameFactory));
 }
Esempio n. 4
0
        private static Context CreateContext(SKColor backgroundColor, Logging.ILog log, double opacity, double scale, int width, int height, Size currentSize)
        {
            if (scale > 0)
            {
                return(new Context(
                           backgroundColor,
                           log,
                           opacity,
                           (int)(currentSize.Width * scale),
                           (int)(currentSize.Height * scale),
                           (float)scale));
            }

            return(new Context(
                       backgroundColor,
                       log,
                       opacity,
                       width,
                       height,
                       (float)width / currentSize.Width,
                       (float)height / currentSize.Height));
        }
Esempio n. 5
0
        public static string[] Build(Arguments.IBuildArguments buildArguments, Logging.ILog log = null)
        {
            if (log == null)
            {
                log = new Logging.NoLogging();
            }
            if (string.IsNullOrEmpty(buildArguments.ScriptPath))
            {
                buildArguments.ScriptPath = System.Environment.CurrentDirectory;
            }

            if (string.IsNullOrEmpty(buildArguments.DbProviderFactory))
            {
                buildArguments.DbProviderFactory = "System.Data.SqlClient";
            }

            if (string.IsNullOrEmpty(buildArguments.ScriptProcessor))
            {
                buildArguments.ScriptProcessor = typeof(SqlScriptRunner.ScriptProcessing.SqlServerScriptProcessor).FullName;
            }

            if (string.IsNullOrEmpty(buildArguments.VersionParser))
            {
                buildArguments.VersionParser = typeof(SqlScriptRunner.Versioning.VersionDateParser).AssemblyQualifiedName;
            }


            Type t = Type.GetType(buildArguments.VersionParser);

            SqlScriptRunner.Versioning.IParseVersions versionParser =
                (Activator.CreateInstance(t) as
                 SqlScriptRunner.Versioning.IParseVersions);


            SqlScriptRunner.Versioning.Version minVersion = null;
            SqlScriptRunner.Versioning.Version maxVersion = null;

            if (string.IsNullOrEmpty(buildArguments.MinimumVersion))
            {
                minVersion = SqlScriptRunner.Versioning.Version.Min;
            }
            else
            {
                minVersion = versionParser.Parse(buildArguments.MinimumVersion);
            }

            if (string.IsNullOrEmpty(buildArguments.MaximumVersion))
            {
                maxVersion = SqlScriptRunner.Versioning.Version.Max;
            }
            else
            {
                maxVersion = versionParser.Parse(buildArguments.MaximumVersion);
            }
            log.Info("--------------------------------");
            log.Info(string.Format("Min:{0}, Max:{1}, ScriptPath:{2}, Transactional:{4}, DryRun:{5}\r\nConnectionString:{3}", minVersion, maxVersion, buildArguments.ScriptPath, buildArguments.ConnectionString, buildArguments.Transactional, buildArguments.DryRun));
            log.Info("--------------------------------");
            DbConnection connection = null;

            if (!buildArguments.DryRun)
            {
                //make sure we can connect to the database
                DbProviderFactory factory = DbProviderFactories.GetFactory(buildArguments.DbProviderFactory);
                connection = factory.CreateConnection();
                if (connection == null)
                {
                    throw new ArgumentException(
                              "Could not create a connection to the database, via the Provider Factory:" +
                              buildArguments.DbProviderFactory);
                }
                else
                {
                    connection.ConnectionString = buildArguments.ConnectionString;
                    connection.Open();
                }
            }

            SortedList <string, string> Files = SqlScriptRunner.ScriptRunner.ResolveScriptsFromPathAndVersion(buildArguments.ScriptPath, buildArguments.ScriptPattern, buildArguments.Recurse, System.Environment.CurrentDirectory, minVersion, maxVersion, versionParser);

            log.Info(string.Format("Resolved:{0} files.", Files.Count));

            foreach (var file in Files.Keys)
            {
                log.Info(file);
                if (!buildArguments.DryRun)
                {
                    try
                    {
                        log.Info("Executing");
                        string script = System.IO.File.ReadAllText(Files[file]);
                        SqlScriptRunner.ScriptRunner runner = new ScriptRunner(script, null);
                        if (buildArguments.Transactional)
                        {
                            if (connection.State == ConnectionState.Closed)
                            {
                                connection.Open();
                            }
                            System.Data.IDbTransaction transaction = null;
                            if (buildArguments.Transactional)
                            {
                                transaction = connection.BeginTransaction();
                            }
                            try
                            {
                                runner.Execute(connection, transaction);
                                if (buildArguments.Transactional)
                                {
                                    transaction.Commit();
                                }
                                log.Info("Success:" + file);
                            }
                            catch (Exception e)
                            {
                                log.Info("Fail [In Trx:" + buildArguments.Transactional + "]:" + file);
                                log.Fatal(e);
                                if (buildArguments.Transactional)
                                {
                                    transaction.Rollback();
                                }
                                throw;
                            }
                        }
                        else
                        {
                            runner.Execute(connection);
                        }
                    }
                    catch (Exception e)
                    {
                        if (buildArguments.BreakOnError)
                        {
                            throw;
                        }
                        else
                        {
                            log.Debug("There was an error with a script, since BreakOnError is false, we will continue.File:" + file, e);
                        }
                    }
                }
            }
            log.Info("Done Executing");
            return((from f in Files select f.Value).ToArray());
        }
Esempio n. 6
0
        public static string[] Package(Arguments.IPackageArguments packageArguments, Logging.ILog log = null)
        {
            if (log == null)
            {
                log = new Logging.NoLogging();
            }

            Arguments.BuildArguments ba = new BuildArguments();
            ba.ScriptPath     = packageArguments.ScriptPath;
            ba.ScriptPattern  = packageArguments.ScriptPattern;
            ba.Recurse        = packageArguments.Recurse;
            ba.MinimumVersion = packageArguments.MinimumVersion;
            ba.MaximumVersion = packageArguments.MaximumVersion;
            ba.DryRun         = true;
            ba.VersionParser  = packageArguments.VersionParser;

            string[] files = BuildTask.Build(ba, log);

            string tempFolder = System.IO.Path.GetTempPath();
            string newFolder  = System.Guid.NewGuid().ToString();
            string ourFolder  = System.IO.Path.Combine(tempFolder, newFolder);
            string ourZip     = System.IO.Path.Combine(tempFolder, newFolder + ".zip");

            System.IO.Directory.CreateDirectory(ourFolder);


            //create copies of our deployable files
            foreach (var file in files)
            {
                System.IO.FileInfo fi         = new FileInfo(file);
                string             dir        = fi.Directory.FullName.Replace(packageArguments.ScriptPath, "");
                string             newTempDir = System.IO.Path.Combine(ourFolder, dir);
                if (!System.IO.Directory.Exists(newTempDir))
                {
                    System.IO.Directory.CreateDirectory(newTempDir);
                }
                System.IO.File.Copy(file, System.IO.Path.Combine(newTempDir, fi.Name));
            }

            string DeploySample     = "SqlScriptRunner.Resources.Deploy.sample.msbuild";
            string deploySampleFile = System.IO.Path.Combine(ourFolder, "Deploy.sample.msbuild");

            using (System.IO.Stream stm = typeof(PackageTask).Assembly.GetManifestResourceStream(DeploySample))
            {
                using (System.IO.StreamReader rdr = new StreamReader(stm))
                {
                    string contents = rdr.ReadToEnd();
                    if (!string.IsNullOrEmpty(contents))
                    {
                        System.IO.FileInfo fi = new FileInfo(packageArguments.ArtifactFile);
                        contents = contents.Replace("[PACKAGEFILENAME]", fi.Name);
                        System.IO.File.WriteAllText(deploySampleFile, contents);
                    }
                }
            }

            //zip them up!
            ICSharpCode.SharpZipLib.Zip.FastZip fz = new FastZip();
            fz.CreateZip(ourZip, ourFolder, true, null);

            string path = ourZip;

            if (!packageArguments.DryRun)
            {
                //if (!System.IO.Directory.Exists(packageArguments.ArtifactFolder)) System.IO.Directory.CreateDirectory(packageArguments.ArtifactFolder);
                //path = System.IO.Path.Combine(packageArguments.ArtifactFolder, PackageFile);
                path = packageArguments.ArtifactFile;
                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }
                System.IO.File.Copy(ourZip, path);
            }

            return(new string[] { path });
        }