public void Invoke <T>(CareTaker <T> careTaker) { var fact = new SheetReaderFactory(); var extensions = fact.GetAllSupportedExtension().Select(x => { var e = $"*{x.ext}"; if (x.ext.StartsWith("(", StringComparison.InvariantCultureIgnoreCase)) { e = x.ext.Replace("(", "").Replace(")", "").Replace("|", ";").Replace(".", "*."); } return($"{x.name}|{e}"); }); var fileService = ServiceLocator.Current.GetInstance <IFileService>(); var path = fileService.RequestReadPath(string.Join("|", extensions.ToArray())); if (!string.IsNullOrWhiteSpace(path)) { Messenger.Default.Send(new CurrentPathMessage() { FilePath = path }); } }
// Use this for initialization void Start() { GEM.registerListener(this); addon= new BaseAddon(); history= new CareTaker(); history.memento= new Memento(jumpForce,moveAmount,addon); }
public void MementoPositiveTest() { // player has completed level 1 OriginatorPlayer player = new OriginatorPlayer { Level = 1, Score = 100, Health = "100%" }; Console.WriteLine("----------- Player info after completing level 1 ---------------------"); player.DisplayPlayerInfo(); // when player completes any level then create checkpoint for that level. CareTaker careTaker = new CareTaker { LevelMarker = player.CreateMarker(player) }; player.Level = 2; player.Score = 130; player.Health = "80%"; Console.WriteLine("--------------- Player info in level 2 --------------------------------"); player.DisplayPlayerInfo(); // if players loses all the lifeline then restore the game from level 1 player.RestoreLevel(careTaker.LevelMarker); Console.WriteLine("------------- Player info after restoring level 1 data ----------------"); player.DisplayPlayerInfo(); Console.ReadLine(); }
public bool Handle <T>(string key, CareTaker <T> careTaker) { bool didCommand = false; foreach (var keyBinding in keyBindings) { if (keyBinding.Value.Match(key)) { last = nameBindings[keyBinding.Key]; if (!keyBindings.Any(x => x.Value.HasPartialMatch) && last?.CanInvoke(careTaker) == true) { last?.Invoke(careTaker); didCommand = true; } } } if (didCommand) { Reset(); } return(didCommand); }
public CareTaker AddCareTaker(CareTaker careTaker, IPasswordHasher hasher) { IPasswordHasher passwordHasher = hasher; PasswordHash hash = passwordHasher.ComputeHash(careTaker); using (SqlConnection conn = new SqlConnection(this.connectionString)) { conn.Open(); // Stored Procedure created in db/init_scrip.sql SqlCommand cmd = new SqlCommand("dbo.addCareTaker", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@street", careTaker.Address.Street); cmd.Parameters.AddWithValue("@city", careTaker.Address.City); cmd.Parameters.AddWithValue("@state", careTaker.Address.State); cmd.Parameters.AddWithValue("@zip", careTaker.Address.Zip); cmd.Parameters.AddWithValue("@county", careTaker.Address.County); cmd.Parameters.AddWithValue("@country", careTaker.Address.Country); cmd.Parameters.AddWithValue("@first_name", careTaker.FirstName); cmd.Parameters.AddWithValue("@last_name", careTaker.LastName); cmd.Parameters.AddWithValue("@email_address", careTaker.EmailAddress); cmd.Parameters.AddWithValue("@password", hash.Password); cmd.Parameters.AddWithValue("@salt", hash.Salt); cmd.Parameters.AddWithValue("@phone_number", careTaker.PhoneNumber); // Finally, executes the caretaker insert careTaker.CareTakerId = Convert.ToInt32(cmd.ExecuteScalar()); return(careTaker); } }
public bool UpdatePassword(string password, int careTakerId, IPasswordHasher hasher) { CareTaker caretaker = new CareTaker(); caretaker.Password = password; IPasswordHasher passwordHasher = hasher; PasswordHash hash = passwordHasher.ComputeHash(caretaker); using (SqlConnection conn = new SqlConnection(this.connectionString)) { conn.Open(); const string sql = @"UPDATE caretaker SET password = @password, SALT = @salt WHERE caretaker_id = @caretaker_id"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@password", hash.Password); cmd.Parameters.AddWithValue("@salt", hash.Salt); cmd.Parameters.AddWithValue("@caretaker_id", careTakerId); return(cmd.ExecuteNonQuery() == 1); } }
static void Main(string[] args) { var originator = new Originator <Udemy>(); var careTaker = new CareTaker <Udemy>(); originator.State = new Udemy { DersNo = "01", DersAdi = "Gerekli Kurulumlar" }; careTaker.Add(originator.SetState()); originator.State = new Udemy { DersNo = "29", DersAdi = "Çember Tespiti" }; careTaker.Add(originator.SetState()); originator.GetState(careTaker[0]); Console.WriteLine(originator.State); }
public void TestAddCareTaker() { // Arrange CareTakerSqlDAO dao = new CareTakerSqlDAO(this.connectionString); CareTaker testCareTaker = new CareTaker() { AddressId = berkshire, FirstName = "Jason", LastName = "Howie", EmailAddress = "*****@*****.**", Password = "******", PhoneNumber = "342342432", }; testCareTaker.Address.Street = "34243243"; testCareTaker.Address.City = "sdlktgj"; testCareTaker.Address.State = "akedgihj"; testCareTaker.Address.Zip = 324234; testCareTaker.Address.County = "asf"; testCareTaker.Address.Country = "ertwseg"; // Act dao.AddCareTaker(testCareTaker, new PasswordHasher()); CareTaker careTaker = dao.GetCareTakerByEmail("*****@*****.**"); // Assert Assert.AreEqual("*****@*****.**", careTaker.EmailAddress); }
public IActionResult Authenticate(LoginCareTaker userParam) { // Default to bad username/password message IActionResult result = BadRequest(new { message = "Username or password is incorrect" }); // Get the user by username CareTaker user = careTakerDAO.GetCareTakerByEmail(userParam.EmailAddress); // If we found a user and the password hash matches if (user != null && passwordHasher.VerifyHashMatch(user.Password, userParam.Password, user.Salt)) { // Create an authentication token string token = tokenGenerator.GenerateToken(user.CareTakerId, user.EmailAddress /*, user.Role*/); // Create a ReturnUser object to return to the client ReturnCareTaker retUser = new ReturnCareTaker() { CareTakerId = user.CareTakerId, EmailAddress = user.EmailAddress /*Role = user.Role,*/, Token = token }; // Switch to 200 OK return(Ok(retUser)); } return(Unauthorized(result)); }
static bool TestMementoPattern() { Console.WriteLine("TESTING THE MEMENTO DESIGN PATTERN: "); Originator <StateObject> current = new Originator <StateObject>(); current.SetState(new StateObject { Id = 1, Name = "Object 1" }); CareTaker <StateObject> .SaveState(current); current.ShowState(); current.SetState(new StateObject { Id = 2, Name = "Object 2" }); CareTaker <StateObject> .SaveState(current); current.ShowState(); current.SetState(new StateObject { Id = 3, Name = "Object 3" }); CareTaker <StateObject> .SaveState(current); current.ShowState(); Console.WriteLine("Restoring the first state"); CareTaker <StateObject> .RestoreState(current, 0); current.ShowState(); return(true); }
private bool AddMomento(int id) { var oldAuthor = Get(id, null).FirstOrDefault(); if (oldAuthor == null) { return(false); } var careTaker = new CareTaker() { Momento = new Momento(oldAuthor.Id, oldAuthor.Name) }; try { careTakers[id].Push(careTaker); } catch { careTakers.Add(id, new Stack <CareTaker>(new List <CareTaker>() { careTaker })); } return(true); }
static void Main(string[] args) { Book book = new Book { Isbn = "12345", Title = "Sefiller", Author = "Victor Hugo" }; book.ShowBook(); CareTaker history = new CareTaker(); history.Memento = book.CreateUndo(); book.Isbn = "54321"; book.Title = "SEFILLER"; book.Author = "VICTOR HUGO"; book.ShowBook(); book.RestoreFromUndo(history.Memento); book.ShowBook(); }
public IActionResult Edit(int id, [Bind("Id,Name,PhoneNumber")] CareTaker careTaker) { if (id != careTaker.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(careTaker); _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CareTakerExists(careTaker.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(careTaker)); }
static void Main(string[] args) { Book book = new Book { Isbn = "12345", Title = "Sefiller", Author = "Victor Hugo" }; book.ShowBook(); CareTaker history = new CareTaker(); history.Memento = book.CreateUndo(); book.Isbn = "33333"; book.Title = "SEFİLLER"; book.ShowBook(); book.RestoreFromUndo(history.Memento); book.ShowBook(); Console.ReadLine(); }
public async System.Threading.Tasks.Task AddTaker() { try { HttpClient client = new HttpClient(); //Fetches Care Giver to later use as data for Care Taker CareGiver selectedGiver = (CareGiver)cmbGiver.SelectedItem; CareTaker newCareTaker = new CareTaker(); //Sets input as value for new Care Taker newCareTaker.firstName = txtFirstName.Text; newCareTaker.lastName = txtLastName.Text; newCareTaker.careGiverId = selectedGiver.Id; string jsonString = JsonConvert.SerializeObject(newCareTaker); var content = new StringContent(jsonString, Encoding.UTF8, "application/json"); string URL = BASE_URL + "CareTakers"; var response = await client.PostAsync(URL, content); var responseString = await response.Content.ReadAsStringAsync(); System.Diagnostics.Debug.WriteLine(responseString); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } }
private void Start() { /* * Originator originator = new Originator(); * originator.SetState("Test1"); * originator.ShowState(); * * Memento memento1 = originator.CreateMemento(); * * originator.SetState("Test2"); * originator.ShowState(); * * originator.SetMemento(memento1); */ CareTaker careTaker = new CareTaker(); Originator originator = new Originator(); originator.SetState("Test1"); originator.ShowState(); careTaker.AddMemento("V1.0", originator.CreateMemento()); originator.SetState("Test2"); originator.ShowState(); careTaker.AddMemento("V2.0", originator.CreateMemento()); originator.SetState("Test3"); originator.ShowState(); careTaker.AddMemento("V3.0", originator.CreateMemento()); originator.SetMemento(careTaker.GetMemento("V2.0")); originator.ShowState(); }
public static void Run() { ConcreteOriginator originator = new ConcreteOriginator("Super-duper-super-puper-super."); CareTaker careTaker = new CareTaker(originator); careTaker.BackUp(); originator.DoSomething(); careTaker.BackUp(); originator.DoSomething(); careTaker.BackUp(); originator.DoSomething(); System.Console.WriteLine(); careTaker.ShowHistory(); System.Console.WriteLine("\nClient: Now, let's rollback\n"); careTaker.Undo(); System.Console.WriteLine("\n\nClient: once more!\n"); careTaker.Undo(); System.Console.WriteLine(); }
private void Start() { //Originator originator = new Originator(); //originator.SetState("State1"); //originator.ShowState(); //Memento memento = originator.CreateMemento(); //创建快照 //originator.SetState("State2"); //originator.ShowState(); //originator.SetMemento(memento); //originator.ShowState(); CareTaker careTaker = new CareTaker(); Originator originator = new Originator(); originator.SetState("state1"); originator.ShowState(); careTaker.AddMemento("v1.0", originator.CreateMemento()); originator.SetState("state2"); originator.ShowState(); careTaker.AddMemento("v2.0", originator.CreateMemento()); originator.SetState("state3"); originator.ShowState(); careTaker.AddMemento("v3.0", originator.CreateMemento()); originator.SetMemento(careTaker.GetMemento("v2.0")); originator.ShowState(); originator.SetMemento(careTaker.GetMemento("v1.0")); originator.ShowState(); }
public void Init() { systems = new List <IGameSystem>(); achievementSystem = new AchievementSystem(); campSystem = new CampSystem(); CharacterSystem = new CharacterSystem(); EnergySystem = new EnergySystem(); EventSystem = new GameEventSystem(); StageSystem = new StageSystem(); CampInfoUI = new CampInfoUI(); gamePauseUI = new GamePauseUI(); GameStateInfoUI = new GameStateInfoUI(); soldierInfoUI = new SoldierInfoUI(); systems.Add(achievementSystem); systems.Add(campSystem); systems.Add(CharacterSystem); systems.Add(EnergySystem); systems.Add(EventSystem); systems.Add(StageSystem); systems.Add(CampInfoUI); systems.Add(gamePauseUI); systems.Add(GameStateInfoUI); systems.Add(soldierInfoUI); systems.ForEach(s => s.Init()); var memento = CareTaker.RetrieveMemento(); //取回备忘录 achievementSystem.RestoreMemento(memento); //根据备忘录,恢复成就系统 }
private void Start() { CareTaker careTaker = new CareTaker(); Originator originator = new Originator(); originator.SetState("state1"); originator.ShowState(); Memento memento = originator.CreateMemento(); careTaker.AddMemento("v1.0", memento); originator.SetState("state2"); originator.ShowState(); memento = originator.CreateMemento(); careTaker.AddMemento("v2.0", memento); originator.SetState("state3"); originator.ShowState(); memento = originator.CreateMemento(); careTaker.AddMemento("v3.0", memento); originator.RecoverFromMemento(careTaker.GetMemento("v1.0")); originator.ShowState(); originator.RecoverFromMemento(careTaker.GetMemento("v2.0")); originator.ShowState(); originator.RecoverFromMemento(careTaker.GetMemento("v3.0")); originator.ShowState(); }
public void TestDeleteCareTaker() { // Arrange CareTakerSqlDAO dao = new CareTakerSqlDAO(this.connectionString); CareTaker testCareTaker = new CareTaker() { CareTakerId = ruth, AddressId = berkshire, FirstName = "Ru", LastName = "Howie", EmailAddress = "askdfja", Password = "******", PhoneNumber = "342342432", }; testCareTaker.Address.Street = "34243243"; testCareTaker.Address.City = "sdlktgj"; testCareTaker.Address.State = "akedgihj"; testCareTaker.Address.Zip = 324234; testCareTaker.Address.County = "asf"; testCareTaker.Address.Country = "ertwseg"; // Act dao.DeleteCareTaker(testCareTaker); CareTaker expected = dao.GetCareTakerById(ruth); // Assert Assert.AreEqual(null, expected); }
static void Memento(string path) { CareTaker careTaker = CareTaker.RestoreFromFile(); Originator originator = null; WebCrawler webcrawler = WebCrawler.GetInstance(); if (careTaker != null) { originator = careTaker.Originator; } if (careTaker == null) { var model = webcrawler.LoadFromFile(path); originator = new Originator(model); careTaker = new CareTaker(originator); } //careTaker.Restore("nkbrrk"); //Console.WriteLine($"Originator stateName {originator.StateName}"); careTaker.Compare("citmxv"); //originator.MakeChanges(webcrawler); //await careTaker.Save(); //Console.WriteLine("History"); //careTaker.ShowHistory(); }
public void Release() { systems.ForEach(s => s.Release()); IMemento memento = achievementSystem.CreateMemento(); //成就系统创建备忘录 CareTaker.SaveMemento(memento); //保存到备忘录 }
public void InvokeLast <T>(CareTaker <T> careTaker) { if (last?.CanInvoke(careTaker) == true) { last.Invoke(careTaker); Reset(); } }
static void Main(string[] args) { Duck monty = new Duck(); Duck robert = new RobotDuck(); CareTaker kate = new CareTaker(); kate.FeedPet(monty); kate.FeedPet(robert); }
public void Invoke <T>(CareTaker <T> careTaker) { if (careTaker is EditorCareTaker ect) { var clone = ect.Current?.Clone() as EditorMemento ?? new EditorMemento(); clone.InsertText("\\clef treble"); ect.Save(clone); } }
public IActionResult Create([Bind("Id,Name,PhoneNumber")] CareTaker careTaker) { if (ModelState.IsValid) { _context.Add(careTaker); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(careTaker)); }
public void Invoke <T>(CareTaker <T> careTaker) { if (careTaker is DummyCareTaker dm) { dm.Save(new Dummy { Value = Hallo3CommandName }); } }
public Cuenta(int id, double saldo, ref Originator originator, ref CareTaker careTaker) { this.Id = id; this.Saldo = saldo; this.CareTaker = careTaker; this.Originator = originator; this.Originator.setEstado(new Cuenta(this.Id, this.Saldo)); this.CareTaker.AgregarMomento(this.Originator.Guardar()); }
private void endRound(Hero hero) { timer.Stop(); mapNumber++; // DateTime ElapsedTime = DateTime.Parse(elapsedTime); int totalSeconds = (elapsedTimeDateTime.Hours * 360) + (elapsedTimeDateTime.Minutes * 60) + elapsedTimeDateTime.Seconds; if (totalSeconds < 20) { totalPoints = totalPoints + 100; } if (totalSeconds >= 20 && totalSeconds <= 40) { totalPoints = totalPoints + 50; } if (totalSeconds > 40) { totalPoints = totalPoints + 20; } double pointsForSteps = ((double)hero.getNumberSteps()) * 0.1; totalPoints = totalPoints - (int)pointsForSteps; if (totalPoints < 0) { totalPoints = 0; } this.Controls.Clear(); if (mapNumber < 5) { RetroMapBuilder ret = new RetroMapBuilder(); newDirector.setMapBuilder(ret); newDirector.constructMap(mapNumber); newMap = newDirector.getMap(); } else { ClassicMapBuilder clas = new ClassicMapBuilder(); newDirector.setMapBuilder(clas); newDirector.constructMap(mapNumber); newMap = newDirector.getMap(); } initMap(newMap); originator = new Originator(); careTaker = new CareTaker(); //UZUPELNIC ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ }
static void Main(string[] args) { note note = new note("Naslov", "text, tijelo poruke"); note.Show(); StringBuilder sbTitle = new StringBuilder("Naslov p"); StringBuilder sbBody = new StringBuilder("Text pp0"); Notebook notebook = new Notebook(); for (int i = 0; i < 8; i++) { sbTitle.Append('w', i / 2); sbBody.Append('b', i / 3); notebook.AddNote(new note(sbTitle.ToString(), sbBody.ToString())); } CIterator iterator = new CIterator(notebook); iterator.First().Show(); while (iterator.Next() != null) { iterator.Current.Show(); } notebook.Clear(); CareTaker careTaker = new CareTaker(); ToDoItem tdi1 = new ToDoItem("naslov1", "text1", DateTime.Now); ToDoItem tdi2 = new ToDoItem("naslov12", "text12", DateTime.Now); ToDoItem tdi3 = new ToDoItem("naslov123", "text123", DateTime.MinValue); ToDoItem tdi4 = new ToDoItem("naslov1234", "text1234", DateTime.MaxValue); tdi1.AddStateCT(careTaker); tdi2.AddStateCT(careTaker); tdi3.AddStateCT(careTaker); tdi4.AddStateCT(careTaker); ToDoItem getStateTdi = new ToDoItem("", "", DateTime.MinValue); getStateTdi.RestoreState(careTaker.GetByTitle("naslov12")); Console.WriteLine(getStateTdi.ToString()); HomeThermostat termostat1 = new HomeThermostat(); HomeThermostat termostat2 = new HomeThermostat(); CarThermostat termostatAuto = new CarThermostat(); WeatherStation station = new WeatherStation(44); station.AddObserver(termostat1); station.AddObserver(termostat2); station.AddObserver(termostatAuto); station.SetTemperature(22); station.SetTemperature(2); }
public static void EX1() { CareTaker careTaker = new CareTaker(); Originator objeto = new Originator(); objeto.SetState("estado original"); objeto.ShowState(); careTaker.AddStep(new Memento.Exemplo1.Memento(objeto.SaveState())); objeto.SetState("mutação de estado 1"); objeto.SetState("mutação de estado 2"); objeto.RestoreState(careTaker.GetLastStep()); objeto.ShowState(); }
static void Main(string[] args) { ////Struture for memento pattern //Originator origiator = new Originator(); //origiator.State = "ON"; //CareTaker careTaker = new CareTaker(); //careTaker.Memento = origiator.CreateMemento(); //origiator.State = "OFF"; //origiator.SetMemento(careTaker.Memento); List<ContactPerson> contactPersons = new List<ContactPerson>() { new ContactPerson() { Name= "Learning Hard", MobileNum = "123445"}, new ContactPerson() { Name = "Tony", MobileNum = "234565"}, new ContactPerson() { Name = "Jock", MobileNum = "231455"} }; MobileOwner owner = new MobileOwner(contactPersons); owner.ShowContacts(); CareTaker careTaker = new CareTaker(); careTaker.ContactMementos.Add(DateTime.Now.ToString(), owner.CreateMemento()); //Remove some contacts; owner.ContactPersons.RemoveAt(2); owner.ShowContacts(); Thread.Sleep(1000); careTaker.ContactMementos.Add(DateTime.Now.ToString(), owner.CreateMemento()); Console.WriteLine("Restore Date Index:"); var keyCollections = careTaker.ContactMementos.Keys; foreach(var key in keyCollections) { Console.WriteLine(key); } while(true) { int index = -1; try { index = Int32.Parse(Console.ReadLine()); } catch { Console.WriteLine("The format is wrong"); continue; } ContactMemento contactMentor = null; if (index < keyCollections.Count && careTaker.ContactMementos.TryGetValue(keyCollections.ElementAt(index), out contactMentor)) { owner.RestoreMemento(contactMentor); owner.ShowContacts(); } else { Console.WriteLine(""); } } Console.Read(); }