Example #1
0
        public void ExistingSourceDirectory_FileNotExists_MappedPathReturned()
        {
            var sut = new LocalFileReader(new[] { FileManager.GetCSharpReportDirectory() });

            string[] lines = sut.LoadFile(NotExistingFile, out string error);
            Assert.Null(error);
            Assert.True(lines.Length > 0);
        }
Example #2
0
        public void NotExistingSourceDirectory_FileNotExists_DefaultPathReturned()
        {
            var sut = new LocalFileReader(new[] { FileManager.GetCPlusPlusReportDirectory() });

            string[] lines = sut.LoadFile(NotExistingFile, out string error);
            Assert.NotNull(error);
            Assert.Null(lines);
        }
Example #3
0
        public void DeterminicticPath_ExistingSourceDirectory_FileExists_MappedPathReturned(string filename)
        {
            var sut = new LocalFileReader(new[] { FileManager.GetCSharpReportDirectory() });

            string[] lines = sut.LoadFile(filename, out string error);
            Assert.Null(error);
            Assert.True(lines.Length > 0);
        }
Example #4
0
        public void NoSourceDirectories_FileNotExists_DefaultPathReturned()
        {
            var sut = new LocalFileReader();

            string[] lines = sut.LoadFile(NotExistingFile, out string error);
            Assert.NotNull(error);
            Assert.Null(lines);
        }
        private void FileTransferList(string[] filePathList, int targetPort, RemoteOnlineClientProxy proxy)
        {
            List <Task> taskList = new List <Task>();

            foreach (var path in filePathList)
            {
                Task t = new Task(() =>
                {
                    var reader = new LocalFileReader(new FileRemoteSendAdapter(targetPort, proxy), this, this);
                    reader.RunFileTransfer(path);
                });
                taskList.Add(t);
                t.Start();
            }
            Task.WaitAll(taskList.ToArray());//使用多线程上传文件
        }
        public void GetLatestFilePath_Testing()
        {
            //Arrange
            string          directory        = "../../../00_TestCashData/";
            string          searchForName    = "Kontostand";
            string          expectedFilePath = "../../../00_TestCashData/Kontostand_newerFile.csv";
            LocalFileReader localFileReader  = new LocalFileReader();

            //Act
            string actualFilePath = localFileReader.GetLatestFilePath(directory, searchForName);

            Console.WriteLine(actualFilePath);

            //Assert
            Assert.AreEqual(expectedFilePath, actualFilePath, "FilePath is wrong.");
        }
        private void LanFileListTransfer(ClientToken targetToken, string[] filePathList)
        {
            IFileSender adapter      = FileUpdateClientProxy.CreateTcpProxy(targetToken.GenServiceAddress());
            var         easyTransfer = new LocalFileReader(adapter, this, this);

            List <Task> taskList = new List <Task>();

            foreach (var path in filePathList)
            {
                Task t = new Task(() =>
                {
                    //bug : appeared throw
                    easyTransfer.RunFileTransfer(path);//这个接口目前只支持局域网
                });
                taskList.Add(t);
                t.Start();
            }
            Task.WaitAll(taskList.ToArray());//使用多线程上传文件
        }
Example #8
0
 /// <summary>
 /// Constructor which forwards drive service instance to base class.
 /// </summary>
 public GoogleDriveReader(DriveService driveService, IFileReader fileReader)
     : base(driveService)
 {
     _localFileReader = new LocalFileReader(fileReader);
 }
