static void DemoChatRoom() { Console.WriteLine(nameof(DemoChatRoom)); Console.WriteLine("============================="); // Create chatroom ChatRoomBase chatroom = new ChatRoom(); // Create participants and register them Participant George = new Beatle("George"); Participant Paul = new Beatle("Paul"); Participant Ringo = new Beatle("Ringo"); Participant John = new Beatle("John"); Participant Yoko = new NonBeatle("Yoko"); chatroom.Register(George); chatroom.Register(Paul); chatroom.Register(Ringo); chatroom.Register(John); chatroom.Register(Yoko); // Chatting participants Yoko.Send("John", "Hi John!"); Paul.Send("Ringo", "All you need is love"); Ringo.Send("George", "My sweet Lord"); Paul.Send("John", "Can't buy me love"); John.Send("Yoko", "My sweet love"); // Wait for user Console.ReadKey(); }
public static void MediatorRealWorld() { // Create chatroom Chatroom chatroom = new Chatroom(); // Create participants and register them Participant George = new Beatle("George"); Participant Paul = new Beatle("Paul"); Participant Ringo = new Beatle("Ringo"); Participant John = new Beatle("John"); Participant Yoko = new NonBeatle("Yoko"); chatroom.Register(George); chatroom.Register(Paul); chatroom.Register(Ringo); chatroom.Register(John); chatroom.Register(Yoko); // Chatting participants Yoko.Send("John", "Hi John!"); Paul.Send("Ringo", "All you need is love"); Ringo.Send("George", "My sweet Lord"); Paul.Send("John", "Can't buy me love"); John.Send("Yoko", "My sweet love"); }
// Entry point into console application. static void Main() { // Create chatroom Chatroom chatroom = new Chatroom(); // Create participants and register them Participant George = new Beatle("George"); Participant Paul = new Beatle("Paul"); Participant Ringo = new Beatle("Ringo"); Participant John = new Beatle("John"); Participant Yoko = new NonBeatle("Yoko"); Participant Mike = new NonBeatle("Mike"); chatroom.Register(George); chatroom.Register(Paul); chatroom.Register(Ringo); chatroom.Register(John); chatroom.Register(Yoko); chatroom.Register(Mike); // Chatting participants Mike.Send("John", "We miss you!"); Yoko.Send("John", "Hi John!"); Paul.Send("Ringo", "All you need is love"); Ringo.Send("George", "My sweet Lord"); Paul.Send("John", "Can't buy me love"); John.Send("Yoko", "My sweet love"); John.Send("Mike", "Hi Mike"); John.Send("Bob", "Hi Bob"); // Note that Bob has not been registered with the chatroom // Wait for user Console.ReadKey(); }
void Page_Loaded(object sender, RoutedEventArgs e) { // connect toolbar to C1RichTextBox _rtbToolbar.RichTextBox = _richTextBox; _richTextBox.SpellChecker = _c1SpellChecker; // bind DataGrid _dataGrid.ItemsSource = Beatle.GetBeatles(); // load sample text into text boxes using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SpellCheckerSamples.Resources.test.txt")) using (var sr = new StreamReader(stream)) { var text = sr.ReadToEnd(); _plainTextBox.Text = text; _richTextBox.Text = text; } // set up ignore list WordList il = _c1SpellChecker.IgnoreList; il.Add("ComponentOne"); il.Add("Silverlight"); // monitor events _c1SpellChecker.BadWordFound += _c1SpellChecker_BadWordFound; _c1SpellChecker.CheckControlCompleted += _c1SpellChecker_CheckControlCompleted; // load main dictionary if (_c1SpellChecker.MainDictionary.State != DictionaryState.Loaded) { _c1SpellChecker.MainDictionary.Load(Application.GetResourceStream(new Uri("/" + new AssemblyName(Assembly.GetExecutingAssembly().FullName).Name + ";component/Resources/C1Spell_en-US.dct", UriKind.Relative)).Stream); } if (_c1SpellChecker.MainDictionary.State == DictionaryState.Loaded) { _btnBatch.IsEnabled = _btnModal.IsEnabled = true; WriteLine("loaded main dictionary ({0:n0} words).", _c1SpellChecker.MainDictionary.WordCount); } else { WriteLine("failed to load dictionary: {0}", _c1SpellChecker.MainDictionary.State); } // load user dictionary //UserDictionary ud = _c1SpellChecker.UserDictionary; //ud.LoadFromIsolatedStorage("Custom.dct"); // save user dictionary when app exits App.Current.Exit += App_Exit; _cmbControl.SelectedIndex = 0; // set focus to textbox //_plainTextBox.Focus(); }
public static void TestChatroom() { Chatroom chatroom = new Chatroom(); Participant George = new Beatle("George"); Participant Paul = new Beatle("Paul"); Participant Ringo = new Beatle("Ringo"); Participant John = new Beatle("John"); Participant Yoko = new NonBeatle("Yoko"); chatroom.Register(George); chatroom.Register(Paul); chatroom.Register(Ringo); chatroom.Register(John); chatroom.Register(Yoko); var participantsByName = chatroom.GetParticipants(); Assert.True(participantsByName.ContainsKey("George") && participantsByName.ContainsKey("Paul") && participantsByName.ContainsKey("Ringo") && participantsByName.ContainsKey("John") && participantsByName.ContainsKey("Yoko")); var ytj = Yoko.Send("John", "Hi John!", true); StringAssert.AreEqualIgnoringCase(ytj["from"], "Yoko"); StringAssert.AreEqualIgnoringCase(ytj["to"], "John"); StringAssert.AreEqualIgnoringCase(ytj["msg"], "Hi John!"); var ptr = Paul.Send("Ringo", "All you need is love", true); StringAssert.AreEqualIgnoringCase(ptr["from"], "Paul"); StringAssert.AreEqualIgnoringCase(ptr["to"], "Ringo"); StringAssert.AreEqualIgnoringCase(ptr["msg"], "All you need is love"); var rtg = Ringo.Send("George", "My sweet Lord", true); StringAssert.AreEqualIgnoringCase(rtg["from"], "Ringo"); StringAssert.AreEqualIgnoringCase(rtg["to"], "George"); StringAssert.AreEqualIgnoringCase(rtg["msg"], "My sweet Lord"); var ptj = Paul.Send("John", "Can't buy me love", true); StringAssert.AreEqualIgnoringCase(ptj["from"], "Paul"); StringAssert.AreEqualIgnoringCase(ptj["to"], "John"); StringAssert.AreEqualIgnoringCase(ptj["msg"], "Can't buy me love"); var jty = John.Send("Yoko", "My sweet love", true); StringAssert.AreEqualIgnoringCase(jty["from"], "John"); StringAssert.AreEqualIgnoringCase(jty["to"], "Yoko"); StringAssert.AreEqualIgnoringCase(jty["msg"], "My sweet love"); }
static void MediatorTester() { #region sample 1 ConcreteMediator m = new ConcreteMediator(); ConcreteColleague1 c1 = new ConcreteColleague1(m); ConcreteColleague2 c2 = new ConcreteColleague2(m); m.Colleague1 = c1; m.Colleague2 = c2; c1.Send("How are you?"); c2.Send("Fine, thanks"); #endregion #region sample 2 // Create chatroom Chatroom chatroom = new Chatroom(); // Create participants and register them Participant George = new Beatle("George"); Participant Paul = new Beatle("Paul"); Participant Ringo = new Beatle("Ringo"); Participant John = new Beatle("John"); Participant Yoko = new NonBeatle("Yoko"); chatroom.Register(George); chatroom.Register(Paul); chatroom.Register(Ringo); chatroom.Register(John); chatroom.Register(Yoko); // Chatting participants Yoko.Send("John", "Hi John!"); Paul.Send("Ringo", "All you need is love"); Ringo.Send("George", "My sweet Lord"); Paul.Send("John", "Can't buy me love"); John.Send("Yoko", "My sweet love"); #endregion }
static void Main() { Chatroom chatroom = new Chatroom(); Participant George = new Beatle("George"); Participant Paul = new Beatle("Paul"); Participant Ringo = new Beatle("Ringo"); Participant John = new Beatle("John"); Participant Yoko = new NonBeatle("Yoko"); //登録するのはチャットルーム chatroom.Register(George); chatroom.Register(Paul); chatroom.Register(Ringo); chatroom.Register(John); chatroom.Register(Yoko); //ユーザーが送信すると、チャットルームを介してメッセージがSENDされる Yoko.Send("John", "Hi John!"); Paul.Send("Ringo", "All you need is love"); Ringo.Send("George", "My sweet Lord"); Paul.Send("John", "Can't buy me love"); John.Send("Yoko", "My sweet love"); }
public void MediatorUsage() { IChatroom chatroom = new Chatroom(); Participant George = new Beatle("George"); Participant Paul = new Beatle("Paul"); Participant Ringo = new Beatle("Ringo"); Participant John = new Beatle("John"); Participant Yoko = new NonBeatle("Yoko"); chatroom.Register(George); chatroom.Register(Paul); chatroom.Register(Ringo); chatroom.Register(John); chatroom.Register(Yoko); Yoko.Send("John", "Hi John!"); Paul.Send("Ringo", "All you need is love"); Ringo.Send("George", "My sweet Lord"); Paul.Send("John", "Can't buy me love"); John.Send("Yoko", "My sweet love"); Assert.IsTrue(true); }
void Update() { if (!EventSystem.current.IsPointerOverGameObject()) { // Click somewhere in the Game View. if (Input.GetMouseButtonDown(0)) { // Get the initial click position of the mouse. No need to convert to GUI space // since we are using the lower left as anchor and pivot. initialClickPosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y); // The anchor is set to the same place. selectionBox.anchoredPosition = initialClickPosition; } // While we are dragging. if (Input.GetMouseButton(0)) { // Store the current mouse position in screen space. Vector2 currentMousePosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y); // How far have we moved the mouse? Vector2 difference = currentMousePosition - initialClickPosition; // Copy the initial click position to a new variable. Using the original variable will cause // the anchor to move around to wherever the current mouse position is, // which isn't desirable. Vector2 startPoint = initialClickPosition; //Debug.Log ("Width: " + difference.x + " Height: " + difference.y); // The following code accounts for dragging in various directions. if (difference.x < 0) { startPoint.x = currentMousePosition.x; difference.x = -difference.x; } if (difference.y < 0) { startPoint.y = currentMousePosition.y; difference.y = -difference.y; } // Set the anchor, width and height every frame. selectionBox.transform.position = startPoint; selectionBox.sizeDelta = difference; } } // After we release the mouse button. if (Input.GetMouseButtonUp(0)) { Rect rect = new Rect(selectionBox.anchoredPosition, selectionBox.sizeDelta); foreach (GameObject unit in WorldHandler.countUnitsAsArray()) { if (rect.Contains((Vector2)Camera.main.WorldToScreenPoint(unit.transform.position))) { /*if (!WorldHandler.isShiftDown ()) { * WorldHandler.deselectUnits (); * WorldHandler.deselectAntHill (); * WorldHandler.hideAnthillInfo (); * }*/ GameObject indicator = unit.transform.FindChild("Indicator").gameObject; if (unit.GetComponent <BasicAnt> () != null) // changed with addition of beatle { BasicAnt unitScript = unit.GetComponent <BasicAnt> (); indicator.SetActive(!indicator.activeSelf); unitScript.isUnitSelected = indicator.activeSelf; if (unitScript.isUnitSelected) { WorldHandler.PlayUnitBattleSound(); } if (unitScript.isUnitSelected) { WorldHandler.unitsSelected.Add(unit); } else { WorldHandler.unitsSelected.Remove(unit); } } if (unit.GetComponent <Beatle> () != null) // changed with addition of beatle. { Beatle unitScript = unit.GetComponent <Beatle> (); indicator.SetActive(!indicator.activeSelf); unitScript.isUnitSelected = indicator.activeSelf; if (unitScript.isUnitSelected) { WorldHandler.PlayUnitBattleSound(); } if (unitScript.isUnitSelected) { WorldHandler.unitsSelected.Add(unit); } else { WorldHandler.unitsSelected.Remove(unit); } } } } // Reset initialClickPosition = Vector2.zero; selectionBox.anchoredPosition = Vector2.zero; selectionBox.sizeDelta = Vector2.zero; } }
public void Test1(int pos) { var ex = Assert.Throws <ArgumentException>(() => Beatle.AddBeatle(pos, "Brian")); Assert.AreEqual($"The Beatles do not have a posiotn {pos}", ex.Message, "Exeception message not correct"); }
public void PartcipantCtor_Arg1_SetValue() { var george = new Beatle(_georgeName); Assert.Equal(_georgeName, george.Name); }
public DesignPatternModule() { Get["/testStatePattern"] = _ => { var traficLight = new TraficLight(); var process = traficLight.StartTheTraficLight(); return(process); }; Get["/testNullObjectPattern"] = _ => { var dog = new Dog(); var dougSound = "Dog Sound: " + dog.MakeSound() + ", "; var unknown = Animal.Null; var noAnimalSound = "No Animal Sound: " + unknown.MakeSound(); return(dougSound + noAnimalSound); }; Get["/testObserverPattern"] = _ => { var observable = new Observable(); var observer = new Observer(); observable.SomethingHappened += observer.HandleEvent; var observerValue = observable.DoSomething(); return(observerValue); }; Get["/testBridgePattern/{currentSource}"] = _ => { var currentSource = (string)_.currentSource; var myCustomTv = new MyCustomTv(); switch (currentSource) { case "1": myCustomTv.VideoSource = new LocalCableTv(); break; case "2": myCustomTv.VideoSource = new CableColorTv(); break; case "3": myCustomTv.VideoSource = new TigoService(); break; } var tvGuide = myCustomTv.ShowTvGuide(); var playVideo = myCustomTv.ShowTvGuide(); return(tvGuide + " / " + playVideo); }; Get["/testVisitorPattern"] = _ => { var popRock = new PopRockMusicVisitor(); var musicLibrary = new MusicLibrary(); var songs = musicLibrary.Accept(popRock); return(songs); }; Get["/testBuilderPattern"] = _ => { var shop = new Shop(); VehicleBuilder builder = new CarBuilder(); shop.Construct(builder); var getBuilderProcess = builder.Vehicle.Show(); return(getBuilderProcess); }; Get["/testInterpreterPattern"] = _ => { const string roman = "MCMXXVIII"; var context = new Context(roman); var tree = new List <Expression> { new ThousandExpression(), new HundredExpression(), new TenExpression(), new OneExpression() }; foreach (var exp in tree) { exp.Interpret(context); } return("Interpreter Input: " + roman + ", Interpreter Output: " + context.Output); }; Get["/testChainOfResponsabilityPattern"] = _ => { var response = ""; var pamela = new Director(); var byron = new VicePresident(); var colin = new President(); pamela.SetSuccessor(byron); byron.SetSuccessor(colin); var p = new Purchase(2034, 350.00, "Assets"); response = pamela.ProcessRequest(p); p = new Purchase(2035, 32590.10, "Project X"); response += " / " + pamela.ProcessRequest(p); p = new Purchase(2036, 90000.00, "Project Y"); response += " / " + pamela.ProcessRequest(p); p = new Purchase(2036, 122100.00, "Project Z"); response += " / " + pamela.ProcessRequest(p); return(response); }; Get["/testIteratorPattern"] = _ => { var collection = new Collection(); collection[0] = new Item("Item 0"); collection[1] = new Item("Item 1"); collection[2] = new Item("Item 2"); collection[3] = new Item("Item 3"); collection[4] = new Item("Item 4"); collection[5] = new Item("Item 5"); collection[6] = new Item("Item 6"); collection[7] = new Item("Item 7"); collection[8] = new Item("Item 8"); var iterator = collection.CreateIterator(); iterator.Step = 2; var response = "Iterating over collection:"; for (var item = iterator.First(); !iterator.IsDone; item = iterator.Next()) { response += item.Name + " / "; } return(response); }; Get["/testAdapterPattern"] = _ => { var response = ""; var unknown = new Compound("Unknown"); response += " / " + unknown.Display(); var water = new RichCompound("Water"); response += " / " + water.Display(); var benzene = new RichCompound("Benzene"); response += " / " + benzene.Display(); var ethanol = new RichCompound("Ethanol"); response += " / " + ethanol.Display(); return(response); }; Get["/testCommandPattern"] = _ => { var response = ""; var user = new User(); response += user.Compute('+', 100) + " / "; response += user.Compute('-', 50) + " / "; response += user.Compute('*', 10) + " / "; response += user.Compute('/', 2) + " / "; response += user.Undo(4) + " / "; response += user.Redo(3); return(response); }; Get["/testFactoryPattern"] = _ => { var response = ""; var documents = new Document[2]; documents[0] = new Resume(); documents[1] = new Report(); foreach (var document in documents) { response += document.GetType().Name + "--"; foreach (var page in document.Pages) { response += " " + page.GetType().Name; } } return(response); }; Get["/testStrategyPattern"] = _ => { var response = ""; var studentRecords = new SortedList(); studentRecords.Add("Samual"); studentRecords.Add("Jimmy"); studentRecords.Add("Sandra"); studentRecords.Add("Vivek"); studentRecords.Add("Anna"); studentRecords.SetSortStrategy(new QuickSort()); response += "Quicksort: " + studentRecords.Sort() + " -- "; studentRecords.SetSortStrategy(new ShellSort()); response += "ShellSort: " + studentRecords.Sort() + " -- "; studentRecords.SetSortStrategy(new MergeSort()); response += "MergeSort: " + studentRecords.Sort(); return(response); }; Get["/testTemplatePattern"] = _ => { var response = ""; AbstractClass aA = new ConcreteClassA(); response += aA.TemplateMethod(); AbstractClass aB = new ConcreteClassB(); response += aB.TemplateMethod(); return(response); }; Get["/testFacadePattern"] = _ => { var response = ""; var mortgage = new Mortgage(); var customer = new Customer("Ann McKinsey"); var eligible = mortgage.IsEligible(customer, 125000); response += customer.Name + " has been " + (eligible ? "Approved" : "Rejected"); return(response); }; Get["/mediatorPattern"] = _ => { var response = ""; var chatroom = new Chatroom(); Participant paul = new Beatle("Paul"); Participant john = new Beatle("John"); Participant yoko = new NonBeatle("Yoko"); Participant ringo = new Beatle("Ringo"); chatroom.Register(paul); chatroom.Register(john); chatroom.Register(yoko); chatroom.Register(ringo); response += yoko.Send("John", "Hi John!") + " "; response += paul.Send("Ringo", "All you need is love") + " "; response += paul.Send("John", "Can't buy me love") + " "; response += john.Send("Yoko", "My sweet love"); return(response); }; Get["/testFlyweightPattern"] = _ => { var response = ""; const string document = "AAZZBBZB"; var chars = document.ToCharArray(); var factory = new CharacterFactory(); var pointSize = 10; foreach (var c in chars) { pointSize++; var character = factory.GetCharacter(c); response += character.Display(pointSize) + " "; } return(response); }; Get["/testMomentoPattern"] = _ => { var response = "Save Sales, Restore Memento"; var s = new SalesProspect { Name = "Noel van Halen", Phone = "(412) 256-0990", Budget = 25000.0 }; var m = new ProspectMemory { Memento = s.SaveMemento() }; s.Name = "Leo Welch"; s.Phone = "(310) 209-7111"; s.Budget = 1000000.0; s.RestoreMemento(m.Memento); return(response); }; Get["/testDoubleDispatchPattern"] = _ => { var response = ""; object x = 5; var dispatch = new DoubleDispatch(); response += dispatch.Foo <int>(x); response += dispatch.Foo <string>(x.ToString()); return(response); }; Get["/testTransactionScriptPattern"] = _ => { var response = ""; response += "Booked Holiday: " + HolidayService.BookHolidayFor(1, new DateTime(2016, 12, 31), new DateTime(2017, 1, 5)) + " - "; response += "Employes Leaving in Holiday: " + string.Join(", ", HolidayService.GetAllEmployeesOnLeaveBetween(new DateTime(2016, 12, 31), new DateTime(2017, 1, 5)).Select(x => x.Name)) + " - "; response += "Employes without Holiday: " + string.Join(", ", HolidayService.GetAllEmployeesWithHolidayRemaining().Select(x => x.Name)); return(response); }; }