/// <summary> /// Intialization of FileIO missing files are created. /// </summary> /// <param name="existing"></param> private void Init(bool[] existing) { bool isFine = true; foreach (var item in existing) { if (!item) { isFine = false; } } if (!isFine) { _t.Display("Seems like some files dont exist. Do you wish to initialize missing files?(Admin PIN=0000)"); if (_t.GetBool()) { _t.Display("Do you wish to create some default basedata?"); bool CreationMode = _t.GetBool(); for (int i = 0; i < _paths.Length; i++) { if (!existing[i]) { Byte[] info; #pragma warning disable IDE0063 // Use simple 'using' statement using (FileStream fs = File.Create(_paths[i])) #pragma warning restore IDE0063 // Use simple 'using' statement { StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.Default); if (i == 1) { string PIN = "0000"; info = new UTF8Encoding(true).GetBytes(@"{""PIN"":""" + PIN.GetHashCode().ToString() + @""",""Status"":""ADMIN"",""Id"":1,""FirstName"":""FirstName"",""LastName"":""LastName""}"); fs.Write(info, 0, info.Length); } else { if (CreationMode) { Byte[] newline = Encoding.ASCII.GetBytes(Environment.NewLine); string temp = ""; switch (i) { case 2: Pkw p = new Pkw("Pkw", 80, 4); Firetruck ft = new Firetruck("LFZ", 200, 4, false, 400); Ambulance a = new Ambulance("Ambulance", 150, 6, 300); Turntableladder tl = new Turntableladder("Turntableladder", 300, 4, true, 20); temp = JSONConverter.ObjectToJSON(p); sw.WriteLine(temp); temp = JSONConverter.ObjectToJSON(ft); sw.WriteLine(temp); temp = JSONConverter.ObjectToJSON(a); sw.WriteLine(temp); temp = JSONConverter.ObjectToJSON(tl); sw.Write(temp); break; case 3: Hose h = new Hose("A regular Hose", 1, 'B', 20); Gasanalyzer ga = new Gasanalyzer("A regular gasanalyzer", 2); Distributer d = new Distributer("A regular Distributer", 3); Jetnozzle jn = new Jetnozzle("A regular Jetnozzle", 4); temp = JSONConverter.ObjectToJSON(h); sw.WriteLine(temp); temp = JSONConverter.ObjectToJSON(ga); sw.WriteLine(temp); temp = JSONConverter.ObjectToJSON(d); sw.WriteLine(temp); temp = JSONConverter.ObjectToJSON(jn); sw.Write(temp); break; case 4: FireFighter ff1 = new FireFighter("Max", "Mustermann", 1); FireFighter ff2 = new FireFighter("Marina", "Musterfrau", 2); temp = JSONConverter.ObjectToJSON(ff1); sw.WriteLine(temp); temp = JSONConverter.ObjectToJSON(ff2); sw.Write(temp); break; default: info = new UTF8Encoding(true).GetBytes(""); fs.Write(info, 0, info.Length); break; } } else { info = new UTF8Encoding(true).GetBytes(""); fs.Write(info, 0, info.Length); } } sw.Close(); } } } } } }
public T Edit <T>(T t) // to use T or not to use T that is thy question(T to obj oder var) // ja ne is klar nice edit skillz { string Answer; int Number; if (t.GetType() == typeof(FireFighter)) { _t.Display(" \".\"(dot) for no changes (0 in case of number)" + "\n"); FireFighter tmp = (FireFighter)(object)t; Answer = EditHelperString("Lastname: " + tmp.LastName + "\n"); if (Answer != "") { tmp.LastName = Answer; } Answer = EditHelperString("Firstname: " + tmp.FirstName + "\n"); if (Answer != ".") { tmp.FirstName = Answer; } Number = EditHelperInt("ID(number): " + tmp.Id + "\n"); if (Number != 0) { tmp.Id = Number; } } if (t.GetType() == typeof(User)) { _t.Display(" \".\"(dot) for no changes (0 in case of number)" + "\n"); User tmp = (User)(object)t; Answer = EditHelperString("Lastname: " + tmp.LastName + "\n"); if (Answer != ".") { tmp.LastName = Answer; } Answer = EditHelperString("Firstname: " + tmp.FirstName + "\n"); if (Answer == " hallo") { Answer = "."; } if (Answer != ".") { tmp.FirstName = Answer; } Number = EditHelperInt("ID(number): " + tmp.Id + "\n"); if (Number != 0) { tmp.Id = Number; } Answer = EditHelperString("PIN(number(Hashed)): " + tmp.PIN + "\n"); if (Answer != ".") { tmp.PIN = Answer.GetHashCode().ToString(); } Number = EditHelperInt("Status(1=USER,2=ADMIN,3=LOCKED): " + tmp.Status + "\n", 0, 3); if (Number != 0) { tmp.Status = ((UserStates)Number).ToString(); } } if (t.GetType() == typeof(Firetruck)) { _t.Display(" \".\"(dot) for no changes (0 in case of number)" + "\n"); Firetruck tmp = (Firetruck)(object)t; Answer = EditHelperString("Type: " + tmp.Type + "\n"); if (Answer != ".") { tmp.Type = Answer; } Number = EditHelperInt("Seats: " + tmp.Seats + "\n"); if (Number != 0) { tmp.Seats = Number; } Number = EditHelperInt("Fillquantity: " + tmp.FillQuantity + "\n"); if (Number != 0) { tmp.FillQuantity = Number; } Number = EditHelperInt("Enginepower: " + tmp.EnginePower + "\n"); if (Number != 0) { tmp.EnginePower = Number; } Answer = EditHelperBool("Chainsaw: " + tmp.Chainsaw + "\n"); if (Answer != "") { if ((Answer == "y") || (Answer == "Y") || (Answer == "Yes") || (Answer == "yes")) { tmp.Chainsaw = true; } else { tmp.Chainsaw = false; } } } if (t.GetType() == typeof(Turntableladder)) { _t.Display(" \".\"(dot) for no changes (0 in case of number)" + "\n"); Turntableladder tmp = (Turntableladder)(object)t; Answer = EditHelperString("Type: " + tmp.Type + "\n"); if (Answer != ".") { tmp.Type = Answer; } Number = EditHelperInt("Seats: " + tmp.Seats + "\n"); if (Number != 0) { tmp.Seats = Number; } Number = EditHelperInt("Ladderheight: " + tmp.LadderHeight + "\n"); if (Number != 0) { tmp.LadderHeight = Number; } Number = EditHelperInt("Enginepower: " + tmp.EnginePower + "\n"); if (Number != 0) { tmp.EnginePower = Number; } Answer = EditHelperBool("Chainsaw: " + tmp.Chainsaw + "\n"); if (Answer != "") { if ((Answer == "y") || (Answer == "Y") || (Answer == "Yes") || (Answer == "yes")) { tmp.Chainsaw = true; } else { tmp.Chainsaw = false; } } } if (t.GetType() == typeof(Ambulance)) { _t.Display(" \".\"(dot) for no changes (0 in case of number)" + "\n"); Ambulance tmp = (Ambulance)(object)t; Answer = EditHelperString("Type: " + tmp.Type + "\n"); if (Answer != ".") { tmp.Type = Answer; } Number = EditHelperInt("Seats: " + tmp.Seats + "\n"); if (Number != 0) { tmp.Seats = Number; } Number = EditHelperInt("Max Patientweight: " + tmp.PatientWeight + "\n"); if (Number != 0) { tmp.PatientWeight = Number; } Number = EditHelperInt("Enginepower: " + tmp.EnginePower + "\n"); if (Number != 0) { tmp.EnginePower = Number; } } if (t.GetType() == typeof(Pkw)) { _t.Display(" \".\"(dot) for no changes (0 in case of number)" + "\n"); Pkw tmp = (Pkw)(object)t; Answer = EditHelperString(" \".\"Type: " + tmp.Type + "\n"); if (Answer != ".") { tmp.Type = Answer; } Number = EditHelperInt("Seats: " + tmp.Seats + "\n"); if (Number != 0) { tmp.Seats = Number; } Number = EditHelperInt("Enginepower: " + tmp.EnginePower + "\n"); if (Number != 0) { tmp.EnginePower = Number; } } if (t.GetType() == typeof(Resources)) { _t.Display(" \".\"(dot) for no changes (0 in case of number)" + "\n"); Resources tmp = (Resources)(object)t; Answer = EditHelperString("Description: " + tmp.Description + "\n"); if (Answer != ".") { tmp.Description = Answer; } Number = EditHelperInt("Inventory Number: " + tmp.InventoryNumber + "\n"); if (Number != 0) { tmp.InventoryNumber = Number; } } if (t.GetType() == typeof(Hose)) { _t.Display(" \".\"(dot) for no changes (0 in case of number)" + "\n"); Hose tmp = (Hose)(object)t; Answer = EditHelperString("Description: " + tmp.Description + "\n"); if (Answer != ".") { tmp.Description = Answer; } Number = EditHelperInt("Inventory Number: " + tmp.InventoryNumber + "\n"); if (Number != 0) { tmp.InventoryNumber = Number; } Number = EditHelperInt("Hose length(5, 10, 20, 30): " + tmp.HoseLength + "\n"); if ((Number != 0 && Number % 10 == 0 && Number <= 30) || Number == 5) { tmp.HoseLength = Number; } else { _t.Display("Valid lenghts are 5, 10, 20, 30. No changes were made" + "\n"); } Answer = EditHelperString("Hose type(B,C,D): " + tmp.Letter + "\n"); char letter = ' '; if (Answer.Length == 1) { letter = Answer.ToCharArray().ElementAt(0); } if (letter == 'B' || letter == 'C' || letter == 'D') { tmp.Letter = letter; } } if (t.GetType() == typeof(Gasanalyzer)) { _t.Display(" \".\"(dot) for no changes (0 in case of number)" + "\n"); Gasanalyzer tmp = (Gasanalyzer)(object)t; Answer = EditHelperString("Description: " + tmp.Description + "\n"); if (Answer != ".") { tmp.Description = Answer; } Number = EditHelperInt("Inventory Number: " + tmp.InventoryNumber + "\n"); if (Number != 0) { tmp.InventoryNumber = Number; } } if (t.GetType() == typeof(Jetnozzle)) { _t.Display(" \".\"(dot) for no changes (0 in case of number)" + "\n"); Jetnozzle tmp = (Jetnozzle)(object)t; Answer = EditHelperString("Description: " + tmp.Description + "\n"); if (Answer != ".") { tmp.Description = Answer; } Number = EditHelperInt("Inventory Number: " + tmp.InventoryNumber + "\n"); if (Number != 0) { tmp.InventoryNumber = Number; } } if (t.GetType() == typeof(Distributer)) { _t.Display(" \".\"(dot) for no changes (0 in case of number)" + "\n"); Distributer tmp = (Distributer)(object)t; Answer = EditHelperString("Description: " + tmp.Description + "\n"); if (Answer != ".") { tmp.Description = Answer; } Number = EditHelperInt("Inventory Number: " + tmp.InventoryNumber + "\n"); if (Number != 0) { tmp.InventoryNumber = Number; } } return(t); }