private void timerEvent_Tick(object sender, System.Timers.ElapsedEventArgs e) { ValidateMe(); timerEvent.Enabled = false; CustomBase.Rec rec = new CustomBase.Rec(); L.Log(LogType.FILE, LogLevel.INFORM, "Service Started"); string readQuery = null; AccessConnection ac = new AccessConnection(); OleDbConnection connection = null; OleDbCommand command = null; OleDbDataReader readReader = null; try { if (!reg_flag) { if (!Read_Registry()) { L.Log(LogType.FILE, LogLevel.ERROR, "Error on Reading the Registry "); return; } else if (!Initialize_Logger()) { L.Log(LogType.FILE, LogLevel.ERROR, "Error on Intialize Logger on Avira Recorder functions may not be running"); return; } reg_flag = true; } if (fromend) { if (!Set_LastPosition()) L.Log(LogType.FILE, LogLevel.INFORM, "Error on setting last position see eventlog for more details"); fromend = false; } readQuery = "Select TOP " + max_record_send + " Actor_ID,Product_ID,Product_Name,Module_Name,Event_Type,Issue_Time2,Msg,Msg_Index,P1,P2,Event_ID from Events where Event_ID > " + last_recordnumEvent + " ORDER BY Event_ID"; L.Log(LogType.FILE, LogLevel.DEBUG, " Query for EventLogTable is " + readQuery); ac.OpenAccessConnection(mcdb_name); readReader = ac.ExecuteAccessQuery(readQuery); if (!readReader.HasRows) // hatalı access kayıtları için. hatalı kayıtları atlar... { string readQuery1 = "select MAX(Event_ID) FROM Events"; OleDbDataReader readReader22 = ac.ExecuteAccessQuery(readQuery1); long max_record_num = 0; while (readReader22.Read()) { max_record_num = Convert.ToInt64(readReader22.GetDecimal(0)); } L.Log(LogType.FILE, LogLevel.DEBUG, "Maximum Record Num for EventsLog Table is : " + max_record_num); if (!readReader22.IsClosed) { readReader22.Close(); } if (last_recordnumEvent < max_record_num) { last_recordnumEvent += 1; } } while (readReader.Read()) { rec.LogName = "Avira Recorder"; if (!Convert.IsDBNull(readReader["Actor_ID"])) { rec.CustomInt6 = readReader.GetInt64(0); } if (!Convert.IsDBNull(readReader["Product_ID"])) { rec.CustomInt7 = readReader.GetInt64(1); } if (!Convert.IsDBNull(readReader["Product_Name"])) { rec.CustomStr1 = readReader.GetString(2); } if (!Convert.IsDBNull(readReader["Module_Name"])) { rec.CustomStr2 = readReader.GetString(3); } if (!Convert.IsDBNull(readReader["Event_Type"])) { rec.CustomInt8 = readReader.GetInt64(4); } if (!Convert.IsDBNull(readReader["Issue_Time2"])) { rec.Datetime = readReader.GetDateTime(5).ToString("yyyy/MM/dd HH:mm:ss.fff"); } if (!Convert.IsDBNull(readReader["Msg"])) { rec.CustomStr3 = readReader.GetString(6); } if (!Convert.IsDBNull(readReader["Msg_Index"])) { rec.CustomInt9 = readReader.GetInt64(7); } if (!Convert.IsDBNull(readReader["P1"])) { rec.CustomStr4 = readReader.GetString(8); } if (!Convert.IsDBNull(readReader["P2"])) { rec.CustomStr5 = readReader.GetString(9); } if (!Convert.IsDBNull(readReader["Event_ID"])) { rec.CustomInt10 = readReader.GetInt64(10); } L.Log(LogType.FILE, LogLevel.DEBUG, "Start sending Data for EventLog"); 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, LogLevel.DEBUG, "sendingg dataaaa"); } L.Log(LogType.FILE, LogLevel.DEBUG, "Finish Sending Data"); last_recordnumEvent = rec.CustomInt10; last_recdate = rec.Datetime; L.Log(LogType.FILE, LogLevel.DEBUG, "Record Number is For Event Log " + last_recordnumEvent.ToString()); if (usingRegistry) Set_Registry(last_recordnumEvent.ToString()); else { CustomServiceBase s = base.GetInstanceService("Security Manager Remote Recorder"); s.SetReg(Id, last_recordnumEvent.ToString(), "", "", "", last_recdate); } } L.Log(LogType.FILE, LogLevel.DEBUG, "Finish getting the data"); } catch (Exception er) { L.Log(LogType.FILE, LogLevel.ERROR, er.ToString()); } finally { timerEvent.Enabled = true; L.Log(LogType.FILE, LogLevel.INFORM, "Service Stopped"); if (command != null && connection != null) { command.Dispose(); connection.Close(); } ac.CloseAccessConnection(); } }
public bool Set_LastPosition() { string readQueryEvent = null; AccessConnection ac = new AccessConnection(); ; OleDbDataReader readReader; try { readQueryEvent = "select MAX(Event_ID) FROM Events"; L.Log(LogType.FILE, LogLevel.DEBUG, " Query Event is " + readQueryEvent); ac.OpenAccessConnection(mcdb_name); readReader = ac.ExecuteAccessQuery(readQueryEvent); L.Log(LogType.FILE, LogLevel.DEBUG, "Finish executing the query"); while (readReader.Read()) { last_recordnumEvent = Convert.ToInt64(readReader.GetInt32(0)); } if (usingRegistry) Set_Registry(last_recordnumEvent.ToString()); else { CustomServiceBase s = base.GetInstanceService("Security Manager Remote Recorder"); s.SetReg(Id, last_recordnumEvent.ToString(), "", "", "", last_recdate); } return true; } catch (Exception er) { L.Log(LogType.FILE, LogLevel.ERROR, er.ToString()); return false; } finally { ac.CloseAccessConnection(); } }