Пример #1
0
 public VisitItemsRepository(
     IDateTimeProvider dateTimeProvider,
     DemoDataContext dataContext
     )
 {
     _dateTimeProvider = dateTimeProvider;
     _dataContext      = dataContext;
 }
Пример #2
0
 public ResourcesRepository(
     IDateTimeProvider dateTimeProvider,
     DemoDataContext dataContext
     )
 {
     _dateTimeProvider = dateTimeProvider;
     _dataContext      = dataContext;
 }
Пример #3
0
 public PatientsRepository(
     IDateTimeProvider dateTimeProvider,
     DemoDataContext dataContext
     )
 {
     _dateTimeProvider = dateTimeProvider;
     _dataContext      = dataContext;
 }
Пример #4
0
 public DispanserizationsRepository(
     IDateTimeProvider dateTimeProvider,
     DemoDataContext dataContext
     )
 {
     _dateTimeProvider = dateTimeProvider;
     _dataContext      = dataContext;
 }
Пример #5
0
 /// <summary>
 /// setup the database with some sample data
 /// </summary>
 public static void InitializeSampleDatabase()
 {
     using (DemoDataContext dataCtx = new DemoDataContext())
     {
         dataCtx.RunMigrations();
         dataCtx.EnsureFullTextIndices();
         LoadSampleData(dataCtx);
     }
 }
Пример #6
0
        /// <summary>
        /// some examples
        /// </summary>
        public static void ExampleFullTextQueries()
        {
            using (DemoDataContext dataCtx = new DemoDataContext())
            {
                //Boolean references https://dev.mysql.com/doc/refman/8.0/en/fulltext-boolean.html
                //simple find any text by Boyett
                long totalNotes = dataCtx.NotesWithFulltext.Count();

                Contact   oneCt    = dataCtx.Contacts.BooleanFullTextContains("Boyett").FirstOrDefault();
                Stopwatch watchOne = new Stopwatch();
                //Find all notes with ignorant or marriage in it
                watchOne.Start();
                List <NoteWithFulltext> matchOne = dataCtx.NotesWithFulltext.BooleanFullTextContains("ignorant marriage").ToList();
                watchOne.Stop();
                long ftElapsedMilliseconds = watchOne.ElapsedMilliseconds;
                Console.WriteLine($"using fulltext found {matchOne.Count} in {watchOne.ElapsedMilliseconds} milliseconds");

                //Now do it with a simple contains
                watchOne.Reset();
                watchOne.Start();
                List <NoteWithoutFulltext> matchOldFashioned = dataCtx.NotesWithoutFullText.Where(nt => nt.Note.Contains("ignorant") ||
                                                                                                  nt.Note.Contains("marriage") ||
                                                                                                  nt.Topic.Contains("marriage") ||
                                                                                                  nt.Topic.Contains("ignorant")).ToList();
                watchOne.Stop();
                long containsElapsedMilliseconds = watchOne.ElapsedMilliseconds;
                Console.WriteLine($"using contains found {matchOldFashioned.Count} in {watchOne.ElapsedMilliseconds} milliseconds");

                decimal percentImproved = ((decimal)containsElapsedMilliseconds / (decimal)ftElapsedMilliseconds);
                string  textPercent     = percentImproved.ToString("P2");
                Console.WriteLine($"FullText is {textPercent} %  better than Contains for searching accross {totalNotes} items");

                //Find all notes with ignorant and marriage in it
                List <NoteWithFulltext> matchTwo = dataCtx.NotesWithFulltext.BooleanFullTextContains("+ignorant +marriage").ToList();
                Console.WriteLine($"using fulltext found {matchTwo.Count} with complex rules '+ignorant +marriage'");

                //fully composable query example
                List <NoteWithFulltext> matchThree = dataCtx.NotesWithFulltext.BooleanFullTextContains("ignorant +marriage -wife")
                                                     .Where(nt => nt.Id < 50).ToList();
                Console.WriteLine($"combined fulltext and Where found {matchThree.Count} with complex rules '+ignorant +marriage -wife' ");

                //Search an pull back a sorter to sort the results by rank
                List <NoteWithFulltext> matchFourPointOne = dataCtx.NotesWithFulltext.NaturalLanguageFullTextSearch("what the hell?", out OrderedResultSetComparer <NoteWithFulltext> rankSorter).Where(f => f.Id > 0).ToList();
                Console.WriteLine($"Natural language fulltext  found {matchFourPointOne.Count} with complex rules 'what the hell?' ");
                matchFourPointOne.Sort(rankSorter);
                Console.WriteLine($"Results now sorted in ranking order ");

                List <NoteWithFulltext> matchFour = dataCtx.NotesWithFulltext.Where(f => f.Id > 0).NaturalLanguageFullTextSearch("what the hell?").ToList();
                Console.WriteLine($"Natural language fulltext  found {matchFour.Count} with complex rules 'what the hell?' ");

                //search again with natural language query expansion, ordered by score
                List <NoteWithFulltext> matchFive = dataCtx.NotesWithFulltext.NaturalLanguageFullTextSearchWithQueryExpansion("what the hell?").ToList();

                Console.WriteLine($"Natural language expanded fulltext  found {matchFive.Count} with complex rules 'what the hell?' ");
            }
        }
