예제 #1
0
        public void TestExitApplicationCommand_ReturnsApplicationActionsCommand()
        {
            var delegateCommand    = new DelegateCommand();
            var applicationActions = Substitute.For <IApplicationActions>();

            applicationActions.ExitApplicationCommand.Returns(delegateCommand);
            var systemUnderTest = new TrayIconViewModel(applicationActions);

            Assert.That(systemUnderTest.ExitApplicationCommand, Is.EqualTo(delegateCommand));
        }
예제 #2
0
        public void TestTooltipText_WhenStatusIsNotUpdateSuccessful_ReturnsMatchingMessage(MonitorStatus monitorStatus, string expectedMessage)
        {
            var trayIcon = Substitute.For <ITrayIcon>();

            trayIcon.MonitorStatus.Returns(monitorStatus);
            var systemUnderTest = new TrayIconViewModel(Substitute.For <IApplicationActions>());

            systemUnderTest.Model = trayIcon;

            Assert.That(systemUnderTest.TooltipText, Is.EqualTo(expectedMessage));
        }
예제 #3
0
        public void TestPullRequestCount_ReturnsModelPullRequestCount(int?pullRequestCount)
        {
            var systemUnderTest = new TrayIconViewModel(Substitute.For <IApplicationActions>());
            var trayIcon        = Substitute.For <ITrayIcon>();

            trayIcon.PullRequestCount.Returns(pullRequestCount);

            systemUnderTest.Model = trayIcon;

            Assert.That(systemUnderTest.PullRequestCount, Is.EqualTo(pullRequestCount));
        }
예제 #4
0
        public void TestCanSetAndGetModel()
        {
            var systemUnderTest = new TrayIconViewModel(Substitute.For <IApplicationActions>());

            Assert.That(systemUnderTest.Model, Is.Null);

            var trayIcon = Substitute.For <ITrayIcon>();

            systemUnderTest.Model = trayIcon;

            Assert.That(systemUnderTest.Model, Is.EqualTo(trayIcon));
        }
예제 #5
0
        public void TestModelSetter_WhenValueIsNewAndExistingIsNotNull_UnsubscribesFromExistingValue()
        {
            var systemUnderTest = new TrayIconViewModel(Substitute.For <IApplicationActions>());
            var existingValue   = Substitute.For <ITrayIcon>();

            systemUnderTest.Model = existingValue;
            var newValue = Substitute.For <ITrayIcon>();

            systemUnderTest.Model = newValue;

            existingValue.Received().UpdateCompleted -= Arg.Any <EventHandler>();
        }
예제 #6
0
        public void TestOnModelCompleted_CallsApplicationActionsUpdateMonitorViewModel()
        {
            var applicationActions = Substitute.For <IApplicationActions>();
            var systemUnderTest    = new TrayIconViewModel(applicationActions);
            var trayIcon           = Substitute.For <ITrayIcon>();

            systemUnderTest.Model = trayIcon;

            trayIcon.UpdateCompleted += Raise.Event();

            applicationActions.Received().UpdateMonitorViewModel();
        }
예제 #7
0
        public void TestModelSetter_WhenValueIsNew_Subscribes()
        {
            var systemUnderTest = new TrayIconViewModel(Substitute.For <IApplicationActions>());

            Assert.That(systemUnderTest.Model, Is.Null);

            var trayIcon = Substitute.For <ITrayIcon>();

            systemUnderTest.Model = trayIcon;

            trayIcon.Received().UpdateCompleted += Arg.Any <EventHandler>();
        }
예제 #8
0
        public void TestModelSetter_WhenValueIsExistingAndNotNull_DoesNotResubscribe()
        {
            var systemUnderTest = new TrayIconViewModel(Substitute.For <IApplicationActions>());
            var trayIcon        = Substitute.For <ITrayIcon>();

            systemUnderTest.Model = trayIcon;

            trayIcon.Received(1).UpdateCompleted += Arg.Any <EventHandler>();

            systemUnderTest.Model = trayIcon;

            trayIcon.Received(1).UpdateCompleted += Arg.Any <EventHandler>();
        }
예제 #9
0
 public StartupViewModel(
     IEventAggregator events,
     IShell shell,
     TrayIconViewModel trayIcon,
     CustomWindowManager windowManager,
     UserPreferences.UserPreferences userPreferences)
 {
     this.events          = events;
     this.windowManager   = windowManager;
     this.userPreferences = userPreferences;
     this.Shell           = shell;
     this.trayIcon        = trayIcon;
     events.Subscribe(this);
     Shell.Deactivated += ShellOnDeactivated;
 }
