Exemplo n.º 1
0
        //GET (ALL FILES) IN DEFAULT FOLDER
        public string[] GetFilesInDefaultFolder()
        {
            TransactionDB transactionDB = new TransactionDB();

            string[] files = transactionDB.GetFilesInDefaultFolder("*.csv");

            return(files);
        }
Exemplo n.º 2
0
        //TEST RETURN ALL FILES IN FOLDER
        public void TestGetFilesInFolder()
        {
            TransactionDB transactionDB = new TransactionDB();

            string[] files = transactionDB.GetFilesInDefaultFolder("*.csv");

            for (int i = 0; i < files.Length; i++)
            {
                Console.WriteLine(files[i]);
            }
        }
Exemplo n.º 3
0
        //CREATE A TEST FROM FILE
        public void CreateTestFromFile()
        {
            string path     = "C:\\_txttofile";
            string filename = "export1.txt";

            Transaction transaction = new Transaction();

            transaction = TransactionDB.ReadTransactionFromFile(path, filename, '\t');

            Console.WriteLine("---testfromfile---");
            Console.WriteLine(transaction.ToString());
            Console.WriteLine("---testfromfile---");
        }
Exemplo n.º 4
0
        //CREATE A TEST (TO WRITE TO FILE)
        public void CreateTestWriteToFile()
        {
            //----------
            //INPUT FILE
            string inPath     = "C:\\_txttofile";
            string inFileName = "export1.txt";

            Transaction transaction = new Transaction();

            //create a (Transaction) object (from file)
            transaction = TransactionDB.ReadTransactionFromFile(inPath, inFileName, '\t');
            //----------
            //OUTPUT FILE
            string outPath     = "C:\\_txttofile";
            string outFileName = "output1.txt";

            TransactionDB.SaveTransactionToFile(outPath, outFileName, transaction);
            //----------
        }
Exemplo n.º 5
0
        ////GET (ALL FILES) IN DEFAULT FOLDER
        //public string[] GetFilesInDefaultFolder()
        //{
        //    Transaction transaction = new Transaction();
        //    string[] files = transaction.GetFilesInDefaultFolder("*.csv");

        //    return files;
        //}

        ////TEST RETURN ALL FILES IN FOLDER
        //public void TestGetFilesInFolder()
        //{
        //    Transaction transaction = new Transaction();
        //    string[] files = transaction.GetFilesInDefaultFolder("*.csv");

        //    for (int i = 0; i < files.Length; i++)
        //    {
        //        Console.WriteLine(files[i]);
        //    }
        //}


        //CREATE A TEST (TO WRITE TO FILE)
        public void CreateTestWriteToFile2()
        {
            //----------
            //INPUT FILE
            string inPath     = PATH_DEFAULT;
            string inFileName = "Export506.csv";

            //create (Transaction) object
            Transaction transaction = new Transaction();

            //create a (Transaction) object (from file)
            transaction = TransactionDB.ReadTransactionFromFile(inPath, inFileName, ',');
            //----------
            //OUTPUT FILE
            //string outPath = PATH_DEFAULT + "\\" + PATH_COMPLETED;
            string outPath     = PATH_OUTBOUND;
            string outFileName = "output1.txt";

            //save to file
            TransactionDB.SaveTransactionToFile(outPath, outFileName, transaction);
            //----------

            Console.WriteLine("complete...");
        }
Exemplo n.º 6
0
        //CREATE TEST (WRITE TO FILE)(WITH NEW FILENAME METHOD)
        public Status WriteToFile(string filename)
        {
            //keep track of status through this procedure
            Status status = Status.Start;

            try
            {
                //----------
                //CHECK FILE IS ACCESSIBLE
                FileInfo f = new FileInfo(PATH_DEFAULT + "\\" + filename);
                if (TransactionDB.IsFileLocked(f))
                {
                    //write to log
                    WriteToLog("--------------------------------------------");
                    WriteToLog("Filename: " + filename + ", Date run: " + dateTime);
                    WriteToLog("FILE IS NOT ACCESSIBLE");
                    WriteToLog("--------------------------------------------");
                }
                else
                {
                    //----------
                    //INPUT FILE
                    if (status == Status.Start)
                    {
                        inPath = PATH_DEFAULT;
                        //CSV file...
                        //FIND ALL FILES IN THIS FOLDER (to process ONE AT A TIME)
                        inFileName = filename;                                   //"export1.txt";

                        //create (Transaction) object
                        transaction = new Transaction();

                        //create a (Transaction) object (from file)
                        transaction = TransactionDB.ReadTransactionFromFile(inPath, inFileName, ',');

                        //write to log
                        WriteToLog("--------------------------------------------");
                        WriteToLog("Filename: " + inFileName + ", Date run: " + dateTime);

                        //pass status...
                        if (transaction != null)
                        {
                            status = Status.ReadTransactionFromFile;
                            //write to log file
                            WriteToLog("\t" + status.ToString());
                        }
                    }
                    //----------
                    //OUTPUT FILE
                    if (status == Status.ReadTransactionFromFile)
                    {
                        bool savedFile = false;

                        outPath     = PATH_OUTBOUND;
                        outFileName = transaction.GetTransactionFileName();         //get filename FROM (Transaction) object

                        //save to file
                        savedFile = TransactionDB.SaveTransactionToFile(outPath, outFileName, transaction);
                        //----------

                        //pass status...
                        if (savedFile)
                        {
                            status = Status.SaveTransactionToFile;
                            //write to log file
                            WriteToLog("\t" + status.ToString());
                        }
                    }
                    //--------------------
                    //CONFIRM FILE CREATED
                    if (status == Status.SaveTransactionToFile)
                    {
                        bool confirmFile = false;

                        //confirm file
                        confirmFile = TransactionDB.ConfirmNewFileCreated(outPath, outFileName);

                        //pass status...
                        if (confirmFile)
                        {
                            status = Status.ConfirmNewFileCreated;
                            //write to log file
                            WriteToLog("\t" + status.ToString());
                        }
                    }
                    //--------------------
                    //MOVE CSV FILE (TO COMPLETED FOLDER)
                    if (status == Status.ConfirmNewFileCreated)
                    {
                        bool moveCsv = false;

                        //move CSV file
                        moveCsv = TransactionDB.MoveCsvFileToCompleted(PATH_DEFAULT, PATH_COMPLETED, inFileName);

                        //pass status...
                        if (moveCsv)
                        {
                            status = Status.MoveCsvFileToCompleted;
                            //write to log file
                            WriteToLog("\t" + status.ToString());
                        }
                    }
                    //--------------------
                    //FINISH STATUS
                    if (status == Status.MoveCsvFileToCompleted)
                    {
                        //then finished...
                        status = Status.Finished;
                        //write to log file
                        WriteToLog("\t" + status.ToString());
                        WriteToLog("--------------------------------------------");
                    }
                }
            }
            catch (Exception ex2)
            {
                Console.WriteLine(ex2.Message + "\n" + ex2.StackTrace);
            }

            return(status);
        }