Exemplo n.º 1
0
        /// <summary>
        /// Generates all the Information from getting the Data to Saving it in Excel or/and the Database
        /// </summary>
        /// <param name="directory">The Path where the Data if the Student is.</param>
        /// <param name="acumulatedExcel">The Excel where all information from students is stored.</param>
        /// <param name="db">The Database used. If there is no database, dataList is used as default.</param>
        /// <returns>Returns the Name of the Student that its Information is beeing Generated.</returns>
        public string GenerateInformation(string directory, DashboardExcel acumulatedExcel, DashboardContext db)
        {
            //Gets the zip file
            string zipFile = Directory.GetFiles(directory).FirstOrDefault(file => file.startsWithPrefix(prefix));

            if (zipFile == null)
            {
                return(null);
            }

            //Creates a linker to store and process data
            IDataManager link;

            if (db != null)
            {
                link = db;
            }
            else
            {
                link = new DataList();
            }

            //Gets the name of the student and adds it to the database
            var    studentInfo = new StudentInformation(directory, zipFile);
            string studentName = studentInfo.getStudent("global.dat");

            studentInfo.student = link.AddOrGet(studentName);

            //Generates all the Information about the Student
            studentInfo.generateInformation(link);

            //Saves data to the database
            if (db != null)
            {
                ((DashboardContext)link).SaveChanges();
            }

            //Checks if Excels are going to be Generated
            if (isGenerateExcels || isAcumulatedExcel)
            {
                //Orders Data
                var allDefectLogs = link.defectLogs.order().ToList();
                var allTimeLogs   = link.timeLogs.order().ToList();
                var allSETS       = link.sets.order().ToList();
                var allPROBES     = link.probes.order().ToList();
                var allPhases     = link.phases.order().ToList();
                var allSummaries  = link.summaries.order().ToList();

                if (isGenerateExcels)
                {
                    //Uses the Excel File to create a new Excel
                    using (DashboardExcel excel = new DashboardExcel(excelFile)) {
                        //Fills Data into the Excel
                        excel.fillAll(allDefectLogs, allTimeLogs, allSETS, allPROBES, allPhases, allSummaries);
                        //Saves As a New Excel
                        excel.Save(directory, studentInfo.programs.Count, studentInfo.student.Name);
                    }
                }

                if (isAcumulatedExcel)
                {
                    //Adds Data into the Acumulated Excel
                    acumulatedExcel?.fillAll(allDefectLogs, allTimeLogs, allSETS, allPROBES, allPhases, allSummaries);
                }
            }
            return(studentInfo.student.Name);
        }