Ejemplo n.º 1
0
        //foreach fco in fco table, create weekly report and copy to report folder
        public async Task GenerateWeeklyReport()
        {
            if (!FCOPath.TestRootDir())
            {
                LogHelper.Instance.Error("Fail to generate weekly report.");
                return;
            }

            foreach (string fco in FCOList)
            {
                FCOPath      fcoPath      = new FCOPath(fco, DateTime.Now);
                WeeklyReport weeklyReport = new WeeklyReport(fco, DateTime.Now);
                weeklyReport.GenerateReportTo(fcoPath.GetReportFilePath((int)Constants.REPORTTYPE.WEEKLY));
                LogHelper.Instance.Info(string.Format("Generate weekly report for FCO {0}.", fco));
            }
        }
Ejemplo n.º 2
0
        //Create new daily report and copy to report folder despite of the fco number, archive to archive folder
        public async Task GenerateDailyReport()
        {
            if (!FCOPath.TestRootDir())
            {
                return;
            }


            FCOPath fcoPath = new FCOPath(DateTime.Now);
            //DailyReport dailyReport = new DailyReport(fco, DateTime.Now);
            DailyReport dailyReport = new DailyReport(DateTime.Now);

            if (Directory.Exists(fcoPath.GetUpgradeCodeDir()))
            {
                dailyReport.Import(fcoPath.GetUpgradeCodeDir());
                dailyReport.GenerateReportTo(fcoPath.GetReportFilePath((int)Constants.REPORTTYPE.DAILY));
            }
        }
Ejemplo n.º 3
0
        public void Import(string upgradeCodeDir)
        {
            //foreach spread sheet under the dir, import it to database
            DirectoryInfo dirUpgradeCode = new DirectoryInfo(upgradeCodeDir);

            FileInfo[] files = dirUpgradeCode.GetFiles("*.csv");


            foreach (FileInfo fInfo in files)
            {
                Dictionary <string, int> mapHeaderIndex = new Dictionary <string, int>();
                string fileName = fInfo.FullName;
                LogHelper.Instance.Info("START importing UpgradeCode spreadsheet " + fileName);
                Encoding curEncoding = GetEncoding(fileName);

                try
                {
                    using (var reader = new StreamReader(fileName, curEncoding))
                    {
                        var header = reader.ReadLine().Split(',');

                        int i = 0;
                        while (i < header.Length)
                        {
                            if (!mapHeaderIndex.ContainsKey(header[i].Trim()))
                            {
                                mapHeaderIndex.Add(header[i].Trim(), i);
                                i++;
                            }
                            else
                            {
                                LogHelper.Instance.Error("Duplicate column header " + header[i] + "in " + fileName);
                                break;
                            }
                        }

                        if (i != header.Length) // break the loop due to duplicate column header name
                        {
                            continue;
                        }

                        if (!mapHeaderIndex.ContainsKey(UCColHeaderSN))
                        {
                            LogHelper.Instance.Error("Unable to find column" + UCColHeaderSN + "in " + fileName);

                            continue;
                        }
                        if (!mapHeaderIndex.ContainsKey(UCColHeaderUpgradeCode))
                        {
                            LogHelper.Instance.Error("Unable to find column" + UCColHeaderUpgradeCode + "in " + fileName);

                            continue;
                        }

                        using (var dbContext = new FcoDBEntities())
                        {
                            while (!reader.EndOfStream)
                            {
                                UpgradeResult item   = new UpgradeResult();
                                var           line   = reader.ReadLine();
                                var           values = line.Split(',');
                                if (string.IsNullOrWhiteSpace(values[mapHeaderIndex[UCColHeaderSN]]) &&
                                    string.IsNullOrWhiteSpace(values[mapHeaderIndex[UCColHeaderUpgradeCode]]))
                                {
                                    continue; //skip the empty line
                                }
                                item.Id             = Guid.NewGuid().ToString();
                                item.SystemSerialNo = values[mapHeaderIndex[UCColHeaderSN]].Trim().ToUpper();
                                item.UpgradeCode    = values[mapHeaderIndex[UCColHeaderUpgradeCode]].Trim().ToUpper();
                                if (mapHeaderIndex.ContainsKey(UCColHeaderModelNumber)) //TC upgrade code
                                {
                                    item.ModelNumber = values[mapHeaderIndex[UCColHeaderModelNumber]].Trim().ToUpper();
                                }

                                dbContext.UpgradeResults.Add(item);
                            }

                            dbContext.SaveChanges();
                        } //End dbcontext
                    }     //End stream reader

                    FCOPath fcoPath         = new FCOPath(m_dt);
                    string  archiveFilePath = fcoPath.GetArchiveFilePath();
                    ArchiveTo(fileName, archiveFilePath);
                    LogHelper.Instance.Info(string.Format("SUCCESSFULLY imported {0} to database.", fileName));
                }
                catch (Exception e1)
                {
                    LogHelper.Instance.Error(string.Format("FAIL to import upgradecode file {0} due to {1}.", fileName, e1.Message));
                    continue;
                }
            }
        }