using System;
using Microsoft.SPOT;

using Microsoft.SPOT.Hardware;

using Microsoft.VisualStudio.TestTools.UnitTesting;
using CPF;

using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using GHI.IO;
using GHI.IO.Storage;
using System.IO;

using System.Text;
using System.Threading;
using HWModules;
using SWModules;
using CPF.Surface_States;
using CPF.Profile_States;

namespace CPFUnitTests
{
    class ReadFile
    {
        [TestMethod]
        public void TestReadFile()
        {
            int numFilesToGet = 20;
            int numFilesOnDisk = 0;
            
            string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
            
            string dataDirectory = "\\SD\\Data";
            String[] fileNames = Directory.GetFiles(dataDirectory);

            numFilesOnDisk = Directory.GetFiles(dataDirectory).Length;

            if (numFilesOnDisk > 0)
            {
                for (int i = numFilesOnDisk - 1; i > numFilesOnDisk - numFilesToGet; i--)
                {
                    try
                    {
                        FileInfo fileInfo = new FileInfo(fileNames[i]);
                        Debug.Print(" File Name = " + fileInfo.Name
                                     + "  Creation Date = " + fileInfo.CreationTime.ToString()
                                    + "  Length = " + fileInfo.Length.ToString());
                    }
                    catch
                    {
                        EngrLogger.writeToColumns("Error in getDir get FileInfo");
                    }
                }
            }
            else
            {
                Debug.Print("No files on disk!");
            }


            StreamReader sciFileStream;
            string fileLine;
            string temp = " ";

            StringBuilder fileName = new StringBuilder(64);

            fileName.Clear();
            fileName.Append(dataDirectory);
            fileName.Append("\\");
            fileName.Append(temp);

            sciFileStream = new StreamReader(fileName.ToString());

            while ((fileLine = sciFileStream.ReadLine()) != null)
                Debug.Print(fileLine);

            sciFileStream.Close();

        }

 

 
    }
}
