Ejemplo n.º 1
0
        public ZombieViewModel(ZombieSettings settings, ZombieModel model)
        {
            Settings = settings;
            Model    = model;

            WindowClosing = new RelayCommand <CancelEventArgs>(OnWindowClosing);
            WindowLoaded  = new RelayCommand <Window>(OnWindowLoaded);

            var gitHub = new TabItem {
                Content = new GitHubView {
                    DataContext = new GitHubViewModel(Settings, model)
                }, Header = "GitHub"
            };
            var mappings = new TabItem {
                Content = new MappingsView {
                    DataContext = new MappingsViewModel(Settings, model)
                }, Header = "Mappings"
            };
            var general = new TabItem {
                Content = new GeneralView {
                    DataContext = new GeneralViewModel(Settings, model)
                }, Header = "General"
            };

            TabItems = new ObservableCollection <TabItem>
            {
                gitHub,
                mappings,
                general
            };

            Messenger.Default.Register <StoreSettings>(this, OnStoreSettings);
            Messenger.Default.Register <ChangeFrequency>(this, OnChangeFrequency);
            Messenger.Default.Register <UpdateStatus>(this, OnUpdateStatus);
        }
Ejemplo n.º 2
0
        public UpdateRunner(ZombieSettings settings, ZombieModel model)
        {
            // (Konrad) We can launch the updater immediately.
            var interval = FrequencyUtils.TimeSpanFromFrequency(settings.CheckFrequency);

            Timer = new Timer(x =>
            {
                try
                {
                    model.GetLatestRelease(settings);
                }
                catch (Exception e)
                {
                    _logger.Fatal(e.Message);
                }
            }, null, TimeSpan.Zero, interval);
        }
Ejemplo n.º 3
0
        public ZombieViewModel(ZombieModel model)
        {
            Model = model;
            Title = "Zombie v." + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

            WindowClosing = new RelayCommand <CancelEventArgs>(OnWindowClosing);
            WindowLoaded  = new RelayCommand <Window>(OnWindowLoaded);
            StateChanged  = new RelayCommand <Window>(OnStateChanged);

            var gitHub = new TabItem
            {
                Content = new GitHubView {
                    DataContext = new GitHubViewModel(model)
                },
                Header = "GitHub"
            };
            var mappings = new TabItem
            {
                Content = new MappingsView {
                    DataContext = new MappingsViewModel(model)
                },
                Header = "Mappings"
            };
            var general = new TabItem
            {
                Content = new GeneralView {
                    DataContext = new GeneralViewModel(model)
                },
                Header = "General"
            };

            TabItems = new ObservableCollection <TabItem>
            {
                gitHub,
                mappings,
                general
            };

            Messenger.Default.Register <StoreSettings>(this, OnStoreSettings);
            Messenger.Default.Register <GuiUpdate>(this, OnGuiUpdate);
            Messenger.Default.Register <UpdateStatus>(this, OnUpdateStatus);
        }
Ejemplo n.º 4
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.º 5
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!");
        }