Пример #1
0
 public void ConfigureServices(IServiceCollection services)
 {
     // Application-specific singletons.
     services.AddSingleton(new CountryResolver());
     services.AddSingleton(new PageProvider(loggerFactory, env.IsDevelopment()));
     services.AddSingleton(new Sampler(loggerFactory, config["sampleFileName"]));
     resultRepo = new ResultRepo(loggerFactory, config["dbFileName"]);
     services.AddSingleton(resultRepo);
     // MVC for serving pages and REST
     services.AddMvc();
     // Configuration singleton
     services.AddSingleton <IConfiguration>(sp => { return(config); });
 }
Пример #2
0
        public override void Process()
        {
            string fileNameFull = Path.GetFullPath("../_work/90-dbstress.db");

            Console.WriteLine("DB file: " + fileNameFull);
            if (File.Exists(fileNameFull))
            {
                File.Delete(fileNameFull);
            }
            DateTime      date   = DateTime.Now;
            Stopwatch     watch  = new Stopwatch();
            List <string> ids    = new List <string>();
            int           cycles = 10;

            Console.WriteLine("Stopwatch > Frequency: " + Stopwatch.Frequency + "; IsHighResolution: " + Stopwatch.IsHighResolution);

            using (ResultRepo rr = new ResultRepo(null, fileNameFull))
            {
                for (int i = 0; i < cycles; ++i)
                {
                    StoredResult sr = new StoredResult("NNN", date, 0, 0, 1200, encRes, encSurv);

                    // Store a single item: measure time
                    watch.Restart();
                    string uid     = rr.StoreResult(sr);
                    long   msStore = watch.ElapsedMilliseconds;
                    ids.Add(uid);
                    // Retrieve all UIDs
                    watch.Restart();
                    foreach (string x in ids)
                    {
                        rr.LoadScore(x);
                    }
                    long msLoad = watch.ElapsedMilliseconds / ids.Count;
                    // Speak out
                    Console.WriteLine("Cycle " + (i + 1).ToString("00") + " > Store: " + msStore.ToString("000") + " msec; load: " + msLoad.ToString("000") + " msec");

                    // No time wasted storing the very last batch
                    if (i == cycles - 1)
                    {
                        break;
                    }
                    // Store 50k items
                    rr.StoreBatch(sr, 50000);
                    // Next day :)
                    date = date.AddDays(1);
                }
            }
        }
Пример #3
0
        private void storeFun(object para)
        {
            ResultRepo rr    = para as ResultRepo;
            Stopwatch  watch = new Stopwatch();

            Thread.Sleep(2000);
            while (finished == 0)
            {
                watch.Restart();
                StoredResult sr = new StoredResult("NNN", DateTime.Now, 0, 0, 1200, encRes, encSurv);
                rr.StoreResult(sr);
                long msec = watch.ElapsedMilliseconds;
                Console.WriteLine("Worker thread stored new result in " + msec + " msec.");
                Thread.Sleep(2000);
            }
        }
Пример #4
0
        public void ConfigureServices(IServiceCollection services)
        {
            if (env.IsDevelopment())
            {
                services.AddLogging(loggingBuilder => loggingBuilder.AddConsole());
            }

            // Application-specific singletons.
            services.AddSingleton(new CountryResolver());
            services.AddSingleton(new PageProvider(loggerFactory, env.IsDevelopment()));
            services.AddSingleton(new Sampler(loggerFactory, config["sampleFileName"]));
            resultRepo = new ResultRepo(loggerFactory, config["dbFileName"]);
            services.AddSingleton(resultRepo);
            // MVC for serving pages and REST
            services.AddMvc(options =>
            {
                options.EnableEndpointRouting = false;
            }).AddRazorRuntimeCompilation();
            // Configuration singleton
            services.AddSingleton <IConfiguration>(sp => { return(config); });
        }