Example #9
0
        static void Main(string[] args)
        {
            var fileReader  = new LocalFileReader();
            var lineParser  = new LineParser();
            var coffeeMaker = new CoffeeFactory();

            try
            {
                var lines = fileReader.GetAllLines(FILE_PATH);

                var ingredients = lines.Select(line => lineParser.ParseLine(line)).ToArray();
                var recipe      = new Recipe(ingredients);

                var        coffee         = coffeeMaker.GetCoffee(recipe);
                Director   coffeeDirector = null;
                BaseCoffee madeCoffee     = null;

                switch (coffee)
                {
                case Coffee.Espresso:
                    var espressoBuilder = new EspressoBuilder();
                    coffeeDirector = new Director(espressoBuilder);
                    coffeeDirector.MakeCoffee();
                    madeCoffee = espressoBuilder.GetResult();
                    break;

                case Coffee.Cappuccino:
                    var cappucinoBuilder = new CappuccinoBuilder();
                    coffeeDirector = new Director(cappucinoBuilder);
                    coffeeDirector.MakeCoffee();
                    madeCoffee = cappucinoBuilder.GetResult();
                    break;

                case Coffee.Americano:
                    var americanoBuilder = new AmericanoBuilder();
                    coffeeDirector = new Director(americanoBuilder);
                    coffeeDirector.MakeCoffee();
                    madeCoffee = americanoBuilder.GetResult();
                    break;

                case Coffee.FlatWhite:
                    var flatWhiteBuilder = new FlatWhiteBuilder();
                    coffeeDirector = new Director(flatWhiteBuilder);
                    coffeeDirector.MakeCoffee();
                    madeCoffee = flatWhiteBuilder.GetResult();
                    break;

                default:
                    Console.WriteLine("Recipe not recognized");
                    Console.ReadLine();
                    return;
                }

                Console.WriteLine(madeCoffee.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.ReadLine();
        }
Example #10
0
 public FileTransferTest(IFileSender fileSender)
 {
     reader = new LocalFileReader(fileSender);
 }
        public double CalculateAvailableCash()
        {
            //preliminary value
            double availableCash = 0;

            GlobalLocalFileNames globalLocalFileNames = new GlobalLocalFileNames();
            LocalFileReader      localFileReader      = new LocalFileReader();

            try
            {
                //(0) Search for local financial data with latest modifications
                string bankDataFilePath            = localFileReader.GetLatestFilePath(GlobalLocalFileNames.finDataDirectoryPath, GlobalLocalFileNames.bankAccountDataFileName);
                string loanDataFilePath            = localFileReader.GetLatestFilePath(GlobalLocalFileNames.finDataDirectoryPath, GlobalLocalFileNames.treasuryDataFileName);
                string investmentDataFilePath      = localFileReader.GetLatestFilePath(GlobalLocalFileNames.finDataDirectoryPath, GlobalLocalFileNames.investmentDataFileName);
                string salesDataFilePath           = localFileReader.GetLatestFilePath(GlobalLocalFileNames.finDataDirectoryPath, GlobalLocalFileNames.salesDataFileName);
                string payrollDataFilePath         = localFileReader.GetLatestFilePath(GlobalLocalFileNames.finDataDirectoryPath, GlobalLocalFileNames.payrollDataFileName);
                string autoCashCalculationFilePath = localFileReader.GetLatestFilePath(GlobalLocalFileNames.finReportsDirectoryPath, GlobalLocalFileNames.autoCashCalculationFileName);

                //(1) Start Available Cash Calculation
                AvailableCashCalculator      availableCashCalculator  = new AvailableCashCalculator();
                DataMapAutoCashCalculation[] autoCashCalculationTable = availableCashCalculator.GetAutoCashCalculationData(autoCashCalculationFilePath);

                //(1.a) GetBankAccountBalance
                var currentBankBalance = availableCashCalculator.GetCurrentBankBalance(bankDataFilePath);

                //For demo purposes 23rd Feb 2020 is used as current date
                //DateTime dateToday = DateTime.Now.Date;
                DateTime dateToday = Convert.ToDateTime("23.02.2020");

                //Enter current bank balance into cash calculation table
                int daysPassed = Convert.ToInt32((dateToday - autoCashCalculationTable[0].Datum).TotalDays);
                autoCashCalculationTable[daysPassed].Kontostand = currentBankBalance;

                //(1.b) Get expected loan data and calculate loan cash flow
                LoanCashflowCalculator loanCashflowCalculator = new LoanCashflowCalculator();
                autoCashCalculationTable = loanCashflowCalculator.CalculateLoanCashFlow(autoCashCalculationTable, loanDataFilePath);

                //(1.c) Get long term investment data and calculate cashflow
                LongInvestmentCashflowCalculator longInvestmentCashflowCalculator = new LongInvestmentCashflowCalculator();
                autoCashCalculationTable = longInvestmentCashflowCalculator.CalculateLongInvestmentCashflow(autoCashCalculationTable, investmentDataFilePath);

                //(1.d-e) Get sales data and calculate sales cashflow
                SalesCashflowCalculator salesCashflowCalculator = new SalesCashflowCalculator();
                autoCashCalculationTable = salesCashflowCalculator.CalculateSalesCashflow(autoCashCalculationTable, salesDataFilePath);

                //(1.f-g) Get payroll data and calculate payroll cashflow
                PayrollCashflowCalculator payrollCashflowCalculator = new PayrollCashflowCalculator();
                autoCashCalculationTable = payrollCashflowCalculator.CalculatePayrollCashflow(autoCashCalculationTable, payrollDataFilePath);

                //(1.h) Calculate available cash

                //First entry till today have to be adjusted according to the actuals
                for (int j = 0; j < daysPassed; j++)
                {
                    //Calculate unpredicted cash developments
                    autoCashCalculationTable[j].Sonstige =
                        autoCashCalculationTable[j + 1].Kontostand -
                        autoCashCalculationTable[j].Kontostand -
                        autoCashCalculationTable[j].Treasury -
                        autoCashCalculationTable[j].Anlagenbuchhaltung -
                        autoCashCalculationTable[j].Sales -
                        autoCashCalculationTable[j].Payroll;
                }

                for (int g = 0; g < daysPassed; g++)
                {
                    //Create sums
                    autoCashCalculationTable[g].Summe =
                        autoCashCalculationTable[g].Kontostand +
                        autoCashCalculationTable[g].Treasury +
                        autoCashCalculationTable[g].Anlagenbuchhaltung +
                        autoCashCalculationTable[g].Sales +
                        autoCashCalculationTable[g].Payroll +
                        autoCashCalculationTable[g].Sonstige;
                }

                //Create prognosis for cash available today
                autoCashCalculationTable[daysPassed].Summe =
                    autoCashCalculationTable[daysPassed].Kontostand +
                    autoCashCalculationTable[daysPassed].Treasury +
                    autoCashCalculationTable[daysPassed].Anlagenbuchhaltung +
                    autoCashCalculationTable[daysPassed].Sales +
                    autoCashCalculationTable[daysPassed].Payroll;

                //Cash available for next 24h
                availableCash = autoCashCalculationTable[daysPassed].Summe;

                //Create prognosis for the future cash available
                for (int k = daysPassed + 1; k < autoCashCalculationTable.Length; k++)
                {
                    //Assume: Balance at the begining of the day is the same as at the end of the last

                    autoCashCalculationTable[k].Kontostand = autoCashCalculationTable[k - 1].Summe;
                    //Create sums
                    autoCashCalculationTable[k].Summe =
                        autoCashCalculationTable[k].Kontostand +
                        autoCashCalculationTable[k].Treasury +
                        autoCashCalculationTable[k].Anlagenbuchhaltung +
                        autoCashCalculationTable[k].Sales +
                        autoCashCalculationTable[k].Payroll;
                }

                availableCashCalculator.SaveAutoCashCalculation(autoCashCalculationTable, autoCashCalculationFilePath);
            }
            catch (BankBalanceException eBB)
            {
                Console.WriteLine(" Exception: " + eBB);
                Log.Debug("Exception: " + eBB);
            }
            catch (LocalFileNotFoundException eFNF)
            {
                Console.WriteLine(" Exception: " + eFNF);
                Log.Debug("Exception: " + eFNF);
            }
            catch (DataNotFoundException eDNF)
            {
                Console.WriteLine(" Exception: " + eDNF);
                Log.Debug("Exception: " + eDNF);
            }
            return(availableCash);
        }