Пример #1
0
        private void run()
        {
            processRBox.Invoke(new MethodInvoker(delegate { processRBox.Clear(); }));
            //processRBox.Clear();
            running = true;
            startBtn.Invoke(new MethodInvoker(delegate { startBtn.Enabled = false; }));
            //startBtn.Enabled = false;
            //string dailyFileFolderPath = inputPathTxtBox.Text;
            string dailyFileFolderPath = null;
            inputPathTxtBox.Invoke(new MethodInvoker(delegate { dailyFileFolderPath = inputPathTxtBox.Text; }));
            try
            {
                if (!System.IO.Directory.Exists(dailyFileFolderPath))
                {
                    MessageBox.Show("The input daily file folder does not exist.");
                    return;
                }

                Logger.setLogFile(null, processRBox);
                Logger.printLog("Validating folder structure of " + dailyFileFolderPath + "......");
                if (!DailyFile.isValidDailyFolder(dailyFileFolderPath))
                {
                    Logger.printLog(dailyFileFolderPath + " does not have a good folder structure.");
                    return;
                }
                Logger.setLogFile(dailyFileFolderPath, processRBox);

                Logger.printLog("Loading dailyLoanAndDepositFiles and dailyRateFiles......");
                List<DailyLoanAndDepositFile> dailyLoanAndDepositFiles = DailyLoanAndDepositFile.getSortedFiles(Path.Combine(dailyFileFolderPath, DailyLoanAndDepositFile.dailyLoanAndDepositFolderName));
                List<DailyRateFile> dailyRateFiles = DailyRateFile.getSortedFiles(Path.Combine(dailyFileFolderPath, DailyRateFile.dailyRateFolderName));
                DateTime newBaseDate = Utility.findLastCommonDate(dailyLoanAndDepositFiles, dailyRateFiles);
                if (newBaseDate == DateTime.MinValue)
                {
                    Logger.printLog("The input daily files does not match on the time.");
                    return;
                }
                Logger.printLog("The input daily files include information up to " + newBaseDate.ToString("yyyy-MM-dd"));

                string baseFilePath = Path.Combine(dailyFileFolderPath, PortfolioFile.baseFileFolder);
                Logger.printLog("Loading the base files under " + baseFilePath + " ......");
                string[] baseFiles = Directory.GetFiles(baseFilePath);
                List<PortfolioFile> portfolioFiles = new List<PortfolioFile>();
                foreach (string bf in baseFiles)
                {
                    PortfolioFile basePortfolioFile = PortfolioFile.loadPortfolioFile(bf);
                    if (basePortfolioFile.DTime > newBaseDate)
                    {
                        Logger.printLog("The base portfolio file " + bf + " already includes all information of the input daily files. Skip!");
                        continue;
                    }
                    PortfolioFile newPortfolioFile = new PortfolioFile(basePortfolioFile.Type, newBaseDate, dailyFileFolderPath);
                    string newFileFolderPath = Path.GetDirectoryName(newPortfolioFile.getPath());
                    Directory.CreateDirectory(newFileFolderPath);
                    File.Copy(basePortfolioFile.getPath(), newPortfolioFile.getPath(), true);
                    Logger.printLog("Create the new portfolio file " + newPortfolioFile.getPath() + " based on the file " + basePortfolioFile.getPath());

                    Logger.printLog("Filtering dailyLoanAndDepositFiles and dailyRateFiles");
                    List<DailyLoanAndDepositFile> clonedDailyLoanAndDepositFiles = Utility.cloneList<DailyLoanAndDepositFile>(dailyLoanAndDepositFiles);
                    List<DailyRateFile> clonedDailyRateFiles = Utility.cloneList<DailyRateFile>(dailyRateFiles);
                    basePortfolioFile.filterDailyFiles(clonedDailyLoanAndDepositFiles, clonedDailyRateFiles);
                    for (int i = 0; i < clonedDailyLoanAndDepositFiles.Count && running; i++)
                    {
                        Logger.printLog("\n==========Adding " + clonedDailyLoanAndDepositFiles[i].Path + " to " + newPortfolioFile.getPath() + "==========");
                        newPortfolioFile.addDailyData(clonedDailyLoanAndDepositFiles[i], clonedDailyRateFiles[i]);
                        if (running)
                        {
                            Logger.printLog("Successfully added " + clonedDailyLoanAndDepositFiles[i].Path + " to " + newPortfolioFile.getPath());
                        }
                    }
                }
                if (running)
                {
                    Logger.printLog("\n=========Congratulations! All files are processed!!=========");
                    Logger.printLog("Please check all outputs and logs under folder " + Path.Combine(dailyFileFolderPath, PortfolioFile.folder));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ":" + System.Environment.NewLine + ex.StackTrace);
                return;
            }
            finally
            {
                startBtn.Invoke(new MethodInvoker(delegate { startBtn.Enabled = true; }));
                //startBtn.Enabled = true;
                generatorThread.Abort();
            }
        }
Пример #2
0
        public static PortfolioFile loadPortfolioFile(string path)
        {
            if (!File.Exists(path))
            {
                throw new FileNotFoundException();
            }

            PortfolioFile pf = new PortfolioFile(path);
            pf.Name = Path.GetFileName(path);
            int portfolioType = validatePortfolioFileName(pf.Name);
            switch (portfolioType)
            {
                case 1:
                    pf.Type = PortfolioType.DepositPortfolio;
                    break;
                case -1:
                    pf.Type = PortfolioType.LoanPortfolio;
                    break;
                default:
                    throw new InvalidFileNameException();
            }

            pf.DTime = getDateTimeFromPortfolioFileName(pf.Name);
            return pf;
        }