/// <summary> /// Tests the case where both threads arrive so both continue /// </summary> private bool Test2(int timeoutSeconds = 3) { _rendezvous = new Rendezvous(); _aThread = new Thread(DoSomething); _bThread = new Thread(DoSomething); var timeout = TimeSpan.FromSeconds(timeoutSeconds); var timeStarted = DateTime.UtcNow; _aThread.Start(); if (!_aThread.Join(timeout - (DateTime.UtcNow - timeStarted))) { // Thread A is blocking as it should timeStarted = DateTime.UtcNow; _bThread.Start(); if (_bThread.Join(timeout - (DateTime.UtcNow - timeStarted))) { // Thread B has passed the rendezvous point and finished return(true); } else { // Thread B is blocking, kill it _bThread.Abort(); } } return(false); }
private ProcessResult IsExistOtherRendezvous(Rendezvous rendezvous) { ProcessResult result = new ProcessResult(); DoctorManager doctorManager = new DoctorManager(); Doctor doctor = doctorManager.Select(rendezvous.DoctorId); List <Doctor> doctors = doctorManager.Doctors(); List <int> depDocList = doctors.Where(d => d.DepartmentId == doctor.DepartmentId).Select(d => d.Id).ToList(); List <Rendezvous> rendezvouses = Rendezvouses(DateTime.Today, null, null); bool any = rendezvouses.Any(r => r.PatientId == rendezvous.PatientId && depDocList.Contains(r.DoctorId)); if (any) { result.Errors.Add("Hastanın aynı bölüme aynı güne zaten randevusu var"); } if (!any) { foreach (Doctor _doctor in doctors) { if (Rendezvouses(DateTime.Today, _doctor.Id, null).Any(p => p.PatientId == rendezvous.PatientId && p.RendezvousTimeId == rendezvous.RendezvousTimeId)) { result.Errors.Add(String.Format("{0} {1} doktorunda aynı saatte randevu alınmış", _doctor.Name, _doctor.Surname)); } } } result.Result = result.Errors.Count > 0 ? Extensions.BLLResult.AlreadyFound : Extensions.BLLResult.Success; return(result); }
public ActionResult Calendar([Bind(Include = "TimeSlot,CustomerId,EmployeeId,IsUnavailable")] Rendezvous r) { if (ModelState.IsValid) { if (r.IsUnavailable != 2) { r.RendezvousId = new Random().Next() % 100000000; Debug.WriteLine(r.RendezvousId + " " + r.IsUnavailable + " " + r.EmployeeId + " " + r.TimeSlot); db.Rendezvouses.Add(r); db.SaveChanges(); } else { SqlConnection cn = new SqlConnection("Data Source=(localdb)\\MSSQLLocalDB; Initial Catalog=MVCKuaforContext-20180723110834; Integrated Security=True; MultipleActiveResultSets=True; AttachDbFilename=|DataDirectory|MVCKuaforContext-20180723110834.mdf"); cn.Open(); Debug.WriteLine(r.TimeSlot.ToString()); string timeconvert = r.TimeSlot.ToString("yyyy-MM-dd HH:mm:ss.fff"); using (SqlCommand command = new SqlCommand("DELETE FROM " + "Rendezvous" + " WHERE " + "timeslot = " + "'" + timeconvert + "'", cn)) { command.ExecuteNonQuery(); } } } else { Debug.WriteLine("Something is invalid."); } return(RedirectToAction("Calendar")); }
private void buttonEditFindRendezvous_ButtonClick(object sender, ButtonPressedEventArgs e) { Extensions.Extensions.ShowWaitForm(description: "Randevu bilgisi isteniyor..."); int id; object value = buttonEditFindRendezvous.EditValue; try { id = Convert.ToInt32(value); } catch (Exception) { XtraMessageBox.Show("Randevu numarası hatalı girildi.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } RendezvousSolClient client = Extensions.Extensions.GetRendezvousService(); rendezvous = client.Select(id); simpleButtonDelete.Enabled = rendezvous.IsNotNull(); simpleButtonUpdate.Enabled = rendezvous.IsNotNull(); if (rendezvous.IsNull()) { XtraMessageBox.Show(String.Format("{0} numaralı bir randevu bulunamadı.", id), "Uyarı!", MessageBoxButtons.OK, MessageBoxIcon.Warning); SplashScreenManager.CloseForm(false); return; } textEditPatientName.Text = String.Format("{0} {1}", rendezvous.Patient.Name, rendezvous.Patient.Surname); textEditDoctorName.Text = String.Format("{0} {1}", rendezvous.Doctor.Name, rendezvous.Doctor.Surname); textEditDate.Text = rendezvous.Date.ToString("D"); textEditTime.Text = rendezvous.RendezvousTime.StartTime.ToString(@"hh\:mm"); SplashScreenManager.CloseForm(false); }
// Creates the agents of the game. public void CreateAgents() { GameObject piece = null; Rendezvous = Children.First().Value.Location; Instantiate(rendezvousPrefab, Rendezvous.ToVector(), Quaternion.identity); int i = 0; foreach (ChildAgent agt in Children.Values) { piece = Instantiate(childPrefabs[i], agt.Location.ToVector(), Quaternion.identity); agt.Piece = piece.GetComponent <AgentPiece>(); AgentPieces.Add(agt.ID, piece); Agents.Add(agt.ID, agt); i++; } if (!ReferenceEquals(Cat, null)) { piece = Instantiate(catPrefab, Cat.Location.ToVector(), Quaternion.identity); Cat.Piece = piece.GetComponent <AgentPiece>(); Cat.Piece.clothsRnderer.color = Color.black; AgentPieces.Add(Cat.ID, piece); Agents.Add(Cat.ID, Cat); } }
private ProcessResult Verifyrendezvous(Rendezvous rendezvous) { ProcessResult result = new ProcessResult(); DoctorManager doctorManager = new DoctorManager(); Doctor doctor = doctorManager.Select(rendezvous.DoctorId); DepartmentManager departmentManager = new DepartmentManager(); Department department = departmentManager.Select(doctor != null ? doctor.DepartmentId : 0); PatientManager patientManager = new PatientManager(); Patient patient = patientManager.Select(rendezvous.PatientId); new RendezvousTimeManager(); if (rendezvous.PatientId <= 0) { result.Errors.Add(String.Format("Hasta bilgisi olmadan randevu alınamaz")); } if (doctor == null || rendezvous.DoctorId <= 0) { result.Errors.Add(String.Format("Doktor bilgisi olmadan randevu alınamaz")); } if (rendezvous.RendezvousTimeId <= 0) { result.Errors.Add(String.Format("Randevu saati bilgisi olmadan randevu alınamaz")); } if (rendezvous.Date < DateTime.Today) { result.Errors.Add(String.Format("Geriye dönük tarihe randevu alınamaz")); } if (department != null) { if (patient != null) { if (department.MinAge != null && department.MinAge > patient.GetAge()) { result.Errors.Add(String.Format("{0} aylıktan küçükler {1} bölümüne gidemez. Hastanın yaşı {2} ay", department.MinAge, department.Name, patient.GetAge())); } if (department.MaxAge != null && department.MaxAge < patient.GetAge()) { result.Errors.Add(String.Format("{0} aylıktan büyükler {1} bölümüne gidemez. Hastanın yaşı {2} ay", department.MaxAge, department.Name, patient.GetAge())); } if (department.Gender != null && department.Gender != patient.Gender) { result.Errors.Add(String.Format("{0} hastalar {1} bölümüne gidemez.", patient.Gender ? "Erkek" : "Kadın", department.Name)); } } } else { result.Errors.Add("Departman seçilmeden randevu alınamaz."); } result.Result = result.Errors.Count > 0 ? Extensions.BLLResult.NotVerified : Extensions.BLLResult.Verified; return(result); }
public Extensions.DataBaseResult Insert(ref Rendezvous newRendezvous) { using (MySqlHealthContext ctx = new MySqlHealthContext()) { if (!ctx.ServerIsEnable) { return(Extensions.DataBaseResult.ServerDisable); } ctx.Rendezvouses.Add(newRendezvous); return(ctx.SaveChanges() > -1 ? Extensions.DataBaseResult.Success : Extensions.DataBaseResult.Error); } }
public ActionResult Create(Rendezvous r) { try { rs.Add(r); rs.Commit(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ProcessResult Delete(int id) { ProcessResult result = new ProcessResult(); RendezvousManager rendezvousManager = new RendezvousManager(); Rendezvous rendezvous = rendezvousManager.Select(id); ExaminationManager examinationManager = new ExaminationManager(); foreach (Examination examination in examinationManager.Examinations(rendezvous.Date, rendezvous.DoctorId, null).Where(e => e.RendezvousId == id).ToList()) { examinationManager.Delete(examination.Id); } switch (_rendezvousDal.Delete(id)) { case DAL.Extensions.DataBaseResult.Success: result.Errors.Add("Randevu silindi"); result.Result = Extensions.BLLResult.Success; break; case DAL.Extensions.DataBaseResult.Referanced: result.Errors.Add("Silinmeye çalışılan randevu muayene olduğundan randevu silinemedi."); result.Result = Extensions.BLLResult.Referanced; break; case DAL.Extensions.DataBaseResult.NotFound: result.Errors.Add("Randevu bulunamadı"); result.Result = Extensions.BLLResult.NotFound; break; case DAL.Extensions.DataBaseResult.Error: result.Errors.Add("Randevu silinirken bir hata ile karşılaşıldı"); result.Result = Extensions.BLLResult.Error; break; case DAL.Extensions.DataBaseResult.ServerDisable: result.Result = Extensions.BLLResult.ServerDisable; result.Errors.Add(Extensions.ServerDisable); break; case DAL.Extensions.DataBaseResult.AlreadyFound: break; default: throw new ArgumentOutOfRangeException(); } return(result); }
public ActionResult Delete(int id, Rendezvous r) { try { Rendezvous c1 = new Rendezvous(); c1 = rs.GetById(id); rs.Delete(c1); rs.Commit(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult ByDate([Bind(Include = "TimeSlot,EmployeeId")] Rendezvous r) { if (ModelState.IsValid) { r.RendezvousId = new Random().Next() % 100000000; r.CustomerId = int.Parse(Session["ID"].ToString()); r.IsUnavailable = 0; Debug.WriteLine(r.RendezvousId + " " + r.IsUnavailable + " " + r.EmployeeId + " " + r.TimeSlot); db.Rendezvouses.Add(r); db.SaveChanges(); } else { Debug.WriteLine("Something is invalid."); } return(RedirectToAction("ByDate")); }
public bool Update(Rendezvous newInfoRendezvous) { using (MySqlHealthContext ctx = new MySqlHealthContext()) { Rendezvous rendezvous = ctx.Rendezvouses.FirstOrDefault(d => d.Id == newInfoRendezvous.Id); if (rendezvous == null) { return(false); } rendezvous.Date = newInfoRendezvous.Date; rendezvous.RendezvousTimeId = newInfoRendezvous.RendezvousTimeId; rendezvous.Patient = newInfoRendezvous.Patient; rendezvous.DoctorId = newInfoRendezvous.DoctorId; rendezvous.IsActive = newInfoRendezvous.IsActive; return(ctx.SaveChanges() > -1); } }
/* ----------------------------- * Test One * ---------------------------- */ // Proves that threads can proceed and it is in a reusable pattern // Slows one thread, so prove that the others are slowed along with it, this proves that the threads do not race ahead // Rendezvous, this is done internally by counting how many threads have passed, and a turnstile public static void TestOne() { Thread[] threadCollection = { new Thread(ThreadOperation), new Thread(ThreadOperation), new Thread(ThreadOperation) }; meetingPoint = new Rendezvous(threadCollection.Length); // Gives the thread a name and starts each of them int threadNumber = 0; foreach (Thread thread in threadCollection) { thread.Name = (++threadNumber).ToString(); thread.Start(); } }
public ActionResult Edit(int id, Rendezvous r) { try { Rendezvous x = rs.GetById(id); x.Description = r.Description; x.DateRendezVous = r.DateRendezVous; x.NomAssurance = r.NomAssurance; x.oks = r.oks; x.Insured_cin = r.Insured_cin; rs.Update(x); rs.Commit(); return(RedirectToAction("Index")); } catch { return(View()); } }
/// <summary> /// Tests the case where one thread arrives and the other does not arrive, so neither continue /// </summary> private bool Test1(int timeoutSeconds = 3) { _rendezvous = new Rendezvous(); _aThread = new Thread(DoSomething); _bThread = new Thread(DoSomething); var timeout = TimeSpan.FromSeconds(timeoutSeconds); var timeStarted = DateTime.UtcNow; _aThread.Start(); // Check if thread A is blocking if (_aThread.Join(timeout - (DateTime.UtcNow - timeStarted))) { return(false); } // Thread A is blocking as it should _bThread.Abort(); return(true); }
static void Main(string[] args) { Rendezvous<string> rendezvous = new Rendezvous<string>(); var inputColors = new[] { ConsoleColor.DarkRed, ConsoleColor.DarkGreen, ConsoleColor.DarkBlue, ConsoleColor.DarkYellow }; var outputColors = new[] { ConsoleColor.Red, ConsoleColor.Green, ConsoleColor.Blue, ConsoleColor.Yellow }; for (int i = 0; i < 4; i++) { Thread.Sleep(1000); new Thread((param) => { int n = (int)param; Random random = new Random(); for (int j = 0; true; j++) { Thread.Sleep(random.Next(2500, 4000)); string input = string.Concat(n, ":", j); WriteLineWithColor(inputColors[n], "Thread {0} --> {1}", n, input); string output = rendezvous.Exchange(input); WriteLineWithColor(outputColors[n], "Thread {0} <-- {1}", n, output); } }).Start(i); } }
/* ----------------------------- * Test Two * ---------------------------- */ // Proves that the first thread does not continue until the second hits the Rendezvous // The second thread starts when a user presses a key public static void TestTwo() { Thread[] threadCollection = { new Thread(ThreadOperation), new Thread(ThreadOperation) }; // Will purposely stop one of the threads, until the second one starts meetingPoint = new Rendezvous(2); // Gives the thread a name and starts each of them int threadNumber = 0; threadCollection[0].Name = (++threadNumber).ToString(); threadCollection[0].Start(); Console.WriteLine("Pressing any key allows to other thread to go to the Rendezvous"); Console.ReadLine(); Console.WriteLine("Key pressed!"); threadCollection[1].Name = (++threadNumber).ToString(); threadCollection[1].Start(); }
public Extensions.DataBaseResult Delete(int id) { using (MySqlHealthContext ctx = new MySqlHealthContext()) { if (!ctx.ServerIsEnable) { return(Extensions.DataBaseResult.ServerDisable); } bool b = ctx.Examinations.Any(e => e.RendezvousId == id && !e.IsActive); if (b) { return(Extensions.DataBaseResult.Referanced); } Rendezvous rendezvous = ctx.Rendezvouses.FirstOrDefault(d => d.Id == id); if (rendezvous == null) { return(Extensions.DataBaseResult.NotFound); } ctx.Rendezvouses.Remove(rendezvous); return(ctx.SaveChanges() > -1 ? Extensions.DataBaseResult.Success : Extensions.DataBaseResult.Error); } }
public WeightedMemberStrategy() { _members = new List <MemberStatus>(); _rdv = new Rendezvous(this); _wrr = new WeightedRoundRobin(this); }
// GET: Rendezvous/Delete/5 public ActionResult Delete(int id) { Rendezvous r = rs.GetById(id); return(View(r)); }
public bool Update(Rendezvous newInfoRendezvous) { return(_rendezvousDal.Update(newInfoRendezvous)); }
public ProcessResult Insert(Rendezvous newRendezvous, bool toExamination) { newRendezvous.IsActive = !toExamination; newRendezvous.Date = toExamination ? DateTime.Today : newRendezvous.Date; ProcessResult result = Verifyrendezvous(newRendezvous); if (result.Result != Extensions.BLLResult.Verified) { return(result); } result = IsHoliday(newRendezvous.Date); if (result.Result != Extensions.BLLResult.Success) { return(result); } result = IsExistOtherRendezvous(newRendezvous); if (result.Result == Extensions.BLLResult.AlreadyFound) { return(result); } DAL.Extensions.DataBaseResult baseResult = _rendezvousDal.Insert(ref newRendezvous); switch (baseResult) { case DAL.Extensions.DataBaseResult.Error: result.Errors.Add(Extensions.InnerException); result.Result = Extensions.BLLResult.InnerException; break; case DAL.Extensions.DataBaseResult.ServerDisable: result.Result = Extensions.BLLResult.ServerDisable; result.Errors.Add(Extensions.ServerDisable); break; case DAL.Extensions.DataBaseResult.Success: break; case DAL.Extensions.DataBaseResult.AlreadyFound: break; case DAL.Extensions.DataBaseResult.Referanced: break; case DAL.Extensions.DataBaseResult.NotFound: break; default: throw new ArgumentOutOfRangeException(); } if (toExamination) { DiagnosisManager diagnosisManager = new DiagnosisManager(); Diagnosis diagnosis = diagnosisManager.GetDefaultDiagnosis(); ExaminationManager manager = new ExaminationManager(); manager.Insert(new Examination { CanSendMessage = false, PatientId = newRendezvous.PatientId, DoctorId = newRendezvous.DoctorId, Time = newRendezvous.Date, RendezvousId = newRendezvous.Id, IsActive = true, DiagnosisId = diagnosis.Id }); } result.Errors.Add(Extensions.SuccessProcess); result.Errors.Add(String.Format("Kayıt numarası: {0}", newRendezvous.Id)); result.Result = Extensions.BLLResult.Success; return(result); }