Esempio n. 1
0
        /// <summary>
        /// Shows one record.
        /// </summary>
        /// <param name="record">Record to show.</param>
        private static void ShowRecord(FileCabinetRecord record)
        {
            string output = "#";

            PropertyInfo[] properties = record.GetType().GetProperties();

            for (int i = 0; i < properties.Length; i++)
            {
                if (properties[i].PropertyType == typeof(DateTime))
                {
                    DateTime date = (DateTime)properties[i].GetValue(record);
                    output += "Date of birth" + ": ";
                    output += date.ToString("yyyy-MMM-d", CultureInfo.InvariantCulture);
                }
                else
                {
                    if (properties[i].Name != "Id")
                    {
                        output += properties[i].Name + ": ";
                    }

                    output += properties[i].GetValue(record);
                }

                if (i != properties.Length - 1)
                {
                    output += ", ";
                }
            }

            Console.WriteLine(output);
        }
Esempio n. 2
0
        /// <summary>
        /// Generating random data in the interval.
        /// </summary>
        /// <param name="amountOfGeneratedRecords">Count of generated records.</param>
        /// <param name="valueToStart">Start id.</param>
        public void CreateRecordRandomValues(int amountOfGeneratedRecords, int valueToStart)
        {
            if (valueToStart == 0)
            {
                valueToStart = 1;
            }

            var lastIdRecord = amountOfGeneratedRecords + valueToStart;

            while (valueToStart < lastIdRecord)
            {
                this.GeneratorGenderAndDateOfBirth();

                var record = new FileCabinetRecord
                {
                    Id          = valueToStart,
                    FirstName   = Faker.Name.First(),
                    LastName    = Faker.Name.Last(),
                    DateOfBirth = new DateTime(this.randomYear, this.randomMonth, this.randomDay).Date,
                    Salary      = new Random().Next(0, int.MaxValue),
                    Age         = (short)Faker.RandomNumber.Next(0, 130),
                    Gender      = this.arrayGender[this.index],
                };
                valueToStart++;
                this.list.Add(record);
            }
        }
Esempio n. 3
0
        public void Write(FileCabinetRecord record)
        {
            if (record is null)
            {
                throw new ArgumentNullException($"{nameof(record)} cannot be null.");
            }

            writer.WriteLine(record.ToString(), CultureInfo.InvariantCulture);
        }
Esempio n. 4
0
        private void WriteOneRecord(FileCabinetRecord record)
        {
            var recordToWrite =
                record.Id.ToString() + ";" +
                record.FirstName + ";" +
                record.LastName + ";" +
                record.Sex.ToString() + ";" +
                record.DateOfBirth.ToShortDateString() + ";" +
                record.Weight.ToString() + ";" +
                record.Balance.ToString();

            this.writer.Write(recordToWrite);
            this.writer.Write(this.writer.NewLine);
        }
Esempio n. 5
0
        public FileCabinetRecord Generate(int recordId)
        {
            var validParameters = this.setter.GetParameters();
            var record          = new FileCabinetRecord();

            record.Id           = recordId;
            record.FirstName    = this.GenerateName(validParameters.FirstNameMinLength, validParameters.FirstNameMaxLenght);
            record.LastName     = this.GenerateName(validParameters.LastNameMinLength, validParameters.LastNameMaxLength);
            record.DateOfBirth  = GenerateDateOfBirth(validParameters.DateOfBirthFrom, validParameters.DateOfBirthTo);
            record.Balance      = randomGenerator.Next(validParameters.BalanceMinValue);
            record.Experience   = Convert.ToInt16(randomGenerator.Next(validParameters.ExperienceMinValue, validParameters.ExperienceMaxValue));
            record.EnglishLevel = GenerateEnglishLevel(validParameters.EnglishLevels);

            return(record);
        }
Esempio n. 6
0
        public FileCabinetRecord Generate(int recordId)
        {
            var record = new FileCabinetRecord();

            record.Id          = recordId;
            record.FirstName   = this.GenerateName(randomGenerator.Next(3, 60));
            record.LastName    = this.GenerateName(randomGenerator.Next(3, 60));
            record.DateOfBirth = GenerateDateOfBirth();
            record.Gender      = char.ToUpper(gender[randomGenerator.Next(gender.Length)]);
            record.Account     = randomGenerator.Next();
            record.Experience  = Convert.ToInt16(randomGenerator.Next(DateTime.Now.Year - record.DateOfBirth.Year));


            return(record);
        }
