Ejemplo n.º 1
0
        protected override void BeginProcessing()
        {
            try
            {
                var currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE",
                                                Path.Combine(currentDirectory, "Sitecore.Courier.dll.config"));
                ResetConfigMechanism();
                string version = Guid.NewGuid().ToString();

                Console.WriteLine("Source: {0}", Source);
                Console.WriteLine("Target: {0}", Target);
                Console.WriteLine("Output: {0}", Output);
                Console.WriteLine("SerializationProvider: {0}", SerializationProvider);
                Console.WriteLine("CollisionBehavior: {0}", CollisionBehavior);
                Console.WriteLine("IncludeFiles: {0}", IncludeFiles);
                Console.WriteLine("DacPac: {0}", DacPac);

                RainbowSerializationProvider.Enabled        = SerializationProvider == SerializationProvider.Rainbow;
                RainbowSerializationProvider.IncludeFiles   = IncludeFiles;
                RainbowSerializationProvider.EnsureRevision = EnsureRevision;

                var diff = new DiffInfo(
                    DiffGenerator.GetDiffCommands(Source, Target, IncludeSecurity, version, CollisionBehavior),
                    "Sitecore Courier Package",
                    string.Empty,
                    string.Format("Diff between serialization folders '{0}' and '{1}'.", Source, Target));

                if (IncludeSecurity)
                {
                    diff.Commands.Add(new PostStepFileSystemDataItem(currentDirectory, string.Empty, PostDeployDll)
                                      .GenerateAddCommand().FirstOrDefault());
                    diff.PostStep = PostStep;
                    diff.Version  = version;
                }

                if (DacPac)
                {
                    SqlConverter c = new SqlConverter();
                    c.ConvertPackage(diff, Output);

                    var           builder = new DacPacBuilder();
                    DirectoryInfo d       = new DirectoryInfo(Output);
                    foreach (var file in d.GetFiles("*.sql"))
                    {
                        builder.ConvertToDacPac(file.FullName, Path.Combine(file.DirectoryName, $"{Path.GetFileNameWithoutExtension(file.Name)}.dacpac"));
                    }
                }
                else
                {
                    PackageGenerator.GeneratePackage(diff, string.Empty, Output);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                throw ex;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Mains the specified args.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public static void Main(string[] args)
        {
            var options = new Options();

            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {
                Console.WriteLine("Source: {0}", options.Source);
                Console.WriteLine("Target: {0}", options.Target);
                Console.WriteLine("Output: {0}", options.Output);
                Console.WriteLine("Collision behavior: {0}", options.CollisionBehavior);
                Console.WriteLine("Use Rainbow: {0}", options.UseRainbow);
                Console.WriteLine("Include Security: {0}", options.IncludeSecurity);
                Console.WriteLine("Include Files: {0}", options.IncludeFiles);
                Console.WriteLine("Configuration: {0}", options.Configuration);
                Console.WriteLine("Ensure Revision: {0}", options.EnsureRevision);
                Console.WriteLine("Path to project file: {0}", options.ScProjFilePath);
                Console.WriteLine("DacPac Output: {0}", options.DacPac);

                string version = Guid.NewGuid().ToString();
                SanitizeOptions(options);

                if (ExclusionHandler.HasValidExclusions(options.Configuration, options.ScProjFilePath))
                {
                    var exclusions = ExclusionHandler.GetExcludedItems(options.ScProjFilePath, options.Configuration);

                    ExclusionHandler.RemoveExcludedItems(options.Source, exclusions);
                    ExclusionHandler.RemoveExcludedItems(options.Target, exclusions);
                }

                RainbowSerializationProvider.Enabled        = options.UseRainbow;
                RainbowSerializationProvider.IncludeFiles   = options.IncludeFiles;
                RainbowSerializationProvider.EnsureRevision = options.EnsureRevision;

                var commands = DiffGenerator.GetDiffCommands(options.Source, options.Target, options.IncludeSecurity, version, options.CollisionBehavior);

                var diff = new DiffInfo(
                    commands,
                    "Sitecore Courier Package",
                    string.Empty,
                    string.Format("Diff between serialization folders '{0}' and '{1}'.", options.Source, options.Target));

                if (options.IncludeSecurity)
                {
                    var currentDirectory = Directory.GetCurrentDirectory();
                    commands.Add(new PostStepFileSystemDataItem(currentDirectory, string.Empty, PostDeployDll)
                                 .GenerateAddCommand().FirstOrDefault());
                    diff.PostStep = PostStep;
                    diff.Version  = version;
                }

                if (options.DacPac)
                {
                    SqlConverter c = new SqlConverter();
                    c.ConvertPackage(diff, options.Output);

                    var           builder = new DacPacBuilder();
                    DirectoryInfo d       = new DirectoryInfo(options.Output);
                    foreach (var file in d.GetFiles("*.sql"))
                    {
                        builder.ConvertToDacPac(file.FullName, Path.Combine(file.DirectoryName, $"{Path.GetFileNameWithoutExtension(file.Name)}.dacpac"));
                    }
                }
                else
                {
                    PackageGenerator.GeneratePackage(diff, string.Empty, options.Output);
                }
            }
            else
            {
                Console.WriteLine(options.GetUsage());
            }
        }