예제 #1
0
        public void addAssignment(Assignment assignment, bool isNew = true)
        {
            if (isNew)
            {
                myModule.AddAssignment(assignment);
            }


            ListViewItem li = new ListViewItem();

            li.Text = assignment.FormString;

            if (assignment.FormString.Contains("Deadline Passed"))
            {
                li.BackColor = Color.OrangeRed;
                li.ForeColor = Color.Yellow;
            }

            assignmentLst.Items.Add(li);
        }
예제 #2
0
파일: Parser.cs 프로젝트: TGRHavoc/ModNote
        /// <summary>
        /// Try an parse a file into a module object
        /// </summary>
        ///
        /// <param name="file">The file to try and parse</param>
        /// <returns>A module that the file represents, new module if parsing failes and null if file isn't a txt file.</returns>
        public static Module ParseFile(string file)
        {
            Module parsedModule = new Module();         // Our module obj

            int loSize = 0, assSize = 0, notesSize = 0; //Sizes of the arrays (used for determining whether module needs saving)

            FileInfo fi = new FileInfo(file);           //The file info.. Just need to double check it's a txt file

            if (fi.Extension != ".txt")                 // Make sure it's a txt file
            {
                return(null);                           // If not, return nothing
            }
            using (PeakedStreamReader reader = new PeakedStreamReader(File.Open(file, FileMode.Open)))
            {                                              // Open the file for reading
                string line = null;                        //the current line
                while ((line = reader.ReadLine()) != null) //Whilst we're not at the end
                {
                    line = line.Trim();                    // Get rid of them pesky whitespaces!

                    if (line == "CODE")
                    {
                        //Next line is the code
                        parsedModule.Code = reader.ReadLine();
                    }
                    if (line == "TITLE")
                    {
                        parsedModule.Title = reader.ReadLine();
                    }
                    if (line == "SYNOPSIS")
                    {
                        parsedModule.Synopsis = reader.ReadLine();
                    }
                    if (line == "LO")
                    {
                        //We have an array now...
                        string nextLine = null;
                        while ((nextLine = reader.PeekReadLine()) != "ASSIGNMENT")
                        {
                            if (nextLine == null || string.IsNullOrEmpty(nextLine))
                            {
                                break;
                            }
                            Console.WriteLine("Added LO: " + nextLine);
                            parsedModule.AddLearningOutcome(reader.ReadLine()); //Add the read learning outcome
                            loSize++;
                            //We've just read this line via peek
                        }
                    }
                    //Console.WriteLine("Line: " + line + " : " + (line == null));
                    if (line == "ASSIGNMENT")
                    {
                        string nextLine = null;
                        while ((nextLine = reader.PeekReadLine()) != "NOTE")
                        {
                            Console.WriteLine("nextLine: " + nextLine);
                            if (nextLine == null || string.IsNullOrEmpty(nextLine))
                            {
                                break;
                            }

                            nextLine = reader.ReadLine();
                            string[]   objs       = nextLine.Split('\t');
                            Assignment assignment = new Assignment(objs[0], objs[1]);
                            parsedModule.AddAssignment(assignment);
                            assSize++;
                            Console.WriteLine("Adding assignment: " + nextLine);
                        }
                    }
                    if (line == "NOTE")
                    {
                        string nextLine = null;
                        while ((nextLine = reader.PeekReadLine()) != null)
                        {
                            // First readLine() = title
                            // Second readLine() = content
                            string title          = reader.ReadLine();
                            string encodedContent = reader.ReadLine();
                            if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(encodedContent))
                            {
                                continue;
                            }

                            Note note = new Note(title, decode(encodedContent));
                            parsedModule.AddNote(note);
                            notesSize++;
                        }
                    }
                }
            }

            parsedModule.AssignmentsSize      = assSize;
            parsedModule.NotesSize            = notesSize;
            parsedModule.LearningOutcomesSize = loSize;
            Console.WriteLine("Finished parsing");
            return(parsedModule);
        }