/// <summary>
        /// Validates <see cref="WhistleOptions"/>. This method makes sure that -
        /// <list type="number">
        ///     <item>
        ///         <description>
        ///         <see cref="WhistleOptions"/> object is not null.
        ///         </description>
        ///     </item>
        ///     <item>
        ///         <description>
        ///         ExecutableName is not null or empty and it is a valid and existing path.
        ///         </description>
        ///     </item>
        ///     <item>
        ///         <description>
        ///         If WorkingDirectory is not null or empty then it is a valid and existing path.
        ///         </description>
        ///     </item>
        /// </list>
        /// </summary>
        /// <param name="whistleOptions">
        /// <see cref="WhistleOptions"/> object to be validated.
        /// </param>
        public void Validate(WhistleOptions whistleOptions)
        {
            if (whistleOptions == null)
            {
                throw new ArgumentNullException(nameof(whistleOptions));
            }

            if (string.IsNullOrWhiteSpace(whistleOptions.ExecutableName))
            {
                throw new ArgumentException("WhistleOptions.ExecutableName cannot be null or empty.",
                                            nameof(whistleOptions));
            }

            if (!File.Exists(whistleOptions.ExecutableName))
            {
                throw new ArgumentException(
                          "Could not find the executable specified in the ExecutableName. Please make sure that the executale exists at the path specified by the ExecutableName and user has at least ReadOnly permission for the executable file.");
            }

            if (!string.IsNullOrWhiteSpace(whistleOptions.WorkingDirectory) &&
                !Directory.Exists(whistleOptions.WorkingDirectory))
            {
                throw new ArgumentException(
                          "Could not find directory specified in the WorkingDirectory. Please make sure that a directory exists at the path specified by the WorkingDirectory and user has at least ReadOnly permission for the directory.");
            }

            if (whistleOptions.ExitTimeout != null && whistleOptions.ExitTimeout <= 0)
            {
                throw new ArgumentException("ExitTimeout must be an integer value greater than zero.");
            }
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of <see cref="Whistle"/> with the given <see cref="WhistleOptions"/>.
        /// </summary>
        /// <param name="whistleOptions">Options that can be passed to <see cref="Whistle"/> to change its behaviour.</param>
        /// <param name="whistleOptionsValidator">Implementation of <see cref="IWhistleOptionsValidator"/></param>
        /// <param name="processStartInformationBuilder">Implementation of <see cref="IProcessStartInformationBuilder"/></param>
        internal Whistle(
            WhistleOptions whistleOptions,
            IWhistleOptionsValidator whistleOptionsValidator,
            IProcessStartInformationBuilder processStartInformationBuilder)
        {
            if (whistleOptionsValidator == null)
                throw new ArgumentNullException(nameof(whistleOptionsValidator));

            if (processStartInformationBuilder == null)
                throw new ArgumentNullException(nameof(processStartInformationBuilder));

            _whistleOptions = whistleOptions;
            _processStartInformationBuilder = processStartInformationBuilder;
            _whistleOptionsValidator = whistleOptionsValidator;
        }
示例#3
0
        /// <summary>
        /// Build <see cref="ProcessStartInfo"/> object from the given <see cref="WhistleOptions"/> object.
        /// </summary>
        /// <param name="whistleOptions"><see cref="WhistleOptions"/></param>
        /// <param name="arguments">Extra arguments for the executable.</param>
        /// <returns>
        /// <see cref="ProcessStartInfo"/>
        /// </returns>
        public ProcessStartInfo Build(WhistleOptions whistleOptions, IEnumerable <string> arguments = null)
        {
            var processStartInformation = new ProcessStartInfo
            {
                UseShellExecute        = false,
                CreateNoWindow         = true,
                ErrorDialog            = false,
                WindowStyle            = ProcessWindowStyle.Hidden,
                RedirectStandardError  = true,
                RedirectStandardInput  = true,
                RedirectStandardOutput = true,
                FileName         = whistleOptions.ExecutableName,
                WorkingDirectory = whistleOptions.WorkingDirectory
            };

            //Populate arguments
            var processArguments = new List <string>();

            if (whistleOptions.Arguments != null && whistleOptions.Arguments.Any())
            {
                processArguments.AddRange(whistleOptions.Arguments);
            }

            if (arguments != null)
            {
                var extraArguments = arguments as string[] ?? arguments.ToArray();
                if (extraArguments.Any())
                {
                    processArguments.AddRange(extraArguments);
                }
            }

            if (processArguments.Count > 0)
            {
                processStartInformation.Arguments = string.Join(" ", processArguments);
            }

            //Populate Environment Variables
            if (whistleOptions.EnvironmentVariables != null && whistleOptions.EnvironmentVariables.Count > 0)
            {
                foreach (var environmentVariable in whistleOptions.EnvironmentVariables)
                {
                    processStartInformation.EnvironmentVariables.Add(environmentVariable.Key, environmentVariable.Value);
                }
            }

            return(processStartInformation);
        }
        /// <summary>
        /// Build <see cref="ProcessStartInfo"/> object from the given <see cref="WhistleOptions"/> object.
        /// </summary>
        /// <param name="whistleOptions"><see cref="WhistleOptions"/></param>
        /// <param name="arguments">Extra arguments for the executable.</param>
        /// <returns>
        /// <see cref="ProcessStartInfo"/>
        /// </returns>
        public ProcessStartInfo Build(WhistleOptions whistleOptions, IEnumerable<string> arguments = null)
        {
            var processStartInformation = new ProcessStartInfo
            {
                UseShellExecute = false,
                CreateNoWindow = true,
                ErrorDialog = false,
                WindowStyle = ProcessWindowStyle.Hidden,
                RedirectStandardError = true,
                RedirectStandardInput = true,
                RedirectStandardOutput = true,
                FileName = whistleOptions.ExecutableName,
                WorkingDirectory = whistleOptions.WorkingDirectory
            };

            //Populate arguments
            var processArguments = new List<string>();

            if (whistleOptions.Arguments != null && whistleOptions.Arguments.Any())
            {
                processArguments.AddRange(whistleOptions.Arguments);
            }

            if (arguments != null)
            {
                var extraArguments = arguments as string[] ?? arguments.ToArray();
                if (extraArguments.Any())
                {
                    processArguments.AddRange(extraArguments);
                }
            }

            if (processArguments.Count > 0)
            {
                processStartInformation.Arguments = string.Join(" ", processArguments);
            }

            //Populate Environment Variables
            if (whistleOptions.EnvironmentVariables != null && whistleOptions.EnvironmentVariables.Count > 0)
            {
                foreach (var environmentVariable in whistleOptions.EnvironmentVariables)
                {
                    processStartInformation.EnvironmentVariables.Add(environmentVariable.Key, environmentVariable.Value);
                }
            }

            return processStartInformation;
        }
示例#5
0
        /// <summary>
        /// Initializes a new instance of <see cref="Whistle"/> with the given <see cref="WhistleOptions"/>.
        /// </summary>
        /// <param name="whistleOptions">Options that can be passed to <see cref="Whistle"/> to change its behaviour.</param>
        /// <param name="whistleOptionsValidator">Implementation of <see cref="IWhistleOptionsValidator"/></param>
        /// <param name="processStartInformationBuilder">Implementation of <see cref="IProcessStartInformationBuilder"/></param>
        internal Whistle(
            WhistleOptions whistleOptions,
            IWhistleOptionsValidator whistleOptionsValidator,
            IProcessStartInformationBuilder processStartInformationBuilder)
        {
            if (whistleOptionsValidator == null)
            {
                throw new ArgumentNullException(nameof(whistleOptionsValidator));
            }

            if (processStartInformationBuilder == null)
            {
                throw new ArgumentNullException(nameof(processStartInformationBuilder));
            }

            _whistleOptions = whistleOptions;
            _processStartInformationBuilder = processStartInformationBuilder;
            _whistleOptionsValidator        = whistleOptionsValidator;
        }
        /// <summary>
        /// Validates <see cref="WhistleOptions"/>. This method makes sure that - 
        /// <list type="number">
        ///     <item>
        ///         <description>
        ///         <see cref="WhistleOptions"/> object is not null.
        ///         </description>
        ///     </item> 
        ///     <item>
        ///         <description>
        ///         ExecutableName is not null or empty and it is a valid and existing path.
        ///         </description>
        ///     </item>        
        ///     <item>
        ///         <description>
        ///         If WorkingDirectory is not null or empty then it is a valid and existing path.
        ///         </description>
        ///     </item>
        /// </list>
        /// </summary>
        /// <param name="whistleOptions">
        /// <see cref="WhistleOptions"/> object to be validated.
        /// </param>
        public void Validate(WhistleOptions whistleOptions)
        {
            if (whistleOptions == null)
                throw new ArgumentNullException(nameof(whistleOptions));

            if (string.IsNullOrWhiteSpace(whistleOptions.ExecutableName))
                throw new ArgumentException("WhistleOptions.ExecutableName cannot be null or empty.",
                    nameof(whistleOptions));

            if (!File.Exists(whistleOptions.ExecutableName))
                throw new ArgumentException(
                    "Could not find the executable specified in the ExecutableName. Please make sure that the executale exists at the path specified by the ExecutableName and user has at least ReadOnly permission for the executable file.");

            if (!string.IsNullOrWhiteSpace(whistleOptions.WorkingDirectory) &&
                !Directory.Exists(whistleOptions.WorkingDirectory))
                throw new ArgumentException(
                    "Could not find directory specified in the WorkingDirectory. Please make sure that a directory exists at the path specified by the WorkingDirectory and user has at least ReadOnly permission for the directory.");

            if(whistleOptions.ExitTimeout != null && whistleOptions.ExitTimeout <= 0)
                throw new ArgumentException("ExitTimeout must be an integer value greater than zero.");
        }
示例#7
0
 /// <summary>
 /// Initializes a new instance of <see cref="Whistle"/> with the given <see cref="WhistleOptions"/>.
 /// </summary>
 /// <param name="options">
 /// Options that can be passed to <see cref="Whistle"/> to change its behaviour.
 /// </param>
 public Whistle(WhistleOptions options)
     : this(options,
            new WhistleOptionsValidator(),
            new ProcessStartInformationBuilder())
 {
 }
示例#8
0
 /// <summary>
 /// Initializes a new instance of <see cref="Whistle"/> with the given <see cref="WhistleOptions"/>.
 /// </summary>
 /// <param name="options">
 /// Options that can be passed to <see cref="Whistle"/> to change its behaviour.
 /// </param>
 public Whistle(WhistleOptions options)
     : this(options,
         new WhistleOptionsValidator(),
         new ProcessStartInformationBuilder())
 {
 }