protected override void ParseFileNameRemote()
        {
            try
            {
                Log.Log(LogType.FILE, LogLevel.INFORM, " TinyProxyRecorder In ParseFileNameRemote() -->> Enter The Function");

                String stdOut = "";
                String stdErr = "";
                String line = "";

                se = new SshExec(remoteHost, user);
                se.Password = password;

                if (Dir.EndsWith("/") || Dir.EndsWith("\\"))
                {
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "Home Directory | " + Dir);

                    se.Connect();
                    se.SetTimeout(Int32.MaxValue);
                    String command = "ls -lt " + Dir + " | grep messages";
                    Log.Log(LogType.FILE, LogLevel.DEBUG, " TinyProxyRecorder In ParseFileNameRemote() -->> SSH command : " + command);
                    se.RunCommand(command, ref stdOut, ref stdErr);
                    StringReader sr = new StringReader(stdOut);

                    ArrayList arrFileNameList = new ArrayList();

                    while ((line = sr.ReadLine()) != null)
                    {
                        String[] arr = line.Split(' ');
                        if (arr[arr.Length - 1].Contains("messages") == true && arr[arr.Length - 1].Contains("gz") == false && arr[arr.Length - 1].Contains("bz2") == false)
                            arrFileNameList.Add(arr[arr.Length - 1]);
                    }

                    String[] dFileNameList = SortFiles(arrFileNameList);

                    if (!String.IsNullOrEmpty(lastFile))
                    {
                        Log.Log(LogType.FILE, LogLevel.DEBUG, " TinyProxyRecorder In ParseFileNameRemote() -->> LastFile Is = " + lastFile);

                        bool bLastFileExist = false;

                        for (int i = 0; i < dFileNameList.Length; i++)
                        {
                            if ((base.Dir + dFileNameList[i]) == base.lastFile)
                            {
                                bLastFileExist = true;
                                break;
                            }
                        }

                        if (bLastFileExist)
                        {
                            stdOut = "";
                            stdErr = "";
                            String commandRead;

                            if (readMethod == "nread")
                            {
                                commandRead = tempCustomVar1 + " -n " + Position + "," + lineLimit + "p " + lastFile;
                                Log.Log(LogType.FILE, LogLevel.DEBUG, " TinyProxyRecorder In ParseFileNameRemote() -->> commandRead For nread Is : " + commandRead);
                            }
                            else
                            {
                                commandRead = readMethod + " -n " + Position + "," + lineLimit + "p " + lastFile;
                                Log.Log(LogType.FILE, LogLevel.DEBUG, " TinyProxyRecorder In ParseFileNameRemote() -->> commandRead For sed Is : " + commandRead);
                            }

                            se.RunCommand(commandRead, ref stdOut, ref stdErr);
                            se.Close();

                            StringReader srTest = new StringReader(stdOut);
                            Int64 posTest = Position;
                            String lineTest = "";
                            while ((lineTest = srTest.ReadLine()) != null)
                            {
                                if (lineTest.StartsWith("~?`Position"))
                                {
                                    try
                                    {
                                        String[] arrIn = lineTest.Split('\t');
                                        String[] arrPos = arrIn[0].Split(':');
                                        String[] arrLast = arrIn[1].Split('`');
                                        posTest = Convert.ToInt64(arrPos[1]); // değişti Convert.ToUInt32s
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.Log(LogType.FILE, LogLevel.ERROR, " TinyProxyRecorder In ParseFileNameRemote() In Try Catch -->> " + ex.Message);
                                    }
                                }
                            }

                            if (posTest > Position)
                            {
                                Log.Log(LogType.FILE, LogLevel.INFORM,
                                    " TinyProxyRecorder In ParseFileNameRemote() -->> posTest > Position So Continiou With Same File ");

                                FileName = lastFile;

                                Log.Log(LogType.FILE, LogLevel.INFORM,
                                    " TinyProxyRecorder In ParseFileNameRemote() -->> LastFile Is " + lastFile);
                            }
                            else
                            {

                                Log.Log(LogType.FILE, LogLevel.INFORM,
                                   " TinyProxyRecorder In ParseFileNameRemote() -->> Finished Reading The File");

                                for (int i = 0; i < dFileNameList.Length; i++)
                                {
                                    if (Dir + dFileNameList[i].ToString() == lastFile)
                                    {
                                        if (i + 1 == dFileNameList.Length)
                                        {
                                            FileName = lastFile;
                                            Log.Log(LogType.FILE, LogLevel.INFORM,
                                                " TinyProxyRecorder In ParseFileNameRemote() -->> There Is No New File And Continiou With Same File And Waiting For a New Record " + FileName);
                                            break;
                                        }
                                        else
                                        {
                                            FileName = Dir + dFileNameList[(i + 1)].ToString();
                                            Position = 0;
                                            lastFile = FileName;
                                            Log.Log(LogType.FILE, LogLevel.INFORM,
                                                " TinyProxyRecorder In ParseFileNameRemote() -->> Finished Reading The File And Continiou With New File " + FileName);
                                            break;

                                        }
                                    }
                                }
                            }
                        }
                        else
                            SetNextFile(dFileNameList, "ParseFileNameRemote()");

                    }
                    else
                    {

                        if (dFileNameList.Length > 0)
                        {
                            FileName = Dir + dFileNameList[dFileNameList.Length - 1].ToString();
                            lastFile = FileName;
                            Position = 0;
                            Log.Log(LogType.FILE, LogLevel.INFORM,
                                "  TinyProxyRecorder In ParseFileNameRemote() -->>  Last File Is Null And Setted The File To " + FileName);

                        }
                    }
                    stdOut = "";
                    stdErr = "";
                    se.Close();
                }
                else
                {
                    FileName = Dir;
                }
            }
            catch (Exception exp)
            {
                Log.Log(LogType.FILE, LogLevel.ERROR, "  TinyProxyRecorder In ParseFileNameRemote() In Catch -->>" + exp.Message);
                Log.Log(LogType.FILE, LogLevel.ERROR, "  TinyProxyRecorder In ParseFileNameRemote() In Catch -->>" + exp.StackTrace);
                return;
            }

            Log.Log(LogType.FILE, LogLevel.INFORM, " TinyProxyRecorder In ParseFileNameRemote() -->>  Exit The Function");
        }
        private void timer1_Tick(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                timer1.Enabled = false;
                L.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick -->> Timer is Started");
                String stdOut = "";
                String stdErr = "";

                string _fileId = "";
                string _filePattern = "";
                string _fileName = "";
                string _fileCreateTime = "";
                int port;
                String remoteHost = null;
                String line = "";

                if (remote_host.Contains(":"))
                {
                    port = Convert.ToInt32(remote_host.Split(':')[1]);
                    remoteHost = remote_host.Split(':')[0];
                }
                else
                {
                    remoteHost = remote_host;
                    port = 22;
                }

                se = new SshExec(remoteHost, user);
                se.Password = password;

                if (location.EndsWith("/"))
                {
                    L.Log(LogType.FILE, LogLevel.DEBUG,
                            " NginxAccessV_1_0_0Recorder In timer1_Tick() --> Directory | " + location);
                    if (!se.Connected)
                    {
                        se.Connect(port);
                    }
                    se.SetTimeout(Int32.MaxValue);
                    L.Log(LogType.FILE, LogLevel.DEBUG, " NginxAccessV_1_0_0Recorder In timer1_Tick() --> lastFile: " + lastFile);

                    string[] linuxFileParameters = lastFile.Trim().Split(';');

                    if (linuxFileParameters.Length > 0)
                    {
                        _fileId = linuxFileParameters[0];
                        _fileName = linuxFileParameters[1];
                        _filePattern = linuxFileParameters[2];
                        _fileCreateTime = linuxFileParameters[3];
                    }
                    else
                    {
                        L.Log(LogType.FILE, LogLevel.ERROR, "LastFile is unrecognized:" + lastFile);
                        return;
                    }

                    if (_fileCreateTime == "-1")
                    {
                        long dt = (long)DateTimeToUnixTimestamp(DateTime.Now);
                        _fileCreateTime = dt.ToString();
                    }

                    L.Log(LogType.FILE, LogLevel.DEBUG, "_fileId: " + _fileId);
                    L.Log(LogType.FILE, LogLevel.DEBUG, "_fileName: " + _fileName);
                    L.Log(LogType.FILE, LogLevel.DEBUG, "_filePattern: " + _filePattern);
                    L.Log(LogType.FILE, LogLevel.DEBUG, "_fileCreateTime: " + _fileCreateTime);

                    if (last_recordnum == 0)
                    {
                        last_recordnum = 1;
                    }

                    String command = location + "printLog.sh" + " key " + location + " " + _fileId.Trim() + " " +
                                     _fileName.Trim() + " '"
                                     + _filePattern.Trim() + "' "
                                     + _fileCreateTime + " "
                                     + last_recordnum + " " +
                                     (last_recordnum + max_record_send);

                    se.RunCommand(command, ref stdOut, ref stdErr);
                    L.Log(LogType.FILE, LogLevel.DEBUG, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> SSH command : " + command);

                    StringReader sr = new StringReader(stdOut);
                    L.Log(LogType.FILE, LogLevel.DEBUG,
                          "NginxAccessV_1_0_0Recorder In timer1_Tick() -->> Result: " + stdOut);

                    int state = 1;
                    int lineCounter = 0;

                    while ((line = sr.ReadLine()) != null)
                    {
                        switch (state)
                        {
                            case 1:
                                L.Log(LogType.FILE, LogLevel.DEBUG, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> Start While.");
                                if (line.Equals("key;BEGIN;NEW"))
                                {
                                    state = 2;
                                }
                                else if (line.Equals("key;BEGIN;OK"))
                                {
                                    state = 5;
                                }
                                else if (line.Equals("key;NOFILE"))
                                {
                                    L.Log(LogType.FILE, LogLevel.WARN, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> State 1 Error There is no file.");
                                    return;
                                }
                                else
                                {
                                    L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> State 1 Error Unknown Line. " + line);
                                    return;
                                }
                                break;
                            case 2:
                                if (line.StartsWith("FILE;"))
                                {
                                    string[] lineArr = line.Split(new char[] { ';' }, 4);
                                    if (lineArr.Length == 4)
                                    {
                                        _fileId = lineArr[1];
                                        _fileCreateTime = lineArr[2];
                                        _fileName = lineArr[3];
                                        state = 3;
                                        break;
                                    }
                                    L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> State 2 Error Missing Fields. " + line);
                                }
                                else
                                {
                                    L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> State 2 Error Unknown Line. " + line);
                                }
                                return;
                            case 3:
                                if (line.Equals("key;ENDS"))
                                {
                                    try
                                    {
                                        CustomServiceBase customServiceBase = base.GetInstanceService("Security Manager Remote Recorder");

                                        L.Log(LogType.FILE, LogLevel.DEBUG, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> Record sending. " + lastFile + " / " + _fileId + ";" + _fileName + ";" + _filePattern + ";" + _fileCreateTime);
                                        customServiceBase.SetReg(Id, "0", "", _fileId + ";" + _fileName + ";" + _filePattern + ";" + _fileCreateTime, "", LastRecordDate);
                                        last_recordnum = 0;
                                        lastFile = _fileId + ";" + _fileName + ";" + _filePattern + ";" +
                                                   _fileCreateTime;
                                        L.Log(LogType.FILE, LogLevel.DEBUG, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> Record sended." + lastFile);
                                    }
                                    catch (Exception exception)
                                    {
                                        L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> Record sending Error." + exception.Message);
                                    }
                                }
                                else
                                {
                                    L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> State 3 Error Unknown Line. " + line);
                                }
                                return;
                            case 5:
                                if (line.StartsWith("FILE;"))
                                {
                                    string[] lineArr = line.Split(new char[] { ';' }, 4);
                                    if (lineArr.Length == 4)
                                    {
                                        _fileId = lineArr[1];
                                        _fileCreateTime = lineArr[2];
                                        _fileName = lineArr[3];
                                        state = 6;
                                        break;
                                    }
                                    L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> State 5 Error Missing Fields. " + line);
                                }
                                else
                                {
                                    L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> State 5 Error Unknown Line. " + line);
                                }
                                return;
                            case 6:
                                if (line.Equals("OUTPUT;BEGIN"))
                                {
                                    try
                                    {
                                        CustomServiceBase customServiceBase = base.GetInstanceService("Security Manager Remote Recorder");
                                        L.Log(LogType.FILE, LogLevel.DEBUG, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> Record sending.");
                                        customServiceBase.SetReg(Id, last_recordnum.ToString(), line, _fileId + ";" + _fileName + ";" + _filePattern + ";" + _fileCreateTime, "", LastRecordDate);
                                        lastFile = _fileId + ";" + _fileName + ";" + _filePattern + ";" +
                                                   _fileCreateTime;
                                        L.Log(LogType.FILE, LogLevel.DEBUG, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> Record sended.");
                                        state = 7;
                                        break;
                                    }
                                    catch (Exception exception)
                                    {
                                        L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In CoderParse() -->> Record sending Error." + exception.Message);
                                    }
                                }
                                else
                                {
                                    L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> State 3 Error Unknown Line. " + line);
                                }
                                return;
                            case 7:
                                if (line.StartsWith("+"))
                                {
                                    L.Log(LogType.FILE, LogLevel.DEBUG, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> lines: " + line);
                                    if (CoderParse(line.Substring(1).Trim()))
                                    {
                                        L.Log(LogType.FILE, LogLevel.DEBUG, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> Date inserted. ");
                                        lineCounter++;
                                        break;
                                    }
                                }
                                else
                                {
                                    L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> State 7 Error Unknown Line. " + line);
                                }
                                return;
                        }
                    }
                    L.Log(LogType.FILE, LogLevel.DEBUG, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> DEBUG." + state + " / " + lineCounter + " / " + max_record_send);

                    if (state > 1)
                    {
                        if (lineCounter < max_record_send)
                        {
                            CheckEOF(_fileId, _fileName, _filePattern, _fileCreateTime);
                        }
                    }
                    else
                    {
                        L.Log(LogType.FILE, LogLevel.ERROR, " NginxAccessV_1_0_0Recorder In timer1_Tick() -->> State 0 Error Unexpected end of stream.");
                    }
                }
            }
            catch (Exception exception)
            {
                L.Log(LogType.FILE, LogLevel.ERROR, " timer1_Tick -->> Error : " + exception.ToString());
            }
            finally
            {
                timer1.Enabled = true;
                L.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick -->> Timer is finished.");
            }
        }
        protected override void ParseFileNameRemote()
        {
            try
            {
                Log.Log(LogType.FILE, LogLevel.DEBUG, "  ParseFileNameRemote() -->> Enter the Function.");
                String stdOut = "";
                String stdErr = "";

                se = new SshExec(remoteHost, user);
                se.Password = password;

                ArrayList folderNameList = new ArrayList();
                ArrayList fileNameList = new ArrayList();

                if (Dir.EndsWith("/") || Dir.EndsWith("\\"))
                {
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "  ParseFileNameRemote() -->> Searce in Directory. Dir: " + Dir);

                    String command = "ls " + Dir;
                    if (!se.Connected)
                        se.Connect();
                    se.RunCommand(command, ref stdOut, ref stdErr);
                    se.Close();
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "  ParseFileNameRemote() -->> Ssh Command Result: " + stdOut);
                    StringReader sr = new StringReader(stdOut);
                    string file = "";

                    while ((file = sr.ReadLine()) != null)
                    {
                        folderNameList.Add(file);
                    }
                    sr.Dispose();
                    sortedFolderList = SortFolders(folderNameList);

                    if (!String.IsNullOrEmpty(tempCustomVar1))
                    {
                        // daha önceden log okunmuş kaldığımız yeri bulmamız lazım.
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "  ParseFileNameRemote() -->> CustomVar1 is not null. CustomVar1: " + tempCustomVar1);
                        bool bLastFolderExist = false;

                        for (int i = 0; i < sortedFolderList.Length; i++)
                        {
                            if (sortedFolderList[i].ToString() == base.tempCustomVar1)
                            {
                                bLastFolderExist = true;
                                break;
                            }
                        }
                        if (bLastFolderExist)
                        {
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "  ParseFileNameRemote() -->> Month found read before. CustomVar1: " + tempCustomVar1);

                            //Bu klasör içindeki dosyaları sıralıyoruz.
                            sortedFileList = GetSortedFileList(tempCustomVar1);

                            bool bLastFileExist = false;
                            if (!String.IsNullOrEmpty(lastFile))
                            {
                                //daha önceden log okuduğumuz ayı bulduk. Şimdi kaldığımız günü de bulmamız lazım.
                                Log.Log(LogType.FILE, LogLevel.DEBUG, "  ParseFileNameRemote() -->> LastFile is not null. Lastfile: " + lastFile);
                                if (sortedFileList.Length == 0)
                                {
                                    Log.Log(LogType.FILE, LogLevel.DEBUG, "  ParseFileNameRemote() -->> There is no file in directory. Change your CustomVar1 or Folder will be changed. CustomVar1: " + tempCustomVar1);
                                    //Sıradaki Klasörü atıyoruz.
                                    tempCustomVar1 = SetFolderName(tempCustomVar1);
                                    //Klasördeki ilk dosyayı atıyoruz.
                                    SetFileName(tempCustomVar1, "");
                                    Log.Log(LogType.FILE, LogLevel.DEBUG, "  ParseFileNameRemote() -->> There is no file in directory. Folder changed: " + tempCustomVar1);
                                }
                                else
                                {
                                    for (int i = 0; i < sortedFileList.Length; i++)
                                    {
                                        if ((base.Dir + tempCustomVar1 + "/" + sortedFileList[i].ToString()) == base.lastFile)
                                        {
                                            bLastFileExist = true;
                                            break;
                                        }
                                    }

                                    if (bLastFileExist)
                                    {
                                        Log.Log(LogType.FILE, LogLevel.DEBUG, "  ParseFileNameRemote() -->> LastFile found read before. Lastfile: " + lastFile);

                                        if (CheckPositionInFile(lastFile) > 1)
                                        {
                                            //Dosyada okuyacak satır var ise okumaya devam edeceğiz.
                                            Log.Log(LogType.FILE, LogLevel.DEBUG, "  ParseFileNameRemote() -->> There is still line to be read. Continue to Lastfile: " + lastFile);
                                            FileName = lastFile;
                                        }
                                        else
                                        {
                                            //Sıradaki dosyayı atıyoruz.
                                            SetFileName(tempCustomVar1, lastFile);
                                        }
                                    }
                                    else
                                    {
                                        Log.Log(LogType.FILE, LogLevel.DEBUG, "  ParseFileNameRemote() -->> LastFile is not found in that Directory. Lastfile will be assigned first file in Folder: " + tempCustomVar1);
                                        //Klasördeki ilk dosyayı atıyoruz.
                                        SetFileName(tempCustomVar1, "");
                                        Log.Log(LogType.FILE, LogLevel.DEBUG, "  ParseFileNameRemote() -->> New file to be read: " + lastFile);
                                    }
                                }
                            }
                            else
                            {
                                //Bu ay için hiç log alınmamış. İlk günden log almaya başlayacağız
                                Log.Log(LogType.FILE, LogLevel.DEBUG, "  ParseFileNameRemote() -->> There is any file read before in that directory. We will read first file.");
                                //Klasördeki ilk dosyayı atıyoruz.
                                SetFileName(tempCustomVar1, "");
                            }
                        }
                        else
                        {
                            // okunan son dosya directory'de bulunamadı. Kullanıcının directory'i kontrol etmesini isteriz.
                            //Yada o directorydeki ilk dosyayı atayabiliriz. İsteğe göre yazılacak.
                        }
                    }
                    else
                    {
                        //İlk defa log okuma işlemi yapılacak. İlk klasörün ilk dosyasını okuyacağız.
                        //Dir'deki ilk dosyayı atıyoruz.
                        tempCustomVar1 = SetFolderName("");
                        //Klasördeki ilk dosyayı atıyoruz.
                        SetFileName(tempCustomVar1, "");
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "  ParseFileNameRemote() -->> Service is started first time or CustomVar1 and LastFile are initilized to null.");
                    }
                }
                else
                {
                    FileName = Dir;
                    lastFile = FileName;
                    Position = 0;
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "  ParseFileNameRemote() -->> Directory assigned to a file. Filename: " + lastFile);
                }
            }
            catch (Exception ex)
            {
                Log.Log(LogType.FILE, LogLevel.ERROR, "  ParseFileNameRemote() -->> Error on finding LastFile. Message: " + ex.Message.ToString());
                Log.Log(LogType.FILE, LogLevel.ERROR, "  ParseFileNameRemote() -->> Error on finding LastFile. Trace: " + ex.StackTrace);
                Log.Log(LogType.FILE, LogLevel.ERROR, "  ParseFileNameRemote() -->> Last Values: LastFile: " + lastFile + ", Customvar1: " + tempCustomVar1 + ", Dir: " + Dir);
            }
            localFolderName = tempCustomVar1;
        }
        protected override void ParseFileNameRemote()
        {
            try
            {

                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() | Started ");

                String stdOut = "";
                String stdErr = "";
                String line = "";

                se = new SshExec(remoteHost, user);
                se.Password = password;

                if (Dir.EndsWith("/") || Dir.EndsWith("\\"))
                {

                    Log.Log(LogType.FILE, LogLevel.DEBUG, "Home Directory | " + Dir);

                    se.Connect();
                    se.SetTimeout(Int32.MaxValue);
                    String command = "ls -lt " + Dir + " | grep ^-";
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() | SSH command -1 : " + command);
                    se.RunCommand(command, ref stdOut, ref stdErr);
                    StringReader sr = new StringReader(stdOut);

                    ArrayList arrFileNameList = new ArrayList();
                    while ((line = sr.ReadLine()) != null)
                    {

                        String[] arr = line.Split(' ');
                        if (arr[arr.Length - 1].StartsWith("MSGTRKM") == true)
                            arrFileNameList.Add(arr[arr.Length - 1]);

                    }

                    String[] dFileNameList = SortFileNameByFileNumber(arrFileNameList);

                    if (string.IsNullOrEmpty(lastFile) == false)
                    {
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() | LastFile  = " + lastFile);

                        bool bLastFileExist = false;
                        for (int i = 0; i < dFileNameList.Length; i++)
                        {
                            if ((base.Dir + dFileNameList[i].ToString()) == base.lastFile)
                            {
                                bLastFileExist = true;
                                break;
                            }
                        }

                        if (bLastFileExist)
                        {

                            String wcArg = "";
                            String wcCmd = "";
                            if (readMethod == "sed")
                            {
                                wcCmd = "wc";
                                wcArg = "-l";
                            }
                            else if (readMethod == "nread")
                            {
                                wcCmd = "wc";
                                wcArg = "-c";
                            }

                            command = wcCmd + " " + wcArg + " " + lastFile;

                            stdOut = "";
                            stdErr = "";

                            se.RunCommand(command, ref stdOut, ref stdErr);

                            String[] arr = SpaceSplit(stdOut, false);
                            Int64 lFileIndex = Convert.ToInt64(arr[0]);//Dosyadaki satýr sayýsý
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() | FileIndex  = " + lFileIndex.ToString());

                            if (lFileIndex > Position)
                            {

                                //Dosya Sonuna Kadar okunmamýs Ayný Dosyaya Devam Edecek;
                                Log.Log(LogType.FILE, LogLevel.DEBUG,
                                    "ParseFileNameRemote() | FileIndex ( " + lFileIndex.ToString() + " ) > Position (" + Position.ToString() + " )");

                                FileName = lastFile;

                                Log.Log(LogType.FILE, LogLevel.DEBUG,
                                    "ParseFileNameRemote() | FileName = LastFile " + lastFile);

                            }
                            else
                            {

                                Log.Log(LogType.FILE, LogLevel.DEBUG,
                                   "ParseFileNameRemote() | ParseFileNameRemote() | Dosya Sonuna Kadar Okundu Position (" + this.Position.ToString() + " )  > FileIndex ( " + lFileIndex.ToString() + " )");

                                for (int i = 0; i < dFileNameList.Length; i++)
                                {
                                    if (Dir + dFileNameList[i].ToString() == lastFile)
                                    {
                                        if (i + 1 == dFileNameList.Length)
                                        {
                                            FileName = lastFile;
                                            Log.Log(LogType.FILE, LogLevel.DEBUG,
                                                "ParseFileNameRemote() | Yeni Dosya Yok Ayný Dosyaya Devam : " + FileName);
                                            break;

                                        }
                                        else
                                        {
                                            FileName = Dir + dFileNameList[(i + 1)].ToString();
                                            Position = 0;
                                            lastFile = FileName;
                                            Log.Log(LogType.FILE, LogLevel.DEBUG,
                                                "ParseFileNameRemote() | Yeni Dosya  : " + FileName);
                                            break;

                                        }
                                    }
                                }
                            }
                        }
                        else
                            SetNextFile(dFileNameList, "ParseFileNameRemote()");

                    }
                    else
                    {

                        if (dFileNameList.Length > 0)
                        {
                            FileName = Dir + dFileNameList[dFileNameList.Length - 1].ToString();
                            lastFile = FileName;
                            Log.Log(LogType.FILE, LogLevel.DEBUG,
                                "ParseFileNameRemote() |LastName is null Ýlk FileName Set  : " + FileName);

                        }

                    }
                    stdOut = "";
                    stdErr = "";
                    se.Close();

                }
                else
                    FileName = Dir;

            }
            catch (Exception exp)
            {

                Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() |" + exp.Message);
                Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() |" + exp.StackTrace);
                return;
            }
        }
        protected override void ParseFileNameRemote()
        {
            String stdOut = "";
            String stdErr = "";
            se = new SshExec(remoteHost, user);
            se.Password = password;
            if (Dir.EndsWith("/") || Dir.EndsWith("\\"))
            {
                se.Connect();
                String cmd = "ls -lt " + Dir;
                Log.Log(LogType.FILE, LogLevel.DEBUG, "Searching in folder " + Dir + " with command " + cmd);
                se.RunCommand(cmd, ref stdOut, ref stdErr);
                Log.Log(LogType.FILE, LogLevel.DEBUG, "Command Returned: " + stdOut);
                StringReader sr = new StringReader(stdOut);
                String line = "";
                while ((line = sr.ReadLine()) != null)
                {
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "Checking line: " + line);
                    if (line.StartsWith("-"))
                        break;
                }

                String[] arr = line.Split(' ');

                FileName = Dir + arr[arr.Length - 1];
                Log.Log(LogType.FILE, LogLevel.DEBUG, "Filename is " + FileName);
                stdOut = "";
                stdErr = "";
                se.Close();
            }
            else
                FileName = Dir;
        }
        protected override void ParseFileNameRemote()
        {
            String stdOut = "";
            String stdErr = "";
            se = new SshExec(remoteHost, user);
            se.Password = password;
            if (Dir.EndsWith("/") || Dir.EndsWith("\\"))
            {
                se.Connect();
                se.RunCommand("ls -lt " + Dir + " | grep ^-", ref stdOut, ref stdErr);
                StringReader sr = new StringReader(stdOut);
                String line = sr.ReadLine();
                String[] arr = line.Split(' ');

                FileName = Dir + arr[12];
                stdOut = "";
                stdErr = "";
                se.Close();
            }
            else
                FileName = Dir;
        }
 protected override void ParseFileNameRemote()
 {
     Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> is STARTED");
     try
     {
         se = new SshExec(remoteHost, user);
         se.Password = password;
         if (Dir.EndsWith("/") || Dir.EndsWith("\\"))
         {
             Log.Log(LogType.FILE, LogLevel.DEBUG, " ParseFileNameRemote() -->> Searching files in directory : " + Dir);
             List<String> fileNameList = GetFileNamesOnRemote();
             fileNameList = SortFileNames(fileNameList);
             SetLastFile(fileNameList);
         }
         else
         {
             FileName = Dir;
         }
     }
     catch (Exception ex)
     {
         Log.Log(LogType.FILE, LogLevel.ERROR, " ParseFileNameRemote() -->> An eror occurred : " + ex.ToString());
     }
 }
        protected override void ParseFileNameRemote()
        {
            string line = "";
            String stdOut = "";
            String stdErr = "";

            try
            {
                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Enter the Function.");
                se = new SshExec(remoteHost, user);
                se.Password = password;
                if (Dir.EndsWith("/") || Dir.EndsWith("\\"))
                {
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Home Directory | " + Dir);
                    String command = "ls -lt " + Dir;
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> SSH command : " + command);

                    try
                    {
                        se.Connect(port);
                        se.RunCommand(command, ref stdOut, ref stdErr);
                        se.Close();
                    }
                    catch (Exception exception)
                    {
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "Exception : " + exception);
                    }

                    StringReader sr = new StringReader(stdOut);
                    ArrayList arrFileNameList = new ArrayList();
                    while ((line = sr.ReadLine()) != null)
                    {
                        String[] arr = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        //if (arr[arr.Length - 1].StartsWith("audit")  && arr[arr.Length - 1].Split(new char[] { '.', '_' }, StringSplitOptions.RemoveEmptyEntries).Length <= 3)//Name changed
                        if (arr[arr.Length - 1].StartsWith("access"))//Name changed
                        {
                            arrFileNameList.Add(arr[arr.Length - 1]);
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Dosya ismi okundu: " + arr[arr.Length - 1]);
                        }
                    }
                    //audit.log.2012-10-08
                    dFileNameList = SortFiles(arrFileNameList);
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> arrayFileNameList'e atılan dosya isimleri sıralandı.");

                    if (!String.IsNullOrEmpty(lastFile))
                    {
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> LastFile is not null: " + lastFile);
                        bool bLastFileExist = false;

                        for (int i = 0; i < dFileNameList.Length; i++)
                        {
                            if ((base.Dir + dFileNameList[i]) == base.lastFile)
                            {
                                bLastFileExist = true;
                                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> LastFile is found: " + lastFile);
                                break;
                            }
                        }

                        if (bLastFileExist)
                        {
                            if (Is_File_Finished(lastFile))
                            {
                                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Last File is finished. Previous File: " + lastFile);

                                for (int i = 0; i < dFileNameList.Length; i++)
                                {
                                    if (Dir + dFileNameList[i].ToString(CultureInfo.InvariantCulture) == lastFile)
                                    {
                                        if (dFileNameList.Length > i + 1)
                                        {
                                            FileName = Dir + dFileNameList[i + 1].ToString(CultureInfo.InvariantCulture);
                                            Position = 0;
                                            lastFile = FileName;
                                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> New File is assigned. New File: " + FileName);
                                            break;
                                        }
                                        else
                                        {
                                            FileName = lastFile;
                                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> There is no new file to assign. Wait this file for log: " + FileName);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                FileName = lastFile;
                                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> There is still line in lastfile.  Continue to read this file: " + FileName);
                            }
                        }
                        else
                        {
                            FileName = Dir + dFileNameList[dFileNameList.Length - 1].ToString(CultureInfo.InvariantCulture);
                            Position = 0;
                            lastFile = FileName;
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> LastFile Silinmis , Dosya Bulunamadı.  Yeni File : " + FileName);
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Start to read  main file from beginning: " + FileName);
                        }
                    }
                    else
                    {
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Last File Is Null");
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> ilk defa log okunacak.");

                        if (dFileNameList.Length > 0)
                        {
                            FileName = Dir + dFileNameList[0].ToString(CultureInfo.InvariantCulture);
                            lastFile = FileName;
                            Position = 0;
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> FileName ve LastFile en eski dosya olarak ayarlandy: " + lastFile);
                        }
                        else
                        {
                            Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() -->> In The Log Location There Is No Log File to read.");
                        }
                    }
                }
                else
                {
                    FileName = Dir;
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Directory file olarak gösterildi.: " + FileName);
                }
            }
            catch (Exception ex)
            {
                Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() -->> Dosya isimleri getirilirken problemle kar?yla?yldy.");
                Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() -->> Hata Mesajy: " + ex.ToString());
            }
        }
        protected override void ParseFileNameRemote()
        {
            try
            {
                Log.Log(LogType.FILE, LogLevel.INFORM, " LabrisAdministrativeRecorder In ParseFileNameRemote() -->> Enter The Function ");

                string stdOut = "";
                string stdErr = "";
                String line = "";

                se = new SshExec(remoteHost, user);
                se.Password = password;

                if (Dir.EndsWith("/") || Dir.EndsWith("\\"))
                {
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "Home Directory | " + Dir);

                    se.Connect();
                    se.SetTimeout(Int32.MaxValue);
                    String command = "ls -lt " + Dir + " | grep administrative";
                    Log.Log(LogType.FILE, LogLevel.DEBUG, " LabrisAdministrativeRecorder In ParseFileNameRemote() -->> SSH command : " + command);
                    se.RunCommand(command, ref stdOut, ref stdErr);
                    se.Close();

                    StringReader sr = new StringReader(stdOut);
                    ArrayList arrFileNameList = new ArrayList();

                    while ((line = sr.ReadLine()) != null)
                    {
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "LabrisAdministrativeRecorder In ParseFileNameRemote() -->> Dosya ismi okundu: " + line);
                        String[] arr = line.Split('.');
                        if (arr[0].StartsWith("administrative") == true)
                        {
                            arrFileNameList.Add(arr);
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "LabrisAdministrativeRecorder In ParseFileNameRemote() -->> Okunan Dosya ismi arrayFileNameList'e atıldı. ");
                        }
                    }

                    String[] dFileNameList = SortFiles(arrFileNameList);
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "LabrisAdministrativeRecorder In ParseFileNameRemote() -->> arrayFileNameList'e atılan dosya isimleri sıralandı. ");

                    if (!String.IsNullOrEmpty(lastFile))
                    {
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "LabrisAdministrativeRecorder In ParseFileNameRemote() -->> LastFile is not null: " + lastFile);

                        bool bLastFileExist = false;

                        for (int i = 0; i < dFileNameList.Length; i++)
                        {
                            if ((base.Dir + dFileNameList[i].ToString()) == base.lastFile)
                            {
                                bLastFileExist = true;
                                break;
                            }
                        }

                        if (bLastFileExist)
                        {
                            if (IsLineHereRemote(dFileNameList) == false)
                            {
                                Log.Log(LogType.FILE, LogLevel.DEBUG, " LabrisAdministrativeRecorder In ParseFileNameRemote() -->>Last line could not find any file : " + lastFile);
                                Log.Log(LogType.FILE, LogLevel.DEBUG, " LabrisAdministrativeRecorder In ParseFileNameRemote() -->>Directorydeki tüm dosyalar alınmak isteniyor ise LastFile ve Position'ı sıfırlayınız. ");
                            }
                            else
                            {
                                Log.Log(LogType.FILE, LogLevel.DEBUG, " LabrisAdministrativeRecorder In ParseFileNameRemote() -->> FileName ayarlandı. FileName: " + FileName);
                            }
                        }
                        else
                        {
                            FileName = Dir + dFileNameList[0].ToString();
                            Position = 0;
                            lastFile = FileName;
                            Log.Log(LogType.FILE, LogLevel.DEBUG, " | LastFile Silinmis , Dosya Bulunamadı  Yeni File : " + FileName);
                        }
                    }
                    else
                    {
                            if (dFileNameList.Length > 0)
                            {
                                FileName = Dir + dFileNameList[0].ToString();
                                lastFile = FileName;
                                Position = 0;
                                Log.Log(LogType.FILE, LogLevel.DEBUG, "LabrisAdministrativeRecorder In ParseFileNameRemote() -->> LastName Is Null and FileName Is Setted To : " + FileName);
                            }
                            else
                            {
                                Log.Log(LogType.FILE, LogLevel.DEBUG, "  LabrisAdministrativeRecorder In ParseFileNameRemote() -->> In The Log Location There Is No Log File");
                            }
                    }
                }
                else
                {
                    FileName = Dir;
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "  LabrisAdministrativeRecorder In ParseFileNameRemote() -->> Directory file olarak gösterildi.: " + FileName);
                }
            }
            catch (Exception exp)
            {
                Log.Log(LogType.FILE, LogLevel.ERROR, "LabrisAdministrativeRecorder In ParseFileNameRemote() In Catch -->>" + exp.Message);
                Log.Log(LogType.FILE, LogLevel.ERROR, "LabrisAdministrativeRecorder In ParseFileNameRemote() In Catch -->>" + exp.StackTrace);
                return;
            }

            Log.Log(LogType.FILE, LogLevel.INFORM, "LabrisAdministrativeRecorder In ParseFileNameRemote() -->>  Exit The Function");
        }
        public void CheckEof(SshExec se, string fileId, string fileName, string filePattern, string fileCreateTime)
        {
            string stdOut = "";
            string stdErr = "";
            string newFileId = "";
            string newFileName = "";
            string newFileCreationTime = "";
            try
            {
                String command = _location + "printLog.sh" + " key " + _location + " 0 - '"
                                 + filePattern.Trim() + "' "
                                 + fileCreateTime + " 1 2";
                _l.Log(LogType.FILE, LogLevel.DEBUG, " CryptTechHotspotV_1_0_1Recorder In CheckEOF() -->> command: " + command);

                se.RunCommand(command, ref stdOut, ref stdErr);
                var sr = new StringReader(stdOut);
                var state = 1;
                var line = "";
                while ((line = sr.ReadLine()) != null)
                {
                    switch (state)
                    {
                        case 1:
                            if (line.Equals("key;BEGIN;NEW"))
                            {
                                state = 2;
                                break;
                            }
                            if (line.Equals("key;NOFILE"))
                            {
                                _l.Log(LogType.FILE, LogLevel.INFORM, " CryptTechHotspotV_1_0_1Recorder In CheckEOF() -->> State 1 There is no file.");
                                return;
                            }
                            _l.Log(LogType.FILE, LogLevel.ERROR, " CryptTechHotspotV_1_0_1Recorder In CheckEOF() -->> State 1 Error Unknown Line");
                            return;
                        case 2:
                            if (line.StartsWith("FILE;"))
                            {
                                var lineArr = line.Split(new[] { ';' }, 4);
                                if (lineArr.Length == 4)
                                {
                                    newFileId = lineArr[1];
                                    newFileCreationTime = lineArr[2];
                                    newFileName = lineArr[3];
                                    state = 3;
                                    break;
                                }
                                _l.Log(LogType.FILE, LogLevel.ERROR, " CryptTechHotspotV_1_0_1Recorder In CheckEOF() -->> State 2 Error Missing Fields. " + line);
                            }
                            else
                            {
                                _l.Log(LogType.FILE, LogLevel.ERROR, " CryptTechHotspotV_1_0_1Recorder In CheckEOF() -->> State 2 Error Unknown Line. " + line);
                            }
                            return;
                        case 3:
                            if (line.Equals("key;ENDS"))
                            {
                                if (newFileId != fileId)
                                {
                                    try
                                    {
                                        CustomServiceBase customServiceBase = GetInstanceService("Security Manager Remote Recorder");
                                        _l.Log(LogType.FILE, LogLevel.DEBUG, " CryptTechHotspotV_1_0_1Recorder In CheckEOF() -->> Record sending.");
                                        customServiceBase.SetReg(id, "0", "", newFileId + ";" + newFileName + ";" + filePattern + ";" + newFileCreationTime, "", _lastRecordDate);
                                        _lastRecordnum = 0;
                                        _lastFile = newFileId + ";" + newFileName + ";" + filePattern + ";" +
                                                   newFileCreationTime;
                                        _l.Log(LogType.FILE, LogLevel.DEBUG, " CryptTechHotspotV_1_0_1Recorder In CheckEOF() -->> Record sended.");
                                    }
                                    catch (Exception exception)
                                    {
                                        _l.Log(LogType.FILE, LogLevel.ERROR, " CryptTechHotspotV_1_0_1Recorder In CheckEOF() -->> Record sending Error." + exception.Message);
                                    }
                                }
                            }
                            else
                            {
                                _l.Log(LogType.FILE, LogLevel.ERROR,
                                      " CryptTechHotspotV_1_0_1Recorder In CheckEOF() -->> State 3 Unexpected line: " + line);
                            }
                            return;
                    }
                }

            }
            catch (Exception exception)
            {
                _l.Log(LogType.FILE, LogLevel.ERROR, " CryptTechHotspotV_1_0_1Recorder In CheckEOF() -->> Error: " + exception.Message);
            }
        }
        public void DandikParseFileNameRemote()
        {
            string line = "";
            String stdOut = "";
            String stdErr = "";

            try
            {
                L.Log(LogType.FILE, LogLevel.INFORM, "ParseFileNameRemote() -->> Enter the Function.");
                se = new SshExec(remote_host, user);
                se.Password = password;
                if (location.EndsWith("/") || location.EndsWith("\\"))
                {
                    L.Log(LogType.FILE, LogLevel.INFORM, "ParseFileNameRemote() -->> Home Directory | " + location);
                    String command = "ls -lt " + location;
                    L.Log(LogType.FILE, LogLevel.INFORM, "ParseFileNameRemote() -->> SSH command : " + command);

                    try
                    {
                        se.Connect();
                        se.RunCommand(command, ref stdOut, ref stdErr);
                        se.Close();
                    }
                    catch (Exception exception)
                    {
                        L.Log(LogType.FILE, LogLevel.ERROR, "Exception : " + exception);
                    }

                    StringReader sr = new StringReader(stdOut);
                    ArrayList arrFileNameList = new ArrayList();
                    while ((line = sr.ReadLine()) != null)
                    {
                        String[] arr = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        //if (arr[arr.Length - 1].StartsWith("audit")  && arr[arr.Length - 1].Split(new char[] { '.', '_' }, StringSplitOptions.RemoveEmptyEntries).Length <= 3)//Name changed
                        if (arr[arr.Length - 1].StartsWith("bimiq"))//Name changed
                        {
                            arrFileNameList.Add(arr[arr.Length - 1]);
                            L.Log(LogType.FILE, LogLevel.INFORM, "ParseFileNameRemote() -->> Dosya ismi okundu: " + arr[arr.Length - 1]);
                        }
                    }
                    dFileNameList = SortFiles(arrFileNameList);
                    L.Log(LogType.FILE, LogLevel.INFORM, "ParseFileNameRemote() -->> arrayFileNameList'e atılan dosya isimleri sıralandı.");

                    if (!String.IsNullOrEmpty(_lastFile))
                    {
                        L.Log(LogType.FILE, LogLevel.INFORM, "ParseFileNameRemote() -->> LastFile is not null: " + _lastFile);
                        bool bLastFileExist = false;

                        for (int i = 0; i < dFileNameList.Length; i++)
                        {
                            if ((location + dFileNameList[i]) == _lastFile)
                            {
                                bLastFileExist = true;
                                L.Log(LogType.FILE, LogLevel.INFORM, "ParseFileNameRemote() -->> LastFile is found: " + _lastFile);
                                break;
                            }
                        }

                        if (bLastFileExist)
                        {
                            if (Is_File_Finished(_lastFile))
                            {
                                L.Log(LogType.FILE, LogLevel.INFORM, "ParseFileNameRemote() -->> Last File is finished. Previous File: " + _lastFile);

                                for (int i = 0; i < dFileNameList.Length; i++)
                                {
                                    if (location + dFileNameList[i].ToString(CultureInfo.InvariantCulture) == _lastFile)
                                    {
                                        L.Log(LogType.FILE, LogLevel.INFORM, "ParseFileNameRemote() -->> dFileNameList.length: " + dFileNameList.Length.ToString());
                                        L.Log(LogType.FILE, LogLevel.INFORM, "ParseFileNameRemote() -->> i: " + i.ToString());

                                        if (dFileNameList.Length > i + 1)
                                        {
                                            FileName = location + dFileNameList[i + 1].ToString(CultureInfo.InvariantCulture);
                                            last_recordnum = 0;
                                            _lastFile = FileName;
                                            L.Log(LogType.FILE, LogLevel.INFORM, "ParseFileNameRemote() -->> New File is assigned. New File: " + FileName);
                                            break;
                                        }
                                        else
                                        {
                                            //DandikParseFileNameRemote();
                                            int index = Array.IndexOf(dFileNameList, _lastFile);
                                            if (index + 1 != dFileNameList.Length)
                                            {
                                                DandikParseFileNameRemote();
                                            }
                                            else
                                            {
                                                FileName = _lastFile;
                                                L.Log(LogType.FILE, LogLevel.INFORM, "ParseFileNameRemote() -->> There is no new file to assign. Wait this file for log: " + FileName);
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                FileName = _lastFile;
                                L.Log(LogType.FILE, LogLevel.INFORM, "ParseFileNameRemote() -->> There is still line in lastfile.  Continue to read this file: " + FileName);
                            }
                        }
                        else
                        {
                            FileName = location + dFileNameList[dFileNameList.Length - 1].ToString(CultureInfo.InvariantCulture);
                            last_recordnum = 0;
                            _lastFile = FileName;
                            L.Log(LogType.FILE, LogLevel.INFORM, "ParseFileNameRemote() -->> LastFile Silinmis , Dosya Bulunamadı.  Yeni File : " + FileName);
                            L.Log(LogType.FILE, LogLevel.INFORM, "ParseFileNameRemote() -->> Start to read  main file from beginning: " + FileName);
                        }
                    }
                    else
                    {
                        L.Log(LogType.FILE, LogLevel.INFORM, "ParseFileNameRemote() -->> Last File Is Null");
                        L.Log(LogType.FILE, LogLevel.INFORM, "ParseFileNameRemote() -->> ilk defa log okunacak.");

                        if (dFileNameList.Length > 0)
                        {
                            FileName = location + dFileNameList[0].ToString(CultureInfo.InvariantCulture);
                            _lastFile = FileName;
                            last_recordnum = 0;
                            L.Log(LogType.FILE, LogLevel.INFORM, "ParseFileNameRemote() -->> FileName ve LastFile en eski dosya olarak ayarlandı: " + _lastFile);
                        }
                        else
                        {
                            L.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() -->> In The Log Location There Is No Log File to read.");
                        }
                    }
                }
                else
                {
                    FileName = location;
                    L.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Directory file olarak gösterildi.: " + FileName);
                }

                LastRecordDate = DateTime.Now.ToString(dateFormat);
                line = "";

                try
                {
                    CustomServiceBase customServiceBase = base.GetInstanceService("Security Manager Remote Recorder");
                    L.Log(LogType.FILE, LogLevel.INFORM,
                          " SybaseIqStdErrV_1_0_0Recorder In CoderParse() -->> Record sending." + "Id: " + Id +
                          "last_recordnum: " + last_recordnum + "line: " + line + "LastRecordDate: " + LastRecordDate);

                    customServiceBase.SetReg(Id, last_recordnum.ToString(), line, _lastFile, "", LastRecordDate);
                    L.Log(LogType.FILE, LogLevel.INFORM, " SybaseIqStdErrV_1_0_0Recorder In CoderParse() -->> Record sended.");
                }
                catch (Exception exception)
                {
                    L.Log(LogType.FILE, LogLevel.ERROR, " SybaseIqStdErrV_1_0_0Recorder In CoderParse() -->> Record sending Error." + exception.Message);
                }
                GetLinuxFileLines(_lastFile);
            }
            catch (Exception ex)
            {
                L.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() -->> Dosya isimleri getirilirken problemle karşılaşıldı.");
                L.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() -->> Hata Mesajı: " + ex.ToString());
            }
        }
        private void timer1_Tick(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
                _timer1.Enabled = false;
                _l.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick -->> Timer is Started");
                var stdOut = "";
                var stdErr = "";

                if (string.IsNullOrEmpty(_remoteHost))
                {
                    _l.Log(LogType.FILE, LogLevel.ERROR,
                           " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() --> Remote host is empty");
                    return;
                }

                string host;
                int port;
                int index = _remoteHost.IndexOf(':');
                if (index >= 0 && ++index < _remoteHost.Length)
                {
                    if (int.TryParse(_remoteHost.Substring(index), out port))
                        host = _remoteHost.Substring(0, index - 1);
                    else
                    {
                        _l.Log(LogType.FILE, LogLevel.ERROR,
                               " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() --> Invalid Port in remote host:" +
                               _remoteHost);
                        return;
                    }
                }
                else
                {
                    host = index >= 0 ? _remoteHost.Substring(0, index - 1) : _remoteHost;
                    port = 22;
                }

                SshExec se = null;
                try
                {
                    se = new SshExec(host, _user) { Password = _password };
                    se.ConnectTimeout(int.MaxValue);
                    if (_location.EndsWith("/"))
                    {
                        _l.Log(LogType.FILE, LogLevel.DEBUG,
                               " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() --> Directory | " + _location);
                        se.Connect(port);

                        _l.Log(LogType.FILE, LogLevel.DEBUG,
                               " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() --> lastFile: " + _lastFile);

                        var linuxFileParameters = _lastFile.Trim().Split(';');

                        var fileId = "";
                        var fileCreateTime = "";
                        var fileName = "";
                        var filePattern = "";
                        if (linuxFileParameters.Length > 0)
                        {
                            fileId = linuxFileParameters[0];
                            fileName = linuxFileParameters[1];
                            filePattern = linuxFileParameters[2];
                            fileCreateTime = linuxFileParameters[3];
                        }
                        else
                        {
                            _l.Log(LogType.FILE, LogLevel.ERROR, "LastFile is unrecognized:" + _lastFile);
                            return;
                        }

                        if (fileCreateTime == "-1")
                        {
                            var dt = (long)DateTimeToUnixTimestamp(DateTime.Now);
                            fileCreateTime = dt.ToString(CultureInfo.InvariantCulture);
                        }

                        _l.Log(LogType.FILE, LogLevel.DEBUG, "_fileId: " + fileId);
                        _l.Log(LogType.FILE, LogLevel.DEBUG, "_fileName: " + fileName);
                        _l.Log(LogType.FILE, LogLevel.DEBUG, "_filePattern: " + filePattern);
                        _l.Log(LogType.FILE, LogLevel.DEBUG, "_fileCreateTime: " + fileCreateTime);

                        if (_lastRecordnum == 0)
                        {
                            _lastRecordnum = 1;
                        }

                        var command = _location + "printLog.sh" + " key " + _location + " " + fileId.Trim() + " " +
                                      fileName.Trim() + " '"
                                      + filePattern.Trim() + "' "
                                      + fileCreateTime + " "
                                      + _lastRecordnum + " " +
                                      (_lastRecordnum + _maxRecordSend);

                        se.RunCommand(command, ref stdOut, ref stdErr);
                        _l.Log(LogType.FILE, LogLevel.INFORM,
                               " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> SSH command : " + command);

                        var sr = new StringReader(stdOut);
                        _l.Log(LogType.FILE, LogLevel.INFORM,
                               "CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> Result: " + stdOut);

                        var state = 1;
                        var lineCounter = 0;

                        var line = "";
                        while ((line = sr.ReadLine()) != null)
                        {
                            switch (state)
                            {
                                case 1:
                                    _l.Log(LogType.FILE, LogLevel.INFORM,
                                           " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> Start While.");
                                    if (line.Equals("key;BEGIN;NEW"))
                                    {
                                        state = 2;
                                    }
                                    else if (line.Equals("key;BEGIN;OK"))
                                    {
                                        state = 5;
                                    }
                                    else if (line.Equals("key;NOFILE"))
                                    {
                                        _l.Log(LogType.FILE, LogLevel.WARN,
                                               " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> State 1 Error There is no file.");
                                        return;
                                    }
                                    else
                                    {
                                        _l.Log(LogType.FILE, LogLevel.ERROR,
                                               " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> State 1 Error Unknown Line. " +
                                               line);
                                        return;
                                    }
                                    break;
                                case 2:
                                    if (line.StartsWith("FILE;"))
                                    {
                                        var lineArr = line.Split(new[] { ';' }, 4);
                                        if (lineArr.Length == 4)
                                        {
                                            fileId = lineArr[1];
                                            fileCreateTime = lineArr[2];
                                            fileName = lineArr[3];
                                            state = 3;
                                            break;
                                        }
                                        _l.Log(LogType.FILE, LogLevel.ERROR,
                                               " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> State 2 Error Missing Fields. " +
                                               line);
                                    }
                                    else
                                    {
                                        _l.Log(LogType.FILE, LogLevel.ERROR,
                                               " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> State 2 Error Unknown Line. " +
                                               line);
                                    }
                                    return;
                                case 3:
                                    if (line.Equals("key;ENDS"))
                                    {
                                        try
                                        {
                                            CustomServiceBase customServiceBase =
                                                GetInstanceService("Security Manager Remote Recorder");
                                            _l.Log(LogType.FILE, LogLevel.DEBUG,
                                                   " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> Record sending. " +
                                                   _lastFile + " / " + fileId + ";" + fileName + ";" + filePattern + ";" +
                                                   fileCreateTime);
                                            customServiceBase.SetReg(id, "0", "",
                                                                     fileId + ";" + fileName + ";" + filePattern + ";" +
                                                                     fileCreateTime, "", _lastRecordDate);
                                            _lastRecordnum = 0;
                                            _lastFile = fileId + ";" + fileName + ";" + filePattern + ";" +
                                                        fileCreateTime;
                                            _l.Log(LogType.FILE, LogLevel.DEBUG,
                                                   " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> Record sended." +
                                                   _lastFile);
                                        }
                                        catch (Exception exception)
                                        {
                                            _l.Log(LogType.FILE, LogLevel.ERROR,
                                                   " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> Record sending Error." +
                                                   exception.Message);
                                        }
                                    }
                                    else
                                    {
                                        _l.Log(LogType.FILE, LogLevel.ERROR,
                                               " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> State 3 Error Unknown Line. " +
                                               line);
                                    }
                                    return;
                                case 5:
                                    if (line.StartsWith("FILE;"))
                                    {
                                        var lineArr = line.Split(new[] { ';' }, 4);
                                        if (lineArr.Length == 4)
                                        {
                                            fileId = lineArr[1];
                                            fileCreateTime = lineArr[2];
                                            fileName = lineArr[3];
                                            state = 6;
                                            break;
                                        }
                                        _l.Log(LogType.FILE, LogLevel.ERROR,
                                               " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> State 5 Error Missing Fields. " +
                                               line);
                                    }
                                    else
                                    {
                                        _l.Log(LogType.FILE, LogLevel.ERROR,
                                               " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> State 5 Error Unknown Line. " +
                                               line);
                                    }
                                    return;
                                case 6:
                                    if (line.Equals("OUTPUT;BEGIN"))
                                    {
                                        try
                                        {
                                            CustomServiceBase customServiceBase =
                                                GetInstanceService("Security Manager Remote Recorder");
                                            _l.Log(LogType.FILE, LogLevel.DEBUG,
                                                   " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> Record sending.");
                                            customServiceBase.SetReg(id,
                                                                     _lastRecordnum.ToString(
                                                                         CultureInfo.InvariantCulture), line,
                                                                     fileId + ";" + fileName + ";" + filePattern + ";" +
                                                                     fileCreateTime, "", _lastRecordDate);
                                            _lastFile = fileId + ";" + fileName + ";" + filePattern + ";" +
                                                        fileCreateTime;
                                            _l.Log(LogType.FILE, LogLevel.DEBUG,
                                                   " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> Record sended.");
                                            state = 7;
                                            break;
                                        }
                                        catch (Exception exception)
                                        {
                                            _l.Log(LogType.FILE, LogLevel.ERROR,
                                                   " CryptTechHotspotV_1_0_1Recorder In CoderParse() -->> Record sending Error." +
                                                   exception.Message);
                                        }
                                    }
                                    else
                                    {
                                        _l.Log(LogType.FILE, LogLevel.ERROR,
                                               " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> State 3 Error Unknown Line. " +
                                               line);
                                    }
                                    return;
                                case 7:
                                    if (line.StartsWith("+"))
                                    {
                                        _l.Log(LogType.FILE, LogLevel.DEBUG,
                                               " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> lines: " + line);
                                        if (CoderParse(line.Substring(1).Trim()))
                                        {
                                            _l.Log(LogType.FILE, LogLevel.DEBUG,
                                                   " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> Date inserted. ");
                                            lineCounter++;
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        _l.Log(LogType.FILE, LogLevel.ERROR,
                                               " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> State 7 Error Unknown Line. " +
                                               line);
                                    }
                                    return;
                            }
                        }
                        _l.Log(LogType.FILE, LogLevel.DEBUG,
                               " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> Inform." + state + " / " +
                               lineCounter + " / " + _maxRecordSend);

                        if (state > 1)
                        {
                            if (lineCounter < _maxRecordSend)
                            {
                                CheckEof(se, fileId, fileName, filePattern, fileCreateTime);
                            }
                        }
                        else
                        {
                            _l.Log(LogType.FILE, LogLevel.ERROR,
                                   " CryptTechHotspotV_1_0_1Recorder In timer1_Tick() -->> State 0 Error Unexpected end of stream.");
                        }
                    }
                }
                finally
                {
                    if (se != null)
                        se.Close();
                }
            }
            catch (Exception exception)
            {
                _l.Log(LogType.FILE, LogLevel.ERROR, " timer1_Tick -->> Error : " + exception);
            }
            finally
            {
                _timer1.Enabled = true;
                _l.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick -->> Timer is finished.");
            }
        }
        private string[] Get_Files_From_Subdir(string DirWithSub)
        {
            string line = "";
            String stdOut = "";
            String stdErr = "";
            string[] filenamelist = null;
            ArrayList arrFileNameList = new ArrayList();

            try
            {
                se = new SshExec(remoteHost, user);
                se.Password = password;
                if (DirWithSub.EndsWith("/") || DirWithSub.EndsWith("\\"))
                {

                    ///var/cluster/members/member1/adm/syslog.dated/08-Feb-08:31/
                    //Find sub folder.

                    Log.Log(LogType.FILE, LogLevel.DEBUG, " Get_Files_From_Subdir() -->> Home Directory | " + DirWithSub);
                    String command = "ls -lt " + DirWithSub; //String command = "ls -lt " + Dir + " | grep access";
                    Log.Log(LogType.FILE, LogLevel.DEBUG, " Get_Files_From_Subdir() -->> SSH command : " + command);
                    se.Connect();
                    se.RunCommand(command, ref stdOut, ref stdErr);
                    se.Close();

                    StringReader sr = new StringReader(stdOut);
                    arrFileNameList = new ArrayList();

                    while ((line = sr.ReadLine()) != null)
                    {
                        String[] arr = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        Log.Log(LogType.FILE, LogLevel.DEBUG, " Get_Files_From_Subdir() -->> Dosya ismi okundu: " + arr[arr.Length - 1]);

                        //auth,daemon,kern,lpr,mail,syslog,user
                        if (arr[arr.Length - 1].Contains("."))
                        {
                            arrFileNameList.Add(arr[arr.Length - 1]);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Log(LogType.FILE, LogLevel.ERROR, " Get_Files_From_Subdir() -->> Error on getting file of SubDir: " + DirWithSub);
                Log.Log(LogType.FILE, LogLevel.ERROR, " Get_Files_From_Subdir() -->> " + ex.ToString());
            }

            filenamelist = new string[arrFileNameList.Count];

            for (int i = 0; i < filenamelist.Length; i++)
            {
                filenamelist[i] = arrFileNameList[i].ToString();
            }

            return filenamelist;
        }
        protected override void ParseFileNameRemote()
        {
            string line = "";
            String stdOut = "";
            String stdErr = "";
            string DirWithSub = "";
            bool bLastFolderExist = false;
            bool bLastFileExist = false;
            String[] dFolderNameList;
            string[] filenames;
            string[] sortedFileNames;

            try
            {
                Log.Log(LogType.FILE, LogLevel.DEBUG, " ParseFileNameRemote() -->> Enter the Function.");
                se = new SshExec(remoteHost, user);
                se.Password = password;
                if (Dir.EndsWith("/") || Dir.EndsWith("\\"))
                {
                    ///var/cluster/members/member1/adm/syslog.dated/08-Feb-08:31/
                    //Find sub folder.
                    Log.Log(LogType.FILE, LogLevel.INFORM, " ParseFileNameRemote() -->> Home Directory | " + Dir);

                    String command = "ls -lt " + Dir; //String command = "ls -lt " + Dir + " | grep access";
                    Log.Log(LogType.FILE, LogLevel.INFORM, " ParseFileNameRemote() -->> SSH command : " + command);
                    se.Connect();
                    se.RunCommand(command, ref stdOut, ref stdErr);
                    se.Close();
                    StringReader sr = new StringReader(stdOut);
                    ArrayList arrFolderNameList = new ArrayList();

                    while ((line = sr.ReadLine()) != null)
                    {
                        String[] arr = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        //08-Feb-08:31
                        if (arr[arr.Length - 1].Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries).Length == 3)//Name changed
                        {
                            arrFolderNameList.Add(arr[arr.Length - 1]);
                            Log.Log(LogType.FILE, LogLevel.DEBUG, " ParseFileNameRemote() -->> Klasör ismi okundu: " + arr[arr.Length - 1]);
                        }
                    }

                    dFolderNameList = SortFolders(arrFolderNameList);
                    Log.Log(LogType.FILE, LogLevel.DEBUG, " ParseFileNameRemote() -->> arrFolderNameList'e atılan klasör isimleri sıralandı.");

                    if (dFolderNameList.Length > 0)
                    {
                        if (!String.IsNullOrEmpty(lastFile))
                        {
                            Log.Log(LogType.FILE, LogLevel.DEBUG, " ParseFileNameRemote() -->> LastFile is not null: " + lastFile);

                            string[] lastFileparts = lastFile.Split(new char[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
                            string lastfolder = lastFileparts[lastFileparts.Length - 2];

                            Log.Log(LogType.FILE, LogLevel.DEBUG, " ParseFileNameRemote() -->> LastFolder name : " + lastfolder);

                            for (int i = 0; i < dFolderNameList.Length; i++)
                            {
                                if ((dFolderNameList[i].ToString()) == lastfolder)
                                {
                                    Log.Log(LogType.FILE, LogLevel.DEBUG, " ParseFileNameRemote() -->> LastFolder is found: " + lastFile);
                                    bLastFolderExist = true;
                                    DirWithSub = Dir + dFolderNameList[i].ToString() + "/";
                                    break;
                                }
                            }

                            if (bLastFolderExist)
                            {
                                filenames = Get_Files_From_Subdir(DirWithSub);

                                if (filenames.Length > 0)
                                {
                                    sortedFileNames = SortFiles(filenames);

                                    for (int i = 0; i < sortedFileNames.Length; i++)
                                    {
                                        if (lastFile == DirWithSub + sortedFileNames[i])
                                        {
                                            Log.Log(LogType.FILE, LogLevel.DEBUG, " ParseFileNameRemote() -->> LastFile is found: " + lastFile);
                                            bLastFileExist = true;
                                            break;
                                        }
                                    }

                                    if (bLastFileExist)
                                    {
                                        if (Is_File_Finished(lastFile))
                                        {
                                            Log.Log(LogType.FILE, LogLevel.DEBUG, " ParseFileNameRemote() -->> Last File is finished. Previous File: " + lastFile + " Position : " + Position);

                                            for (int i = 0; i < sortedFileNames.Length; i++)
                                            {
                                                if (DirWithSub + sortedFileNames[i].ToString() == lastFile)
                                                {
                                                    if (sortedFileNames.Length > i + 1)
                                                    {
                                                        FileName = DirWithSub + sortedFileNames[i + 1].ToString();
                                                        Position = 0;
                                                        lastFile = FileName;
                                                        Log.Log(LogType.FILE, LogLevel.INFORM, " ParseFileNameRemote() -->> New File is assigned. New File: " + FileName);
                                                    }
                                                    else
                                                    {
                                                        Log.Log(LogType.FILE, LogLevel.INFORM, " ParseFileNameRemote() -->> There is no new file to assign. If there is new folder we will change folder.");

                                                        //lastFileparts = lastFile.Split(new char[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
                                                        //string lastfolder = lastFileparts[lastFileparts.Length - 2];

                                                        Log.Log(LogType.FILE, LogLevel.DEBUG, " ParseFileNameRemote() -->> LastFolder name : " + lastfolder);

                                                        for (int j = 0; j < dFolderNameList.Length; j++)
                                                        {
                                                            if ((dFolderNameList[j].ToString()) == lastfolder)
                                                            {
                                                                if (dFolderNameList.Length > j + 2)
                                                                {
                                                                    DirWithSub = Dir + dFolderNameList[j+1].ToString() + "/";
                                                                    Log.Log(LogType.FILE, LogLevel.DEBUG, " ParseFileNameRemote() -->> New Folder is assigned: " + DirWithSub);

                                                                     filenames = Get_Files_From_Subdir(DirWithSub);

                                                                     if (filenames.Length > 0)
                                                                     {
                                                                         sortedFileNames = SortFiles(filenames);

                                                                         FileName = DirWithSub + sortedFileNames[0].ToString();
                                                                         Position = 0;
                                                                         lastFile = FileName;
                                                                         Log.Log(LogType.FILE, LogLevel.INFORM, " ParseFileNameRemote() -->> New File is assigned. New File: " + FileName);
                                                                     }
                                                                     else
                                                                     {
                                                                         Log.Log(LogType.FILE, LogLevel.INFORM, " ParseFileNameRemote() -->> There is no filr in new folder.");
                                                                     }
                                                                }
                                                                else
                                                                {
                                                                    Log.Log(LogType.FILE, LogLevel.INFORM, " ParseFileNameRemote() -->> There is no new folder to assign. We will wait on this folder.");
                                                                }

                                                                break;
                                                            }
                                                        }

                                                        FileName = lastFile;
                                                        Log.Log(LogType.FILE, LogLevel.INFORM, " ParseFileNameRemote() -->> There is no new file to assign. Wait this file for log: " + FileName);
                                                    }
                                                    break;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            FileName = lastFile;
                                            Log.Log(LogType.FILE, LogLevel.INFORM, " ParseFileNameRemote() -->> File did not finished continue to read. FileName : " + FileName);
                                        }
                                    }
                                    else
                                    {
                                        Log.Log(LogType.FILE, LogLevel.INFORM, " ParseFileNameRemote() -->> Last File could not found in last directory. LastFile : " + lastFile);
                                    }
                                }
                                else
                                {
                                    Log.Log(LogType.FILE, LogLevel.INFORM, " ParseFileNameRemote() -->> There is no file in subdirectory. DirWithSub : " + DirWithSub);
                                }
                            }
                            else
                            {
                                Log.Log(LogType.FILE, LogLevel.INFORM, " ParseFileNameRemote() -->> Last Folder could not found in main directory. Lastfolder : " + lastfolder);

                                DirWithSub = Dir + dFolderNameList[0].ToString() + "/";
                                Log.Log(LogType.FILE, LogLevel.INFORM, " ParseFileNameRemote() -->> New folder is assined: " + DirWithSub);
                                filenames = Get_Files_From_Subdir(DirWithSub);
                                if (filenames.Length > 0)
                                {
                                    sortedFileNames = SortFiles(filenames);
                                    FileName = DirWithSub + sortedFileNames[0].ToString();
                                    Position = 0;
                                    lastFile = FileName;
                                    Log.Log(LogType.FILE, LogLevel.INFORM, " ParseFileNameRemote() -->> New file is assigned. FileName : " + FileName);

                                }
                                else
                                {
                                    Log.Log(LogType.FILE, LogLevel.INFORM, " ParseFileNameRemote() -->> There is no file in New folder!! ");
                                }
                            }
                        }
                        else
                        {
                            //İlk defa log okunacak. En eski klasör atanacak.
                            DirWithSub = Dir + dFolderNameList[0] + "/";
                            Log.Log(LogType.FILE, LogLevel.INFORM, " ParseFileNameRemote() -->> Lastfile empty. Oldest directory will be assign. DirWithSub : " + DirWithSub);

                            filenames = Get_Files_From_Subdir(DirWithSub);

                            if (filenames.Length > 0)
                            {
                                sortedFileNames = SortFiles(filenames);
                                FileName = DirWithSub + sortedFileNames[0];
                                lastFile = FileName;
                                Position = 0;

                                Log.Log(LogType.FILE, LogLevel.INFORM, " ParseFileNameRemote() -->> First file of oldest direcort is assiged : Filename: " + lastFile + " | Position: " + Position);
                            }
                            else
                            {
                                Log.Log(LogType.FILE, LogLevel.INFORM, " ParseFileNameRemote() -->> There is no file in subdirectory. DirWithSub : " + DirWithSub);
                            }
                        }
                    }
                    else
                    {
                        Log.Log(LogType.FILE, LogLevel.ERROR, " ParseFileNameRemote() -->> There is no subfolder that we want!!!");
                    }
                }
                else
                {
                    Log.Log(LogType.FILE, LogLevel.ERROR, " ParseFileNameRemote() -->> Lütfen doğru formatta bir path giriniz.");
                }
            }
            catch (Exception ex)
            {
                Log.Log(LogType.FILE, LogLevel.ERROR, " ParseFileNameRemote() -->> Dosya isimleri getirilirken problemle karþýlaþýldý.");
                Log.Log(LogType.FILE, LogLevel.ERROR, " ParseFileNameRemote() -->> Hata Mesajý: " + ex.ToString());
            }
            finally
            {
            }
        }
        protected override void ParseFileNameRemote()
        {
            try
            {
                Log.Log(LogType.FILE, LogLevel.INFORM, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() -->> Enter The ParseFileNameRemote Function");

                String stdOut = "";
                String stdErr = "";
                String line = "";

                se = new SshExec(remoteHost, user);
                se.Password = password;
                if (Dir.EndsWith("/") || Dir.EndsWith("\\"))
                {
                    Log.Log(LogType.FILE, LogLevel.DEBUG, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() --> Directory | " + Dir);
                    se.Connect();
                    Log.Log(LogType.FILE, LogLevel.DEBUG, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() --> Remote Host Already Connected ");
                    se.SetTimeout(Int32.MaxValue);
                    String command = "ls -lt " + Dir + " | grep secure";
                    se.RunCommand(command, ref stdOut, ref stdErr);
                    Log.Log(LogType.FILE, LogLevel.DEBUG, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() -->> SSH command : " + command + " Result : " + stdOut);
                    //stdout : -rwxrw-rw- 1 ibrahim ibrahim 1920 2011-07-04 11:17 secure

                    StringReader sr = new StringReader(stdOut);
                    Boolean fileExistControl = false;

                    while ((line = sr.ReadLine()) != null)
                    {
                        String[] arr = line.Split(' ');
                        if (arr[arr.Length - 1].Equals("secure") == true)
                            fileExistControl = true;
                    }

                    if (!String.IsNullOrEmpty(lastFile))
                    {
                        if (fileExistControl)
                        {
                            Log.Log(LogType.FILE, LogLevel.DEBUG, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() -->> Secure File is Exist");
                            stdOut = "";
                            stdErr = "";
                            String commandRead;

                            if (readMethod == "nread")
                            {
                                commandRead = tempCustomVar1 + " -n " + Position + "," + lineLimit + "p " + lastFile;
                                Log.Log(LogType.FILE, LogLevel.DEBUG, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() -->> commandRead For nread Is : " + commandRead);
                            }
                            else
                            {
                                commandRead = readMethod + " -n " + Position + "," + lineLimit + "p " + lastFile;
                                Log.Log(LogType.FILE, LogLevel.DEBUG, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() -->> commandRead For sed Is : " + commandRead);
                            }

                            Log.Log(LogType.FILE, LogLevel.DEBUG, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() --> Position : " + Position);
                            se.RunCommand(commandRead, ref stdOut, ref stdErr);
                            Log.Log(LogType.FILE, LogLevel.DEBUG, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() --> Result : " + stdOut);
                            //Jun 26 04:34:14 SAMBASERVER sshd[20314]: Accepted password for natek from 172.16.1.14 port 55200 ssh2

                            StringReader srTest = new StringReader(stdOut);
                            se.Close();

                            if (String.IsNullOrEmpty(stdOut))
                            {
                                Log.Log(LogType.FILE, LogLevel.DEBUG, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() --> Restart The Position");
                                Position = 0;
                            }
                        }
                        else
                            Log.Log(LogType.FILE, LogLevel.DEBUG, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() -->> Secure File is NOT Exist");

                    }
                    else
                    {
                        if (fileExistControl)
                        {
                            FileName = Dir + "secure";
                            lastFile = FileName;
                            Position = 0;
                            Log.Log(LogType.FILE, LogLevel.INFORM,
                                "  RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() -->>  Last File Is Null And Setted The File To " + FileName);

                        }
                    }

                    stdOut = "";
                    stdErr = "";
                    se.Close();
                }
                else
                {
                    FileName = Dir;
                }
            }
            catch (Exception exp)
            {
                Log.Log(LogType.FILE, LogLevel.ERROR, "  RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() In Catch -->>" + exp.Message);
                Log.Log(LogType.FILE, LogLevel.ERROR, "  RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() In Catch -->>" + exp.StackTrace);
                return;
            }

            Log.Log(LogType.FILE, LogLevel.INFORM, " RedhatSecureV_1_0_0Recorder In ParseFileNameRemote() -->>  Exit The Function");
        }
        private SshExec ConnectRemoteHost()
        {
            if (string.IsNullOrEmpty(_remoteHost))
            {
                _logger.Log(LogType.FILE, LogLevel.ERROR, "Error ProcessLogs: No remote host defined");
                return null;
            }
            var address = _remoteHost.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
            int port;
            if (address.Length != 2 || int.TryParse(address[1], out port))
                port = 0;

            var ssh = new SshExec(address[0], _user);
            if (!string.IsNullOrEmpty(_password))
                ssh.Password = _password;
            if (port > 0)
                ssh.Connect(port);
            else
                ssh.Connect();
            return ssh;
        }
        //protected override void ParseFileNameRemote()
        //{
        //    string line = "";
        //    String stdOut = "";
        //    String stdErr = "";
        //    try
        //    {
        //        Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Enter the Function.");
        //        se = new SshExec(remoteHost, user);
        //        se.Password = password;
        //        if (Dir.EndsWith("/") || Dir.EndsWith("\\"))
        //        {
        //            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Home Directory | " + Dir);
        //            String command = "ls -lt " + Dir;
        //            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> SSH command : " + command);
        //            try
        //            {
        //                se.Connect();
        //                se.RunCommand(command, ref stdOut, ref stdErr);
        //                se.Close();
        //            }
        //            catch (Exception exception)
        //            {
        //                Log.Log(LogType.FILE, LogLevel.DEBUG, "Exception : " + exception);
        //            }
        //            StringReader sr = new StringReader(stdOut);
        //            ArrayList arrFileNameList = new ArrayList();
        //            while ((line = sr.ReadLine()) != null)
        //            {
        //                String[] arr = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        //                if (arr[arr.Length - 1].StartsWith("radius_") == true && arr[arr.Length - 1].Split(new char[] { '.', '_' }, StringSplitOptions.RemoveEmptyEntries).Length <= 3)//Name changed
        //                {
        //                    arrFileNameList.Add(arr[arr.Length - 1]);
        //                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Dosya ismi okundu: " + arr[arr.Length - 1]);
        //                }
        //            }
        //            String[] dFileNameList = SortFiles(arrFileNameList);
        //            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> arrayFileNameList'e atılan dosya isimleri sıralandı.");
        //            if (!String.IsNullOrEmpty(lastFile))
        //            {
        //                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> LastFile is not null: " + lastFile);
        //                bool bLastFileExist = false;
        //                for (int i = 0; i < dFileNameList.Length; i++)
        //                {
        //                    if ((base.Dir + dFileNameList[i].ToString()) == base.lastFile)
        //                    {
        //                        bLastFileExist = true;
        //                        Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> LastFile is found: " + lastFile);
        //                        break;
        //                    }
        //                }
        //                if (bLastFileExist)
        //                {
        //                    if (Is_File_Finished(lastFile))
        //                    {
        //                        Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Last File is finished. Previous File: " + lastFile);
        //                        for (int i = 0; i < dFileNameList.Length; i++)
        //                        {
        //                            if (Dir + dFileNameList[i].ToString() == lastFile)
        //                            {
        //                                if (dFileNameList.Length > i + 1)
        //                                {
        //                                    FileName = Dir + dFileNameList[i + 1].ToString();
        //                                    Position = 0;
        //                                    lastFile = FileName;
        //                                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> New File is assigned. New File: " + FileName);
        //                                    break;
        //                                }
        //                                else
        //                                {
        //                                    FileName = lastFile;
        //                                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> There is no new file to assign. Wait this file for log: " + FileName);
        //                                }
        //                            }
        //                        }
        //                    }
        //                    else
        //                    {
        //                        FileName = lastFile;
        //                        Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> There is still line in lastfile.  Continue to read this file: " + FileName);
        //                    }
        //                }
        //                else
        //                {
        //                    FileName = Dir + dFileNameList[dFileNameList.Length - 1].ToString(CultureInfo.InvariantCulture);
        //                    Position = 0;
        //                    lastFile = FileName;
        //                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> LastFile Silinmis , Dosya Bulunamadı.  Yeni File : " + FileName);
        //                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Start to read  main file from beginning: " + FileName);
        //                }
        //            }
        //            else
        //            {
        //                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Last File Is Null");
        //                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> ilk defa log okunacak.");
        //                if (dFileNameList.Length > 0)
        //                {
        //                    FileName = Dir + dFileNameList[0].ToString();
        //                    lastFile = FileName;
        //                    Position = 0;
        //                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> FileName ve LastFile en eski dosya olarak ayarlandý: " + lastFile);
        //                }
        //                else
        //                {
        //                    Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() -->> In The Log Location There Is No Log File to read.");
        //                }
        //            }
        //        }
        //        else
        //        {
        //            FileName = Dir;
        //            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Directory file olarak gösterildi.: " + FileName);
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() -->> Dosya isimleri getirilirken problemle karþýlaþýldý.");
        //        Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() -->> Hata Mesajý: " + ex.ToString());
        //    }
        //} // ParseFileNameRemote
        protected override void ParseFileNameRemote()
        {
            string line = "";
            String stdOut = "";
            String stdErr = "";

            try
            {
                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Enter the Function.");

                try
                {
                    se = new SshExec(remoteHost, user);
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> antin kuntin.......");
                    se.Password = password;
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> user: "******"ParseFileNameRemote() -->> password: "******"ParseFileNameRemote() -->> connect time out." + exception12.Message.ToString());
                }
                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Dir." + Dir);
                //IConnector connector = ConnectionManager.getConnector("SSH");
                //connector.SetConfigData(Log);
                //connector.Port = 22;
                //connector.Init();

                if (Dir.EndsWith("/") || Dir.EndsWith("\\"))
                {
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Home Directory | " + Dir);
                    String command = "ls -lt " + Dir;
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> SSH command : " + command);

                    try
                    {
                        Thread.Sleep(2000);
                        se.Connect();
                        se.RunCommand(command, ref stdOut, ref stdErr);
                        se.Close();

                        //if (connector.initConnection(remoteHost, user, password, "", 0))
                        //{
                        //    connector.runCommand(command);
                        //    stdOut = connector.read();
                        //    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Connection open : ");
                        //    connector.dropConnection();
                        //}
                        //else
                        //{
                        //    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> SSH connection couldn't open.");
                        //}//
                    }
                    catch (Exception exception)
                    {
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "Exception : " + exception);
                    }

                    StringReader sr = new StringReader(stdOut);
                    ArrayList arrFileNameList = new ArrayList();
                    while ((line = sr.ReadLine()) != null)
                    {
                        String[] arr = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        if (arr[arr.Length - 1].StartsWith("radius_") == true && arr[arr.Length - 1].Split(new char[] { '.', '_' }, StringSplitOptions.RemoveEmptyEntries).Length <= 3)//Name changed
                        {
                            arrFileNameList.Add(arr[arr.Length - 1]);
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Dosya ismi okundu: " + arr[arr.Length - 1]);
                        }
                    }

                    String[] dFileNameList = SortFiles(arrFileNameList);
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> arrayFileNameList'e atılan dosya isimleri sıralandı.");

                    if (!String.IsNullOrEmpty(lastFile))
                    {
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> LastFile is not null: " + lastFile);
                        bool bLastFileExist = false;

                        for (int i = 0; i < dFileNameList.Length; i++)
                        {
                            if ((base.Dir + dFileNameList[i].ToString()) == base.lastFile)
                            {
                                bLastFileExist = true;
                                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> LastFile is found: " + lastFile);
                                break;
                            }
                        }

                        if (bLastFileExist)
                        {
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> File Sizeing. ");

                            if (Is_File_Finished(lastFile))
                            {
                                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Last File is finished. Previous File: " + lastFile);

                                for (int i = 0; i < dFileNameList.Length; i++)
                                {
                                    if (Dir + dFileNameList[i].ToString() == lastFile)
                                    {
                                        if (dFileNameList.Length > i + 1)
                                        {
                                            FileName = Dir + dFileNameList[i + 1].ToString();
                                            Position = 0;
                                            lastFile = FileName;
                                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> New File is assigned. New File: " + FileName);
                                            break;
                                        }
                                        else
                                        {
                                            FileName = lastFile;
                                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> There is no new file to assign. Wait this file for log: " + FileName);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                FileName = lastFile;
                                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> There is still line in lastfile.  Continue to read this file: " + FileName);
                            }
                        }
                        else
                        {
                            FileName = Dir + dFileNameList[dFileNameList.Length - 1].ToString(CultureInfo.InvariantCulture);
                            Position = 0;
                            lastFile = FileName;
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> LastFile Silinmis , Dosya Bulunamadı.  Yeni File : " + FileName);
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Start to read  main file from beginning: " + FileName);
                        }
                    }
                    else
                    {
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Last File Is Null");
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> ilk defa log okunacak.");

                        if (dFileNameList.Length > 0)
                        {
                            FileName = Dir + dFileNameList[0].ToString();
                            lastFile = FileName;
                            Position = 0;
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> FileName ve LastFile en eski dosya olarak ayarlandý: " + lastFile);
                        }
                        else
                        {
                            Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() -->> In The Log Location There Is No Log File to read.");
                        }
                    }
                }
                else
                {
                    FileName = Dir;
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Directory file olarak gösterildi.: " + FileName);
                    RecordFields.fileName = FileName;
                    //GetLinuxFileSizeControl(FileName);
                    //Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> File Size: " + GetLinuxFileSizeControl(FileName));
                }
            }
            catch (Exception ex)
            {
                Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() -->> Dosya isimleri getirilirken problemle karþýlaþýldý.");
                Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() -->> Hata Mesajý: " + ex.ToString());
            }
        }
        private void ProcessRemoteFile(SshExec ssh, string filename)
        {
            var proc = GetProcessor();
            if (!filename.Contains("/"))
                filename = _location + "/" + filename;
            string stdout = null;
            string stderr = null;

            var key = DateTime.Now.Ticks + "@" + new Random((int)DateTime.Now.Ticks).Next();
            var command = _maxLineToWait > 0
                              ? proc + " \"" + filename + "\"|sed -n " + (_lastPosition + 1) + "," +
                                (_lastPosition + _maxLineToWait) + "p"
                              : proc + " \"" + filename + "\"";
            ssh.RunCommand("echo BEGIN " + key + " && (" + command + ") && echo END " + key, ref stdout, ref stderr);

            using (var reader = new StringReader(stdout))
            {
                var line = "";
                if ((line = reader.ReadLine()) != null && line == "BEGIN " + key)
                {
                    key = "END " + key;
                    var record = new List<string>();
                    while ((line = reader.ReadLine()) != null && line != key)
                    {
                        if (!ProcessRecord(line, record))
                            break;
                    }
                }
            }
        }
        protected override void ParseFileNameRemote()
        {
            string line = "";
            String stdOut = "";
            String stdErr = "";

            try
            {
                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Enter the Function.");
                se = new SshExec(remoteHost, user);
                se.Password = password;
                if (Dir.EndsWith("/") || Dir.EndsWith("\\"))
                {
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Home Directory | " + Dir);
                    String command = "ls -lt " + Dir + " | grep access_";
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> SSH command : " + command);

                    se.Connect();
                    se.RunCommand(command, ref stdOut, ref stdErr);
                    se.Close();

                    StringReader sr = new StringReader(stdOut);
                    ArrayList arrFileNameList = new ArrayList();

                    while ((line = sr.ReadLine()) != null)
                    {
                        String[] arr = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        if (arr[arr.Length - 1].StartsWith("access_") && arr[arr.Length - 1].Split('.').Length == 3) //Name changed
                        {
                            arrFileNameList.Add(arr[arr.Length - 1]);
                            Log.Log(LogType.FILE, LogLevel.DEBUG,
                                    "ParseFileNameRemote() -->> Dosya ismi okundu: " + arr[arr.Length - 1]);
                        }
                    }

                    String[] dFileNameList = SortFiles(arrFileNameList);
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> arrayFileNameList'e atılan dosya isimleri sıralandı.");

                    if (!String.IsNullOrEmpty(lastFile))
                    {
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> LastFile is not null: " + lastFile);
                        bool bLastFileExist = false;

                        for (int i = 0; i < dFileNameList.Length; i++)
                        {
                            if ((base.Dir + dFileNameList[i + 1].ToString()) == base.lastFile)
                            {
                                bLastFileExist = true;
                                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> LastFile is found: " + lastFile);
                                break;
                            }
                        }

                        if (bLastFileExist)
                        {
                            if (Is_File_Finished(lastFile))
                            {
                                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Last File is finished. Previous File: " + lastFile);

                                for (int i = 0; i < dFileNameList.Length; i++)
                                {
                                    if (Dir + dFileNameList[i + 1].ToString() == lastFile)
                                    {

                                        if (dFileNameList.Length > i + 1)
                                        {
                                            FileName = Dir + dFileNameList[i + 2].ToString();
                                            Position = 0;
                                            lastFile = FileName;
                                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> New File is assigned. New File: " + FileName);
                                            Log.Log(LogType.FILE, LogLevel.INFORM, "ParseFileNameRemote() -->> Recorder durduruldu. ");
                                            base.Stop();
                                            Log.Log(LogType.FILE, LogLevel.INFORM, "ParseFileNameRemote() -->> Recorder Başlatıldı. ");
                                            base.Start();
                                            break;
                                        }
                                        else
                                        {
                                            FileName = lastFile;
                                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> There is no new file to assign. Wait this file for log: " + FileName);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                //Continue to read current file.
                                FileName = lastFile;
                                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> There is still line in lastfile.  Continue to read this file: " + FileName);
                            }
                        }
                        else
                        {
                            //Last file bulunamadı silinmiş olabilir. En yeni dosya atanacak.
                            FileName = Dir + dFileNameList[dFileNameList.Length - 1].ToString();
                            Position = 0;
                            lastFile = FileName;
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> LastFile Silinmis , Dosya Bulunamadý.  Yeni File : " + FileName);
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Start to read  main file from beginning: " + FileName);
                        }
                    }
                    else
                    {
                        //İlk defa log atanacak.

                        Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Last File Is Null");
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> ilk defa log okunacak.");

                        if (dFileNameList.Length > 0)
                        {
                            FileName = Dir + dFileNameList[1].ToString();
                            lastFile = FileName;
                            Position = 0;
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> FileName ve LastFile en eski dosya olarak ayarlandý: " + lastFile);
                        }
                        else
                        {
                            Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() -->> In The Log Location There Is No Log File to read.");
                        }
                    }
                }
                else
                {
                    FileName = Dir;
                    Position = 0;
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Directory file olarak gösterildi.: " + FileName);
                }
            }
            catch (Exception ex)
            {
                Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() -->> Dosya isimleri getirilirken problemle karþýlaþýldý.");
                Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() -->> Hata Mesajý: " + ex.ToString());
            }
            finally
            {
            }
        }
        protected override void ParseFileNameRemote()
        {
            string line = "";
            String stdOut = "";
            String stdErr = "";

            try
            {
                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Enter the Function.");
                se = new SshExec(remoteHost, user);
                se.Password = password;
                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Directory : ");
                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Directory : " + Dir);

                if (Dir.EndsWith("/") || Dir.EndsWith("\\"))
                {//# ls -lt /cache1/nateklog/  | grep ^-
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Home Directory  " + Dir);
                    //String command = "ls -lt " + Dir + " | grep ^ access_";
                    String command = "ls -lt " + Dir + " | grep access_";
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> SSH command : " + command);

                    se.Connect();
                    se.RunCommand(command, ref stdOut, ref stdErr);
                    se.Close();

                    StringReader sr = new StringReader(stdOut);
                    ArrayList arrFileNameList = new ArrayList();

                    bool foundAnyFile = false;
                    int fileCnt = 0;
                    while ((line = sr.ReadLine()) != null)
                    {
                        fileCnt++;
                        String[] arr = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        //if (arr[arr.Length - 1].StartsWith("access_") == true && arr[arr.Length - 1].Split(new char[] { '.', '_' }, StringSplitOptions.RemoveEmptyEntries).Length <= 3)//Name changed
                        string ss = arr[arr.Length - 1].ToString();
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Onur : " + ss);
                        if (arr[arr.Length - 1].StartsWith("access") && arr[arr.Length - 1].Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries).Length <= 2)//Name changed
                        //if (arr[arr.Length - 1].StartsWith("access_") == true && arr[arr.Length - 1].Split(new char[] { '.', '_' }, StringSplitOptions.RemoveEmptyEntries).Length <= 3)//Name changed
                        {
                            arrFileNameList.Add(arr[arr.Length - 1]);
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> **Uygun Dosya ismi okundu: " + arr[arr.Length - 1]);
                            foundAnyFile = true;
                        }
                        else
                        {
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> **Uygun OLMAYAN Dosya ismi okundu: " + arr[arr.Length - 1]);
                        }
                    }
                    if (!foundAnyFile)
                    {
                        Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() -->> There is " + fileCnt + " files counted but there is no proper file in directory; starting like 'access_'");
                    }

                    String[] dFileNameList = SortFiles(arrFileNameList);

                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> arrayFileNameList'e atılan dosya isimleri sıralandı.");

                    if (!String.IsNullOrEmpty(lastFile))
                    {
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> LastFile is not null: " + lastFile);
                        bool bLastFileExist = false;

                        for (int i = 0; i < dFileNameList.Length; i++)
                        {
                            if ((base.Dir + dFileNameList[i].ToString()) == base.lastFile)
                            {
                                bLastFileExist = true;
                                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> LastFile is found: " + lastFile);
                                break;
                            }
                        }

                        if (bLastFileExist)
                        {
                            if (Is_File_Finished(lastFile))
                            {
                                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Last File is finished. Previous File: " + lastFile);

                                for (int i = 0; i < dFileNameList.Length; i++)
                                {
                                    if (Dir + dFileNameList[i].ToString() == lastFile)
                                    {
                                        if (dFileNameList.Length > i + 1)
                                        {
                                            FileName = Dir + dFileNameList[i + 1].ToString();
                                            Position = 0;
                                            lastFile = FileName;
                                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> New File is assigned. New File: " + FileName);
                                            break;
                                        }
                                        else
                                        {
                                            FileName = lastFile;
                                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> There is no new file to assign. Wait this file for log: " + FileName);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                FileName = lastFile;
                                Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> There is still line in lastfile.  Continue to read this file: " + FileName);
                            }
                        }
                        else
                        {
                            FileName = Dir + dFileNameList[dFileNameList.Length - 1].ToString();
                            Position = 0;
                            lastFile = FileName;
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> LastFile Silinmis , Dosya Bulunamadý.  Yeni File : " + FileName);
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Start to read  main file from beginning: " + FileName);
                        }
                    }
                    else
                    {
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Last File Is Null");
                        Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> ilk defa log okunacak.");

                        if (dFileNameList.Length > 0)
                        {
                            FileName = Dir + dFileNameList[0].ToString();
                            lastFile = FileName;
                            Position = 0;
                            Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> FileName ve LastFile en eski dosya olarak ayarlandý: " + lastFile);
                        }
                        else
                        {
                            Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() -->> In The Log Location There Is No Log File to read.");
                        }
                    }
                }
                else
                {
                    FileName = Dir;
                    Log.Log(LogType.FILE, LogLevel.DEBUG, "ParseFileNameRemote() -->> Directory file olarak gösterildi.: " + FileName);
                }
            }
            catch (Exception ex)
            {
                Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() -->> Dosya isimleri getirilirken problemle karşılaşıldı.");
                Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() -->> Hata Mesajı: " + ex.ToString());
                Log.Log(LogType.FILE, LogLevel.ERROR, "ParseFileNameRemote() -->> Hata Mesajı: " + ex.StackTrace);
            }
            finally
            {
            }
        }
 protected override void ParseFileNameRemote()
 {
     String stdOut = "";
     String stdErr = "";
     se = new SshExec(remoteHost, user);
     se.Password = password;
     if (Dir.EndsWith("/") || Dir.EndsWith("\\"))
     {
         se.Connect();
         se.SetTimeout(Int32.MaxValue);
         String command = "ls -lt " + Dir + " | grep ^-";
         Log.Log(LogType.FILE, LogLevel.DEBUG, "SSH command is : " + command);
         se.RunCommand(command, ref stdOut, ref stdErr);
         StringReader sr = new StringReader(stdOut);
         String line = "";
         bool first = true;
         while ((line = sr.ReadLine()) != null)
         {
             if (first)
             {
                 Log.Log(LogType.FILE, LogLevel.DEBUG, "Command returned : " + line);
                 first = false;
             }
             String[] arr = line.Split(' ');
             if (arr[arr.Length - 1].Contains("auth.log"))
             {
                 FileName = Dir + arr[arr.Length - 1];
                 break;
             }
         }
         stdOut = "";
         stdErr = "";
         se.Close();
     }
     else
         FileName = Dir;
 }
        private void timer1_Tick_old(object sender, System.Timers.ElapsedEventArgs e)
        {
            L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Timer tetiklenme anı: " + e.SignalTime.ToLongTimeString());

            timer1.Enabled = false;
            String stdOut = "";
            String stdErr = "";
            String line = "";
            Rec rec = new Rec();
            recList = new ArrayList();
            SshExec se = null;

            try
            {
                L.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick() --> SshExec nesnesi için. Host: " + remoteHost + ", User: "******", Pass: *******");

                se = new SshExec(remoteHost, user);
                if (!String.IsNullOrEmpty(password))
                    se.Password = password;

                L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> SshExec nesnesi üretildi.");

                L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Started to connect and parse lines.");

                if (!se.Connected)
                {
                    try
                    {
                        se.Connect(22, 2000);
                        L.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick() --> Bağlantı açıldı.");
                        se.SetTimeout(15000);
                        L.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick() --> Timeout atandı. 15000");
                    }
                    catch (Exception ex)
                    {
                        L.Log(LogType.FILE, LogLevel.ERROR, " timer1_Tick() --> Connection problem. Hata : " + ex.ToString());
                    }
                }
                else
                {
                    L.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick() --> Zaten kurulu olan bağlantı ile devam ediliyor.");
                }

                if (se.Connected)
                {
                    L.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick() --> Bağlantı şuan açık. Komut çalıştırılabilir.");
                }
                else
                {
                    L.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick() --> Bağlantı şuan kapalı. Komut çalışmayacak!!");
                }

                try
                {
                    se.RunCommand("show ip dhcp binding ", ref stdOut, ref stdErr);
                    L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Komut çalıştırıldı. show ip dhcp binding");
                }
                catch (Exception ex)
                {
                    L.Log(LogType.FILE, LogLevel.ERROR, " timer1_Tick() --> Komut çalıştırılamadı!!!   show ip dhcp binding");
                    L.Log(LogType.FILE, LogLevel.ERROR, " timer1_Tick() --> Hata: " + ex.ToString());
                }

                String stdOut1 = "";
                String stdErr1 = "";

                if (se.Connected)
                {
                    L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Bağlantı şuan açık. Komut çalıştırılabilir.");
                }
                else
                {
                    L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Bağlantı kopuk. Komut çalışmayacak!!");
                }

                try
                {
                    se.RunCommand("exit", ref stdOut1, ref stdErr1);
                    L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Komut çalıştırıldı. exit");
                }
                catch (Exception ex)
                {
                    L.Log(LogType.FILE, LogLevel.ERROR, " timer1_Tick() --> Komut çalıştırılamadı!!!  exit");
                    L.Log(LogType.FILE, LogLevel.ERROR, " timer1_Tick() --> Hata: " + ex.ToString());
                }

                if (se.Connected)
                {
                    se.Close();
                    L.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick() --> Bağlantı kesildi.");
                }

                StringReader sr = new StringReader(stdOut);

                while ((line = sr.ReadLine()) != null)
                {
                    L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Line: " + line);
                    rec.Description = line;
                    String[] arr = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                    if (arr.Length >= 8)
                    {
                        rec.Description = line;

                        if (arr[0].Contains("."))
                        {
                            rec.ComputerName = remoteHost;
                            rec.CustomStr1 = arr[0];
                            tempMac = arr[1];

                            tempMac = tempMac.Remove(0, 2);
                            string[] arrMac = tempMac.Split('.');
                            tempMac = "";
                            for (int i = 0; i < arrMac.Length; i++)
                            {
                                tempMac += arrMac[i];
                            }
                            rec.CustomStr2 = tempMac.Trim();
                            rec.EventType = arr[7];

                            for (int i = 2; i < 6; i++)
                            {
                                tempDate += arr[i] + " ";
                            }
                            tempDate = tempDate.Trim();

                            if (arr[6] == "PM" && Convert.ToDateTime(tempDate).Hour != 12)
                            {
                                rec.Datetime = Convert.ToDateTime(tempDate, CultureInfo.InvariantCulture).AddDays(-8).AddHours(12).ToString("dd/MM/yyyy HH:mm:ss");
                            }
                            else
                            {
                                rec.Datetime = Convert.ToDateTime(tempDate, CultureInfo.InvariantCulture).AddDays(-8).ToString("dd/MM/yyyy HH:mm:ss");
                            }

                            if (Convert.ToDateTime(tempDate).Date.Day == DateTime.Now.Date.Day)
                            {
                                rec.CustomStr3 = "Removed";
                            }

                            tempDate = "";
                            recList.Add(rec);
                        }
                    }
                }

                L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Çekilen veriler tarihlerine bakılarak kaydedilecek.");
                L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Kalınan LastPosition: " + Local_LastPosition);

                lastDate = new DateTime();
                bool lastPositionSetted = DateTime.TryParse(Local_LastPosition, out lastDate);

                foreach (Rec r in recList)
                {
                    if (!lastPositionSetted)
                    {
                        //İlk kayıtlar.
                        CustomServiceBase s = base.GetInstanceService("Security Manager Remote Recorder");
                        s.SetData(Dal, virtualhost, r);
                        L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> LastPosition is null. Veri ataması gerçekleştirildi.");
                    }
                    else
                    {
                        //Daha önce kayıt alınmış.
                        if (Convert.ToDateTime(r.Datetime) > lastDate)
                        {
                            //Değişen kayıt olmuş. Veritabanına eklenmeli.
                            CustomServiceBase s = base.GetInstanceService("Security Manager Remote Recorder");
                            s.SetData(Dal, virtualhost, r);
                            L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Record Date daha büyük. Veri ataması gerçekleştirildi. : " + r.Datetime);
                        }
                        else
                        {
                            //Tarih aynı. Kayıt işlemi yapılmayacak.
                            L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Record Date daha küçük. Kaydedilmedi!. Tarih: " + r.Datetime);
                        }
                    }
                }

                L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> En büyük tarih belirleniyor.");
                maxDate = lastDate.ToString();

                foreach (Rec r in recList)
                {
                    if (Convert.ToDateTime(r.Datetime) > Convert.ToDateTime(maxDate))
                    {
                        maxDate = r.Datetime;
                    }
                }

                CustomServiceBase ser = base.GetInstanceService("Security Manager Remote Recorder");
                ser.SetReg(ID, maxDate, "", "", "");
                Local_LastPosition = maxDate;
                L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Yeni LastPosition atandı. LastPostion: " + Local_LastPosition);
            }
            catch (Exception ex)
            {
                L.Log(LogType.FILE, LogLevel.ERROR, " timer1_Tick() --> Recorder Main Exception: " + ex.ToString());
            }
            finally
            {
                if (se != null)
                {
                    if (se.Connected)
                    {
                        se.Close();
                        L.Log(LogType.FILE, LogLevel.INFORM, " timer1_Tick() --> Bağlantı kesildi.");
                    }
                }

                tempDate = "";
                tempMac = "";
                timer1.Enabled = true;
                L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Timer'ın işi bitti. Time: " + DateTime.Now.ToLongTimeString());
                L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> Bir Sonraki Tetikleme " + timer_interval / 60000 + " dakika sonra gerçekleşecektir.");
                L.Log(LogType.FILE, LogLevel.DEBUG, " timer1_Tick() --> ===============================================");
                recList.Clear();
            }
        }