Ejemplo n.º 1
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            var arg1  = GetRemoteSettingsPath(e.Args);
            var local = File.Exists(arg1);

            if (!string.IsNullOrEmpty(arg1) && !local)
            {
                // (Konrad) Arg1 is a path that doesn't exist locally so it is likely
                // a remote file location (HTTP).
                if (SettingsUtils.TryGetRemoteSettings(arg1, out var settings))
                {
                    Settings                  = settings;
                    Settings.AccessToken      = GetAccessToken(e.Args);
                    Settings.SettingsLocation = arg1;
                    Settings.StoreSettings    = false;
                }
                else
                {
                    // (Konrad) We have a path in the Arg1 that doesn't exist or failed to
                    // deserialize so we can treat it as if it didn't exist and override it on close.
                    Settings = new ZombieSettings
                    {
                        SettingsLocation = arg1,
                        StoreSettings    = true
                    };
                }
            }
            else if (!string.IsNullOrEmpty(arg1) && local)
            {
                // (Konrad) Arg1 exists on a user drive or network drive.
                Settings = SettingsUtils.TryGetStoredSettings(arg1, out var settings)
                    ? settings
                    : new ZombieSettings();
                Settings.SettingsLocation = arg1;

                // (Konrad) If AccessToken was in the Settings file we can skip this.
                // If it wasn't it should be set with the Arg2
                if (string.IsNullOrEmpty(Settings.AccessToken))
                {
                    Settings.AccessToken = GetAccessToken(e.Args);
                }
            }
            else
            {
                Settings = new ZombieSettings
                {
                    SettingsLocation = Path.Combine(Directory.GetCurrentDirectory(), "ZombieSettings.json"),
                    StoreSettings    = true
                };
            }

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

            wnd.ShowInTaskbar = true;
            vm.Startup(wnd);
        }
Ejemplo n.º 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!");
        }