Exemple #1
0
 public Employee DefaultDriver()
 {
     using (CarraraSQL context = new CarraraSQL())
     {
         return(context.Employees.Find(DefaultDriverID));
     }
 }
Exemple #2
0
        public static Results <Employee> Employees(CarraraSQL.CarraraSQL context, string query)
        {
            Results <Employee> results = GetResults <Employee>(query, "Employees");

            int[] ids = results.Ids.Select(int.Parse).ToArray();
            results.List      = context.Employees.AsNoTracking().Where(x => ids.Contains(x.EmployeeID)).OrderBy(d => results.Ids.IndexOf(d.EmployeeID.ToString())).ToList();
            results.TotalHits = results.List.Count();
            return(results);
        }
 public Mark GetMark()
 {
     if (PourDetailID == 0)
     {
         return(new Mark
         {
             JobID = DefaultJobID.Value,
             MarkTypeID = DefaultMarkTypeID
         });
     }
     using (CarraraSQL context = new CarraraSQL())
     {
         return(context.Marks.Find(MarkID));
     }
 }
Exemple #4
0
        public static Results <Vehicle> Vehicles(bool?active, CarraraSQL.CarraraSQL context, string query)
        {
            Results <Vehicle> results = GetResults <Vehicle>(query, "Vehicles");

            int[] ids = results.Ids.Select(int.Parse).ToArray();
            if (active.HasValue)
            {
                results.List = context.Vehicles.AsNoTracking().Where(x => ids.Contains(x.VehicleID) && x.IsActive == active.Value).ToList();
            }
            else
            {
                results.List = context.Vehicles.AsNoTracking().Where(x => ids.Contains(x.VehicleID)).ToList();
            }
            results.List      = results.List.OrderBy(d => results.Ids.IndexOf(d.VehicleID.ToString())).ToList();
            results.TotalHits = results.List.Count();
            return(results);
        }
Exemple #5
0
        public static Results <Job> Jobs(bool?active, CarraraSQL.CarraraSQL context, string query)
        {
            Results <Job> results = GetResults <Job>(query, "Jobs");

            int[] ids = results.Ids.Select(int.Parse).ToArray();
            if (active.HasValue && active.Value)
            {
                results.List = context.Jobs.AsNoTracking().Where(x => ids.Contains(x.JobID) && x.JobStatusID.HasValue && x.JobStatusID.Value == 1).ToList();
            }
            else
            {
                results.List = context.Jobs.AsNoTracking().Where(x => ids.Contains(x.JobID)).ToList();
            }
            results.List      = results.List.OrderBy(d => results.Ids.IndexOf(d.JobID.ToString())).ToList();
            results.TotalHits = results.List.Count();
            return(results);
        }
Exemple #6
0
            private static void Vehicles()
            {
                Stopwatch stopWatch = new Stopwatch();

                using (CarraraSQL.CarraraSQL carraraSQL = new CarraraSQL.CarraraSQL())
                {
                    stopWatch.Start();
                    string result = "Ok";
                    try
                    {
                        // Get list of items, but only load the fields we need to maximize query speed
                        var items = (from item in carraraSQL.Vehicles
                                     select new
                        {
                            item.Make,
                            item.VehicleName,
                            item.VehicleCode,
                            item.VehicleTypeID,
                            item.VIN
                        }).ToList();
                        List <Document> list = new List <Document>();
                        foreach (var item in items)
                        {
                            // Create a new search document for this item
                            Document document = new Document();
                            string   code     = string.IsNullOrEmpty(item.VehicleCode) ? string.Empty : item.VehicleCode;
                            string   make     = string.IsNullOrEmpty(item.Make) ? string.Empty : item.Make;
                            string   name     = string.IsNullOrEmpty(item.VehicleName) ? string.Empty : item.VehicleName;
                            string   vin      = string.IsNullOrEmpty(item.VIN) ? string.Empty : item.VIN;
                            string   search   = string.Join(" ", new string[] { code, make, name, vin });
                            document.Add(new Field("Id", item.VehicleTypeID.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
                            // Apply a boost to the name field so it recieves priority over other fields
                            document.Add(new Field("Name", name, Field.Store.YES, Field.Index.ANALYZED)
                            {
                                Boost = 2f
                            });
                            document.Add(new Field("Search", search, Field.Store.YES, Field.Index.ANALYZED));
                            list.Add(document);
                        }
                        // Write the index to disk
                        Directory directory = FSDirectory.Open(IndexDirectory + "Vehicles");
                        Analyzer  analyzer  = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29, CharArraySet.EMPTY_SET);
                        using (IndexWriter writer = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED))
                        {
                            foreach (Document document in list)
                            {
                                writer.AddDocument(document);
                            }
                            writer.Optimize();
                        }
                        // Create a sepearate index for spell checking
                        using (IndexReader reader = IndexReader.Open(directory, true))
                        {
                            new SpellChecker.Net.Search.Spell.SpellChecker(directory).IndexDictionary(new LuceneDictionary(reader, "Search"));
                        }
                    }
                    catch (Exception ex)
                    {
                        result = ex.Message;
                    }
                    stopWatch.Stop();
                    using (DataContext dataContext = new DataContext())
                    {
                        dataContext.TaskLogs.Add(new TaskLog
                        {
                            Date         = DateTime.Now,
                            ElapsedTicks = stopWatch.ElapsedMilliseconds,
                            Result       = result,
                            Task         = "Rebuild Search Indexes: Contacts"
                        });
                        dataContext.SaveChanges();
                    }
                }
            }