public Dictionary <int, List <BasicPWEvent> > GetEventsForPersons(int[] personId, EventType[] eventTypes) { Dictionary <int, List <BasicPWEvent> > result = new Dictionary <int, List <BasicPWEvent> >(); List <string> eventTypesAsString = new List <string>(); foreach (EventType et in eventTypes) { eventTypesAsString.Add(et.ToString()); } using (DbConnection connection = GetMySqlDbConnection()) { connection.Open(); DbCommand command = GetDbCommand( "SELECT " + pwEventFieldSequence + " WHERE AffectedPersonId IN (" + JoinIds(personId) + ") " + (eventTypes.Length > 0 ? " AND PWEventTypes.Name IN (" + JoinStrings(eventTypesAsString.ToArray()) + ") " : "") + " ORDER BY CreatedDateTime desc", connection); using (DbDataReader reader = command.ExecuteReader()) { while (reader.Read()) { BasicPWEvent evt = ReadPWEventFromDataReader(reader); if (!result.ContainsKey(evt.AffectedPersonId)) { result[evt.AffectedPersonId] = new List <BasicPWEvent>(); } result[evt.AffectedPersonId].Add(evt); } return(result); } } }
private static void FetchBatchOfLogs (ref DateTime specificDate, ref DateTime yearLimit, List<int> idlist, Dictionary<int, List<BasicPWEvent>> personLogs) { Dictionary<int, List<BasicPWEvent>> eventRecs = PWEvents.ForPersons(idlist.ToArray(), new EventType[] { EventType.AddedMember, EventType.AddedMembership, EventType.ExtendedMembership }); List<BasicPWEvent> recs = null; foreach (List<BasicPWEvent> eventList in eventRecs.Values) { recs = new List<BasicPWEvent>(); foreach (BasicPWEvent evtRec in eventList) { if (evtRec.DateTime >= yearLimit.AddMonths(-1) && evtRec.DateTime < yearLimit.AddYears(1)) { int organizationId = 0; string parameterText = ""; switch (evtRec.EventType) { case EventType.AddedMember: { string[] split1 = ("" + evtRec.ParameterText).Split(','); if (split1.Length < 2) { split1 = new string[2]; split1[1] = FindIPForEventInLog(evtRec.DateTime, evtRec.AffectedPersonId, evtRec.ActingPersonId); } if (!string.IsNullOrEmpty(split1[0])) { string[] split2 = ("" + split1[0]).Split(' '); foreach (string orgnr in split2) { if (int.Parse(orgnr) != evtRec.OrganizationId) { organizationId = int.Parse(orgnr); parameterText = split1[0]; BasicPWEvent addR = new BasicPWEvent( evtRec.EventId, evtRec.DateTime, evtRec.Open, evtRec.ProcessedDateTime, evtRec.EventType, evtRec.EventSource, evtRec.ActingPersonId, evtRec.AffectedPersonId, organizationId, evtRec.GeographyId, evtRec.ParameterInt, parameterText); recs.Add(addR); } } } parameterText = split1[1]; BasicPWEvent addR2 = new BasicPWEvent( evtRec.EventId, evtRec.DateTime, evtRec.Open, evtRec.ProcessedDateTime, evtRec.EventType, evtRec.EventSource, evtRec.ActingPersonId, evtRec.AffectedPersonId, evtRec.OrganizationId, evtRec.GeographyId, evtRec.ParameterInt, parameterText); recs.Add(addR2); } break; case EventType.AddedMembership: { parameterText = FindIPForEventInLog(evtRec.DateTime, evtRec.AffectedPersonId, evtRec.ActingPersonId); BasicPWEvent addR2 = new BasicPWEvent( evtRec.EventId, evtRec.DateTime, evtRec.Open, evtRec.ProcessedDateTime, evtRec.EventType, evtRec.EventSource, evtRec.ActingPersonId, evtRec.AffectedPersonId, evtRec.OrganizationId, evtRec.GeographyId, evtRec.ParameterInt, parameterText); recs.Add(addR2); } break; case EventType.ExtendedMembership: { string[] split1 = ("" + evtRec.ParameterText).Split(' '); if (split1.Length < 1 || split1[0].Trim() == "") { if (split1.Length < 1) split1 = new string[1]; split1[0] = FindIPForEventInLog(evtRec.DateTime, evtRec.AffectedPersonId, evtRec.ActingPersonId); } if (split1.Length > 1) { foreach (string orgnr in split1) { if (orgnr.Length < 7 && int.Parse(orgnr) != evtRec.OrganizationId) { organizationId = int.Parse(orgnr); parameterText = split1[0]; BasicPWEvent addR = new BasicPWEvent( evtRec.EventId, evtRec.DateTime, evtRec.Open, evtRec.ProcessedDateTime, evtRec.EventType, evtRec.EventSource, evtRec.ActingPersonId, evtRec.AffectedPersonId, organizationId, evtRec.GeographyId, evtRec.ParameterInt, parameterText); recs.Add(addR); } } } parameterText = split1[0]; BasicPWEvent addR2 = new BasicPWEvent( evtRec.EventId, evtRec.DateTime, evtRec.Open, evtRec.ProcessedDateTime, evtRec.EventType, evtRec.EventSource, evtRec.ActingPersonId, evtRec.AffectedPersonId, evtRec.OrganizationId, evtRec.GeographyId, evtRec.ParameterInt, parameterText); recs.Add(addR2); } break; } } } if (recs.Count > 0) personLogs[recs[0].AffectedPersonId] = recs; } }
private static void FetchBatchOfLogs(ref DateTime specificDate, ref DateTime yearLimit, List <int> idlist, Dictionary <int, List <BasicPWEvent> > personLogs) { Dictionary <int, List <BasicPWEvent> > eventRecs = PWEvents.ForPersons(idlist.ToArray(), new EventType[] { EventType.AddedMember, EventType.AddedMembership, EventType.ExtendedMembership }); List <BasicPWEvent> recs = null; foreach (List <BasicPWEvent> eventList in eventRecs.Values) { recs = new List <BasicPWEvent>(); foreach (BasicPWEvent evtRec in eventList) { if (evtRec.DateTime >= yearLimit.AddMonths(-1) && evtRec.DateTime < yearLimit.AddYears(1)) { int organizationId = 0; string parameterText = ""; switch (evtRec.EventType) { case EventType.AddedMember: { string[] split1 = ("" + evtRec.ParameterText).Split(','); if (split1.Length < 2) { split1 = new string[2]; split1[1] = FindIPForEventInLog(evtRec.DateTime, evtRec.AffectedPersonId, evtRec.ActingPersonId); } if (!string.IsNullOrEmpty(split1[0])) { string[] split2 = ("" + split1[0]).Split(' '); foreach (string orgnr in split2) { if (int.Parse(orgnr) != evtRec.OrganizationId) { organizationId = int.Parse(orgnr); parameterText = split1[0]; BasicPWEvent addR = new BasicPWEvent( evtRec.EventId, evtRec.DateTime, evtRec.Open, evtRec.ProcessedDateTime, evtRec.EventType, evtRec.EventSource, evtRec.ActingPersonId, evtRec.AffectedPersonId, organizationId, evtRec.GeographyId, evtRec.ParameterInt, parameterText); recs.Add(addR); } } } parameterText = split1[1]; BasicPWEvent addR2 = new BasicPWEvent( evtRec.EventId, evtRec.DateTime, evtRec.Open, evtRec.ProcessedDateTime, evtRec.EventType, evtRec.EventSource, evtRec.ActingPersonId, evtRec.AffectedPersonId, evtRec.OrganizationId, evtRec.GeographyId, evtRec.ParameterInt, parameterText); recs.Add(addR2); } break; case EventType.AddedMembership: { parameterText = FindIPForEventInLog(evtRec.DateTime, evtRec.AffectedPersonId, evtRec.ActingPersonId); BasicPWEvent addR2 = new BasicPWEvent( evtRec.EventId, evtRec.DateTime, evtRec.Open, evtRec.ProcessedDateTime, evtRec.EventType, evtRec.EventSource, evtRec.ActingPersonId, evtRec.AffectedPersonId, evtRec.OrganizationId, evtRec.GeographyId, evtRec.ParameterInt, parameterText); recs.Add(addR2); } break; case EventType.ExtendedMembership: { string[] split1 = ("" + evtRec.ParameterText).Split(' '); if (split1.Length < 1 || split1[0].Trim() == "") { if (split1.Length < 1) { split1 = new string[1]; } split1[0] = FindIPForEventInLog(evtRec.DateTime, evtRec.AffectedPersonId, evtRec.ActingPersonId); } if (split1.Length > 1) { foreach (string orgnr in split1) { if (orgnr.Length < 7 && int.Parse(orgnr) != evtRec.OrganizationId) { organizationId = int.Parse(orgnr); parameterText = split1[0]; BasicPWEvent addR = new BasicPWEvent( evtRec.EventId, evtRec.DateTime, evtRec.Open, evtRec.ProcessedDateTime, evtRec.EventType, evtRec.EventSource, evtRec.ActingPersonId, evtRec.AffectedPersonId, organizationId, evtRec.GeographyId, evtRec.ParameterInt, parameterText); recs.Add(addR); } } } parameterText = split1[0]; BasicPWEvent addR2 = new BasicPWEvent( evtRec.EventId, evtRec.DateTime, evtRec.Open, evtRec.ProcessedDateTime, evtRec.EventType, evtRec.EventSource, evtRec.ActingPersonId, evtRec.AffectedPersonId, evtRec.OrganizationId, evtRec.GeographyId, evtRec.ParameterInt, parameterText); recs.Add(addR2); } break; } } } if (recs.Count > 0) { personLogs[recs[0].AffectedPersonId] = recs; } } }