Пример #5
0
        public override void Process()
        {
            string fileNameFull = Path.GetFullPath("../_work/90-dbstress.db");

            Console.WriteLine("DB file: " + fileNameFull);
            string outFileNameFull = Path.GetFullPath("../_work/90-dbstress-dump.txt");

            Console.WriteLine("Dump file: " + outFileNameFull);
            ResultRepo rr = new ResultRepo(null, fileNameFull);

            Console.WriteLine("Results DB loaded.");
            Stopwatch watch = new Stopwatch();

            watch.Restart();
            ThreadPool.QueueUserWorkItem(storeFun, rr);
            rr.DumpToFile(outFileNameFull);
            finished = 1;
            long msec = watch.ElapsedMilliseconds;

            Console.WriteLine("Dump completed in " + msec + " msec.");
        }
Пример #6
0
 public UnitOfWork(ExamicaDbContext _context)
 {
     context              = _context;
     Answers              = new AnswerRepo(_context);
     AppUsers             = new AppUserRepo(_context);
     ComplexQuestions     = new ComplexQuestionRepo(_context);
     ExamAppUsers         = new ExamAppUserRepo(_context);
     ExamComplexQuestions = new ExamComplexQuestionRepo(_context);
     ExamQuestions        = new ExamQuestionRepo(_context);
     Exams                    = new ExamRepo(_context);
     Options                  = new OptionRepo(_context);
     OrganizationAdmins       = new OrganizationAdminRepo(_context);
     organizationExaminees    = new OrganizationExamineeRepo(_context);
     OrganizationExaminers    = new OrganizationExaminerRepo(_context);
     OrganizationObservers    = new OrganizationObsereverRepo(_context);
     Organizations            = new OrganizationRepo(_context);
     QuestionComplexQuestions = new QuestionComplexQuestionRepo(_context);
     Questions                = new QuestionRepo(_context);
     QuestionOptions          = new QuestionOptionRepo(_context);
     Results                  = new ResultRepo(_context);
     PricingPlans             = new PricingPlanRepo(_context);
 }