Esempio n. 7
0
        private FileCabinetRecord GenerateRecord()
        {
            FileCabinetRecord newRecord = new FileCabinetRecord()
            {
                Id            = this.currentId++,
                FirstName     = GenerateName(),
                LastName      = GenerateName(),
                DateOfBirth   = GenerateDateOfBirth(),
                Wallet        = RecordsGenerator.random.Next(0, int.MaxValue),
                MaritalStatus = GenerateMaritalStatus(),
                Height        = (short)RecordsGenerator.random.Next(0, 251),
            };

            return(newRecord);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FileCabinetRecordXml"/> class.
        /// </summary>
        /// <param name="record">Records to represent to xml.</param>
        public FileCabinetRecordXml(FileCabinetRecord record)
        {
            if (record is null)
            {
                throw new ArgumentNullException(nameof(record), Configurator.GetConstantString("NullRecord"));
            }

            this.Id   = record.Id;
            this.Name = new NameXml()
            {
                FirstName = record.FirstName, LastName = record.LastName
            };
            this.DateOfBirth      = record.DateOfBirth;
            this.Height           = record.Height;
            this.Income           = record.Income;
            this.PatronymicLetter = record.PatronymicLetter;
        }
Esempio n. 9
0
        /// <summary>
        /// Makes a deep copy of the object.
        /// </summary>
        /// <param name ="record">Input record.</param>
        /// <returns>new new cloned object <see cref ="FileCabinetRecord"/>.</returns>
        public static FileCabinetRecord DeepCopy(FileCabinetRecord record)
        {
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }

            return(new FileCabinetRecord()
            {
                Id = record.Id,
                FirstName = record.FirstName,
                LastName = record.LastName,
                DateOfBirth = record.DateOfBirth,
                Salary = record.Salary,
                Gender = record.Gender,
                Age = record.Age,
            });
        }
        /// <summary>
        /// writes to a record file.
        /// </summary>
        /// <param name="fileCabinetRecord">the record of a <see cref="FileCabinetRecord"/> type.</param>
        public void Write(FileCabinetRecord fileCabinetRecord)
        {
            if (fileCabinetRecord == null)
            {
                throw new ArgumentNullException(nameof(fileCabinetRecord));
            }

            var builder = new StringBuilder();

            builder.Append($"{fileCabinetRecord.Id},");
            builder.Append($"{fileCabinetRecord.FirstName},");
            builder.Append($"{fileCabinetRecord.LastName},");
            builder.Append($"{fileCabinetRecord.DateOfBirth.ToString("yyyy-MMM-dd", CultureInfo.InvariantCulture)},");
            builder.Append($"{fileCabinetRecord.Gender},");
            builder.Append($"{fileCabinetRecord.Age},");
            builder.Append($"{fileCabinetRecord.Salary}");
            this.textWriter.WriteLine(builder.ToString());
        }
Esempio n. 11
0
        /// <summary>
        /// Generation a single record.
        /// </summary>
        /// <returns>Generated record.</returns>
        public FileCabinetRecord Generate()
        {
            FileCabinetRecord record = new FileCabinetRecord();

            record.Id = this.startId;

            char[] sex = { 'w', 'm' };
            record.Sex = sex[this.random.Next(0, 2)];

            string name = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

            for (int i = 0; i <= this.random.Next(2, 61); i++)
            {
                record.FirstName += name[this.random.Next(0, name.Length)];
            }

            for (int i = 0; i <= this.random.Next(2, 61); i++)
            {
                record.LastName += name[this.random.Next(0, name.Length)];
            }

            record.Salary = Math.Round(Convert.ToDecimal(this.random.NextDouble() * 5000), 2);

            while (true)
            {
                try
                {
                    record.DateOfBirth = DateTime.Parse(this.random.Next(1, 13).ToString(new CultureInfo("en-US")) + "/" + this.random.Next(1, 32).ToString(new CultureInfo("en-US")) + "/" + this.random.Next(1950, 2020).ToString(new CultureInfo("en-US")), new CultureInfo("en-US"));
                }
                catch (Exception)
                {
                    continue;
                }

                break;
            }

            record.Age = Convert.ToInt16(DateTime.Now.Year - record.DateOfBirth.Year);

            this.startId++;

            return(record);
        }
