Пример #1
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);
        }
Пример #2
0
        private void Button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            var            r = openFileDialog.ShowDialog();

            if (r == DialogResult.OK)
            {
                string file        = openFileDialog.FileName;
                string filecontent = null;
                try
                {
                    filecontent = File.ReadAllText(file);
                }
                catch
                {
                    ;
                }

                if (string.IsNullOrEmpty(filecontent))
                {
                    MessageBox.Show("Error while reading the file selected.");
                    return;
                }

                esami = GetEsamiFromFile(filecontent, file);
                if (esami == null || esami.GetEsami() == null || esami.GetEsami().Count == 0)
                {
                    return;
                }

                var rispostaCompleta = DistribuisciEsamiCommon.RispostaCompleta.CalcolaRisposta(esami);
                if (rispostaCompleta.Item1 != null)
                {
                    MostraSoluzione(rispostaCompleta.Item1);
                }
                else
                {
                    MessageBox.Show(rispostaCompleta.Item2);
                }
            }
        }
Пример #3
0
        private void MostraSoluzione(RispostaCompleta rispostaCompleta)
        {
            listView1.Items.Clear();
            var esami2 = esami.GetEsami();

            foreach (string x in esami2.Keys)
            {
                string s = "" + esami.GetExam(x).ToStringListBoxGUI();

                ListViewItem newItem = new ListViewItem(s.Substring(0, s.IndexOf("\t")));
                newItem.SubItems.Add(s.Substring(s.IndexOf("\t") + 1, s.Length - s.IndexOf("\t") - 1));
                listView1.Items.Add(newItem);
            }

            SolutionsView.Items.Clear();

            ListViewItem emptyItem = new ListViewItem("");

            for (int i = 0; i < 2; i++)
            {
                emptyItem.SubItems.Add("");
            }

            foreach (List <int> p in rispostaCompleta.punteggi.rank)
            {
                foreach (var p2 in p)
                {
                    foreach (string x in rispostaCompleta.soluzioni[p2].ToConsoleOutput(esami))
                    {
                        string[]     exams   = x.Split('\t');
                        ListViewItem newItem = new ListViewItem(exams[0]);

                        foreach (string y in exams)
                        {
                            if (y != exams[0])
                            {
                                newItem.SubItems.Add(y);
                            }
                        }

                        newItem.SubItems.Add(rispostaCompleta.soluzioni[p2].value.ToString());
                        SolutionsView.Items.Add(newItem);
                    }
                    ListViewItem NewEmpty = (ListViewItem)emptyItem.Clone();
                    NewEmpty.SubItems.Add(rispostaCompleta.soluzioni[p2].value.ToString()); //Ensure that it has the same weight as the other items
                    SolutionsView.Items.Add(NewEmpty);                                      //Add an empty separator item.
                }
            }
        }
Пример #4
0
        public EsamiFromFile CheckText(string filecontent, string[] lines)
        {
            Esami esami = null;

            try
            {
                esami = new Esami(filecontent);
            }
            catch
            {
                ;
            }

            if (esami != null && esami.GetEsami() != null && esami.GetEsami().Count > 0)
            {
                return(new EsamiFromFile(esami));
            }

            //The file isn't formatted like the readme says it should be. Let's see if it's copied from the exams page.
            List <string> JSON = new List <string>
            {
                "["
            };

            foreach (string line in lines)
            {
                if (line.Contains("-"))
                {
                    if (Array.IndexOf(lines, line) + 1 == lines.Length)
                    {
                        break; //This line is a new subject, but there's no lines after this so there can't be any dates.
                    }
                    else
                    {
                        if (lines[Array.IndexOf(lines, line) + 1].IndexOf("/") != 2)
                        {
                            continue; //Is the next line NOT a date? Then keep going. This subject has no listed dates.
                        }
                    }
                    JSON.Add("{");
                    string subjectname = line.Substring(0, line.IndexOf("-")).Trim();
                    JSON.Add("\"name\":\"" + subjectname + "\",");
                    string dateline = "\"date\":[";
                    string nextline = lines[Array.IndexOf(lines, line) + 1];
                    while (nextline.IndexOf("/") == 2)
                    {
                        //So long as the next line is a date
                        dateline += "\"" + Convert.ToDateTime(nextline.Substring(0, nextline.IndexOf(":")).Replace("/", "-")).ToString("yyyy-MM-dd") + "\",";
                        nextline  = lines[Array.IndexOf(lines, nextline) + 1];
                    }
                    dateline = (dateline + "\"],").Replace("\",\"],", "\"],");  //2lazy to fix it properly
                    JSON.Add(dateline);
                    //MessageBox.Show(dateline);

                    JSON.Add("\"cfu\":\"" + "[CFUNUM-PLACEHOLDER-" + subjectname + "]" + "\"");

                    JSON.Add("},");
                }
            }
            JSON.Add("]");
            JSON[JSON.Count - 2] = "}";    //Remove the comma from the last closed curly bracket
            return(new EsamiFromFile(JSON));
        }