Exemple #1
0
        /// <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);
        }
Exemple #2
0
        /// <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();
                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
        /// <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);
        }
Exemple #4
0
        public void Routine(string mode)
        {
            switch (mode)
            {
            case "ADMIN":
                ShowAdminOptions();
                AdminMode(_t.GetString());
                break;

            case "USER":
                ShowUserOptions();
                UserMode(_t.GetString());
                break;

            case "LOCKED":
                _t.Display("Your user is locked contact your local admin");
                System.Environment.Exit(1);
                break;
            }
        }
Exemple #5
0
        public void Routine(string mode)
        {
            switch (mode)   //Sortiert Nutzer ins richtige Menü ein basierend auf seinem Status
            {
            case "ADMIN":
                ShowAdminOptions();
                AdminMode(_t.GetString());
                break;

            case "USER":
                ShowUserOptions();
                UserMode(_t.GetString());
                break;

            case "LOCKED":
                _t.Display("Your user is locked contact your local admin");
                System.Environment.Exit(1);
                break;
            }
        }