Пример #7
0
        public static void ProcessResultsData(OdbcDataReader reader, string fileName, string resultType)
        {
            CompetitionEntity comp = new CompetitionEntity();

            comp = CompetitionRepo.GetCompetition(fileName);
            int resultsCount = 0, resultsInserted = 0;

            logger.Info($"Started Processing : {resultType}");
            while (reader.Read())
            {
                resultsCount++;
                try
                {
                    //Console.WriteLine(reader["Full_Eventname"].ToString() + reader["Rnd_ltr"].ToString() + reader["First_name"].ToString() + reader["Last_name"].ToString() + reader["Team_Abbr"].ToString() + reader["Reg_no"].ToString() + reader["Res_markDisplay"].ToString() + reader["Res_wind"].ToString() + reader["Res_place"].ToString());
                    String   division    = reader["Div_name"].ToString();
                    string   eventGender = reader["Event_gender"].ToString();
                    string   eventName   = "";
                    DateTime Birth_date;
                    if (reader["Birth_date"].ToString() == "")
                    {
                        Birth_date = DateTime.Parse("1900-01-01 00:00:00");
                    }
                    else
                    {
                        Birth_date = DateTime.Parse(reader["Birth_date"].ToString());
                    }

                    if (division.Contains("AMB"))
                    {
                        division = division.Replace("AMB", "Ambulatory");
                    }
                    if (division.Contains("WC"))
                    {
                        division = division.Replace("WC", "Wheelchair");
                    }

                    string[] div_categories = { "U6", "U8", "U10", "U12", "U14", "U16", "U18" };
                    if (div_categories.Contains(division))
                    {
                        if (eventGender.Equals("M"))
                        {
                            eventGender = "Boys";
                        }
                        else if (eventGender.Equals("F"))
                        {
                            eventGender = "Girls";
                        }
                        else
                        {
                            eventGender = "Mixed";
                        }
                    }
                    else
                    if (eventGender.Equals("M"))
                    {
                        eventGender = "Men";
                    }
                    else if (eventGender.Equals("F"))
                    {
                        eventGender = "Women";
                    }
                    else
                    {
                        eventGender = "Mixed";
                    }

                    //for masters
                    if (division.Equals("Masters"))
                    {
                        DateTime sdate = comp.StartDate;
                        int      Years = new DateTime(sdate.Subtract(Birth_date).Ticks).Year - 1;
                        if (Years < 30)
                        {
                            division = "29 & Under Masters";
                        }
                        else if (Years < 35)
                        {
                            division = "30 Masters";
                        }
                        else if (Years < 40)
                        {
                            division = "35 Masters";
                        }
                        else if (Years < 45)
                        {
                            division = "40 Masters";
                        }
                        else if (Years < 50)
                        {
                            division = "45 Masters";
                        }
                        else if (Years < 55)
                        {
                            division = "50 Masters";
                        }
                        else if (Years < 60)
                        {
                            division = "55 Masters";
                        }
                        else if (Years < 65)
                        {
                            division = "60 Masters";
                        }
                        else if (Years < 70)
                        {
                            division = "65 Masters";
                        }
                        else if (Years < 75)
                        {
                            division = "70 Masters";
                        }
                        else if (Years < 80)
                        {
                            division = "75 Masters";
                        }
                        else
                        {
                            division = "80 Masters";
                        }
                    }
                    if (reader["Event_name"].ToString().Contains("athlon"))//combined events
                    {
                        if (!reader["Event_dist"].ToString().Equals("0"))
                        {
                            if (!reader["Event_note"].ToString().Equals(""))
                            {
                                eventName = reader["Event_dist"].ToString() + " Meters " + reader["MultiSubEvent_name"].ToString() + " " + reader["Event_name"].ToString() + " " + reader["Event_note"].ToString();
                            }
                            else
                            {
                                eventName = reader["Event_dist"].ToString() + " Meters " + " " + reader["MultiSubEvent_name"].ToString() + " " + reader["Event_name"].ToString();
                            }
                        }
                        else
                        if (!reader["Event_note"].ToString().Equals(""))
                        {
                            eventName = reader["MultiSubEvent_name"].ToString() + " " + reader["Event_name"].ToString() + " " + reader["Event_note"].ToString();
                        }
                        else
                        {
                            eventName = reader["MultiSubEvent_name"].ToString() + " " + reader["Event_name"].ToString();
                        }
                    }
                    else
                    {
                        if (!reader["Event_dist"].ToString().Equals("0"))
                        {
                            if (!reader["Event_note"].ToString().Equals(""))
                            {
                                eventName = reader["Event_dist"].ToString() + " Meters " + reader["Event_name"].ToString() + " " + reader["Event_note"].ToString();
                            }
                            else
                            {
                                eventName = reader["Event_dist"].ToString() + " Meters " + reader["Event_name"].ToString();
                            }
                        }
                        else
                        if (!reader["Event_note"].ToString().Equals(""))
                        {
                            eventName = reader["Event_name"].ToString() + " " + reader["Event_note"].ToString();
                        }
                        else
                        {
                            eventName = reader["Event_name"].ToString();
                        }
                    }
                    eventName = eventName.Trim();
                    String Rnd_ltr         = reader["Rnd_ltr"].ToString();
                    String First_name      = reader["First_name"].ToString();
                    String Last_name       = reader["Last_name"].ToString();
                    String Team_Abbr       = reader["Team_Abbr"].ToString();
                    String Reg_no          = reader["Reg_no"].ToString();
                    String Ath_Sex         = reader["Ath_Sex"].ToString();
                    String Res_markDisplay = reader["Res_markDisplay"].ToString();
                    String Res_wind        = reader["Res_wind"].ToString();
                    String Res_place       = reader["Res_place"].ToString();

                    ResultEntity result  = new ResultEntity();
                    int          eventId = AthleteEventRepo.GetAthleteEventId(eventGender + " " + eventName + " " + division, Rnd_ltr);
                    if (eventId == 0)
                    {
                        AthleteEventEntity athleteEvent = new AthleteEventEntity();
                        athleteEvent.EventGender   = eventGender;
                        athleteEvent.EventRound    = Rnd_ltr;
                        athleteEvent.EventDivision = division;
                        athleteEvent.EventName     = eventName;
                        AthleteEventRepo.AddAthleteEvent(athleteEvent);
                        eventId = AthleteEventRepo.GetAthleteEventId(eventGender + " " + eventName + " " + division, Rnd_ltr);
                    }
                    int athleteid = 0;
                    athleteid = AthleteRepo.GetAthleteIdByACNum(Reg_no);
                    if (athleteid == 0)
                    {
                        athleteid = AthleteRepo.GetAthleteIdByName(First_name, Last_name, Birth_date);
                        if (athleteid == 0)
                        {
                            AthleteEntity athlete = new AthleteEntity();
                            athlete.ACNum = Reg_no;
                            athlete.ClubAffiliationSince = comp.StartDate;
                            athlete.ClubCode             = Team_Abbr;
                            athlete.DOB                  = Birth_date;
                            athlete.FirstName            = First_name;
                            athlete.LastName             = Last_name;
                            athlete.AthleteGender        = Ath_Sex;
                            athlete.Address              = "";
                            athlete.City                 = "";
                            athlete.AthleteEmail         = "";
                            athlete.Phone                = "";
                            athlete.HeadShot             = "";
                            athlete.AthleteSpecialNoteId = 0;
                            AthleteRepo.AddAthlete(athlete);
                            if (String.IsNullOrWhiteSpace(Reg_no))
                            {
                                result.AthleteId = AthleteRepo.GetAthleteIdByName(First_name, Last_name, Birth_date);
                            }
                            else
                            {
                                result.AthleteId = AthleteRepo.GetAthleteIdByACNum(Reg_no);
                            }
                        }
                        else
                        {
                            result.AthleteId = athleteid;
                        }
                    }
                    else
                    {
                        result.AthleteId = athleteid;
                    }

                    result.CompId  = GetCompId(fileName);
                    result.EventId = eventId;
                    result.Mark    = Res_markDisplay;
                    if (reader["Event_name"].ToString().Contains("athlon"))
                    {
                        result.Position = Convert.ToInt32(reader["Event_score"].ToString());
                    }
                    else
                    {
                        result.Position = Convert.ToInt32(Res_place);
                    }
                    result.Wind = Res_wind;

                    if (ResultRepo.CheckDuplicate(result) == 0)
                    {
                        ResultRepo.AddResult(result);
                        resultsInserted++;
                    }
                    else
                    {
                        logger.Error("Duplicate Result: " + fileName.Replace(".mdb", "") + "->" + eventGender + " " + eventName + " " + division + " " + Rnd_ltr + "->" + First_name + " " + Last_name + " DOB: " + Birth_date.ToString("dd-MM-yyyy"));
                    }
                }
                catch (Exception e)
                {
                    logger.Error("Exception : " + e.Message);
                }
                finally { }
            }
            logger.Info($"Total lines read by application : {resultsCount}");
            logger.Info($"Total results synced to database : {resultsInserted}");
            logger.Info($"Completed Processing : {resultType}");
        }
