Example #1
0
        public static void EnsureNHibernateData()
        {
            SQLAppRepository appRep = new SQLAppRepository();
            SQLLogRepository logRep = new SQLLogRepository();

            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"
                });

                AppDto app1 = appRep.GetByName("Applicazione 1");
                AppDto app2 = appRep.GetByName("Applicazione 2");

                logRep.Save(new LogDto {
                    App = app1, Level = "Info", LogDate = DateTime.Now, Message = "Test message 1"
                });
                logRep.Save(new LogDto {
                    App = app1, Level = "Warn", LogDate = DateTime.Now, Message = "Test message 2"
                });
                logRep.Save(new LogDto {
                    App = app1, Level = "Info", LogDate = DateTime.Now, Message = "Test message 3"
                });
                logRep.Save(new LogDto {
                    App = app1, Level = "Error", LogDate = DateTime.Now, Message = "Test message 4"
                });

                logRep.Save(new LogDto {
                    App = app2, Level = "Info", LogDate = DateTime.Now, Message = "Test message 5"
                });
                logRep.Save(new LogDto {
                    App = app2, Level = "Error", LogDate = DateTime.Now, Message = "Test message 6"
                });
                logRep.Save(new LogDto {
                    App = app2, Level = "Info", LogDate = DateTime.Now, Message = "Test message 7"
                });
                logRep.Save(new LogDto {
                    App = app2, Level = "Warn", LogDate = DateTime.Now, Message = "Test message 8"
                });
            }
        }
Example #2
0
        public HttpResponseMessage SQLReport()
        {
            HttpResponseMessage data;

            using (MeasuredMethod m = new MeasuredMethod("SQLReport"))
            {
                XSSFWorkbook     workbook = new XSSFWorkbook();
                SQLAppRepository appRepo  = new SQLAppRepository();
                SQLLogRepository logRepo  = new SQLLogRepository();
                List <AppDto>    apps     = appRepo.GetAll();
                foreach (AppDto app in apps)
                {
                    ISheet        worksheet = workbook.CreateSheet(app.Name);
                    List <LogDto> logs      = logRepo.GetLogsByAppId(app.Id);
                    BuildExcel(ref worksheet, logs);
                }

                data = SendExcel(workbook, "SQLReport.xlsx");
            }
            return(data);
        }
Example #3
0
        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();
                    }
                }
            }
        }