예제 #10
0
        public void ShowWindowTriggersWindowCommand()
        {
            // Arrange
            var controllerMock = new Mock <IAppController>();

            controllerMock.Setup(x => x.ShowWindow()).Verifiable();

            var vm = new TrayIconViewModel(controllerMock.Object);

            // Act
            vm.ShowWindowCommand.Execute(null);

            // Assert
            controllerMock.VerifyAll();
        }
예제 #11
0
        public void TestTooltipText_WhenStatusIsUpdateSuccessful_IncorporatesPullRequestCounts(int numUnapprovedPullRequests, int numApprovedPullRequests)
        {
            var trayIcon = Substitute.For <ITrayIcon>();

            trayIcon.MonitorStatus.Returns(MonitorStatus.UpdateSuccessful);
            trayIcon.UnapprovedPullRequestCount.Returns(numUnapprovedPullRequests);
            trayIcon.ApprovedPullRequestCount.Returns(numApprovedPullRequests);
            var systemUnderTest = new TrayIconViewModel(Substitute.For <IApplicationActions>());

            systemUnderTest.Model = trayIcon;

            var expectedToolTipText = string.Format(Properties.Resources.PullRequestCountTooltipFormatString,
                                                    numUnapprovedPullRequests, numApprovedPullRequests);

            Assert.That(systemUnderTest.TooltipText, Is.EqualTo(expectedToolTipText));
        }
예제 #12
0
        public OverlayMenuIconView(TrayIconViewModel trayIconVm, bool showPopup)
        {
            this.vm          = trayIconVm;
            this.DataContext = trayIconVm;
            this.showPopup   = showPopup;
            InitializeComponent();
            this.MainMenu.ItemsSource = trayIconVm.MenuItems;

            this.Left    = Properties.Settings.Default.OverlayIconX;
            this.Top     = Properties.Settings.Default.OverlayIconY;
            this.Loaded += OverlayMenuIconView_Loaded;

            if (showPopup) // If we are going to show a pop-up, make the rest of the content fully opaque
            {
                this.MainGrid.Opacity = 1;
            }
        }
예제 #13
0
 public void StartGUI(bool showWindow)
 {
     trayIcon = container.Resolve <TrayIconViewModel>();
     //Tray icon
     trayIcon.Exit         = new DelegateCommand(Exit);
     trayIcon.Model        = model;
     trayIcon.Open         = new DelegateCommand(ShowMainWindow);
     trayIcon.Queue        = new DelegateCommand(ViewQueue);
     trayIcon.Settings     = new DelegateCommand(Settings);
     trayIcon.Shares       = new DelegateCommand(EditShares);
     trayIcon.ViewShare    = new DelegateCommand(viewShare);
     trayIcon.Compare      = new DelegateCommand(Compare);
     trayIcon.OpenExternal = new DelegateCommand(OpenExternal);
     trayIcon.ShowIcon     = true;
     if (showWindow)
     {
         ShowMainWindow();
     }
     ThreadPool.QueueUserWorkItem(MainWindowUpdater);
 }
예제 #14
0
        public ShellViewModel(
            IServiceLocator serviceLocator,
            IDialogManager dialogManager,
            IEventAggregator events,
            Func <HearthStatsDbContext> dbContext,
            [ImportMany] IEnumerable <IFlyout> flyouts,
            [ImportMany] IEnumerable <ITab> tabs,
            [ImportMany] IEnumerable <IWindowCommand> windowCommands,
            [ImportMany] IEnumerable <ICommandBarItem> commandBarItems,
            UpdateViewModel updateViewModel,
            UserPreferences.UserPreferences userPreferences,
            TrayIconViewModel trayIcon,
            SettingsManager settingsManager,
            SupportViewModel supportViewModel)
        {
            this.dialogManager    = dialogManager;
            this.events           = events;
            this.dbContext        = dbContext;
            this.serviceLocator   = serviceLocator;
            this.tabs             = tabs;
            this.updateViewModel  = updateViewModel;
            this.userPreferences  = userPreferences;
            this.trayIcon         = trayIcon;
            this.settingsManager  = settingsManager;
            this.supportViewModel = supportViewModel;
            this.commandBarItems  = new BindableCollection <ICommandBarItem>(commandBarItems.OrderBy(x => x.Order));
            this.windowCommands   = new BindableCollection <IWindowCommand>(windowCommands.OrderByDescending(x => x.Order));
            this.flyouts          = new BindableCollection <IFlyout>(flyouts);

            this.DisplayName = "HearthstoneTracker.com";
            this.events.Subscribe(this);
            this.userPreferences.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == "WindowState")
                {
                    WindowState = userPreferences.WindowState;
                }
            };
            this.WindowState      = UserPreferences.WindowState;
            this.PropertyChanged += ShellViewModel_PropertyChanged;
        }