Пример #7
0
        private IServiceCollection ConfigureDemo(IServiceCollection services)
        {
            CurrentDateTimeProvider dateTimeProvider = new CurrentDateTimeProvider();
            DemoDataContext         dataContext      = new DemoDataContext(dateTimeProvider);

            services.AddTransient <IDateTimeProvider, CurrentDateTimeProvider>(sp => dateTimeProvider);
            services.AddTransient <IPatientsRepository, Demo.PatientsRepository>(sp => new Demo.PatientsRepository(dateTimeProvider, dataContext));
            services.AddTransient <IResourcesRepository, Demo.ResourcesRepository>(sp => new Demo.ResourcesRepository(dateTimeProvider, dataContext));
            services.AddTransient <ITimeItemsRepository, Demo.TimeItemsRepository>(sp => new Demo.TimeItemsRepository(dateTimeProvider, dataContext));
            services.AddTransient <IVisitItemsRepository, Demo.VisitItemsRepository>(sp => new Demo.VisitItemsRepository(dateTimeProvider, dataContext));
            services.AddTransient <IDispanserizationsRepository, Demo.DispanserizationsRepository>(sp => new Demo.DispanserizationsRepository(dateTimeProvider, dataContext));

            return(services);
        }
Пример #8
0
        static void Main(string[] args)
        {
            var db = new DemoDataContext();

            Console.Write("Nombre del nuevo log: ");
            var nuevoLog = new Log()
            {
                Text = Console.ReadLine()
            };

            if (!string.IsNullOrEmpty(nuevoLog.Text))
            {
                db.Logs.Add(nuevoLog);
                Console.WriteLine($"Guardando log {nuevoLog.Text}...");
                db.SaveChanges();
            }

            foreach (var log in db.Logs)
            {
                Console.WriteLine($"{log.Id} - {log.Text}");
            }
            Console.ReadLine();
        }
Пример #9
0
 /// <summary>
 /// loads sample data into the database.
 /// </summary>
 public static void LoadSampleData(DemoDataContext dataCtx, int numItems = 1000)
 {
     if (dataCtx.Contacts.Count() != numItems)
     {
         dataCtx.RemoveRange(dataCtx.Contacts.ToList());
         dataCtx.SaveChanges();
         dataCtx.RemoveRange(dataCtx.NotesWithoutFullText.ToList());
         dataCtx.SaveChanges();
         dataCtx.RemoveRange(dataCtx.NotesWithFulltext.ToList());
         dataCtx.SaveChanges();
         string[] emailDomains = new string[] { "gmail.com", "outlook.com", "yahoo.com", "balsamicsoftware.org" };
         foreach (NameInfo nameInfo in RandomStuff.RandomNames(numItems, emailDomains, null, 5))
         {
             Contact addMe = new Contact(nameInfo);
             dataCtx.Contacts.Add(addMe);
         }
         dataCtx.SaveChanges();
         for (int idx = 0; idx < numItems; idx++)
         {
             string           noteText  = RandomStuff.RandomSentance(100, 2048);
             string           noteTopic = RandomStuff.RandomSentance(50, 512);
             NoteWithFulltext noteWith  = new NoteWithFulltext
             {
                 Topic = noteTopic,
                 Note  = noteText
             };
             NoteWithoutFulltext noteWithOut = new NoteWithoutFulltext
             {
                 Topic = noteTopic,
                 Note  = noteText
             };
             dataCtx.NotesWithFulltext.Add(noteWith);
             dataCtx.NotesWithoutFullText.Add(noteWithOut);
             dataCtx.SaveChanges();
         }
     }
 }
Пример #10
0
 public DataFixture()
 {
     DateTimeProvider = new CurrentDateTimeProvider();
     DataContext      = new DemoDataContext(DateTimeProvider);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EmployeeRepository"/> class.
 /// </summary>
 /// <param name="demoDataContext">
 /// The demo data context.
 /// </param>
 public EmployeeRepository(DemoDataContext demoDataContext)
 {
     _demoDataContext = demoDataContext;
 }
        public async Task <APIDemoData> Get()
        {
            var context = new DemoDataContext();

            return(new APIDemoData(await context.GetList(), System.Environment.MachineName));
        }
Пример #13
0
 public UserRepository(DemoDataContext context)
 {
     _context = context;
 }