/// <summary> /// Reads files. /// </summary> /// <typeparam name="T"></typeparam> /// <returns>returns a list of objects of type T</returns> public List <T> ReadFile <T>() { bool needCast = false; int path = Pathfinder <T>(); List <object> tmp = new List <object>(); List <T> test = new List <T>(); object trial; if (File.Exists(_paths[path])) { foreach (string line in File.ReadLines(_paths[path])) { trial = JSONConverter.JSONToGeneric <T>(line); if (trial.GetType() == typeof(Vehicle)) { tmp.Add(ObjectCast <Vehicle>(line)); needCast = true; } if (trial.GetType() == typeof(Resource)) { tmp.Add(ObjectCast <Resource>(line)); needCast = true; } if (trial.GetType() == typeof(Deployment)) { Deployment prototype = (Deployment)trial; List <Vehicle> v = new List <Vehicle>(); List <Resource> r = new List <Resource>(); List <FireFighter> f = new List <FireFighter>(); string cutting = line; object testNull; int firstIndex = cutting.IndexOf('[') + 1; // first occourence marks array int lastIndex = cutting.IndexOf(']'); // first occourence marks end of array string cutted = cutting.Substring(firstIndex, lastIndex - firstIndex); // extract everything between [ and ] cutting = cutting.Substring(lastIndex + 1, cutting.Length - lastIndex - 1); // remove everything from start till end of array"]" testNull = CreateArray(cutted); string[] VehObjects; if (!(testNull == null)) { VehObjects = (string[])testNull; foreach (var item in VehObjects) { v.Add((Vehicle)ObjectCast <Vehicle>(item)); } } firstIndex = cutting.IndexOf('[') + 1; // first occourence marks array lastIndex = cutting.IndexOf(']'); // first occourence marks end of array cutted = cutting.Substring(firstIndex, lastIndex - firstIndex); // extract everything between [ and ] cutting = cutting.Substring(lastIndex + 1, cutting.Length - lastIndex - 1); // remove everything from start till end of array"]" testNull = CreateArray(cutted); string[] ResObjects; if (!(testNull == null)) { ResObjects = (string[])testNull; foreach (var item in ResObjects) { r.Add((Resource)ObjectCast <Resource>(item)); } } firstIndex = cutting.IndexOf('[') + 1; // first occourence marks array lastIndex = cutting.IndexOf(']'); // first occourence marks end of array cutted = cutting.Substring(firstIndex, lastIndex - firstIndex); // extract everything between [ and ] cutting = cutting.Substring(lastIndex + 1, cutting.Length - lastIndex - 1); // remove everything from start till end of array"]" testNull = CreateArray(cutted); string[] FFObjects; if (!(testNull == null)) { FFObjects = (string[])testNull; foreach (var item in FFObjects) { f.Add(JSONConverter.JSONToGeneric <FireFighter>(item)); } } Deployment fin = new Deployment(prototype.DateAndTime, prototype.Location, v.ToArray(), r.ToArray(), f.ToArray(), prototype.Comment, prototype.Id); tmp.Add(fin); needCast = true; } test.Add(JSONConverter.JSONToGeneric <T>(line)); } if (needCast) { return(ConvertList <T>(tmp)); } return(test); } _t.Display("cannot read file: " + _paths[path] + "<br />"); return(test); }
public void UserMode(string sel) { string toDisplay; int DeployCount; switch (sel) { case "-v": DeployCount = GetListDeployments().Count(); _t.Display("Viewing Deployments(" + DeployCount + "):\n" + "(1)List last X Deployments.\n" + "(2)List by X.\n"); if (DeployCount == 0) { _t.Display("The deployment file seems to be empty.\nBefore you view deployments you should create one!\n"); return; } int UserChoice = ValidInputRange(_t.GetInt(), 1, 2); int howMany; if (UserChoice == 1) { _t.Display("How many deployments do you wish to view?(" + DeployCount + ") \n"); howMany = ValidInputRange(_t.GetInt(), 1, DeployCount); _t.Display("Last " + howMany + " Deployments: \n"); toDisplay = ""; for (int i = 0; i < howMany; i++) { toDisplay += "(" + (i + 1) + ") At: " + GetListDeployments().ElementAt((DeployCount - 1) - i).Location + " Time: " + GetListDeployments().ElementAt((DeployCount - 1) - i).DateAndTime + "\n"; } _t.Display(toDisplay); _t.Display("To go into detail type corresponding number.\n"); howMany = ValidInputRange(_t.GetInt(), 1, DeployCount); _t.Display(GetListDeployments().ElementAt((DeployCount - 1) - (howMany - 1)).ToString() + "\n"); } else { _t.Display("List by:\n" + "(1)List by Firefighter.\n" + "(2)List by Vehicle.\n"); UserChoice = ValidInputRange(_t.GetInt(), 1, 2); _t.Display("How many deployments do you wish to view?(" + DeployCount + ") \n"); howMany = ValidInputRange(_t.GetInt(), 1, DeployCount); List <Deployment> deploys = GetListDeployments(); if (UserChoice == 1 && GetListFireFighter().Count == 0) { _t.Display("Seems like you dont have any Firefighters in your basedata!\n"); return; } if (UserChoice == 1) { List <FireFighter> firefighters = GetListFireFighter(); FireFighter tmp; _t.Display("Select for which Firefighter you wish to search:\n"); ViewList(firefighters); UserChoice = ValidInputRange(_t.GetInt(), 1, firefighters.Count()); tmp = firefighters.ElementAt(UserChoice - 1); int amountD = deploys.Count(); int amountF; int counter = 0; for (int k = 0; k < amountD; k++) { amountF = deploys.ElementAt(k).FireFighters.Length; for (int j = 0; j < amountF; j++) { if (deploys.ElementAt(k).FireFighters[j].Equals(tmp) && counter < howMany) { _t.Display("(" + (k + 1) + ") At: " + deploys.ElementAt(k).Location + " Time: " + deploys.ElementAt(k).DateAndTime + "\n"); counter++; } } } if (!(counter == 0)) { _t.Display("To go into detail type corresponding number.\n"); UserChoice = ValidInputRange(_t.GetInt(), 1, counter); _t.Display(GetListDeployments().ElementAt(UserChoice - 1).ToString() + "\n"); } else { _t.Display("Couldnt find any Deployments with your selection.\n"); } } if (UserChoice == 2 && GetListVehicles().Count == 0) { _t.Display("Seems like you dont have any Vehicles in your basedata!\n"); return; } if (UserChoice == 2) { List <Vehicle> vehicles = GetListVehicles(); Vehicle tmp; _t.Display("Select for which car you wish to search:\n"); ViewList(vehicles); UserChoice = ValidInputRange(_t.GetInt(), 1, vehicles.Count()); tmp = vehicles.ElementAt(UserChoice - 1); int amountD = deploys.Count(); int amountC; int counter = 0; for (int k = 0; k < amountD; k++) { amountC = deploys.ElementAt(k).Cars.Length; for (int j = 0; j < amountC; j++) { if (deploys.ElementAt(k).Cars[j].Equals(tmp) && counter < howMany) { _t.Display("(" + (k + 1) + ") At: " + deploys.ElementAt(k).Location + " Time: " + deploys.ElementAt(k).DateAndTime + "\n"); counter++; } } } if (!(counter == 0)) { _t.Display("To go into detail type corresponding number.\n"); UserChoice = ValidInputRange(_t.GetInt(), 1, counter); _t.Display(GetListDeployments().ElementAt(UserChoice - 1).ToString() + "\n"); } else { _t.Display("Couldnt find any Deployments with your selection.\n"); } } } break; case "-d": int number = 0; Vehicle[] v = new Vehicle[number]; FireFighter[] p = new FireFighter[number]; Resources[] r = new Resources[number]; List <Deployment> liste = GetListDeployments(); _t.Display("Where was the Deployment?\n"); string loc = _t.GetString(); _t.Display("How many Vehicles participated in the Deployment?\n"); List <Vehicle> cars = GetListVehicles(); if (cars.Count == 0) { _t.Display("It appears as if you have no vehicles in your basedata\n" + "You might wish to ask your local admin to create some for you.\n\n"); } else { number = ValidInputRange(_t.GetInt(), 0, cars.Count); v = new Vehicle[number]; for (int i = 0; i < number; i++) { v[i] = cars.ElementAt(ObjectSelection(cars) - 1); } } _t.Display("How much staff participated in the Deployment?\n"); List <FireFighter> staff = GetListFireFighter(); if (staff.Count == 0) { _t.Display("It appears as if you have no staff in your basedata\n" + "You might wish to ask your local admin to create some for you.\n\n"); } else { number = ValidInputRange(_t.GetInt(), 0, staff.Count); p = new FireFighter[number]; for (int i = 0; i < number; i++) { p[i] = staff.ElementAt(ObjectSelection(staff) - 1); } } _t.Display("How many resources were used in the Deployment?\n"); List <Resources> res = GetListResources(); if (res.Count == 0) { _t.Display("It appears as if you have no resources in your basedata\n" + "You might wish to ask your local admin to create some for you.\n\n"); } else { number = ValidInputRange(_t.GetInt(), 0, res.Count); r = new Resources[number]; for (int i = 0; i < number; i++) { r[i] = res.ElementAt(ObjectSelection(res) - 1); } } _t.Display("Any comments?\n"); string com = _t.GetString(); DeploymentFactory DF = new DeploymentFactory(); Deployment test = DF.NewDeployment(loc, v, r, p, com, AllDeployments.Count() + 1); liste.Add(test); GasExaminationCheck(); break; case "-g": GasExaminationCheck(); break; case "-w": DeployCount = GetListDeployments().Count(); if (DeployCount == 0) { _t.Display("The deployment file seems to be empty.\nBefore you view deployments you should create one!\n"); return; } _t.Display("How many deployments do you wish to view?(" + DeployCount + ") \n"); howMany = ValidInputRange(_t.GetInt(), 1, DeployCount); _t.Display("Last " + howMany + " Deployments: \n"); toDisplay = ""; for (int i = 0; i < howMany; i++) { toDisplay += "(" + (i + 1) + ") At: " + GetListDeployments().ElementAt((DeployCount - 1) - i).Location + " Time: " + GetListDeployments().ElementAt((DeployCount - 1) - i).DateAndTime + "\n"; } _t.Display(toDisplay); howMany = ValidInputRange(_t.GetInt(), 1, DeployCount); _t.Display(GetListDeployments().ElementAt((DeployCount - 1) - (howMany - 1)).GenerateWebReport() + "\n"); break; case "-q": System.Environment.Exit(1); break; } }
/// <summary> /// Calls the Constructor of Deployment objects with needed parameters. /// </summary> /// <param name="loc">Location.</param> /// <param name="veh">Vehicles</param> /// <param name="res">Resources</param> /// <param name="Ff">FireFighter</param> /// <param name="com">Comment</param> /// <param name="num">Number</param> /// <returns></returns> public Deployment NewDeployment(string loc, Vehicle[] veh, Resource[] res, FireFighter[] Ff, string com, int num) { var tmp = new Deployment(loc, veh, res, Ff, com, num); return(tmp); }
public void Run() { TUI _t = new TUI(); FileIO _filer = new FileIO(_t); _filer.CheckForFiles(); Authenticator auth = new Authenticator(_t, _filer); object[] lists = _filer.ReadAllLists(); UserFunctions _uf = new UserFunctions(_t, lists); if (Globals.debug && false) { int testsize = 100000; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); Deployment test; List <Deployment> l = (List <Deployment>)lists[0]; test = new Deployment("here", new Vehicle[0], new Resources[0], new FireFighter[0], "hi", (l.Count + 1)); List <Deployment> list = (List <Deployment>)lists[0]; for (int i = 1; i < testsize + 1; i++) { list.Add(test); if (i % (testsize / 20) == 0) { _t.Display((i / (testsize / 100)).ToString() + "%\n"); } } for (int i = 1; i < testsize + 1; i++) { list.Remove(test); if (i % (testsize / 20) == 0) { _t.Display((i / (testsize / 100)).ToString() + "%\n"); } } stopWatch.Stop(); // Get the elapsed time as a TimeSpan value. TimeSpan ts = stopWatch.Elapsed; _t.Display(ts.ToString() + "\n"); LLRBTree <int, Deployment> tree = new LLRBTree <int, Deployment>(); stopWatch = new Stopwatch(); stopWatch.Start(); test = new Deployment("here", new Vehicle[0], new Resources[0], new FireFighter[0], "hi", (l.Count + 1)); for (int i = 1; i < testsize + 1; i++) { tree.Insert(i, test); if (i % (testsize / 20) == 0) { _t.Display((i / (testsize / 100)).ToString() + "%\n"); } } for (int i = 1; i < testsize + 1; i++) { tree.Delete(i); if (i % (testsize / 20) == 0) { _t.Display((i / (testsize / 100)).ToString() + "%\n"); } } stopWatch.Stop(); // Get the elapsed time as a TimeSpan value. ts = stopWatch.Elapsed; _t.Display(ts.ToString() + "\n"); } bool loop = true; string[] user = auth.LogIn(); while (loop) { _uf.Routine(user[0]); _t.Display("Continue?"); loop = _t.GetBool(); } _t.Display("Saving data to files\n"); _filer.SaveAllLists(lists); }
public void UserMode(string sel) { string toDisplay; int DeployCount; switch (sel) //Nutzermenü { case "-v": DeployCount = GetListDeployments().Count(); _t.Display("Viewing Deployments(" + DeployCount + "):<br />" + "(1)List last X Deployments.<br />" + "(2)List by X.<br />"); if (DeployCount == 0) //Checkt die Anzahl der Einsätze { _t.Display("The deployment file seems to be empty.<br />Before you view deployments you should create one!<br />"); return; } int UserChoice = ValidInputRange(_t.GetInt(), 1, 2); //untersucht ob die Angabe 1/2 oder dazwischen ist int howMany; if (UserChoice == 1) { _t.Display("How many deployments do you wish to view?(" + DeployCount + ") <br />"); howMany = ValidInputRange(_t.GetInt(), 1, DeployCount); //ist die gesuchte zahl zwischen 1 und der existierenden Anzahl? _t.Display("Last " + howMany + " Deployments: <br />"); toDisplay = ""; for (int i = 0; i < howMany; i++) //fügt die Einsätze einem String hinzu- { toDisplay += "(" + (i + 1) + ") At: " + GetListDeployments().ElementAt((DeployCount - 1) - i).Location + " Time: " + GetListDeployments().ElementAt((DeployCount - 1) - i).DateAndTime + "<br />"; } _t.Display(toDisplay); //-stellt diesen String dar _t.Display("To go into detail type corresponding number.<br />"); howMany = ValidInputRange(_t.GetInt(), 1, DeployCount); _t.Display(GetListDeployments().ElementAt((DeployCount - 1) - (howMany - 1)).ToString() + "<br />"); } else { _t.Display("List by:<br />" + "(1)List by Firefighter.<br />" + "(2)List by Vehicle.<br />"); UserChoice = ValidInputRange(_t.GetInt(), 1, 2); _t.Display("How many deployments do you wish to view?(" + DeployCount + ") <br />"); howMany = ValidInputRange(_t.GetInt(), 1, DeployCount); List <Deployment> deploys = GetListDeployments(); // fügt der liste "deploys" alle einsätze hinzu if (UserChoice == 1 && GetListFireFighter().Count == 0) { _t.Display("Seems like you dont have any Firefighters in your basedata!<br />"); return; } if (UserChoice == 1) { List <FireFighter> firefighters = GetListFireFighter(); FireFighter tmp; _t.Display("Select for which Firefighter you wish to search:<br />"); ViewList(firefighters); UserChoice = ValidInputRange(_t.GetInt(), 1, firefighters.Count()); tmp = firefighters.ElementAt(UserChoice - 1); //-1 da listen(und arrays) bei 0 anfangen int amountD = deploys.Count(); int amountF; int counter = 0; for (int k = 0; k < amountD; k++) { amountF = deploys.ElementAt(k).FireFighters.Length; for (int j = 0; j < amountF; j++) { if (deploys.ElementAt(k).FireFighters[j].Equals(tmp) && counter < howMany) { _t.Display("(" + (k + 1) + ") At: " + deploys.ElementAt(k).Location + " Time: " + deploys.ElementAt(k).DateAndTime + "<br />"); //gibt nacheinander Feuerwehrmitglieder an counter++; } } } if (!(counter == 0)) { _t.Display("To go into detail type corresponding number.<br />"); UserChoice = ValidInputRange(_t.GetInt(), 1, counter); _t.Display(GetListDeployments().ElementAt(UserChoice - 1).ToString() + "<br />"); //sucht Einsatz nach ID heraus (-1 da [siehe bei vorletztem "if"]) } else { _t.Display("Couldnt find any Deployments with your selection.<br />"); } } if (UserChoice == 2 && GetListVehicles().Count == 0) { _t.Display("Seems like you dont have any Vehicles in your basedata!<br />"); return; } if (UserChoice == 2) { List <Vehicle> vehicles = GetListVehicles(); Vehicle tmp; _t.Display("Select for which car you wish to search:<br />"); ViewList(vehicles); UserChoice = ValidInputRange(_t.GetInt(), 1, vehicles.Count()); //sucht Fahrzeug nach ID tmp = vehicles.ElementAt(UserChoice - 1); int amountD = deploys.Count(); int amountC; int counter = 0; for (int k = 0; k < amountD; k++) { amountC = deploys.ElementAt(k).Cars.Length; for (int j = 0; j < amountC; j++) { if (deploys.ElementAt(k).Cars[j].Equals(tmp) && counter < howMany) { _t.Display("(" + (k + 1) + ") At: " + deploys.ElementAt(k).Location + " Time: " + deploys.ElementAt(k).DateAndTime + "<br />"); //sucht nach Einsätzen mit gewähltem Fahrzeug counter++; } } } if (!(counter == 0)) { _t.Display("To go into detail type corresponding number.<br />"); UserChoice = ValidInputRange(_t.GetInt(), 1, counter); _t.Display(GetListDeployments().ElementAt(UserChoice - 1).ToString() + "<br />"); } else { _t.Display("Couldnt find any Deployments with your selection.<br />"); } } } break; case "-d": { List <Deployment> liste = GetListDeployments(); int number = 0; //erstellt einen Einsatzeintrag Vehicle[] v = new Vehicle[number]; FireFighter[] p = new FireFighter[number]; Resource[] r = new Resource[number]; _t.Display("Where was the Deployment?<br />"); string loc = _t.GetString(); _t.Display("How many Vehicles participated in the Deployment?<br />"); List <Vehicle> cars = GetListVehicles(); if (cars.Count == 0) { _t.Display("It appears as if you have no vehicles in your basedata<br />" + "You might wish to ask your local admin to create some for you.<br /><br />"); } else { number = ValidInputRange(_t.GetInt(), 0, cars.Count); //ist die Zahl der Fahrzeuge valide? v = new Vehicle[number]; for (int i = 0; i < number; i++) { v[i] = cars.ElementAt(ObjectSelection(cars) - 1); } } _t.Display("How much staff participated in the Deployment?<br />"); List <FireFighter> staff = GetListFireFighter(); if (staff.Count == 0) { _t.Display("It appears as if you have no staff in your basedata<br />" + "You might wish to ask your local admin to create some for you.<br /><br />"); } else { number = ValidInputRange(_t.GetInt(), 0, staff.Count); //ist die Zahl der Feuerwehrmänner valide? p = new FireFighter[number]; for (int i = 0; i < number; i++) { p[i] = staff.ElementAt(ObjectSelection(staff) - 1); } } _t.Display("How many resources were used in the Deployment?<br />"); List <Resource> res = GetListResources(); if (res.Count == 0) { _t.Display("It appears as if you have no resources in your basedata<br />" + "You might wish to ask your local admin to create some for you.<br /><br />"); } else { number = ValidInputRange(_t.GetInt(), 0, res.Count); //ist die zahl der resourcen valide? r = new Resource[number]; for (int i = 0; i < number; i++) { r[i] = res.ElementAt(ObjectSelection(res) - 1); } } _t.Display("Any comments?<br />"); string com = _t.GetString(); if (Globals.DLL == false) { DeploymentFactory DF = new DeploymentFactory(); Deployment test = DF.NewDeployment(loc, v, r, p, com, AllDeployments.Count() + 1); liste.Add(test); } else { #pragma warning disable CS0162 // Unreachable code detected var DeploymentDLL = new DeploymentDLL(); #pragma warning restore CS0162 // Unreachable code detected var DF = DeploymentDLL.NewDeployment(loc, v, r, p, com, AllDeployments.Count() + 1); Deployment tmp = new Deployment(DF.Location, DF.Cars, DF.Resources, DF.FireFighters, DF.Comment, DF.Id); liste.Add(tmp); } } GasExaminationCheck(); break; case "-g": GasExaminationCheck(); break; case "-w": DeployCount = GetListDeployments().Count(); if (DeployCount == 0) { _t.Display("The deployment file seems to be empty.<br />Before you view deployments you should create one!<br />"); return; } _t.Display("How many deployments do you wish to view?(" + DeployCount + ") <br />"); howMany = ValidInputRange(_t.GetInt(), 1, DeployCount); _t.Display("Last " + howMany + " Deployments: <br />"); toDisplay = ""; for (int i = 0; i < howMany; i++) { toDisplay += "(" + (i + 1) + ") At: " + GetListDeployments().ElementAt((DeployCount - 1) - i).Location + " Time: " + GetListDeployments().ElementAt((DeployCount - 1) - i).DateAndTime + "<br />"; } _t.Display(toDisplay); howMany = ValidInputRange(_t.GetInt(), 1, DeployCount); _t.Display(GetListDeployments().ElementAt((DeployCount - 1) - (howMany - 1)).GenerateWebReport() + "<br />"); break; case "-q": System.Environment.Exit(1); break; } }