//Method for logging a individual contact event and returns as object public Contact_Event LogContact(int contact_id, DateTime date_time, int individual_id) { Contact_Event newevent = _dataStorage.LogContact(contact_id, date_time, individual_id); _dataStorage.StoreIndividuals(); return(newevent); }
//Method for logging new contact event public Contact_Event LogContact(int contact_id, DateTime date_time, int individual_id) { //Creates new event from factorymethod to ensure ids are correct and counted Contact_Event newevent = _eventFactory.factoryMethod_contact(contact_id); newevent.Date_time = date_time; foreach (Individual ind in _individual) { if (individual_id == ind.Individual_id) { //Add event to individual ind.AddcEvent(newevent); } } return(newevent); }
//Method for loading stoed individuals from csv file public void LoadIndividuals() { //Define input data file string individualsFilePath = "TrackandTraceData\\individualsData.csv"; //Check input file exists if (File.Exists(individualsFilePath)) { //Read Whole file into string variable then split into array of lines string whole_file = System.IO.File.ReadAllText(individualsFilePath); string[] lines = whole_file.Split('\r'); //Loop through each line foreach (string temp in lines) { //Split said line into the individuals class data string[] i_classdata = temp.Split(','); if (i_classdata[0] == "\n" || i_classdata[0] == "") { break; } //Parse individuals individual_id and create temp individual instance int id = int.Parse(i_classdata[0]); Individual tmpind = new Individual(id, i_classdata[1], i_classdata[2]); //Check if individual has stored events if (i_classdata.Length > 3) { //Loop through all events for (int i = 3; i < i_classdata.Length; i++) { //Console.WriteLine($"{i_classdata[i]}"); //For Debugging //Split event string into array string[] e_classdata = i_classdata[i].Split(';'); //Check event type - 0 == Location, else (ie ==1) Contact Event if (int.Parse(e_classdata[3]) == 0) { //Get locationEvents from tmp individual, create new event, add to list of events, update event list, add individual to individual list List <Location_Event> tmp_event_list = tmpind.locationEvents; Location_Event current_event = new Location_Event(int.Parse(e_classdata[0]), DateTime.Parse(e_classdata[1]), int.Parse(e_classdata[2])); tmp_event_list.Add(current_event); tmpind.locationEvents = tmp_event_list; } else { //Get contactEvents from tmp individual, create new event, add to list of events, update event list. List <Contact_Event> tmp_event_list = tmpind.contactEvents; Contact_Event current_event = new Contact_Event(int.Parse(e_classdata[0]), DateTime.Parse(e_classdata[1]), int.Parse(e_classdata[2])); tmp_event_list.Add(current_event); tmpind.contactEvents = tmp_event_list; } } //Add Individual to list _individual.Add(tmpind); } else { //Add Individual to list if there are no event classes _individual.Add(tmpind); } } } //If Input file/dir doesnt exist, create blank input file/dir else { using (System.IO.StreamWriter file = new System.IO.StreamWriter(individualsFilePath)) { } } }