public RESTStatus ReportEventLog(SQLLib sql, ListEventLogReport EventLogList, NetworkConnectionInfo ni) { if (ni.HasAcl(ACLFlags.ComputerLogin) == false) { ni.Error = "Access denied"; ni.ErrorID = ErrorFlags.AccessDenied; return(RESTStatus.Denied); } EventLogList.MachineID = ni.Username; lock (ni.sqllock) { if (Convert.ToInt32(sql.ExecSQLScalar("SELECT COUNT(*) FROM ComputerAccounts WHERE MachineID=@m", new SQLParam("@m", EventLogList.MachineID))) == 0) { ni.Error = "Invalid MachineID"; ni.ErrorID = ErrorFlags.InvalidValue; return(RESTStatus.Denied); } } if (EventLogList.Items == null) { ni.Error = "Invalid Items"; ni.ErrorID = ErrorFlags.InvalidValue; return(RESTStatus.Fail); } if (EventLogList.Items.Count == 0) { return(RESTStatus.Created); } DateTime DT = DateTime.Now; foreach (EventLogReport ar in EventLogList.Items) { if (NullTest.Test(ar) == false) { ni.Error = "Invalid Items"; ni.ErrorID = ErrorFlags.InvalidValue; return(RESTStatus.Fail); } CommonUtilities.CalcEventLogID(ar); } List <SQLParam> sqlparams = new List <SQLParam>(); sqlparams.Add(new SQLParam("@id", EventLogList.MachineID)); int count = 1; string vars = ""; foreach (EventLogReport ar in EventLogList.Items) { sqlparams.Add(new SQLParam("@p" + count.ToString(), ar.LogID)); vars += "@p" + count.ToString() + ","; count++; } if (vars.EndsWith(",") == true) { vars = vars.Substring(0, vars.Length - 1); } List <string> LogIDinDB = new List <string>(); lock (ni.sqllock) { SqlDataReader dr = sql.ExecSQLReader("SELECT LogID FROM EventLog WHERE MachineID=@id and LogID in (" + vars + ")", sqlparams.ToArray()); while (dr.Read()) { LogIDinDB.Add(Convert.ToString(dr["LogID"])); } dr.Close(); } List <EventLogReport> RemoveEVL = new List <EventLogReport>(); foreach (EventLogReport ar in EventLogList.Items) { if (LogIDinDB.Contains(ar.LogID) == true) { RemoveEVL.Add(ar); continue; } if (SettingsManager.Settings.KeepEventLogDays > 0) { if (ar.TimeGenerated < DateTime.UtcNow.AddDays(0 - SettingsManager.Settings.KeepEventLogDays)) { RemoveEVL.Add(ar); continue; } } } foreach (EventLogReport ar in RemoveEVL) { EventLogList.Items.Remove(ar); } List <EventLogReportFull> car = new List <EventLogReportFull>(); lock (ni.sqllock) { try { sql.BeginTransaction(); sql.SEHError = true; foreach (EventLogReport ar in EventLogList.Items) { EventLogReportFull arr = new EventLogReportFull(); ClassCopy.CopyClassData(ar, arr); arr.Reported = DateTime.UtcNow; arr.MachineID = EventLogList.MachineID; List <SQLData> d = sql.InsertFromClassPrep(arr); foreach (SQLData dd in d) { if (dd.Column == "ID") { dd.Data = DBNull.Value; break; } } car.Add(arr); sql.InsertFromClass("EventLog", arr); } sql.CommitTransaction(); } catch (Exception ee) { sql.RollBackTransaction(); FoxEventLog.WriteEventLog("DB Error: Cannot insert data to EventLog: " + ee.ToString() + "\r\n\r\nJSON: " + JsonConvert.SerializeObject(car, Formatting.Indented), System.Diagnostics.EventLogEntryType.Error); return(RESTStatus.ServerError); } finally { sql.SEHError = false; } } Thread t = new Thread(new ParameterizedThreadStart(new DReportingThread(ReportingThread))); t.Start(car); return(RESTStatus.Created); }