public void TestDBCon() { SearchDB dba = new SearchDB(); bool worked = dba.DBConnectionTest(); Assert.AreEqual(true, worked); }
static SearchDB GetDB(string path) { SearchDB db = new SearchDB(); // check if theres a db to read if (File.Exists(path)) { Console.WriteLine("reading from db"); var dbData = File.ReadAllText(path); try { db = JsonConvert.DeserializeObject <SearchDB>(dbData); } catch (Exception e) { Console.WriteLine("invalid db reseting"); db = new SearchDB(); UpdateDB(path, db); } } else { // if the db doesnt exist create it for later updating Console.WriteLine("creating db"); File.WriteAllText(path, JsonConvert.SerializeObject(db)); } return(db); }
static void IndexFiles(SearchDB db, string dbPath) { var storingFolder = "IndexedFiles"; var folder = "C:\\Users\\yehuda nahon\\Documents\\books"; // check the path is a valid path if (!IsDirectory(folder)) { Console.WriteLine("path is not a directory"); } if (!Directory.Exists(storingFolder)) { Directory.CreateDirectory(storingFolder); } Console.WriteLine("indexing files..."); var files = Directory.GetFiles(folder); db.IndexFiles(files, storingFolder); Console.WriteLine("updating data base"); try { UpdateDB(dbPath, db); } catch (Exception e) { Console.WriteLine("failed updating db"); } Console.WriteLine("finished writing to json file"); }
public async Task <SearchResult> GetResult(string sessionId) { bool isComplete = false; var final = new SearchResult() { Hotels = new List <Hotel>() }; var db = new SearchDB(); var res = await db.GetResult(sessionId); if (res.Count == 15) { isComplete = true; } foreach (var result in res) { final.Hotels.AddRange(result.Hotels); //foreach (var hotel in result.Hotels) //{ //} } final.Status = new Status { MoreResults = !isComplete }; return(final); }
static void UpdateDB(string path, SearchDB dB) { using (StreamWriter file = File.CreateText(path)) { JsonSerializer serializer = new JsonSerializer(); //serialize object directly into file stream serializer.Serialize(file, dB); } }
void Awake() { if (instance) { DestroyImmediate(gameObject); return; } instance = this; DontDestroyOnLoad(gameObject); }
public void InitSearch(string sessionId, SearchCriteria criteria) { Parallel.For(0, 15, async(i) => { await Task.Yield(); var randomizer = new Random(); await(Task.Delay(randomizer.Next(10000, 15000))); var supplier = new HotelSupplier(); var result = supplier.Search(criteria); var db = new SearchDB(); await db.StoreSearchResult(sessionId, i, result); }); }
/** * Wyszukiwanie * Ten sam mechanizm co przy dodawaniu **/ private List <Models.Activity> GetSearchList(int search) { var activities = new List <Models.Activity>(); switch (search) { case 1: //date DateTime?d_date = GetFromUser.GetDateFromUser(); if (d_date == null) { return(null); } DateTime date = d_date.Value; activities = SearchDB.SearchDate(date, user); break; case 2: //type var type = GetFromUser.GetTypeFromUser(); if (type == null) { return(null); } activities = SearchDB.SearchType(type, user); break; case 3: //distance var d_distance = GetFromUser.GetDistanceFromUser(); if (d_distance == null) { return(null); } var distance = d_distance.Value; activities = SearchDB.SearchDistance(distance, user); break; case 4: //note var note = GetFromUser.GetNoteFromUser(); if (note == "esc") { return(null); } activities = SearchDB.SearchNote(note, user); break; } return(activities); }
static void Search(SearchDB db) { Console.WriteLine("Enter the words to search"); var text = Console.ReadLine(); // split the text to words and make all words lowercase to fix abnormality (also removing all single letters words from the list) var punctuation = text.Where(Char.IsPunctuation).Distinct().ToArray(); var words = text.Split(new char[0], StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim(punctuation).ToLower()).Where(x => x.Length > 1); foreach (var word in words) { var files = db.SearchWord(word); Console.WriteLine(word + ":"); files.ForEach(file => Console.WriteLine("- " + file)); } }
public bool validateReservationNumber(int resNum) { SearchDB db = new SearchDB(); return(db.searchReservationDB(resNum) == 1 ? true : false); }
public IActionResult Search([Bind("IsCustomDutyPaid,NumberOfSeates,NumberOfDoors,IsRegistered,IsNonSmokingVehicle,//Owners,HasParkingCamera,HasParkingSensors,HasCentralDoorLock,HasPanoramaRoof,HasSportPackage,HasElectricHeatedSeats,HasAirCondition,IsUsed,Interior,Make,Model,City,Kilometers,Fuel,CubicCapacity,IsManual,Color,PriceFrom,PriceTo,ProductionYearFrom,ProductionYearTo,NumberOfDoors")] SearchDB search) { var result = _context.Vehicles.Where(d => d.Brand == search.Make); if (!string.IsNullOrEmpty(search.Model)) { result = result.Where(d => d.Model == search.Model); } if (!string.IsNullOrEmpty(search.City)) { result = result.Where(d => d.City == search.City); } if (!string.IsNullOrEmpty(search.Fuel)) { result = result.Where(d => d.Fuel == search.Fuel); } if (search.Kilometers > 0) { result = result.Where(d => d.Kilometers == search.Kilometers); } if (search.CubicCapacity > 0) { result = result.Where(d => d.CubicCapacity == search.CubicCapacity); } if (search.IsManual == true) { result = result.Where(d => d.IsManual == search.IsManual); } if (search.IsCustomDutyPaid == true) { result = result.Where(d => d.CubicCapacity == search.CubicCapacity); } if (search.PriceFrom > 0) { result = result.Where(d => d.Price >= search.PriceFrom); } if (search.PriceTo > search.PriceFrom) { result = result.Where(d => d.Price <= search.PriceTo); } if (search.ProductionYearFrom >= DateTime.Now.AddYears(-100).Year) { result = result.Where(d => d.ProductionYear >= search.ProductionYearFrom); } if (search.ProductionYearTo > search.ProductionYearFrom) { result = result.Where(d => d.ProductionYear <= search.ProductionYearFrom); } //VhlDetails atributes if (!string.IsNullOrEmpty(search.Interior)) { result = result.Where(d => d.VehicleDetails.Any(l => l.Interior == search.Interior)); } if (search.NumberOfSeates > 0) { result = result.Where(d => d.VehicleDetails.Any(l => l.NumberOfSeates == search.NumberOfSeates)); } if (search.NumberOfDoors > 0) { result = result.Where(d => d.VehicleDetails.Any(l => l.NumberOfDoors == search.NumberOfDoors)); } if (search.IsRegistered == true) { result = result.Where(d => d.VehicleDetails.Any(l => l.IsRegistered == search.IsRegistered)); } if (search.IsNonSmokingVehicle == true) { result = result.Where(d => d.VehicleDetails.Any(l => l.IsNonSmokingVehicle == search.IsNonSmokingVehicle)); } if (search.Owners > 0) { result = result.Where(d => d.VehicleDetails.Any(l => l.Owners == search.Owners)); } if (search.HasParkingCamera == true) { result = result.Where(d => d.VehicleDetails.Any(l => l.HasParkingCamera == search.HasParkingCamera)); } if (search.HasParkingSensors == true) { result = result.Where(d => d.VehicleDetails.Any(l => l.HasParkingSensors == search.HasParkingSensors)); } if (search.HasCentralDoorLock == true) { result = result.Where(d => d.VehicleDetails.Any(l => l.HasCentralDoorLock == search.HasCentralDoorLock)); } if (search.HasPanoramaRoof == true) { result = result.Where(d => d.VehicleDetails.Any(l => l.HasPanoramaRoof == search.HasPanoramaRoof)); } if (search.HasSportPackage == true) { result = result.Where(d => d.VehicleDetails.Any(l => l.HasSportPackage == search.HasSportPackage)); } if (search.HasElectricHeatedSeats == true) { result = result.Where(d => d.VehicleDetails.Any(l => l.HasElectricHeatedSeats == search.HasElectricHeatedSeats)); } if (search.HasAirCondition == true) { result = result.Where(d => d.VehicleDetails.Any(l => l.HasAirCondition == search.HasAirCondition)); } if (search.IsUsed == true) { result = result.Where(d => d.VehicleDetails.Any(l => l.IsUsed == search.IsUsed)); } if (!string.IsNullOrEmpty(search.Color)) { result = result.Where(d => d.VehicleDetails.Any(l => l.Color == search.Color)); } if (search.IsCustomDutyPaid == true) { result = result.Where(d => d.VehicleDetails.Any(l => l.IsCustomDutyPaid == search.IsCustomDutyPaid)); } search.Result = result.ToList(); ViewData["Make"] = _context.CarsList.Select(d => d.Make).Distinct().ToList().Select(d => new SelectListItem { Value = d, Text = d }); return(View("Index", search)); }
public static int validateOwnerForPet(int resNum, int petNum) { SearchDB db = new SearchDB(); return(db.searchPetOwner(resNum, petNum)); }
public bool validateReservationForPet(int petNum, int resNum) { SearchDB db = new SearchDB(); return(db.searchReservationForPet(petNum, resNum) == 1 ? true : false); }
public bool validatePetResNum(int petResNum) { SearchDB db = new SearchDB(); return(db.searchPetResDB(petResNum) == 1 ? true : false); }
public char getPetSize(int petNumber) { SearchDB db = new SearchDB(); return(db.getPetSize(petNumber)); }
public bool validateConflictingReservations(int petNum, DateTime startDate, DateTime endDate) // checks if pet already has vaccination on those days { SearchDB db = new SearchDB(); return(db.searchConflictingReservations(petNum, startDate, endDate) == 0 ? true : false); }
public ActionResult Search(SearchDB searchFor) { return(View(searchFor)); }
public bool validateOwnerNumber(int ownNum) { SearchDB db = new SearchDB(); return(db.searchOwnerDB(ownNum) == 1 ? true : false); }
private void SearchButton_Click(object sender, RoutedEventArgs e) { var mainWindow = (MainWindow)Application.Current.MainWindow; List <Model1.Activity> activities = null; string comboBoxItem = (string)SearchComboBox.SelectedItem; switch (comboBoxItem) { case "type": string type = (string)TypeComboBox.SelectedItem; if (type != null) { activities = SearchDB.SearchType(type, user); } else { InfoLabel.Content = "Bad Data"; } break; case "distance": if (!string.IsNullOrEmpty(DistanceTextBox.Text)) { var distance = float.Parse(DistanceTextBox.Text); activities = SearchDB.SearchDistance(distance, user); } else { InfoLabel.Content = "Bad Data"; } break; case "date": if (DatePicker.SelectedDate != null) { DateTime date = DatePicker.SelectedDate.Value; activities = SearchDB.SearchDate(date, user); } else { InfoLabel.Content = "Bad Data"; } break; case "note": string note = NoteTextBox.Text; if (!string.IsNullOrEmpty(note)) { activities = SearchDB.SearchNote(note, user); } else { InfoLabel.Content = "Bad Data"; } break; } if (activities != null) { mainWindow.Frame.Navigate(new View.Activity.MainView(activities)); } }
public bool validateVaccNumber(int vaccNum) { SearchDB db = new SearchDB(); return(db.searchVaccDB(vaccNum) == 1 ? true : false); }
public List <Search> ReadSaleByBrandIdModelId(int brandId, int modelId) { return(SearchDB.ReadSaleByBrandIdModelId(brandId, modelId)); }