private static Esami GetEsamiFromFile(string filecontent, string file)
        {
            Esami esami = new Esami();

            EsamiFromFile obj = esami.CheckText(filecontent, File.ReadAllLines(file));

            if (obj == null || obj.IsEmpty())
            {
                return(null);
            }

            if (obj.AlreadyContaisExams())
            {
                return(obj.GetExams());
            }

            List <string> Lines    = obj.GetLines();
            string        plchlind = "[CFUNUM-PLACEHOLDER-";

            for (int i = 0; i < Lines.Count; i++)
            {
                string x = Lines[i];
                if (x.Contains(plchlind))
                {
                    string subjectname = x.Substring(x.IndexOf(plchlind) + plchlind.Length, x.IndexOf("]\"") - x.IndexOf(plchlind) - plchlind.Length);
                    Console.WriteLine("How many CFUs is " + subjectname + " worth?");
                    string tmp = Console.ReadLine();
                    while (tmp != "" && !int.TryParse(tmp, out _))
                    {
                        Console.WriteLine("The only accepted values are numbers or nothing at all. Please try again.");
                        Console.WriteLine("How many CFUs is " + Environment.NewLine + subjectname + " worth?");
                        tmp = Console.ReadLine();
                    }
                    Lines[i] = x.Replace(plchlind + subjectname + "]", tmp);
                }
            }

            try
            {
                esami = new Esami(String.Join(Environment.NewLine, Lines));
            }
            catch
            {
                ;
            }

            if (esami == null || esami.GetEsami() == null || esami.GetEsami().Count == 0)
            {
                Console.WriteLine("No exams found in that file. Is it formatted correctly?");
                return(null);
            }

            return(esami);
        }
Beispiel #2
0
        private Esami GetEsamiFromFile(string filecontent, string file)
        {
            Esami esami = new Esami();

            EsamiFromFile obj = esami.CheckText(filecontent, File.ReadAllLines(file));

            if (obj == null || obj.IsEmpty())
            {
                return(null);
            }

            if (obj.AlreadyContaisExams())
            {
                return(obj.GetExams());
            }

            List <string> Lines    = obj.GetLines();
            string        plchlind = "[CFUNUM-PLACEHOLDER-";

            InputForm inpFrm = new InputForm();

            for (int i = 0; i < Lines.Count; i++)
            {
                string x = Lines[i];
                if (x.Contains(plchlind))
                {
                    string subjectname = x.Substring(x.IndexOf(plchlind) + plchlind.Length, x.IndexOf("]\"") - x.IndexOf(plchlind) - plchlind.Length);
                    inpFrm.Label1.Text    = "How many CFUs is " + Environment.NewLine + subjectname + " worth?";
                    inpFrm.InputText.Text = "";
                    inpFrm.ShowDialog();
                    Lines[i] = x.Replace(plchlind + subjectname + "]", inpFrm.InputText.Text);
                }
            }

            try
            {
                esami = new Esami(String.Join(Environment.NewLine, Lines));
            }
            catch
            {
                ;
            }

            if (esami == null || esami.GetEsami() == null || esami.GetEsami().Count == 0)
            {
                Console.WriteLine("No exams found in that file. Is it formatted correctly?");
                return(null);
            }

            return(esami);
        }