Example #1
0
        static void Main(string[] args)
        {
            string[] args01 = {"-targetLocation", @"c:\test", "-sourceFolder", @"c:\tester\tester"};
            string[] args02 = {"-targetLocationd"};
            string[] args03 = {"--help"};
            string[] args04 = {"-targetLocation", @"c:\test", "-sourceFolder"};
            string[] args05 = {"-targetLocation", @"c:\test", "-sourceFolder", "value"};
            string[] args06 = {"-targetLocation", @"c:\test", "-sourceFolder", @"c:\tester\tester", "--debug", "true"};
            string[] args07 = {"/?"};
            string[] args08 = {"-?"};

            //args = args06;

            CommandLineArgs.CmdLine cl = new CommandLineArgs.CmdLine( isConsole : true );

            cl.AddHelpLine("Test CmdLine class.");
            cl.AddHelpLine("More information here.");

            cl.AddRequiredArgumentDefinition("-targetLocation", "Fully qualified folder name of target location.");
            cl.AddOptionalArgumentDefinition("-sourceFolder", "Fully qualified folder name of source location.");

            cl.Initialize(args);

            var argValue = cl.GetArgumentValue("-targetLocation");
            if (!String.IsNullOrEmpty(argValue)) {
                Console.WriteLine(argValue);
            }

            argValue = cl.GetArgumentValue("-sourceFolder");
            if (!String.IsNullOrEmpty(argValue)) {
                Console.WriteLine(argValue);
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Example #2
0
        static void Main(string[] args)
        {
            CommandLineArgs.CmdLine cl = new CommandLineArgs.CmdLine();

            // Add as many header(n) lines as necessary for help.
            cl.ArgumentKeys.Add("header1", "Enumerate files and write file info into SQL Server database.");

            //// Add one line per argument key providing a short description.
            cl.ArgumentKeys.Add("-rootFolder", "Root folder at which to start file info collection.");
            cl.ArgumentKeys.Add("-logFile", "Fully qualified log file name (including extension.");
            cl.ArgumentKeys.Add("-clearDBFirst", "Clear all rows from target table first (true or false).");
            cl.ArgumentKeys.Add("-location", "General source location of data collection (ie, computer name).");
            cl.ArgumentKeys.Add("-DBLocation", "SQL Server CE DB location");

            cl.Initialize(args);

            string startingLocation = cl.GetArgumentValue( "-rootFolder", @"c:\" );
            string logFile = cl.GetArgumentValue("-logFile", @"C:\Users\roger\logfiles\file-list.csv" );
            bool clearDB = cl.GetArgumentValue( "-clearDBFirst", "false" ) == "true" ? true : false;
            string location = cl.GetArgumentValue("-location", "No location provided");
            string DBLocation = cl.GetArgumentValue("-DBLocation", @"C:\Users\roger\SQLServerCE");

            Console.WriteLine( "Starting at root folder: {0}", startingLocation );
            Console.WriteLine( "Writing log file at {0}", logFile );

            System.IO.StreamWriter file = new System.IO.StreamWriter(logFile);

            file.WriteLine( "File,Extension,Path,DateCreated,DateModified" );

            var DBPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            DBPath = DBLocation;
            var connectionString = String.Format( @"Data Source='{0}\FileCatalog.sdf'", DBPath );

            var sq = new SqlServerFactory( connectionString );
            sq.OpenConnection();

            if ( clearDB ) {
                sq.SetSqlCommand("delete from [files]");
                sq.ExecuteNonQuery();
            }

            var totalCounter = 0;
            var subCounter = 0;
            const int INCREMENTER = 500;

            const string INSERT_SQL =
                @"INSERT INTO [Files] (
                    [File],
                    [Extension],
                    [Path],
                    [Location],
                    [DateCreated],
                    [DateModified] )
                values (
                    @file,
                    @extension,
                    @path,
                    @location,
                    @dateCreated,
                    @dateModified )";

            DirectoryInfo diTop = new DirectoryInfo( startingLocation );
            try {
                foreach (var fi in diTop.EnumerateFiles()) {
                    try {
                        if ( ! InsertIntoTable(sq, INSERT_SQL, fi, location) ) {
                            file.WriteLine(CreateOutputLine(fi,location));
                        }
                        else {
                            totalCounter += 1;
                            subCounter +=1;
                        }
                    }
                    catch (UnauthorizedAccessException UnAuthTop) {
                        // file.WriteLine("{0}", fi.FullName);
                    }
                }

                foreach (var di in diTop.EnumerateDirectories("*")) {
                    try {
                        if ( ! di.Name.Contains("$RECYCLE.BIN")) {
                            foreach (var fi in di.EnumerateFiles("*", SearchOption.AllDirectories)) {
                                try {
                                    if (!InsertIntoTable(sq, INSERT_SQL, fi, location)) {
                                        file.WriteLine(CreateOutputLine(fi,location));
                                    }
                                    else {
                                        totalCounter += 1;
                                        subCounter += 1;
                                        if ( subCounter % INCREMENTER == 0 ) {
                                            subCounter = 0;
                                            Console.WriteLine( totalCounter.ToString( "#,##0" ));
                                        }
                                    }
                                }
                                catch (UnauthorizedAccessException UnAuthFile) {
                                }
                            }
                        }
                    }
                    catch (UnauthorizedAccessException UnAuthSubDir) {
                    }
                }
            }
            catch (DirectoryNotFoundException DirNotFound) {
            }
            catch (UnauthorizedAccessException UnAuthDir) {
            }
            catch (PathTooLongException LongPath) {
            }

            file.Close();
            sq.CloseConnection();
            Console.WriteLine( "Total = " + totalCounter.ToString("#,##0"));
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }
Example #3
0
        static void Main(string[] args)
        {
            //Environment.SetEnvironmentVariable( "working-folder", @"C:\rpDocuments\Programs\MR\ParadePrototype\FrankieLee" );
            string workingFolder = Environment.GetEnvironmentVariable( "workingfolder", EnvironmentVariableTarget.Process );

            CommandLineArgs.CmdLine cl = new CommandLineArgs.CmdLine();

            //args = new string[] { "-method", "download", "-pcfilename", @"C:\rpDocuments\Programs\MR\ParadePrototype\FrankieLee\testone.rpg", "-member", "hellorpg" };
            //args = new string[] { "-method", "download", "-pcfilename", "roger.rpg", "-member", "hellorpg" };
            //args = new string[] { "--help" };

            cl.AddHelpLine("FTP source member upload or download.");
            cl.AddHelpLine("Set enviroment variable 'workingfolder' so you");
            cl.AddHelpLine("can use just the filename portion of pcFilename.");

            cl.AddRequiredArgumentDefinition("-method", "get(upload) or put(download).");
            cl.AddRequiredArgumentDefinition("-pcFilename", "Fully qualified PC file name.");
            cl.AddRequiredArgumentDefinition("-member", "IBM i member name.");
            cl.AddOptionalArgumentDefinition("-server", "Server name or IP address.");
            cl.AddOptionalArgumentDefinition("-library", "IBM i library name.");
            cl.AddOptionalArgumentDefinition("-sourceFile", "IBM i source physical file.");
            cl.AddOptionalArgumentDefinition("-user", "IBM i user name.");
            cl.AddOptionalArgumentDefinition("-password", "IBM i user password.");

            cl.Initialize(args);

            string pcFilename = cl.GetArgumentValue("-pcFileName");

            if (!String.IsNullOrEmpty(workingFolder)) {
                workingFolder = (workingFolder.EndsWith(@"\")) ? workingFolder : workingFolder + @"\";
                pcFilename = workingFolder + pcFilename;
            }

            Ftp ftp = new Ftp() {server = cl.GetArgumentValue("-server", "Cypress"),
                                 library = cl.GetArgumentValue("-library", "rpmobile"),
                                 sourceFile = cl.GetArgumentValue("-sourceFile", "qrpglesrc"),
                                 user = cl.GetArgumentValue("-user", "rogerso"),
                                 password = cl.GetArgumentValue("-password", "ASNA")};

            string result = "";
            string member = cl.GetArgumentValue( "-member" );

            try {
                if (cl.GetArgumentValue("-method").ToLower() == "put" || cl.GetArgumentValue("-method").ToLower() == "upload" )  {
                    result = ftp.Put( pcFilename, member );
                    Console.WriteLine("Uploaded {0}\r\n to {1}/{2}/{3}/{4}.", pcFilename, ftp.server, ftp.library, ftp.sourceFile, member);
                }
                else if ( cl.GetArgumentValue( "-method" ).ToLower() == "get" || cl.GetArgumentValue( "-method" ).ToLower() == "download") {
                    result = ftp.Get( pcFilename, member );
                    Console.WriteLine( "Downloaded {0}\r\n from {1}/{2}/{3}/{4}.", pcFilename, ftp.server, ftp.library, ftp.sourceFile, member );
                }
                else {
                    throw new Exception( "-method must be be 'get', 'download',  'put', or 'upload'." );
                }
            }
            catch ( System.Exception e ) {
                Console.WriteLine("*ERROR* Program failure...");
                Console.WriteLine(e.Message);
                Console.WriteLine("Note: 'error (426)' probably means the IBM member doesn't exist.");
            }

            Console.WriteLine(result);
            //Console.WriteLine("Press any key to continue...");
            //Console.ReadKey();
        }