Beispiel #1
0
 private void HalconWindow_HInitWindow(object sender, EventArgs e)
 {
     window     = HalconWindow.HalconID;
     InicioView = new InicioView(window); //Main Page View
     InicioView.ChangeLabelEvent += ConfigDispAquiView_ChangeLabelEvent;
     InicioView.AddMediator(concreteMediator);
     concreteMediator.AddParticipant(InicioView);
     configAcquisitionDevice.FireConfigurationChangedEvent();
     if (HalconAPI.isWindows) // Necessário para fazer o gerenciamento de threads das janelas
     {
         HOperatorSet.SetSystem("use_window_thread", "true");
     }
     Console.WriteLine("Halcon Window loaded");
     contentMain.Content = InicioView;
 }
Beispiel #2
0
        public MainWindow()
        {
            InitializeComponent();
            concreteMediator        = new ConcreteMediator();
            ConfigDispAquiView      = new ConfigDispAquiView();
            configAcquisitionDevice = ConfigAcquisitionDevice.Instance;
            Console.WriteLine("Main view " + configAcquisitionDevice.GetHashCode());
            ConfigDispAquiView.ChangePageEvent  += GoToMain_ChangePageEvent;
            ConfigDispAquiView.ChangeLabelEvent += ConfigDispAquiView_ChangeLabelEvent;
            Console.WriteLine("Main window criada");
            //contentMain.Content = ConfigDispAquiView;

            concreteMediator.AddParticipant(ConfigDispAquiView);
            ConfigDispAquiView.AddMediator(concreteMediator);
        }
Beispiel #3
0
        private static void Main(string[] args)
        {
            int     num;
            Pattern pattern;

            if (args.Length == 0)
            {
                Console.WriteLine("Please 0 for mediator, 1 for observer or 2 for factory.");
                var chosenPattern = Console.ReadLine();
                var test          = int.TryParse(chosenPattern, out num);
                if (!test)
                {
                    Console.WriteLine("You refused to enter a number so we will default to the Mediator.");
                }
            }
            else
            {
                var test = int.TryParse(args[0], out num);
                if (!test)
                {
                    Console.WriteLine("You refused to enter a number so we will default to the Mediator.");
                }
            }

            switch (num)
            {
            case 0:
                pattern = Pattern.Mediator;
                break;

            case 1:
                pattern = Pattern.Observer;
                break;

            case 2:
                pattern = Pattern.Factory;
                break;

            default:
                pattern = Pattern.Mediator;
                break;
            }

            switch (pattern)
            {
            case Pattern.Mediator:
                IMediator    mediator     = new ConcreteMediator();
                IParticipant participant1 = new ConcreteParticipant1(mediator, "Jay Hardcore");
                IParticipant participant2 = new ConcreteParticipant2(mediator, "Chuck");
                IParticipant participant3 = new ConcreteParticipant3(mediator, "Brenda");
                IParticipant participant4 = new ConcreteParticipant4(mediator, "Hal Jordan");
                mediator.AddParticipant(participant1);
                mediator.AddParticipant(participant2);
                mediator.AddParticipant(participant3);
                mediator.AddParticipant(participant4);
                participant1.SendMessage("Sending message for the first participant");
                participant2.SendMessage("Sending message for  the second participant");
                participant3.SendMessage("Sending message for the third participant");
                participant4.SendMessage("Sending message for  the fourth participant");
                mediator.BroadcastMessage("Mediator message for participant:", participant1);
                mediator.BroadcastMessage("Mediator message for participant:", participant2);
                mediator.BroadcastMessage("Mediator message for participant:", participant3);
                mediator.BroadcastMessage("Mediator message for participant:", participant4);
                break;

            case Pattern.Observer:
                var observable        = new Observable();
                var anotherObservable = new AnotherObservable();

                using (IObserver observer = new Observer(observable, "Tony Stark's Observer"))
                {
                    Console.WriteLine(observer.GetName());
                    observer.GetName();
                    observable.DoSomething();
                    observer.Add(anotherObservable);
                    anotherObservable.DoSomething();
                    observer.Remove(observable);
                    observer.Remove(anotherObservable);
                }

                break;

            case Pattern.Factory:
                new FactoryClient().EnergizeStarShipClient();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            Console.WriteLine("----------press enter to exit----------");
            Console.ReadLine();
        }