Exemplo n.º 1
0
        public KuduSync(KuduSyncOptions options, Logger logger)
        {
            _logger  = logger;
            _options = options;

            _from             = Path.GetFullPath(options.From);
            _to               = Path.GetFullPath(options.To);
            _nextManifest     = new DeploymentManifest(options.NextManifestFilePath);
            _previousManifest = new HashSet <string>(DeploymentManifest.LoadManifestFile(options.PreviousManifestFilePath).Paths, StringComparer.OrdinalIgnoreCase);
            _ignoreList       = BuildIgnoreList(options.Ignore);
            _whatIf           = options.WhatIf;

            if (!options.IgnoreManifestFile && string.IsNullOrWhiteSpace(options.NextManifestFilePath))
            {
                throw new InvalidOperationException("The 'nextManifest' option must be specified unless the 'ignoremanifest' option is set.");
            }

            if (_whatIf)
            {
                throw new NotSupportedException("WhatIf flag is currently not supported");
            }

            if (FileSystemHelpers.IsSubDirectory(_from, _to) || FileSystemHelpers.IsSubDirectory(_to, _from))
            {
                throw new InvalidOperationException("Source and destination directories cannot be sub-directories of each other");
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var stopwatch = Stopwatch.StartNew();
            var kuduSyncOptions = new KuduSyncOptions();

            try
            {
                ICommandLineParser parser = new CommandLineParser();
                if (parser.ParseArguments(args, kuduSyncOptions))
                {
                    SetLogger(kuduSyncOptions);
                    new KuduSync(kuduSyncOptions).Run();
                }
                else
                {
                    throw new InvalidOperationException("Failed to parse arguments");
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error: " + ex.Message);
            }

            stopwatch.Stop();

            if (kuduSyncOptions.Perf)
            {
                Console.WriteLine("Time " + stopwatch.ElapsedMilliseconds);
            }
        }
        public static bool IsFullTextCompareFile(this FileInfoBase file, KuduSyncOptions kuduSyncOptions)
        {
            var matched = kuduSyncOptions.GetFullTextCompareFilePatterns()
                          .Any(fileMatchPattern => Regex.IsMatch(file.Name, WildCardToRegular(fileMatchPattern), RegexOptions.IgnoreCase));

            return(matched);
        }
Exemplo n.º 4
0
        public KuduSync(KuduSyncOptions options, Logger logger)
        {
            _logger = logger;
            _options = options;

            _from = Path.GetFullPath(options.From);
            _to = Path.GetFullPath(options.To);
            _nextManifest = new DeploymentManifest(options.NextManifestFilePath);
            _previousManifest = new HashSet<string>(DeploymentManifest.LoadManifestFile(options.PreviousManifestFilePath).Paths, StringComparer.OrdinalIgnoreCase);
            _ignoreList = BuildIgnoreList(options.Ignore);
            _whatIf = options.WhatIf;

            if (!options.IgnoreManifestFile && string.IsNullOrWhiteSpace(options.NextManifestFilePath))
            {
                throw new InvalidOperationException("The 'nextManifest' option must be specified unless the 'ignoremanifest' option is set.");
            }

            if (_whatIf)
            {
                throw new NotSupportedException("WhatIf flag is currently not supported");
            }

            if (FileSystemHelpers.IsSubDirectory(_from, _to) || FileSystemHelpers.IsSubDirectory(_to, _from))
            {
                throw new InvalidOperationException("Source and destination directories cannot be sub-directories of each other");
            }
        }
Exemplo n.º 5
0
        static int Main(string[] args)
        {
            var stopwatch         = Stopwatch.StartNew();
            var kuduSyncOptions   = new KuduSyncOptions();
            int exitCode          = 0;
            var appOfflineCreated = false;
            var appOfflineSetting = Environment.GetEnvironmentVariable(AppOfflineSetting);

            try
            {
                ICommandLineParser parser = new CommandLineParser();
                if (parser.ParseArguments(args, kuduSyncOptions))
                {
                    using (var logger = GetLogger(kuduSyncOptions))
                    {
                        // The default behavior is to create the app_offline.htm page
                        if (string.IsNullOrWhiteSpace(appOfflineSetting) || !appOfflineSetting.Equals("0"))
                        {
                            appOfflineCreated = CreateAppOffline(kuduSyncOptions.To, logger);
                        }
                        new KuduSync(kuduSyncOptions, logger, appOfflineCreated).Run();
                        if (appOfflineCreated)
                        {
                            if (!RemoveAppOffline(kuduSyncOptions.To, logger))
                            {
                                exitCode = 1;
                            }
                            appOfflineCreated = false;
                        }
                    }
                }
                else
                {
                    Console.Error.WriteLine(kuduSyncOptions.GetUsage());
                    return(1);
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error: " + ex.Message);

                // If we created app_offline.htm but caught some exception while running kudusync, try to remove it.
                if (appOfflineCreated)
                {
                    RemoveAppOffline(kuduSyncOptions.To, GetLogger(kuduSyncOptions));
                }
                exitCode = 1;
            }

            stopwatch.Stop();

            if (kuduSyncOptions.Perf)
            {
                Console.WriteLine("Time " + stopwatch.ElapsedMilliseconds);
            }

            return(exitCode);
        }
Exemplo n.º 6
0
 public KuduSync(KuduSyncOptions options)
 {
     _from = Path.GetFullPath(options.From);
     _to = Path.GetFullPath(options.To);
     _nextManifest = new DeploymentManifest(options.NextManifestFilePath);
     _previousManifest = new HashSet<string>(DeploymentManifest.LoadManifestFile(options.PreviousManifestFilePath).Paths, StringComparer.OrdinalIgnoreCase);
     _ignoreList = BuildIgnoreList(options.Ignore);
     _whatIf = options.WhatIf;
 }
Exemplo n.º 7
0
 private static void SetLogger(KuduSyncOptions kuduSyncOptions)
 {
     if (kuduSyncOptions.Quiet)
     {
         Logger.MaxLogLines = -1;
     }
     else if (kuduSyncOptions.Verbose != null)
     {
         Logger.MaxLogLines = kuduSyncOptions.Verbose.Value;
     }
     else
     {
         Logger.MaxLogLines = 0;
     }
 }
Exemplo n.º 8
0
        static int Main(string[] args)
        {
            var stopwatch       = Stopwatch.StartNew();
            var kuduSyncOptions = new KuduSyncOptions();
            int exitCode        = 0;

            Console.WriteLine(ConfigurationManager.AppSettings["KuduSyncDataDirectory"]);
            try
            {
                Parser.Default.ParseArguments <KuduSyncOptions>(args).WithParsed(
                    o =>
                {
                    using (var logger = GetLogger(o))
                    {
                        new KuduSync(o, logger).Run();
                    }
                }).WithNotParsed(
                    errors =>
                {
                    foreach (var error in errors)
                    {
                        Console.Error.WriteLine(error);
                    }
                    exitCode = 1;
                });
                if (exitCode == 1)
                {
                    return(exitCode);
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error: " + ex.Message);
                exitCode = 1;
            }

            stopwatch.Stop();

            if (kuduSyncOptions.Perf)
            {
                Console.WriteLine("Time " + stopwatch.ElapsedMilliseconds);
            }

            return(exitCode);
        }
Exemplo n.º 9
0
        private static Logger GetLogger(KuduSyncOptions kuduSyncOptions)
        {
            int maxLogLines;

            if (kuduSyncOptions.Quiet)
            {
                maxLogLines = -1;
            }
            else if (kuduSyncOptions.Verbose != null)
            {
                maxLogLines = kuduSyncOptions.Verbose.Value;
            }
            else
            {
                maxLogLines = 0;
            }

            return(new Logger(maxLogLines));
        }
Exemplo n.º 10
0
        private static Logger GetLogger(KuduSyncOptions kuduSyncOptions)
        {
            int maxLogLines;

            if (kuduSyncOptions.Quiet)
            {
                maxLogLines = -1;
            }
            else if (kuduSyncOptions.Verbose != null)
            {
                maxLogLines = kuduSyncOptions.Verbose.Value;
            }
            else
            {
                maxLogLines = 0;
            }

            return new Logger(maxLogLines);
        }
Exemplo n.º 11
0
        public KuduSync(KuduSyncOptions options, Logger logger, bool saveAppOffline)
        {
            _logger  = logger;
            _options = options;

            _from             = Path.GetFullPath(options.From);
            _to               = Path.GetFullPath(options.To);
            _targetSubFolder  = options.TargetSubFolder;
            _nextManifest     = new DeploymentManifest(options.NextManifestFilePath);
            _previousManifest = new HashSet <string>(DeploymentManifest.LoadManifestFile(options.PreviousManifestFilePath).Paths, StringComparer.OrdinalIgnoreCase);
            BuildIgnoreList(options.Ignore, out _ignoreList, out _wildcardIgnoreList);
            _whatIf = options.WhatIf;
            _toBeDeletedDirectoryPath = Path.Combine(Environment.ExpandEnvironmentVariables(ConfigurationManager.AppSettings["KuduSyncDataDirectory"]), "tobedeleted");
            _saveAppOffline           = saveAppOffline;

            if (!options.IgnoreManifestFile && string.IsNullOrWhiteSpace(options.NextManifestFilePath))
            {
                throw new InvalidOperationException("The 'nextManifest' option must be specified unless the 'ignoremanifest' option is set.");
            }

            if (_whatIf)
            {
                throw new NotSupportedException("WhatIf flag is currently not supported");
            }

            if (FileSystemHelpers.IsSubDirectory(_from, _to) || FileSystemHelpers.IsSubDirectory(_to, _from))
            {
                throw new InvalidOperationException("Source and destination directories cannot be sub-directories of each other");
            }

            if (!TryCleanupToBeDeletedDirectory())
            {
                _logger.Log("Cannot removed the 'to be deleted' directory, ignoring");
            }

            if (!string.IsNullOrEmpty(_targetSubFolder))
            {
                _to = Path.Combine(_to, _targetSubFolder);
            }
        }
Exemplo n.º 12
0
        public KuduSync(KuduSyncOptions options, Logger logger)
        {
            _logger = logger;
            _options = options;

            _from = Path.GetFullPath(options.From);
            _to = Path.GetFullPath(options.To);
            _targetSubFolder = options.TargetSubFolder;
            _nextManifest = new DeploymentManifest(options.NextManifestFilePath);
            _previousManifest = new HashSet<string>(DeploymentManifest.LoadManifestFile(options.PreviousManifestFilePath).Paths, StringComparer.OrdinalIgnoreCase);
            BuildIgnoreList(options.Ignore, out _ignoreList, out _wildcardIgnoreList);
            _whatIf = options.WhatIf;
            _toBeDeletedDirectoryPath = Path.Combine(Environment.ExpandEnvironmentVariables(ConfigurationManager.AppSettings["KuduSyncDataDirectory"]), "tobedeleted");

            if (!options.IgnoreManifestFile && string.IsNullOrWhiteSpace(options.NextManifestFilePath))
            {
                throw new InvalidOperationException("The 'nextManifest' option must be specified unless the 'ignoremanifest' option is set.");
            }

            if (_whatIf)
            {
                throw new NotSupportedException("WhatIf flag is currently not supported");
            }

            if (FileSystemHelpers.IsSubDirectory(_from, _to) || FileSystemHelpers.IsSubDirectory(_to, _from))
            {
                throw new InvalidOperationException("Source and destination directories cannot be sub-directories of each other");
            }

            if (!TryCleanupToBeDeletedDirectory())
            {
                _logger.Log("Cannot removed the 'to be deleted' directory, ignoring");
            }

            if (!string.IsNullOrEmpty(_targetSubFolder))
            {
                _to = Path.Combine(_to, _targetSubFolder);
            }
        }
Exemplo n.º 13
0
        static int Main(string[] args)
        {
            var stopwatch = Stopwatch.StartNew();
            var kuduSyncOptions = new KuduSyncOptions();
            int exitCode = 0;

            try
            {
                ICommandLineParser parser = new CommandLineParser();
                if (parser.ParseArguments(args, kuduSyncOptions))
                {
                    using (var logger = GetLogger(kuduSyncOptions))
                    {
                        new KuduSync(kuduSyncOptions, logger).Run();
                    }
                }
                else
                {
                    Console.Error.WriteLine(kuduSyncOptions.GetUsage());
                    return 1;
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error: " + ex.Message);
                exitCode = 1;
            }

            stopwatch.Stop();

            if (kuduSyncOptions.Perf)
            {
                Console.WriteLine("Time " + stopwatch.ElapsedMilliseconds);
            }

            return exitCode;
        }
Exemplo n.º 14
0
        static int Main(string[] args)
        {
            var stopwatch       = Stopwatch.StartNew();
            var kuduSyncOptions = new KuduSyncOptions();
            int exitCode        = 0;

            try
            {
                ICommandLineParser parser = new CommandLineParser();
                if (parser.ParseArguments(args, kuduSyncOptions))
                {
                    using (var logger = GetLogger(kuduSyncOptions))
                    {
                        new KuduSync(kuduSyncOptions, logger).Run();
                    }
                }
                else
                {
                    Console.Error.WriteLine(kuduSyncOptions.GetUsage());
                    return(1);
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error: " + ex.Message);
                exitCode = 1;
            }

            stopwatch.Stop();

            if (kuduSyncOptions.Perf)
            {
                Console.WriteLine("Time " + stopwatch.ElapsedMilliseconds);
            }

            return(exitCode);
        }