Пример #8
0
        public static void ProcessResultsData(OdbcDataReader reader, string fileName)
        {
            logger.Info("Started Processing Result Details/Standard");
            while (reader.Read())
            {
                try
                {
                    //Console.WriteLine(reader["Full_Eventname"].ToString() + reader["Rnd_ltr"].ToString() + reader["First_name"].ToString() + reader["Last_name"].ToString() + reader["Team_Abbr"].ToString() + reader["Reg_no"].ToString() + reader["Res_markDisplay"].ToString() + reader["Res_wind"].ToString() + reader["Res_place"].ToString());
                    String Full_Eventname = reader["Full_Eventname"].ToString();
                    if (Full_Eventname.Contains("AMB"))
                    {
                        Full_Eventname = Full_Eventname.Replace("AMB", "Ambulatory");
                    }
                    if (Full_Eventname.Contains("WC"))
                    {
                        Full_Eventname = Full_Eventname.Replace("WC", "Wheelchair");
                    }

                    String   Rnd_ltr    = reader["Rnd_ltr"].ToString();
                    String   First_name = reader["First_name"].ToString();
                    String   Last_name  = reader["Last_name"].ToString();
                    String   Team_Abbr  = reader["Team_Abbr"].ToString();
                    String   Reg_no     = reader["Reg_no"].ToString();
                    DateTime Birth_date;
                    if (reader["Birth_date"].ToString() == "")
                    {
                        Birth_date = DateTime.Parse("1900-01-01 00:00:00");
                    }
                    else
                    {
                        Birth_date = DateTime.Parse(reader["Birth_date"].ToString());
                    }
                    String Ath_Sex         = reader["Ath_Sex"].ToString();
                    String Res_markDisplay = reader["Res_markDisplay"].ToString();
                    String Res_wind        = reader["Res_wind"].ToString();
                    String Res_place       = reader["Res_place"].ToString();

                    ResultEntity result = new ResultEntity();

                    if (AthleteEventRepo.GetAthleteEventId(Full_Eventname, Rnd_ltr) == 0)
                    {
                        string[]           words        = Full_Eventname.Split(' ');
                        List <string>      wList        = new List <string>(words);
                        AthleteEventEntity athleteEvent = new AthleteEventEntity();
                        athleteEvent.EventGender   = words[0];
                        athleteEvent.EventRound    = Rnd_ltr;
                        athleteEvent.EventDivision = words[words.Length - 1];
                        //athleteEvent.Name = Full_Eventname.Replace(words[0], "").Replace(words[words.Length-1], "").Trim();
                        wList.RemoveAt(0);
                        wList.RemoveAt(wList.Count - 1);
                        athleteEvent.EventName = string.Join(" ", wList);
                        AthleteEventRepo.AddAthleteEvent(athleteEvent);
                    }

                    if (AthleteRepo.GetAthleteIdByACNum(Reg_no) == 0)
                    {
                        if (AthleteRepo.GetAthleteIdByName(First_name, Last_name, Birth_date) == 0)
                        {
                            AthleteEntity athlete = new AthleteEntity();
                            athlete.ACNum = Reg_no;
                            athlete.ClubAffiliationSince = DateTime.Now;
                            athlete.ClubCode             = Team_Abbr;
                            athlete.DOB                  = Birth_date;
                            athlete.FirstName            = First_name;
                            athlete.LastName             = Last_name;
                            athlete.AthleteGender        = Ath_Sex;
                            athlete.Address              = "";
                            athlete.City                 = "";
                            athlete.AthleteEmail         = "";
                            athlete.Phone                = "";
                            athlete.HeadShot             = "";
                            athlete.AthleteSpecialNoteId = 0;
                            AthleteRepo.AddAthlete(athlete);
                            result.AthleteId = AthleteRepo.GetAthleteIdByName(First_name, Last_name, Birth_date);
                        }
                        else
                        {
                            result.AthleteId = AthleteRepo.GetAthleteIdByName(First_name, Last_name, Birth_date);
                        }
                    }
                    else
                    {
                        result.AthleteId = AthleteRepo.GetAthleteIdByACNum(Reg_no);
                    }

                    result.CompId   = GetCompId(fileName);
                    result.EventId  = AthleteEventRepo.GetAthleteEventId(Full_Eventname, Rnd_ltr);
                    result.Mark     = Res_markDisplay;
                    result.Position = Convert.ToInt32(Res_place);
                    result.Wind     = Res_wind;

                    if (ResultRepo.CheckDuplicate(result) == 0)
                    {
                        ResultRepo.AddResult(result);
                    }
                    else
                    {
                        logger.Error("Duplicate Result: " + fileName.Replace(".mdb", "") + "->" + Full_Eventname + " " + Rnd_ltr + "->" + First_name + " " + Last_name + " DOB: " + Birth_date.ToString("dd-MM-yyyy"));
                    }
                }
                catch (Exception e)
                {
                    logger.Error("Exception : " + e.Message);
                }
                //finally { reader.Close(); }
            }
            logger.Info("Completed Processing Result Details/Standard");
        }