Пример #1
0
 public WriterService(StreamResultQueue queue, SystemSettingMonitor monitor)
     : base(queue, monitor)
 {
 }
 protected BaseService(StreamResultQueue queue, SystemSettingMonitor monitor)
 {
     this.queue   = queue;
     this.monitor = monitor;
 }
Пример #3
0
        static void Main(string[] args)
        {
            if (args.Length != STANDARD_ARGS_COUNT)
            {
                throw new ArgumentException("Incorrect argument count");
            }

            var operationName = args[0].Trim().ToUpper();

            if (!OperationList.Contains(operationName))
            {
                throw new ArgumentException("Incorrect operation name");
            }

            var isCompressOperation = operationName == COMPRESS_OPERATION;
            var operationType       = isCompressOperation
                ? CompressionMode.Compress
                : CompressionMode.Decompress;

            var inputFilePath = args[1].Trim();

            if (!File.Exists(inputFilePath))
            {
                throw new ArgumentException("Specified as input file is not existed");
            }

            var outputFilePath = args[2].Trim();

            if (!Directory.Exists(Path.GetDirectoryName(outputFilePath)))
            {
                throw new ArgumentException("Specified as output directory is not existed");
            }

            if (File.Exists(outputFilePath))
            {
                throw new ArgumentException("Specified as output file is already existed");
            }

            var destinationDrive = DriveInfo.GetDrives()
                                   .Single(drive => drive.RootDirectory.Name == Path.GetPathRoot(outputFilePath));

            using (var inputFileStream = File.OpenRead(inputFilePath))
            {
                if (isCompressOperation && inputFileStream.IsCompressed())
                {
                    throw new Exception("Specified as input file is already compressed");
                }

                if (!isCompressOperation && !inputFileStream.IsCompressed())
                {
                    throw new Exception("Specified as input file is not compressed");
                }

                if (destinationDrive.AvailableFreeSpace < inputFileStream.Length)
                {
                    throw new Exception("Specified as output directory have not enough free space");
                }
            }

            var monitor = new SystemSettingMonitor();

            AppDomain.CurrentDomain.UnhandledException += delegate(object sender, UnhandledExceptionEventArgs eventArgs)
            {
                monitor.HandleError((Exception)eventArgs.ExceptionObject, "");
            };

            new InitializationLogic(monitor)
            .InitializeWorkers(operationType, inputFilePath, outputFilePath);
        }
        public InitializationLogic(SystemSettingMonitor monitor)
        {
            this.monitor = monitor;

            queue = new StreamResultQueue();
        }