コード例 #1
0
        /// <summary>
        /// Extract files from a zip file.
        /// </summary>
        /// <param name="cmdOptions">The zip program command line arguments.</param>
        /// <param name="zipFilePath">The file path of the zip file from which to extract files.</param>
        /// <param name="outputDirectoryPath">The path where you want to put the extracted files.</param>
        public bool UnzipFile(string cmdOptions, string zipFilePath, string outputDirectoryPath)
        {
            // Verify input file and output path have been specified
            if (string.IsNullOrEmpty(m_ZipProgramPath) || string.IsNullOrEmpty(m_WorkDir))
            {
                var msg = "Zip program path and/or working path not specified";
#pragma warning disable 618
                m_EventLogger?.PostEntry(msg, logMsgType.logError, true);
#pragma warning restore 618
                m_Logger?.Error(msg);

                return(false);
            }

            // Verify input file exists
            if (!File.Exists(zipFilePath))
            {
                var msg = "Input file not found: " + zipFilePath;
#pragma warning disable 618
                m_EventLogger?.PostEntry(msg, logMsgType.logError, true);
#pragma warning restore 618
                m_Logger?.Error(msg);

                return(false);
            }

            // Verify output path exists
            if (!Directory.Exists(outputDirectoryPath))
            {
                var msg = "Output directory " + outputDirectoryPath + " does not exist";
#pragma warning disable 618
                m_EventLogger?.PostEntry(msg, logMsgType.logError, true);
#pragma warning restore 618
                m_Logger?.Error(msg);

                return(false);
            }

            // Setup the unzip program
            var zipper = new ProgRunner
            {
                Arguments          = "-Extract " + cmdOptions + " \"" + zipFilePath + "\" \"" + outputDirectoryPath + "\"",
                MonitoringInterval = m_WaitInterval,
                Name              = "Zipper",
                Program           = m_ZipProgramPath,
                WorkDir           = m_WorkDir,
                Repeat            = false,
                RepeatHoldOffTime = 0,
                CreateNoWindow    = m_CreateNoWindow,
                WindowStyle       = m_WindowStyle,
            };

            // Start the unzip program
            zipper.StartAndMonitorProgram();

            // Wait for zipper program to complete
            var success = WaitForZipProgram(zipper);

            return(success);
        }
コード例 #2
0
        /// <summary>
        /// Create a zip file.
        /// </summary>
        /// <param name="cmdOptions">The zip program command line arguments.</param>
        /// <param name="outputFile">The file path of the output zip file.</param>
        /// <param name="inputSpec">The files and/or directories to archive.</param>
        public bool MakeZipFile(string cmdOptions, string outputFile, string inputSpec)
        {
            // Verify input file and output path have been specified
            if (string.IsNullOrEmpty(m_ZipProgramPath) || string.IsNullOrEmpty(m_WorkDir))
            {
                var msg = "Zip program path and/or working path not specified";
#pragma warning disable 618
                m_EventLogger?.PostEntry(msg, logMsgType.logError, true);
#pragma warning restore 618
                m_Logger?.Error(msg);

                return(false);
            }

            // Setup the zip program
            var zipper = new ProgRunner
            {
                Arguments          = "-Add " + cmdOptions + " \"" + outputFile + "\" \"" + inputSpec + "\"",
                Program            = m_ZipProgramPath,
                WorkDir            = m_WorkDir,
                MonitoringInterval = m_WaitInterval,
                Name              = "Zipper",
                Repeat            = false,
                RepeatHoldOffTime = 0,
                CreateNoWindow    = m_CreateNoWindow
            };

            // Start the zip program
            zipper.StartAndMonitorProgram();

            // Wait for zipper program to complete
            var success = WaitForZipProgram(zipper);

            return(success);
        }
コード例 #3
0
        /// <summary>
        /// Pause the program for the specified number of milliseconds, displaying a period at a set interval while paused
        /// </summary>
        /// <param name="millisecondsToPause">Milliseconds to pause; default 5 seconds</param>
        /// <param name="millisecondsBetweenDots">Seconds between each period; default 1 second</param>
        public static void PauseAtConsole(int millisecondsToPause = 5000, int millisecondsBetweenDots = 1000)
        {
            int totalIterations;

            Console.WriteLine();
            Console.Write("Continuing in " + (millisecondsToPause / 1000.0).ToString("0") + " seconds ");

            try
            {
                if (millisecondsBetweenDots == 0)
                {
                    millisecondsBetweenDots = millisecondsToPause;
                }

                totalIterations = (int)Math.Round(millisecondsToPause / (double)millisecondsBetweenDots, 0);
            }
            catch
            {
                // Ignore errors here
                totalIterations = 1;
            }

            var iteration = 0;

            do
            {
                Console.Write('.');

                ProgRunner.SleepMilliseconds(millisecondsBetweenDots);

                iteration += 1;
            } while (iteration < totalIterations);

            Console.WriteLine();
        }
コード例 #4
0
        /// <summary>
        /// Sleep for the specified number of seconds
        /// </summary>
        /// <param name="waitTimeSeconds"></param>
        /// <remarks>Sleeps for 10 second chunks until waitTimeSeconds has elapsed</remarks>
        public static void SleepSeconds(double waitTimeSeconds)
        {
            var endTime = DateTime.UtcNow.AddSeconds(waitTimeSeconds);

            while (endTime.Subtract(DateTime.UtcNow).TotalMilliseconds > 10)
            {
                var remainingSeconds = endTime.Subtract(DateTime.UtcNow).TotalSeconds;
                if (remainingSeconds > 10)
                {
                    ProgRunner.SleepMilliseconds(10000);
                }
                else
                {
                    var sleepTimeMsec = (int)Math.Ceiling(remainingSeconds * 1000);
                    ProgRunner.SleepMilliseconds(sleepTimeMsec);
                }
            }
        }