/// <summary>
		/// CTOR.
		/// </summary>
		/// <exception cref="ArgumentNullException">Throws when args is null.</exception>
		/// <param name="args">ScanArgs. Cannot be null.</param>
		public ScanJob(ScanArgs args)
		{
			if(args==null)
				throw new ArgumentNullException("args");

			_args		= args;
			_scancount	= 0;
			_vircount	= 0;

			_agent = new ClamdStreamAgent(args.Host, args.Port, args.Verbose);
			_agent.ItemScanCompleted += new ScanCompletedEventHandler(_agent_ItemScanCompleted);
			_agent.VirusFound		 += new ScanCompletedEventHandler(_agent_VirusFound);
		}
 /// <summary>
 /// Application entry point.
 /// </summary>
 /// <param name="args">Command-line arguments.</param>
 public static void Main(string[] args)
 {
     log4net.Config.DOMConfigurator.Configure();
     try
     {
         ScanJob job = new ScanJob(ScanArgs.Parse(args));
         job.Run();
     }
     catch (ArgumentException ex)
     {
         Debug.WriteLine(ex);
         Console.WriteLine(ex.Message);
     }
 }
Exemple #3
0
        /// <summary>
        /// CTOR.
        /// </summary>
        /// <exception cref="ArgumentNullException">Throws when args is null.</exception>
        /// <param name="args">ScanArgs. Cannot be null.</param>
        public ScanJob(ScanArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            _args      = args;
            _scancount = 0;
            _vircount  = 0;

            _agent = new ClamdStreamAgent(args.Host, args.Port, args.Verbose);
            _agent.ItemScanCompleted += new ScanCompletedEventHandler(_agent_ItemScanCompleted);
            _agent.VirusFound        += new ScanCompletedEventHandler(_agent_VirusFound);
        }
		/// <summary>
		/// Parse a string[] of command-line arguments into a ScanArgs object.
		/// </summary>
		/// <exception cref="ArgumentException">Throws when an invalid switch is passed.</exception>
		/// <param name="args">string[] of command-line arguments</param>
		/// <returns></returns>
		public static ScanArgs Parse(string[] args)
		{
			ScanArgs sargs = new ScanArgs();
			
			if ( args.Length==0 )
				sargs.ShowHelp = true;

			for(int i=0; i<args.Length; i++)
			{
				//check if last arg is file or directory name (or at least not a switch starting with "-"
				if( i==args.Length-1 && !args[i].StartsWith("-") )
					sargs.FileSystem = FileSystemFactory.CreateInstance( args[i] );
				else
				{
					switch( args[i] )
					{
						case FLAG_CLAMD_HOST_SHORT :
							goto case FLAG_CLAMD_HOST_LONG;
						case FLAG_CLAMD_HOST_LONG :
							if( args.Length>i+1 && !args[i+1].StartsWith("-") )
							{
								sargs.Host = args[++i];								
							}
							else
							{
								throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, ResourceManagers.Strings.GetString( STR_PARSE_ARGUMENT_EXCEPTION_HOSTNAME ), FLAG_CLAMD_HOST_SHORT, FLAG_CLAMD_HOST_LONG ) );
							}
							break;
						case FLAG_CLAMD_PORT_SHORT :
							goto case FLAG_CLAMD_PORT_LONG;
						case FLAG_CLAMD_PORT_LONG :
							if( args.Length>i+1 && !args[i+1].StartsWith("-") )
							{
								try
								{
									sargs.Port = int.Parse( args[++i], CultureInfo.InvariantCulture );
								}
								catch (FormatException ex)
								{
									throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, ResourceManagers.Strings.GetString( STR_PARSE_ARGUMENT_EXCEPTION_PORT ), ex.Message ) );
								}
								catch (OverflowException ex)
								{
									throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, ResourceManagers.Strings.GetString( STR_PARSE_ARGUMENT_EXCEPTION_PORT ), ex.Message ) );
								}
							}
							else
							{
								throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, ResourceManagers.Strings.GetString( STR_PARSE_ARGUMENT_EXCEPTION_PORT_MISSING ), FLAG_CLAMD_PORT_SHORT, FLAG_CLAMD_PORT_LONG ) );
							}
							break;

						case FLAG_VERSION_SHORT :
							goto case FLAG_VERSION_LONG;
						case FLAG_VERSION_LONG :
							sargs.ShowVersion = true;
							break;

						case FLAG_HELP_SHORT :
							goto case FLAG_HELP_LONG;
						case FLAG_HELP_LONG :
							sargs.ShowHelp = true;
							break;

						case FLAG_RECURSE_SHORT :
							goto case FLAG_RECURSE_LONG;
						case FLAG_RECURSE_LONG :
							sargs.Recurse = true;
							break;

						case FLAG_VERBOSE_SHORT :
							goto case FLAG_VERBOSE_LONG;
						case FLAG_VERBOSE_LONG :
							sargs.Verbose = true;
							break;

						default :
							throw new ArgumentException( string.Format( CultureInfo.CurrentCulture, ResourceManagers.Strings.GetString( STR_PARSE_ARGUMENT_EXCEPTION_UNKNOWN ), args[1] ) );
					}
				}
			}
			return sargs;
		}
        /// <summary>
        /// Parse a string[] of command-line arguments into a ScanArgs object.
        /// </summary>
        /// <exception cref="ArgumentException">Throws when an invalid switch is passed.</exception>
        /// <param name="args">string[] of command-line arguments</param>
        /// <returns></returns>
        public static ScanArgs Parse(string[] args)
        {
            ScanArgs sargs = new ScanArgs();

            if (args.Length == 0)
            {
                sargs.ShowHelp = true;
            }

            for (int i = 0; i < args.Length; i++)
            {
                //check if last arg is file or directory name (or at least not a switch starting with "-"
                if (i == args.Length - 1 && !args[i].StartsWith("-"))
                {
                    sargs.FileSystem = FileSystemFactory.CreateInstance(args[i]);
                }
                else
                {
                    switch (args[i])
                    {
                    case FLAG_CLAMD_HOST_SHORT:
                        goto case FLAG_CLAMD_HOST_LONG;

                    case FLAG_CLAMD_HOST_LONG:
                        if (args.Length > i + 1 && !args[i + 1].StartsWith("-"))
                        {
                            sargs.Host = args[++i];
                        }
                        else
                        {
                            throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, ResourceManagers.Strings.GetString(STR_PARSE_ARGUMENT_EXCEPTION_HOSTNAME), FLAG_CLAMD_HOST_SHORT, FLAG_CLAMD_HOST_LONG));
                        }
                        break;

                    case FLAG_CLAMD_PORT_SHORT:
                        goto case FLAG_CLAMD_PORT_LONG;

                    case FLAG_CLAMD_PORT_LONG:
                        if (args.Length > i + 1 && !args[i + 1].StartsWith("-"))
                        {
                            try
                            {
                                sargs.Port = int.Parse(args[++i], CultureInfo.InvariantCulture);
                            }
                            catch (FormatException ex)
                            {
                                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, ResourceManagers.Strings.GetString(STR_PARSE_ARGUMENT_EXCEPTION_PORT), ex.Message));
                            }
                            catch (OverflowException ex)
                            {
                                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, ResourceManagers.Strings.GetString(STR_PARSE_ARGUMENT_EXCEPTION_PORT), ex.Message));
                            }
                        }
                        else
                        {
                            throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, ResourceManagers.Strings.GetString(STR_PARSE_ARGUMENT_EXCEPTION_PORT_MISSING), FLAG_CLAMD_PORT_SHORT, FLAG_CLAMD_PORT_LONG));
                        }
                        break;

                    case FLAG_VERSION_SHORT:
                        goto case FLAG_VERSION_LONG;

                    case FLAG_VERSION_LONG:
                        sargs.ShowVersion = true;
                        break;

                    case FLAG_HELP_SHORT:
                        goto case FLAG_HELP_LONG;

                    case FLAG_HELP_LONG:
                        sargs.ShowHelp = true;
                        break;

                    case FLAG_RECURSE_SHORT:
                        goto case FLAG_RECURSE_LONG;

                    case FLAG_RECURSE_LONG:
                        sargs.Recurse = true;
                        break;

                    case FLAG_VERBOSE_SHORT:
                        goto case FLAG_VERBOSE_LONG;

                    case FLAG_VERBOSE_LONG:
                        sargs.Verbose = true;
                        break;

                    default:
                        throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, ResourceManagers.Strings.GetString(STR_PARSE_ARGUMENT_EXCEPTION_UNKNOWN), args[1]));
                    }
                }
            }
            return(sargs);
        }