public static CompressHandler GetSingleton()
 {
     if (_handler == null)
     {
         _handler = new CompressHandler();
     }
     return(_handler);
 }
예제 #2
0
        void OnExecute()
        {
            //Source 不存在
            if (!(File.Exists(Source) || Directory.Exists(Source)))
            {
                Console.WriteLine($"File or directory {Source} not exist.");
                return;
            }
            //Source 为文件
            if (File.Exists(Source))
            {
                try
                {
                    CompressHandler.CompressSingle(Source, Destination, this);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error.\n " + e.Message + e.StackTrace);
                }
            }
            //Source 为目录
            else
            {
                try
                {
                    CompressHandler.CompressMultiple(Source, Destination, this);
                }
                catch (AggregateException aggregateException)
                {
                    Console.WriteLine("Error\n");
                    Console.WriteLine("Failed attempts (totally {0}):", aggregateException.InnerExceptions.Count);

                    foreach (var e in aggregateException.InnerExceptions)
                    {
                        Console.WriteLine($"<{e.Source}>failed because:{e.Message}|");
                    }
                }
                Console.WriteLine("Finished!");
            }
        }