private void timer_Tick(object sender, System.Timers.ElapsedEventArgs e)
        {
            timer.Enabled = false;
            CustomBase.Rec rec = new CustomBase.Rec();
            L.Log(LogType.FILE, Log.LogLevel.INFORM, "Service Started");
            string readQuery = null;
            PostGreConnection pgc = new PostGreConnection();
            NpgsqlDataReader readReader = null;
            NpgsqlCommand command = null;

            try
            {
                if (!reg_flag)
                {
                    if (!Read_Registry())
                    {
                        L.Log(LogType.FILE, Log.LogLevel.ERROR, "Error on Reading the Registry ");
                        return;
                    }
                    else
                        if (!Initialize_Logger())
                        {
                            L.Log(LogType.FILE, Log.LogLevel.ERROR, "Error on Intialize Logger on McaffeeEpo Recorder functions may not be running");
                            return;
                        }
                    reg_flag = true;
                }

                if (fromend)
                {
                    if (!Set_LastPosition())
                        L.Log(LogType.FILE, Log.LogLevel.INFORM, "Error on setting last position see eventlog for more details");
                    fromend = false;
                }

                readQuery = "Select kayit_tarih,kayit_saat,kullanici_ip,kullanici_name,table_name,prev_data,current_data,url,kodu from loglar where kodu > " + last_position.ToString() + " ORDER BY kodu";

                //readQuery = "Select * from loglar";
                L.Log(LogType.FILE, Log.LogLevel.DEBUG, " Query for EventLogTable is " + readQuery);

                pgc.OpenPostGreConnection(remote_host, user, password, mcdb_name);

                command = new NpgsqlCommand();

                readReader = pgc.ExecutePostGreQuery(readQuery, ref command);

                //if (readReader.Read() != false)
                //{
                //    L.Log(LogType.FILE, Log.LogLevel.INFORM, "timer_Tick() ----> Query Which Was Executed Bring Data");
                //}

                int i = 0;
                while (readReader.Read())
                {
                    rec.LogName = "NetCadPostGre Recorder";

                    string date = "";
                    string time = "";
                    string date_time = "";

                    date = readReader[0].ToString();
                    time = readReader[1].ToString();

                    string saat = time.Split(' ')[0].Trim();
                    string zamanDilimi = time.Split(' ')[1].Trim();

                    if (zamanDilimi == "AM")
                        time = saat + ":00";
                    else
                        time = (Convert.ToInt32(saat.Split(':')[0]) + 12).ToString() + ":" + saat.Split(':')[1] + ":00";

                    date = date.Split('/')[1] + "/" + date.Split('/')[0] + "/" + date.Split('/')[2];
                    date_time = date + " " + time;

                    try
                    {
                        rec.Datetime = Convert.ToDateTime(date_time).AddMinutes(zone).ToString("yyyy/MM/dd HH:mm:ss.fff");
                    }
                    catch (Exception ex)
                    {
                        rec.Datetime = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff");
                        L.Log(LogType.FILE, Log.LogLevel.ERROR, "In timer_Tick()-->> An Error Occured While Parsing kayit_tarih and kayit_saat " + ex.Message);
                    }

                    //L.Log(LogType.FILE, Log.LogLevel.INFORM, "rec.Datetime is : " +rec.Datetime);

                    string kullaniciIP = "";
                    kullaniciIP = readReader[2].ToString();
                    try
                    {
                        rec.CustomStr1 = System.Net.IPAddress.Parse(kullaniciIP).ToString();
                    }
                    catch (Exception ex)
                    {
                        L.Log(LogType.FILE, Log.LogLevel.ERROR, "In timer_Tick()-->> An Error Occured While Parsing kullanici_ip " + ex.Message);
                        rec.CustomStr1 = kullaniciIP;
                        L.Log(LogType.FILE, Log.LogLevel.ERROR, "In timer_Tick()-->> kullnici_ip olduðu gibi atandý. " + kullaniciIP);
                    }

                    // L.Log(LogType.FILE, Log.LogLevel.INFORM, "rec.CustomStr1 is (kullanici_ip) : " +rec.CustomStr1);

                    string kullaniciAdý = "";
                    kullaniciAdý = readReader[3].ToString();

                    try
                    {
                        rec.UserName = kullaniciAdý;
                    }
                    catch (Exception ex)
                    {
                        L.Log(LogType.FILE, Log.LogLevel.ERROR, "In timer_Tick()-->> An Error Occured While Parsing kullanici_name " + ex.Message);
                    }
                    //L.Log(LogType.FILE, Log.LogLevel.INFORM, "rec.UserName is (kullanici_name) : " + rec.UserName);

                    string tableName = "";
                    tableName = readReader[4].ToString();

                    try
                    {
                        L.Log(LogType.FILE, Log.LogLevel.INFORM, "CustomStr7 Is : " + tableName);
                        rec.CustomStr7 = tableName;
                    }
                    catch (Exception ex)
                    {
                        L.Log(LogType.FILE, Log.LogLevel.ERROR, "In timer_Tick()-->> An Error Occured While Parsing table_name " + ex.Message);
                    }
                    //L.Log(LogType.FILE, Log.LogLevel.INFORM, "rec.CustomStr7 (table_name) is : " + rec.CustomStr7);

                    string url = "";
                    url = readReader[7].ToString();
                    try
                    {
                        rec.CustomStr6 = url;
                    }
                    catch (Exception ex)
                    {
                        L.Log(LogType.FILE, Log.LogLevel.ERROR, "In timer_Tick()-->> An Error Occured While Parsing url " + ex.Message);
                    }
                    //L.Log(LogType.FILE, Log.LogLevel.INFORM, "rec.CustomStr6 (url) is : " + rec.CustomStr6);

                    string tempCurrentData = "";
                    tempCurrentData = readReader[6].ToString();
                    //L.Log(LogType.FILE, Log.LogLevel.INFORM, " (current_data) is : " + tempCurrentData);
                    try
                    {
                        string[] permanentCurrentData = new string[4];
                        for (int f = 0; f < permanentCurrentData.Length; f++)
                        {
                            permanentCurrentData[f] = "";
                        }

                        if (tempCurrentData != "")
                        {
                            permanentCurrentData = parseCurrentData(tempCurrentData);
                        }

                        if (permanentCurrentData[0].Length > 900)
                        {
                            rec.CustomStr9 = permanentCurrentData[0].Substring(0,850);
                            rec.CustomStr10 = permanentCurrentData[0].Substring(851, 850);
                        }
                        else
                        {
                            rec.CustomStr9 = permanentCurrentData[0];
                        }

                        rec.CustomStr4 = permanentCurrentData[1];
                        rec.CustomStr5 = permanentCurrentData[2];
                        rec.CustomStr8 = permanentCurrentData[3];

                        L.Log(LogType.FILE, Log.LogLevel.INFORM, "rec.CustomStr4 Is : " + rec.CustomStr4);
                        L.Log(LogType.FILE, Log.LogLevel.INFORM, "rec.CustomStr5 Is : " + rec.CustomStr5);

                    }
                    catch (Exception ex)
                    {
                        L.Log(LogType.FILE, Log.LogLevel.ERROR, "In timer_Tick()-->> An Error Occured While Parsing current_data " + ex.Message);
                    }

                    string tempPrevData = "";
                    tempPrevData = readReader[5].ToString();
                    //L.Log(LogType.FILE, Log.LogLevel.INFORM, " (tempPrevData) is : " + tempPrevData);
                    string permanentPrevData = "";
                    if (tempPrevData != "")
                    {
                        permanentPrevData = parsePrevData(tempPrevData);
                    }

                    rec.CustomStr2 = permanentPrevData;

                    long recordID = Convert.ToInt64(readReader[8].ToString());

                    L.Log(LogType.FILE, Log.LogLevel.DEBUG, "Start sending Data");

                    if (usingRegistry)
                    {
                        CustomServiceBase s = base.GetInstanceService("Security Manager Sender");
                        s.SetData(rec);
                    }
                    else
                    {
                        CustomServiceBase s = base.GetInstanceService("Security Manager Remote Recorder");
                        s.SetData(Dal, virtualhost, rec);
                    }

                    L.Log(LogType.FILE, Log.LogLevel.DEBUG, "Finish Sending Data");

                    last_position = recordID;
                    last_recdate = rec.Datetime;
                    L.Log(LogType.FILE, Log.LogLevel.DEBUG, "Record Number is " + last_position.ToString());
                    i++;
                    if (i > max_record_send)
                    {
                        command.Cancel();
                        L.Log(LogType.FILE, Log.LogLevel.DEBUG, "max_record_send < " + i.ToString() + " and command canceled");
                        return;
                    }
                    lastDb = mcdb_name;
                    if (usingRegistry)
                        SetNetCadPostGre_Registry(last_position.ToString());
                    else
                    {
                        CustomServiceBase s = base.GetInstanceService("Security Manager Remote Recorder");
                        s.SetReg(Id, last_position.ToString(), "", lastDb, "", last_recdate);
                    }
                }
                L.Log(LogType.FILE, Log.LogLevel.DEBUG, "Finish getting the data");
            }
            catch (Exception er)
            {
                L.Log(LogType.FILE, Log.LogLevel.ERROR, er.ToString());
            }
            finally
            {
                timer.Enabled = true;
                L.Log(LogType.FILE, Log.LogLevel.INFORM, "Service Stopped");

                if (command != null)
                {
                    command.Dispose();
                }
                pgc.ClosePostGreConnection();
            }
        }
        public bool Set_LastPosition()
        {
            string readQuery = null;

            PostGreConnection pgc = new PostGreConnection();
            NpgsqlDataReader readReader;
            NpgsqlCommand command;

            try
            {
                readQuery = "Select kayit_tarih,kayit_saat,kullanici_ip,kullanici_name,table_name,prev_data,current_data,url,kodu from loglar where kodu  = (select max(kodu) from loglar)";

                L.Log(LogType.FILE, Log.LogLevel.DEBUG, " Query Event is " + readQuery);

                //ac.OpenAccessConnection(remote_host, dblocationonServer, location);
                //readReader = ac.ExecuteAccessQuery(readQueryEvent);

                pgc.OpenPostGreConnection(remote_host, user, password, mcdb_name);
                command = new NpgsqlCommand();

                readReader = pgc.ExecutePostGreQuery(readQuery, ref command);

                L.Log(LogType.FILE, Log.LogLevel.DEBUG, "Finish executing the query");

                while (readReader.Read())
                {
                    last_position = Convert.ToInt64(readReader[8]);
                    L.Log(LogType.FILE, Log.LogLevel.DEBUG, "Son pozisyonu ayarlariken. Son Pozisyon: " + last_position);
                }
                readReader.Close();

                if (usingRegistry)
                    SetNetCadPostGre_Registry(last_position.ToString());
                else
                {
                    CustomServiceBase s = base.GetInstanceService("Security Manager Remote Recorder.");
                    s.SetReg(Id, last_position.ToString(), "", "", "", last_recdate);
                }

                return true;
            }
            catch (Exception er)
            {
                L.Log(LogType.FILE, Log.LogLevel.ERROR, "Set_LastPosition() -->> catch hata yakaladý.");
                L.Log(LogType.FILE, Log.LogLevel.ERROR, er.ToString());
                return false;
            }
            finally
            {
                pgc.ClosePostGreConnection();
            }
        }