Пример #1
0
        static void Main(string[] args)
        {
            if (ServicePointManager.DefaultConnectionLimit < 30)
                ServicePointManager.DefaultConnectionLimit = 30;

            Console.Out.Close();
            using (var writer = new StreamWriter(Console.OpenStandardOutput(), Utf8NoBom, 4 * 4096))
            using (new Timer(_ => TaskCollector.Default.Add(Console.Out.FlushAsync(), "Console Flush"), null, 750, 750))
            {
                Console.SetOut(writer);

                var bucket = ConfigurationManager.AppSettings["Bucket"];

                if (string.IsNullOrWhiteSpace(bucket))
                {
                    Console.WriteLine("No bucket name found in the application settings");
                    return;
                }

                var sw = new Stopwatch();

                try
                {
                    var syncer = new S3PathSyncer();

                    sw.Start();

                    ConsoleCancel.RunAsync(ct => syncer.SyncPathsAsync(bucket, args, fi => !ExcludeFiles.Contains(fi.Name, StringComparer.OrdinalIgnoreCase), ct), TimeSpan.Zero).Wait();

                    sw.Stop();
                }
                catch (Exception ex)
                {
                    sw.Stop();

                    Console.WriteLine(ex.Message);
                }

                TaskCollector.Default.Wait();

                var process = Process.GetCurrentProcess();

                Console.WriteLine("Elapsed: {0} CPU {1} User {2}", sw.Elapsed, process.TotalProcessorTime, process.UserProcessorTime);
            }
        }