Ejemplo n.º 1
0
 public static string[] RecordsToString(List<Record> records, RecordFormat recordFormat)
 {
     var rows = new string[records.Count];
     for (var i = 0; i < records.Count; i++)
         rows[i] = RecordToString(records[i], recordFormat);
     return rows;
 }
Ejemplo n.º 2
0
        static public string[] RecordsToString(List <Record> records, RecordFormat recordFormat)
        {
            var rows = new string[records.Count];

            for (var i = 0; i < records.Count; i++)
            {
                rows[i] = RecordToString(records[i], recordFormat);
            }
            return(rows);
        }
Ejemplo n.º 3
0
        static private string RecordToString(Record record, RecordFormat recordFormat)
        {
            var tempRecord = new StringBuilder();

            if (recordFormat.IpIsPresent)
            {
                tempRecord.Append(record.Ip);
                tempRecord.Append(" - - ");
            }
            if (recordFormat.QueryTimeIsPresent)
            {
                tempRecord.Append("[");
                tempRecord.Append(DateConverter.DateToString(record.QueryTime));
                tempRecord.Append("] ");
            }
            if (recordFormat.QueryMethodIsPresent)
            {
                tempRecord.Append(record.QueryMethod);
                tempRecord.Append(" ");
            }
            if (recordFormat.FileNameIsPresent)
            {
                tempRecord.Append(record.FileName);
            }
            if (recordFormat.ExtensionIsPresent)
            {
                tempRecord.Append(".");
                tempRecord.Append(record.Extension);
                tempRecord.Append(" ");
            }
            if (recordFormat.ProtocolIsPresent)
            {
                tempRecord.Append(record.Protocol);
                tempRecord.Append(" ");
            }
            if (recordFormat.ServerResponseCodeIsPresent)
            {
                tempRecord.Append(record.ServerResponseCode);
                tempRecord.Append(" ");
            }
            if (recordFormat.SizeOfTheResponseIsPresent)
            {
                tempRecord.Append(record.SizeOfTheResponse);
            }
            return(tempRecord.ToString());
        }
Ejemplo n.º 4
0
 private static string RecordToString(Record record, RecordFormat recordFormat)
 {
     var tempRecord = new StringBuilder();
     if (recordFormat.IpIsPresent)
     {
         tempRecord.Append(record.Ip);
         tempRecord.Append(" - - ");
     }
     if (recordFormat.QueryTimeIsPresent)
     {
         tempRecord.Append("[");
         tempRecord.Append(DateConverter.DateToString(record.QueryTime));
         tempRecord.Append("] ");
     }
     if (recordFormat.QueryMethodIsPresent)
     {
         tempRecord.Append(record.QueryMethod);
         tempRecord.Append(" ");
     }
     if (recordFormat.FileNameIsPresent)
     {
         tempRecord.Append(record.FileName);
     }
     if (recordFormat.ExtensionIsPresent)
     {
         tempRecord.Append(".");
         tempRecord.Append(record.Extension);
         tempRecord.Append(" ");
     }
     if (recordFormat.ProtocolIsPresent)
     {
         tempRecord.Append(record.Protocol);
         tempRecord.Append(" ");
     }
     if (recordFormat.ServerResponseCodeIsPresent)
     {
         tempRecord.Append(record.ServerResponseCode);
         tempRecord.Append(" ");
     }
     if (recordFormat.SizeOfTheResponseIsPresent)
     {
         tempRecord.Append(record.SizeOfTheResponse);
     }
     return tempRecord.ToString();
 }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            var parametersValidator = new ParametersValidator();
            var parametersAreValid = parametersValidator.Validate(args);

            if (parametersAreValid)
            {
                string nameOfFile;
                string numberOfLines;
                string numberOfUniqueIp;
                var parametersDictionary = CommandLineParser.Parse(args);
                if (parametersDictionary.TryGetValue("nameoffile", out nameOfFile) && parametersDictionary.TryGetValue("numberoflines", out numberOfLines) && parametersDictionary.TryGetValue("numberofuniqueip", out numberOfUniqueIp))
                {
                    var uniqueIpCount = Convert.ToInt32(numberOfUniqueIp);
                    var linesLength = Convert.ToInt32(numberOfLines);
                    var configFileReader = new Settings.ConfigFileReader(@"D:\Univercity\Univercity\3курс-лабы\config.yaml");
                    string[] methods =
                    {
                        "POST", "LINK", "DELETE", "PUT", "PATCH", "GET", "OPTIONS", "HEAD", "TRACE",
                        "UNLINK", "CONNECT"
                    };
                    string[] extensions = {"txt", "pdf", "doc", "exe", "jmp", "cpp", "obj", "iso"};
                    string[] protocols = {"http", "https"};
                    string[] serverResponseCodes = {"200", "401", "204", "404", "501"};
                    const int minIntervalInMilliseconds = 100;
                    const int maxIntervalInMilliseconds = 100000;
                    const int minNumberOfFolders = 3;
                    const int maxNumberOfFolders = 7;
                    const int minNumberOfCharacters = 3;
                    const int maxNumberOfCharacters = 7;
                    const int minSizeOfResponse = 100;
                    const int maxSizeOfResponse = 10000;

                    var recordFormat = new RecordFormat
                    {
                        IpIsPresent = true,
                        QueryTimeIsPresent = true,
                        QueryMethodIsPresent = true,
                        FileNameIsPresent = true,
                        ExtensionIsPresent = true,
                        ProtocolIsPresent = true,
                        ServerResponseCodeIsPresent = true,
                        SizeOfTheResponseIsPresent = true
                    };
                    var generator = new Generator
                    {
                        Extensions = extensions,
                        Protocols = protocols,
                        Methods = methods,
                        Settings = configFileReader.Settings,
                        ServerResponseCodes = serverResponseCodes,
                        MinIntervalInMilliseconds = minIntervalInMilliseconds,
                        MaxIntervalInMilliseconds = maxIntervalInMilliseconds,
                        MinNumberOfCharacters = minNumberOfCharacters,
                        MaxNumberOfCharacters = maxNumberOfCharacters,
                        MinNumberOfFolders = minNumberOfFolders,
                        MaxNumberOfFolders = maxNumberOfFolders,
                        MinSizeOfResponse = minSizeOfResponse,
                        MaxSizeOfResponse = maxSizeOfResponse,
                        NumberOfUniqueIp = uniqueIpCount
                    };
                    var allRecords = generator.GenerateRecords(linesLength);
                    var rows = ApacheLogFormat.RecordsToString(allRecords, recordFormat);
                    SaveToFile.SaveRowsToFile(nameOfFile, rows);
                    Console.WriteLine("Save succesed!");
                }
                else
                {
                    Console.WriteLine("Входные параметры не соответствуют шаблону.");
                }
            }
            else
                Console.WriteLine(parametersValidator.ValidationInformation);
            Console.ReadKey();
        }