~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to test/CreateFiles/.svn/text-base/Main.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// project created on 3/15/2006 at 9:15 AM
2
 
using System;
3
 
using System.IO;
4
 
 
5
 
 
6
 
class MainClass
7
 
{
8
 
        private int maxSize = 4096;
9
 
        private int numberFiles = 1;
10
 
        private string directory = null;
11
 
        private bool random = false;
12
 
        private bool verbose = false;
13
 
        private bool showHelp = false;
14
 
        
15
 
        private void ParseCommandLine( string[] args )
16
 
        {
17
 
                for( int i = 0; i < args.Length; i++ )
18
 
                {
19
 
                        switch( args[ i ].ToLower() )
20
 
                        {
21
 
                        
22
 
                                case "--filesize":
23
 
                                {
24
 
                                        if ( i < args.Length )
25
 
                                        {
26
 
                                                maxSize = Convert.ToInt32( args[ ++i ] );
27
 
                                        }
28
 
                                        break;
29
 
                                }
30
 
                                
31
 
                                case "--number":
32
 
                                {
33
 
                                        if ( i < args.Length )
34
 
                                        {
35
 
                                                numberFiles = Convert.ToInt32( args[ ++i ] );
36
 
                                        }
37
 
                                        break;
38
 
                                }
39
 
                                
40
 
                                case "--dir":
41
 
                                {
42
 
                                        if ( i < args.Length )
43
 
                                        {
44
 
                                                if ( args[ i + 1 ] != "" && args[ i + 1 ].StartsWith( "--" ) == false )
45
 
                                                {
46
 
                                                        directory = args[ ++i ];
47
 
                                                }
48
 
                                        }
49
 
                                        break;
50
 
                                }
51
 
                                
52
 
                                case "--random":
53
 
                                {
54
 
                                        this.random = true;
55
 
                                        break;
56
 
                                }
57
 
                                
58
 
                                case "--help":
59
 
                                {
60
 
                                        this.showHelp = true;
61
 
                                        break;
62
 
                                }
63
 
                        }
64
 
                }
65
 
        }
66
 
        
67
 
        private void ShowUseage()
68
 
        {
69
 
                Console.WriteLine( "Usage: CreateFiles --number <number of files to create> --dir <directory> --filesize <size> --random" );
70
 
                Console.WriteLine( "  --dir  destination directory where to create files" );
71
 
                Console.WriteLine( "  --filesize   destination directory where to create files" );
72
 
                Console.WriteLine( "  --random file size up to and including filesize" );
73
 
        }
74
 
        
75
 
        public MainClass()
76
 
        {
77
 
                directory = Environment.CurrentDirectory;
78
 
        }
79
 
        
80
 
        public static void Main(string[] args)
81
 
        {
82
 
                string fullPathAndFile;
83
 
                int fileSize;
84
 
                
85
 
                MainClass main = new MainClass();
86
 
                
87
 
                if ( args.Length > 0 )
88
 
                {
89
 
                        main.ParseCommandLine( args );
90
 
                        
91
 
                        if ( main.showHelp == true )
92
 
                        {
93
 
                                main.ShowUseage();
94
 
                                return;
95
 
                        }
96
 
                }
97
 
                
98
 
                Random randomSize = new Random( DateTime.Now.Millisecond );
99
 
                
100
 
                Console.WriteLine( "Creating {0} file(s)" );
101
 
                
102
 
                for ( int i = 0; i < main.numberFiles; i++ )
103
 
                {
104
 
                        fullPathAndFile = main.directory + Path.DirectorySeparatorChar.ToString() + Guid.NewGuid();
105
 
                        
106
 
                        if ( main.random == false )
107
 
                        {
108
 
                                fileSize = main.maxSize;
109
 
                        }
110
 
                        else
111
 
                        {
112
 
                                fileSize = randomSize.Next();
113
 
                                while( fileSize > main.maxSize )
114
 
                                {
115
 
                                        fileSize = randomSize.Next();
116
 
                                }
117
 
                        }
118
 
                        
119
 
                        if ( main.verbose == true )
120
 
                        {
121
 
                                Console.WriteLine( "creating: " + fullPathAndFile );
122
 
                                Console.WriteLine( "file size: " + fileSize );
123
 
                        }
124
 
                        
125
 
                        char[] buffer = new char[ fileSize ];
126
 
                        System.IO.StreamWriter sw = File.CreateText( fullPathAndFile );
127
 
                        sw.Write( buffer );
128
 
                        sw.Flush();
129
 
                        sw.Close();
130
 
                        buffer = null;
131
 
                }
132
 
        }
133
 
}
 
 
b'\\ No newline at end of file'