Esempio n. 12
0
        public static IEnumerable <FileCabinetRecord> Generate(int starId, int count)
        {
            Random random = new Random();

            for (int i = starId; i < starId + count; i++)
            {
                FileCabinetRecord record = new FileCabinetRecord
                {
                    FirstName   = StringGenerate(random),
                    LastName    = StringGenerate(random),
                    Department  = (short)random.Next(0, 32766),
                    Salary      = (decimal)(random.NextDouble() * 1000),
                    Class       = CharGenerate(random),
                    DateOfBirth = DateTimeGenerate(random),
                    Id          = i
                };
                yield return(record);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Add generated record using service.
        /// </summary>
        /// <param name="recordAmount">Genereted record amount.</param>
        /// <param name="startId">Start with id.</param>
        /// <returns>Array of records.</returns>
        public FileCabinetRecord[] Generate(int recordAmount, int startId = 1)
        {
            var      startDate = new DateTime(1950, 1, 1);
            TimeSpan period    = DateTime.Now - startDate;
            var      random    = new Random();

            FileCabinetRecord[] result = new FileCabinetRecord[recordAmount];
            for (int i = 0; i < recordAmount; ++i)
            {
                result[i] = new FileCabinetRecord
                {
                    Id          = i + startId,
                    FirstName   = this.firstNames[random.Next(this.firstNames.Length)],
                    LastName    = this.lastNames[random.Next(this.lastNames.Length)],
                    DateOfBirth = startDate + new TimeSpan(0, random.Next(0, (int)period.TotalMinutes), 0),
                    DigitKey    = (short)random.Next(10000),
                    Account     = random.Next(10000),
                    Sex         = (random.Next(100) < 50) ? 'm' : 'f',
                };
            }

            return(result);
        }
Esempio n. 14
0
        private static FileCabinetRecord FileCabinetRecordGenerator(int startId, int index)
        {
            Random   random      = new Random();
            string   genderChars = "MFOU";
            DateTime minDate     = new DateTime(1950, 1, 1);
            DateTime maxDate     = new DateTime(2005, 1, 1);
            int      daysDiff    = Convert.ToInt32(maxDate.Subtract(minDate).TotalDays + 1);

            FileCabinetRecord record = new FileCabinetRecord
            {
                Id       = startId + index,
                FullName = new Name
                {
                    FirstName = "Fn" + random.Next(0, 10000),
                    LastName  = "Ln" + random.Next(0, 10000),
                },
                DateOfBirth = minDate.AddDays(random.Next(0, daysDiff)),
                Gender      = genderChars[random.Next(0, genderChars.Length - 1)],
                Office      = (short)random.Next(0, 500),
                Salary      = (decimal)NextDouble(random, 0, 4000),
            };

            return(record);
        }
Esempio n. 15
0
        private static List <FileCabinetRecord> GenerateRecords(int startId, int recordsAmount)
        {
            List <FileCabinetRecord> records = new List <FileCabinetRecord>();
            Random rnd = new Random();

            for (int i = startId; i < recordsAmount + startId; i++)
            {
                FileCabinetRecord record = new FileCabinetRecord();
                record.Id               = i;
                record.FirstName        = GenRandomString(rnd.Next(2, 60));
                record.LastName         = GenRandomString(rnd.Next(2, 60));
                record.Height           = (short)rnd.Next(120, 250);
                record.Wage             = rnd.Next(300, Int32.MaxValue);
                record.FavouriteNumeral = Char.Parse(rnd.Next(0, 9).ToString());
                int      year     = rnd.Next(1950, DateTime.Now.Year);
                int      month    = rnd.Next(1, 12);
                int      day      = rnd.Next(1, DateTime.DaysInMonth(year, month));
                DateTime dateTime = new DateTime(year, month, day);
                record.DateOfBirth = dateTime;
                records.Add(record);
            }

            return(records);
        }
Esempio n. 16
0
        private static FileCabinetRecord[] GenerateRandomRecords(int start, int amount)
        {
            if (start < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(start), Configurator.GetConstantString("IndexLess1"));
            }

            IConfigurationRoot validationRules = null;

            try
            {
                validationRules = new ConfigurationBuilder()
                                  .SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
                                  .AddJsonFile(Configurator.GetSetting("ValidationRulesFileName"))
                                  .Build();
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine($"{Configurator.GetConstantString("MissingValidation")} {Configurator.GetSetting("ConstantStringsFileName")}");
                Console.WriteLine(Configurator.GetConstantString("ClosingProgram"));
                Environment.Exit(-1);
            }
            catch (FormatException)
            {
                Console.WriteLine(Configurator.GetConstantString("InvalidValidationFile"));
                Console.WriteLine(Configurator.GetConstantString("ClosingProgram"));
                Environment.Exit(-1);
            }

            int      minFirstNameLength  = int.Parse(validationRules.GetSection("default").GetSection("firstName").GetSection("minLength").Value, CultureInfo.InvariantCulture);
            int      maxFirstNameLength  = int.Parse(validationRules.GetSection("default").GetSection("firstName").GetSection("maxLength").Value, CultureInfo.InvariantCulture);
            int      minLastNameLength   = int.Parse(validationRules.GetSection("default").GetSection("lastName").GetSection("minLength").Value, CultureInfo.InvariantCulture);
            int      maxLastNameLength   = int.Parse(validationRules.GetSection("default").GetSection("lastName").GetSection("maxLength").Value, CultureInfo.InvariantCulture);
            DateTime fromDateOfBirth     = DateTime.ParseExact(validationRules.GetSection("default").GetSection("dateOfBirth").GetSection("from").Value, Configurator.GetConstantString("DateFormatDM"), CultureInfo.InvariantCulture);
            DateTime toDateOfBirth       = DateTime.ParseExact(validationRules.GetSection("default").GetSection("dateOfBirth").GetSection("to").Value, Configurator.GetConstantString("DateFormatDM"), CultureInfo.InvariantCulture);
            char     minPatronymicLetter = char.Parse(validationRules.GetSection("default").GetSection("patronymicLetter").GetSection("from").Value);
            char     maxPatronymicLetter = char.Parse(validationRules.GetSection("default").GetSection("patronymicLetter").GetSection("to").Value);
            decimal  minIncome           = decimal.Parse(validationRules.GetSection("default").GetSection("income").GetSection("from").Value, CultureInfo.InvariantCulture);
            decimal  maxIncome           = decimal.Parse(validationRules.GetSection("default").GetSection("income").GetSection("to").Value, CultureInfo.InvariantCulture);
            short    minHeight           = short.Parse(validationRules.GetSection("default").GetSection("height").GetSection("min").Value, CultureInfo.InvariantCulture);
            short    maxHeight           = short.Parse(validationRules.GetSection("default").GetSection("height").GetSection("max").Value, CultureInfo.InvariantCulture);
            string   alphabet            = Configurator.GetConstantString("Alphabet");

            FileCabinetRecord[] records = new FileCabinetRecord[amount];
            Random random = new Random();

            for (int i = 0; i < amount; i++)
            {
                records[i] = new FileCabinetRecord
                {
                    Id               = start++,
                    FirstName        = GetRandomString(alphabet, random.Next(minFirstNameLength, maxFirstNameLength), random),
                    LastName         = GetRandomString(alphabet, random.Next(minLastNameLength, maxLastNameLength), random),
                    DateOfBirth      = GetRandomDate(fromDateOfBirth, toDateOfBirth, random),
                    PatronymicLetter = (char)random.Next((int)minPatronymicLetter, (int)maxPatronymicLetter),
                    Income           = random.Next((int)minIncome, (int)maxIncome - 1) + (((decimal)random.Next(0, 100)) / 100),
                    Height           = (short)random.Next(minHeight, maxHeight),
                };
            }

            return(records);
        }