예제 #15
0
        public void TestOnModelCompleted_RaisesPropertyChangedNotifications()
        {
            var expectedPropertyNotifications = new HashSet <string>();

            expectedPropertyNotifications.Add("PullRequestCount");
            expectedPropertyNotifications.Add("TooltipText");
            var systemUnderTest = new TrayIconViewModel(Substitute.For <IApplicationActions>());
            var trayIcon        = Substitute.For <ITrayIcon>();

            systemUnderTest.Model = trayIcon;

            systemUnderTest.PropertyChanged +=
                (sender, args) =>
            {
                Assert.That(expectedPropertyNotifications.Contains(args.PropertyName));
                expectedPropertyNotifications.Remove(args.PropertyName);
            };

            trayIcon.UpdateCompleted += Raise.Event();

            Assert.That(expectedPropertyNotifications, Is.Empty);
        }
예제 #16
0
 public void StartGUI(bool showWindow)
 {
     trayIcon = container.Resolve<TrayIconViewModel>();
     //Tray icon
     trayIcon.Exit = new DelegateCommand(Exit);
     trayIcon.Model = model;
     trayIcon.Open = new DelegateCommand(ShowMainWindow);
     trayIcon.Queue = new DelegateCommand(ViewQueue);
     trayIcon.Settings = new DelegateCommand(Settings);
     trayIcon.Shares = new DelegateCommand(EditShares);
     trayIcon.ViewShare = new DelegateCommand(viewShare);
     trayIcon.Compare = new DelegateCommand(Compare);
     trayIcon.OpenExternal = new DelegateCommand(OpenExternal);
     trayIcon.ShowIcon = true;
     if (showWindow)
         ShowMainWindow();
     ThreadPool.QueueUserWorkItem(MainWindowUpdater);
 }
