/// <summary>
        /// Broadcasts a an event to all clients that are subscribed. This will
        /// cause GUI updates on all Zombie instances.
        /// </summary>
        /// <param name="update">Update message.</param>
        public void Broadcast(GuiUpdate update)
        {
            var binding  = ServiceUtils.CreateClientBinding(ServiceUtils.FreeTcpPort());
            var endpoint = new EndpointAddress(new Uri("http://localhost:8000/ZombieService/Service.svc"));
            var context  = new InstanceContext(new ZombieServiceCallback());
            var client   = new ZombieServiceClient(context, binding, endpoint);

            client.Open();
            client.Subscribe();

            try
            {
                client.PublishGuiUpdate(update);
                client.Unsubscribe();
                client.Close();
            }
            catch (Exception e)
            {
                _logger.Fatal(e.Message);
                client.Abort();
            }
        }
Exemple #2
0
        private void OnStartup(object sender, StartupEventArgs e)
        {
            _logger.Info("Zombie is powering up...");
            var connected = false;

            try
            {
                var binding  = ServiceUtils.CreateClientBinding(ServiceUtils.FreeTcpPort());
                var endpoint = new EndpointAddress(new Uri("http://localhost:8000/ZombieService/Service.svc"));
                var context  = new InstanceContext(new ZombieServiceCallback());
                Client = new ZombieServiceClient(context, binding, endpoint);

                GuiUpdateCallbackHandler callbackHandler = OnGuiUpdate;
                GuiUpdateCallbackEvent += callbackHandler;

                Client.Open();
                Client.Subscribe();

                // (Konrad) Get latest settings from ZombieService
                Settings = Client.GetSettings();

                connected = true;
                _logger.Info("Successfully connected to Zombie Service at http://localhost:8000/ZombieService/Service.svc");
            }
            catch (Exception ex)
            {
                _logger.Fatal(ex.Message);
            }

            // Register AUMID and COM server (for Desktop Bridge apps, this no-ops)
            DesktopNotificationManagerCompat.RegisterAumidAndComServer <MyNotificationActivator>("HOK.Zombie");

            // Register COM server and activator type
            DesktopNotificationManagerCompat.RegisterActivator <MyNotificationActivator>();

            // (Konrad) Create the startup window
            var m    = new ZombieModel(Settings);
            var vm   = new ZombieViewModel(m);
            var view = new ZombieView
            {
                DataContext = vm
            };

            var show = true;

            if (e.Args.Length == 1)
            {
                show = e.Args[0] == "show";
            }

            vm.Startup(view, show);

            Messenger.Default.Send(connected
                ? new UpdateStatus {
                Message = "Successfully connected to ZombieService!"
            }
                : new UpdateStatus {
                Message = "Connection to ZombieService failed!"
            });
            _logger.Info("Zombie is up and running!");
        }