private void Insert(string parameters) { var(properties, values) = this.Parse(parameters); var recordPropertyInfo = typeof(FileCabinetRecord).GetProperties(); var recordGenerator = new RecordGenerator(); var record = recordGenerator.Generate(1); for (int i = 0; i < properties.Length; i++) { var recordProperty = recordPropertyInfo.FirstOrDefault(prop => string.Equals(prop.Name, properties[i], StringComparison.OrdinalIgnoreCase)); if (recordProperty is null) { continue; } var converter = TypeDescriptor.GetConverter(recordProperty.PropertyType); recordProperty.SetValue(record, converter.ConvertFromInvariantString(values[i])); } var data = new RecordData() { FirstName = record.FirstName, LastName = record.LastName, DateOfBirth = record.DateOfBirth, Experience = record.Experience, Balance = record.Balance, EnglishLevel = record.EnglishLevel, }; this.fileCabinetService.CreateRecord(data); }
private void DoSaveRecord(object obj) { ObservableCollection <string> causes = new ObservableCollection <string>(); for (int i = 0; i < availablePresentationObjects.Count(); i++) { if (availablePresentationObjects[i].IsChecked == true) { availablePresentationObjects[i].IsChecked = false; Debug.WriteLine(availablePresentationObjects[i].Name); causes.Add(availablePresentationObjects[i].Name); } } //FloodRecord record = new FloodRecord(); //record.Latitude = currentLatitude; //record.Longitude = currentLongitude; //record.Time = currentTimeStamp; //record.WaterLevel = _waterLevel.ToString(); //record.causes = causes; if (_waterLevel.ToString() != "" && causes.Count() != 0) { _waterLevel = 230 / 2; RaisePropertyChanged("waterLevel"); } othersIsChecked = false; others = ""; RaisePropertyChanged("AvailablePresentationObjects"); RaisePropertyChanged("others"); RaisePropertyChanged("othersIsChecked"); MenuViewBase recordView = HomeScreenViewModel.GetInstance().ShowRecordView(); //recordView.RaiseUserInputReadyEvent(new SaveButtonClickedEventArgs(record)); // Initialize the record object dynamic record = RecordGenerator.CreateFloodRecord(waterLevel, causes, currentLatitude, currentLongitude, currentTimeStamp); // Signal Core for record recordView.OnSavingRecord(record); }
private void DoSaveRecord(object obj) { dynamic records = RecordGenerator.CreateLandslideRecord( deathToll, injuryToll, checkedLandslideCondition, houseDamage, houseSelected, farmDamage, farmSelected, riverDamage, riverSelected, groundDamage, groundSelected, roadDamage, roadSelected ); MenuViewBase recordView = HomeScreenViewModel.GetInstance().ShowOtherView(); recordView.OnSavingRecord(records); LandslideRecord record = new LandslideRecord(); record.Time = currentDateTime.ToString(); record.Latitude = currentLatitude.ToString(); record.Longitude = currentLongitude.ToString(); record.deathToll = deathToll.ToString(); record.injuryToll = injuryToll.ToString(); record.conditions = new ObservableCollection <string>() { null, null, null, null, null }; photoUploaded = null; Layer = new Microsoft.Maps.MapControl.WPF.MapLayer(); foreach (var e in checkedLandslideCondition.ToList()) { if (e.Contains("House")) { record.conditions[0] = e; } else if (e.Contains("Farm")) { record.conditions[1] = e; } else if (e.Contains("Road")) { record.conditions[2] = e; } else if (e.Contains("River")) { record.conditions[3] = e; } else { record.conditions[4] = e; } checkedLandslideCondition.Remove(e); } deathToll = -1; injuryToll = -1; houseDamage = false; houseSelected = null; riverDamage = false; riverSelected = null; farmDamage = false; farmSelected = null; groundDamage = false; groundSelected = null; roadDamage = false; roadSelected = null; RaisePropertyChanged("deathToll"); RaisePropertyChanged("injuryToll"); RaisePropertyChanged("photoUploaded"); RaisePropertyChanged("saveRecord"); RaisePropertyChanged("checkedLandslideCondition"); RaisePropertyChanged("houseDamage"); RaisePropertyChanged("riverDamage"); RaisePropertyChanged("farmDamage"); RaisePropertyChanged("roadDamage"); RaisePropertyChanged("groundDamage"); RaisePropertyChanged("houseSelected"); RaisePropertyChanged("riverSelected"); RaisePropertyChanged("farmSelected"); RaisePropertyChanged("roadSelected"); RaisePropertyChanged("groundSelected"); recordView.RaiseUserInputReadyEvent(new SaveButtonClickedEventArgs(record)); }
static void Main(string[] args) { string outputType = "unassigned"; string path = "unassigned"; int recordsAmount = 0; int startId = 0; try { if (args.Length >= 1) { for (int i = 0; i < args.Length; i++) { if (args[i].Contains("--output-type", StringComparison.InvariantCultureIgnoreCase)) { var argsArr = args[i].Split('='); outputType = argsArr[1]; } if (args[i].Contains("--output", StringComparison.InvariantCultureIgnoreCase)) { var argsArr = args[i].Split('='); path = argsArr[1]; } if (args[i].Contains("--records-amount", StringComparison.InvariantCultureIgnoreCase)) { var argsArr = args[i].Split('='); if (!Int32.TryParse(argsArr[1], out recordsAmount)) { throw new ArgumentException($"Incorrect records amount: {argsArr[1]}"); } if (recordsAmount <= 0) { throw new ArgumentOutOfRangeException($"Records amount is less or equal to zero."); } } if (args[i].Contains("--start-id", StringComparison.InvariantCultureIgnoreCase)) { var argsArr = args[i].Split('='); if (!Int32.TryParse(argsArr[1], out startId)) { throw new ArgumentException($"Incorrect start ID: {argsArr[1]}"); } if (startId < 0) { throw new ArgumentOutOfRangeException($"Start ID is less than zero."); } } if (args[i].Equals("-t", StringComparison.InvariantCultureIgnoreCase)) { i++; outputType = args[i]; } if (args[i].Equals("-o", StringComparison.InvariantCultureIgnoreCase)) { i++; path = args[i]; } if (args[i].Equals("-a", StringComparison.InvariantCultureIgnoreCase)) { i++; if (!Int32.TryParse(args[i], out recordsAmount)) { throw new ArgumentException($"Incorrect records amount: {args[i]}"); } if (recordsAmount <= 0) { throw new ArgumentOutOfRangeException($"Records amount is less or equal to zero."); } } if (args[i].Equals("-i", StringComparison.InvariantCultureIgnoreCase)) { i++; if (!Int32.TryParse(args[i], out startId)) { throw new ArgumentException($"Incorrect start ID: {args[i]}"); } if (startId < 0) { throw new ArgumentOutOfRangeException($"Start ID is less than zero."); } } } } if (File.Exists(path)) { while (true) { Console.Write($"File is exist - rewrite {path} [Y/n] "); string answer = Console.ReadKey().KeyChar.ToString(CultureInfo.InvariantCulture); Console.WriteLine(); if (answer.Equals("y", StringComparison.InvariantCultureIgnoreCase)) { break; } if (answer.Equals("n", StringComparison.InvariantCultureIgnoreCase)) { return; } } } switch (outputType) { case "csv": using (StreamWriter sw = new StreamWriter(new FileStream(path, FileMode.Create))) { new CSVWriter(sw).Generate(RecordGenerator.Generate(recordsAmount, startId)); } Console.WriteLine($"{recordsAmount} records were written to {path}"); break; case "xml": using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate)) { XmlContainer container = new XmlContainer { Records = RecordGenerator.Generate(recordsAmount, startId) }; new XMLWriter(fs).Generate(container); } Console.WriteLine($"{recordsAmount} records were written to {path}"); break; default: throw new ArgumentException($"Incorrect output type: {outputType}"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void Setup() { records = RecordGenerator.Generate(100000, 0); }