예제 #17
0
        /// <summary>
        /// Application startup
        /// </summary>
        public void AppStartup(object sender, StartupEventArgs e)
        {
            // We save this so that if we perform an upgrade of settings,
            //  we still treat this startup as a first-time run of the application
            bool firstTimeUse = GW2PAO.Properties.Settings.Default.FirstTimeRun;

            // Update settings if neccessary
            if (GW2PAO.Properties.Settings.Default.UpgradeRequired)
            {
                GW2PAO.Properties.Settings.Default.Upgrade();
                GW2PAO.Properties.Settings.Default.UpgradeRequired = false;
                GW2PAO.Properties.Settings.Default.FirstTimeRun    = firstTimeUse;
                GW2PAO.Properties.Settings.Default.Save();
            }

#if DEBUG
            // Enable logging if running in debug
            LogManager.GlobalThreshold = NLog.LogLevel.Trace;
#else
            // Set up logging configuration
            if (!GW2PAO.Properties.Settings.Default.IsLoggingEnabled)
            {
                LogManager.GlobalThreshold = NLog.LogLevel.Fatal;
            }
#endif

            // Disable the debug assert windows that pop-up from NLog
            System.Diagnostics.Trace.Listeners.OfType <System.Diagnostics.DefaultTraceListener>().First().AssertUiEnabled = false;

            // Log application information
            var executingAssembly = System.Reflection.Assembly.GetExecutingAssembly();
            System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(executingAssembly.Location);
            logger.Info("Application starting - " + executingAssembly.GetName().Name + " - " + executingAssembly.GetName().Version + " - " + fvi.FileVersion + " - " + fvi.ProductVersion);

            // Initialize the last chance exception handlers
            logger.Debug("Registering last chance exception handlers");
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

#if !NO_BROWSER
            // Initialize the WebCore for the web browser
            logger.Debug("Initializing Awesomium WebCore");
            if (!WebCore.IsInitialized)
            {
                WebCore.Initialize(new WebConfig()
                {
                    HomeURL = "http://wiki.guildwars2.com/".ToUri(),
                });
            }
#endif

            // Create dummy window so that the only way to exit the app is by using the tray icon
            Window dummyWindow = new Window()
            {
                WindowStyle        = System.Windows.WindowStyle.None,
                AllowsTransparency = true,
                Background         = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Transparent),
                ShowInTaskbar      = false,
                Title = "GW2 Personal Assistant Overlay"
            };
            dummyWindow.Show();
            GW2PAO.Views.OverlayWindow.OwnerWindow = dummyWindow;

            // Create the tray icon
            logger.Debug("Creating tray icon");
            TaskbarIcon                         = (TaskbarIcon)this.FindResource("TrayIcon");
            TrayIconVm                          = new TrayIconViewModel();
            TaskbarIcon.DataContext             = TrayIconVm;
            TaskbarIcon.ContextMenu.DataContext = TrayIconVm;
            TaskbarIcon.ContextMenu.ItemsSource = TrayIconVm.MenuItems;
            App.TrayIcon                        = new ApplicationTrayIcon(TaskbarIcon);
            logger.Debug("Tray icon created");

            // Initialize the application controller
            AppController = new ApplicationController();

            // Initialize the process monitor
            ProcessMonitor = new ProcessMonitor(AppController.SystemService);
            GW2PAO.Views.OverlayWindow.ProcessMonitor = ProcessMonitor;

            // Initialize the OverlayMenuIcon
            ApplicationOverlayMenuIcon = new OverlayMenuIcon(TrayIconVm);

            // Set up the menu items
            logger.Debug("Initializing menu items");
            if (TrayIconVm != null)
            {
                foreach (var item in AppController.GetMenuItems())
                {
                    TrayIconVm.MenuItems.Add(item);
                }

                TrayIconVm.MenuItems.Add(null); // Null is treated as a seperator

                var settingsMenu = new MenuItemViewModel("Settings", null);

                settingsMenu.SubMenuItems.Add(new MenuItemViewModel("Non-Interactive Windows", null, true,
                                                                    () => { return(GW2PAO.Properties.Settings.Default.IsClickthroughEnabled); },
                                                                    (enabled) => {
                    GW2PAO.Properties.Settings.Default.IsClickthroughEnabled = enabled;
                    GW2PAO.Properties.Settings.Default.Save();
                },
                                                                    GW2PAO.Properties.Settings.Default, "IsClickthroughEnabled"));

                settingsMenu.SubMenuItems.Add(new MenuItemViewModel("Sticky Windows", null, true,
                                                                    () => { return(GW2PAO.Properties.Settings.Default.AreWindowsSticky); },
                                                                    (enabled) =>
                {
                    GW2PAO.Properties.Settings.Default.AreWindowsSticky = enabled;
                    GW2PAO.Properties.Settings.Default.Save();
                },
                                                                    GW2PAO.Properties.Settings.Default, "AreWindowsSticky"));

                settingsMenu.SubMenuItems.Add(new MenuItemViewModel("Overlay Menu Icon", null, true,
                                                                    () => { return(ApplicationOverlayMenuIcon.IsVisible); },
                                                                    (show) => { ApplicationOverlayMenuIcon.IsVisible = show; },
                                                                    ApplicationOverlayMenuIcon, "IsVisible"));

                settingsMenu.SubMenuItems.Add(new MenuItemViewModel("Check for Updates at Startup", null, true,
                                                                    () => { return(GW2PAO.Properties.Settings.Default.CheckForUpdates); },
                                                                    (enabled) =>
                {
                    GW2PAO.Properties.Settings.Default.CheckForUpdates = enabled;
                    GW2PAO.Properties.Settings.Default.Save();
                },
                                                                    GW2PAO.Properties.Settings.Default, "CheckForUpdates"));

                TrayIconVm.MenuItems.Add(settingsMenu);
                TrayIconVm.MenuItems.Add(new MenuItemViewModel("About", () => new GW2PAO.Views.AboutView().Show()));
                TrayIconVm.MenuItems.Add(new MenuItemViewModel("Exit", this.ExitAndCleanup));
            }

            logger.Info("Program startup complete");

            // Reopen windows based on user settings
            AppController.ReopenWindowsFromSettings();

            GW2PAO.Properties.Settings.Default.FirstTimeRun = false;
            GW2PAO.Properties.Settings.Default.Save();

            // Perform a check for new updates
            if (GW2PAO.Properties.Settings.Default.CheckForUpdates)
            {
                UpdateChecker.CheckForUpdateAndNotify();
            }
        }
예제 #18
0
 /// <summary>
 /// Initializes a new instance of the MainViewModel class.
 /// </summary>
 public MainViewModel(ITimerService timerService, TrayIconViewModel trayIconViewModel, ReminderViewModel reminderViewModel)
 {
     TimerService      = timerService;
     TrayIconViewModel = trayIconViewModel;
     ReminderViewModel = reminderViewModel;
 }
예제 #19
0
 public TrayIconController(TrayIconViewModel trayIconViewModel)
 {
     _trayIconViewModel = trayIconViewModel;
 }
예제 #20
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="vm">The tray icon view model containing the main menu</param>
 public OverlayMenuIcon(TrayIconViewModel vm)
 {
     this.trayIconViewModel = vm;
     this.IsVisible         = Settings.Default.IsOverlayIconVisible;
 }