Ejemplo n.º 1
0
        /**
         * Constructs a new ScriptRunner object to be used to promote files from the source location, specified in the OptionWrapper.
         * This can be a directory or a zip archive. If it is a zip it will be extracted to a temporary directory.
         * @param pCommandLineWrapper Container for all command line arguments.
         */
        private ScriptRunner(CommandLineWrapper pCommandLineWrapper)
        {

            mCommandLineWrapper = pCommandLineWrapper;
            string lSourceLocation = mCommandLineWrapper.RunDirectory;

            //Validate source location is not null
            if (string.IsNullOrEmpty(lSourceLocation))
            {
                throw new ExFatalError($"-run argument must be specified");
            }

            FileInfo lSourceFile = new FileInfo(lSourceLocation);
            if (!lSourceFile.Exists)
            {
                throw new ExFatalError($"Failed to locate source file at {lSourceLocation}");
            }

            DirectoryInfo sourceFileDirectory = new DirectoryInfo(lSourceLocation);
            if (sourceFileDirectory.Exists)
            {
                mIsBaseDirectoryTemp = false;
                mBaseDirectory = sourceFileDirectory;
            }
            else
            {
                mIsBaseDirectoryTemp = true;
                string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
                mBaseDirectory = Directory.CreateDirectory(tempDirectory);
                try
                {
                    Logger.logInfo("Extracting archive " + lSourceLocation);
                    int lFileCount = ArchiveUtil.extractZipToFolder(lSourceFile, mBaseDirectory);
                    Logger.logInfo("Extracted " + lFileCount + " files");
                }
                catch (ZipException e)
                {
                    throw new ExInternal($"Zip error extracting zip to {mBaseDirectory.FullName}", e);
                }
                catch (IOException e)
                {
                    throw new ExInternal($"IO error extracting zip to {mBaseDirectory.FullName}", e);
                }
            }

            Logger.logInfo($"Base directory is {mBaseDirectory.FullName}");
        }