/// <summary> /// Calls helper functions to ask for a PIN. /// </summary> /// <returns> /// String array[2] containing Status and User name for a successful login attempt. /// returns error in boths slots of the array for invalid inputs or any error while reading file. /// </returns> public string[] LogIn() { _t.Display("Type your PIN:<br />"); string[] result = CheckPIN(); if (!(result[0] == "error") && !(result[1] == "error")) { _t.Display("Login attempt successful! Logged in as: " + result[0] + " : " + result[1] + "<br />"); } else { _t.Display("Login attempt failed. Try again?" + "<br />"); if (_t.GetBool()) { return(LogIn()); } } return(result); }
/// <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(); } } } } } }