public override List <LogDto> GetAll() { using (UnitOfNhibernate op = new UnitOfNhibernate()) { op.BeginTransaction(); List <SQLLogEntity> entity = op.Query <SQLLogEntity>().ToList(); return(ConvertEntityListToDtoList(entity)); } }
public override LogDto GetById(Guid Id) { using (UnitOfNhibernate op = new UnitOfNhibernate()) { op.BeginTransaction(); SQLLogEntity entity = op.Query <SQLLogEntity>().Where(x => x.Id.Equals(Id)).FirstOrDefault(); return(ConvertEntityToDto(entity)); } }
public AppDto GetByName(string Name) { using (UnitOfNhibernate op = new UnitOfNhibernate()) { op.BeginTransaction(); SQLAppEntity entity = op.Query <SQLAppEntity>().Where(x => x.Name.Equals(Name)).FirstOrDefault(); return(ConvertEntityToDto(entity)); } }
public List <LogDto> GetLogsByAppId(Guid AppId) { List <LogDto> result = new List <LogDto>(); using (UnitOfNhibernate op = new UnitOfNhibernate()) { op.BeginTransaction(); List <SQLLogEntity> entity = op.Query <SQLLogEntity>().Where(x => x.App.Id.Equals(AppId)).Take(10000).ToList(); result = ConvertEntityListToDtoList(entity); } return(result); }
public override void Delete(LogDto dto) { using (UnitOfNhibernate op = new UnitOfNhibernate()) { op.BeginTransaction(); SQLLogEntity entity = op.Query <SQLLogEntity>().Where(x => x.Id.Equals(dto.Id)).FirstOrDefault(); if (entity != null) { op.Delete(entity); } op.Commit(); } }
public List <LogReportDto> GetLogsReport() { List <LogReportDto> result = new List <LogReportDto>(); using (UnitOfNhibernate op = new UnitOfNhibernate()) { op.BeginTransaction(); List <AppDto> apps = (new SQLAppRepository()).GetAll(); result = op.Query <SQLLogEntity>().GroupBy(x => new { x.App.Id, x.App.Name, x.Level }).Select(y => new LogReportDto { Id = y.Key.Id, AppName = y.Key.Name, Level = y.Key.Level, Count = y.Count() }).ToList(); } return(result); }
public override void Save(AppDto dto) { using (UnitOfNhibernate op = new UnitOfNhibernate()) { op.BeginTransaction(); SQLAppEntity entity = op.Query <SQLAppEntity>().Where(x => x.Id.Equals(dto.Id)).FirstOrDefault(); if (entity == null) { entity = new SQLAppEntity(); } entity.Name = dto.Name; op.SaveOrUpdate(entity); op.Commit(); } }
private int CountLogs(Guid?SelectedApp, string TextToSearch) { using (UnitOfNhibernate op = new UnitOfNhibernate()) { op.BeginTransaction(); IEnumerable <SQLLogEntity> query = op.Query <SQLLogEntity>(); if (!string.IsNullOrEmpty(TextToSearch)) { query = query.Where(x => x.Message.Contains(TextToSearch)); } if (SelectedApp != null) { query = query.Where(x => x.App.Id.Equals(SelectedApp)); } return(query.Count()); } }
public override void Save(LogDto dto) { using (UnitOfNhibernate op = new UnitOfNhibernate()) { op.BeginTransaction(); SQLLogEntity entity = op.Query <SQLLogEntity>().Where(x => x.Id.Equals(dto.Id)).FirstOrDefault(); if (entity == null) { entity = new SQLLogEntity(); } entity.App = new SQLAppEntity { Id = dto.App.Id }; entity.Level = dto.Level; entity.LogDate = dto.LogDate; entity.Message = dto.Message; op.SaveOrUpdate(entity); op.Commit(); } }
public IPagedList <LogDto> Search(Guid?SelectedApp, string TextToSearch, int PageNum, int SizePage) { using (UnitOfNhibernate op = new UnitOfNhibernate()) { op.BeginTransaction(); IEnumerable <SQLLogEntity> query = op.Query <SQLLogEntity>(); if (!string.IsNullOrEmpty(TextToSearch)) { query = query.Where(x => x.Message.ToLower().Contains(TextToSearch.ToLower())); } if (SelectedApp != null) { query = query.Where(x => x.App.Id.Equals(SelectedApp)); } query = query.Skip((PageNum - 1) * SizePage); query = query.Take(SizePage); List <SQLLogEntity> entity = query.ToList(); List <LogDto> dto = ConvertEntityListToDtoList(entity); return(new StaticPagedList <LogDto>(dto.AsEnumerable <LogDto>(), PageNum, SizePage, CountLogs(SelectedApp, TextToSearch))); } }
public override void Delete(AppDto dto) { using (UnitOfNhibernate op = new UnitOfNhibernate()) { op.BeginTransaction(); SQLAppEntity entity = op.Query <SQLAppEntity>().Where(x => x.Id.Equals(dto.Id)).FirstOrDefault(); if (entity != null) { List <SQLLogEntity> logList = op.Query <SQLLogEntity>().Where(x => x.App.Id.Equals(entity.Id)).ToList(); if (logList != null && logList.Count > 0) { foreach (SQLLogEntity log in logList) { op.Delete(log); } } op.Delete(entity); op.Commit(); } } }
public static void EnsureData() { SQLAppRepository appRep = new SQLAppRepository(); SQLLogRepository SQLlogRep = new SQLLogRepository(); NoSQLLogRepository NoSQLlogRep = new NoSQLLogRepository(); LogRepository MixedlogRep = new LogRepository(); List <AppDto> apps = appRep.GetAll(); if (apps == null || apps.Count == 0) { appRep.Save(new AppDto { Name = "Applicazione 1" }); appRep.Save(new AppDto { Name = "Applicazione 2" }); appRep.Save(new AppDto { Name = "Applicazione 3" }); appRep.Save(new AppDto { Name = "Applicazione 4" }); appRep.Save(new AppDto { Name = "Applicazione 5" }); AppDto app1 = appRep.GetByName("Applicazione 1"); AppDto app2 = appRep.GetByName("Applicazione 2"); AppDto app3 = appRep.GetByName("Applicazione 3"); AppDto app4 = appRep.GetByName("Applicazione 4"); AppDto app5 = appRep.GetByName("Applicazione 5"); List <AppDto> listApp = appRep.GetAll(); List <string> levelList = new List <string>(); levelList.Add("Info"); levelList.Add("Error"); levelList.Add("Warn"); levelList.Add("Debug"); DateTime start = new DateTime(1995, 1, 1); int range = (DateTime.Today - start).Days; Random rand = new Random(); Random randLevel = new Random(); Random randDate = new Random(); using (StreamReader sr = new StreamReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin\\la_divin.txt"), Encoding.GetEncoding(1252))) { using (UnitOfNhibernate op = new UnitOfNhibernate()) { op.BeginTransaction(); int i = 0; while (!sr.EndOfStream) { i++; string line = sr.ReadLine(); AppDto app = listApp[rand.Next(0, listApp.Count - 1)]; string level = levelList[randLevel.Next(0, levelList.Count - 1)]; DateTime date = start.AddDays(randDate.Next(0, range)).AddHours(randDate.Next(0, range)).AddMilliseconds(randDate.Next(0, range)).AddMinutes(randDate.Next(0, range)).AddSeconds(randDate.Next(0, range)); LogEntity entity = new LogEntity { AppId = app.Id, Level = level, Message = line, LogDate = date }; op.SaveOrUpdate(entity); if (i % 100000 == 0) { op.Commit(); } //SQLlogRep.Save(new LogDto { App = app, Level = level, Message = line, LogDate = date }); NoSQLlogRep.Save(new LogDto { App = app, Level = level, Message = line, LogDate = date }); MixedlogRep.Save(new LogDto { App = app, Level = level, Message = line, LogDate = date }); } op.Commit(); } } } }