Beispiel #1
0
        public TrayHandler(ObservationScheduler scheduler, ApplicationConfiguration configuration)
        {
            this.icon          = new System.Windows.Forms.NotifyIcon();
            this.icon.Icon     = new Icon(Properties.Resources.Whatson, new Size(16, 16));
            this.icon.Visible  = true;
            this.scheduler     = scheduler;
            this.configuration = configuration;

            this.contextMenu             = new ContextMenu();
            this.icon.ContextMenu        = this.contextMenu;
            this.contextMenu.Popup      += this.OnContextMenuPopup;
            this.icon.DoubleClick       += (s, e) => this.ShowOrHideWindow();
            this.icon.BalloonTipClicked += (s, e) => this.BringToFront(true);
            this.icon.Click             += (s, e) => this.BringToFront(false);

            this.model = new NotificationsModel(this.scheduler);
            this.model.PropertyChanged += this.CurrentStatusPropertyChanged;

            if (File.Exists(Path.Combine(SerializationHelper.ConfigFolder, VisualSettingsFile)))
            {
                this.visualSettings = SerializationHelper.Load <MainWindowSettigns>(Path.Combine(SerializationHelper.ConfigFolder, VisualSettingsFile));
            }

            if (!this.configuration.OpenMinimized)
            {
                this.ShowOrHideWindow();
            }
        }
Beispiel #2
0
        protected override void OnStartup(StartupEventArgs e)
        {
            System.Globalization.CultureInfo.CurrentCulture   = new CultureInfo("en-US");
            System.Globalization.CultureInfo.CurrentUICulture = new CultureInfo("en-US");
            var configDirArg = e.Args.FirstOrDefault(a => a.ToLower().StartsWith(ConfigDirArgName.ToLower()));

            if (configDirArg != null)
            {
                configDirArg = configDirArg.Substring(ConfigDirArgName.Length);
                SerializationHelper.Instance.SetConfigFolder(configDirArg);
            }

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            var logConfiguration = new LoggingConfiguration();

            logConfiguration.Initialize();
            ExceptionHandlingInitialization.Initialize();

            this.config    = SerializationHelper.Instance.LoadOrCreateConfiguration();
            this.scheduler = new ObservationScheduler();

            // call the plugins with the application args, so plugins can process them
            foreach (var connectorPlugin in PluginManager.Instance.ConnectorPlugins)
            {
                try
                {
                    connectorPlugin.OnStartup(e.Args);
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                }
            }

            // add each connector to the observation scheduler
            foreach (var connectorConfiguration in this.config.ConnectorsConfiguration)
            {
                var connector = PluginManager.Instance.GetConnector(connectorConfiguration);
                this.scheduler.Observe(connector);
            }

            this.handler = new TrayHandler(this.scheduler, this.config);
            this.themeHelper.Initialize(this.handler.VisualSettings?.ColorSettings);
            this.ApplyTheme();

            if (!this.config.OpenMinimized)
            {
                this.handler.ShowOrHideWindow();
            }

            Timeline.DesiredFrameRateProperty.OverrideMetadata(typeof(Timeline), new FrameworkPropertyMetadata {
                DefaultValue = 15
            });

            this.scheduler.Start();
            ComponentDispatcher.ThreadPreprocessMessage += this.ComponentDispatcherThreadPreprocessMessage;

            base.OnStartup(e);
        }
Beispiel #3
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            Task.Run(async() =>
            {
                using (var mgr = UpdateManager.GitHubUpdateManager("https://github.com/lorokl2/whatsONUpdater", null, null, null, true))
                {
                    await mgr.Result.UpdateApp();
                }
            });

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            var logConfiguration = new LoggingConfiguration();

            logConfiguration.Initialize();
            ExceptionHandlingInitialization.Initialize();

            this.config    = SerializationHelper.LoadOrCreateConfiguration();
            this.scheduler = new ObservationScheduler();

            foreach (var connectorConfiguration in this.config.ConnectorsConfiguration)
            {
                var connector = PluginsManager.Instance.GetConnector(connectorConfiguration);
                this.scheduler.Observe(connector);
            }

            this.themeHelper.Initialize();
            this.ApplyTheme();

            this.handler = new TrayHandler(this.scheduler, this.config);
            this.scheduler.Start();
            ComponentDispatcher.ThreadPreprocessMessage += this.ComponentDispatcherThreadPreprocessMessage;
        }
 public void Init(ObservationScheduler scheduler, ApplicationConfiguration configuration, IList <Connector> initialConnectorState)
 {
     this.model = new ConnectorTreeViewModel();
     this.HookUnhookModelEvents(true);
     this.model.Init(scheduler, configuration, initialConnectorState);
     this.DataContext = this.model;
     this.SetupDataContext();
 }
Beispiel #5
0
 public void Init(ObservationScheduler scheduler, ApplicationConfiguration configuration, IList <Connector> initialConnectorState)
 {
     this.model = new ConnectorTreeViewModel();
     this.model.PropertyChanged      += this.ModelPropertyChanged;
     this.model.EditItem             += (s, e) => this.EditItem?.Invoke(s, e);
     this.model.DeleteItem           += (s, e) => this.DeleteItem?.Invoke(s, e);
     this.model.ConfigurationChanged += (s, e) => this.ConfigurationChanged?.Invoke(this, EventArgs.Empty);
     this.model.Init(scheduler, configuration, initialConnectorState);
     this.DataContext = this.model;
     this.SetupDataContext();
 }
Beispiel #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MainWindow"/> class.
 /// </summary>
 /// <param name="scheduler">The scheduler observing build servers.</param>
 /// <param name="configuration">App configuration.</param>
 /// <param name="initialConnectorState">The initial state of observed connectors.</param>
 public MainWindow(ObservationScheduler scheduler, ApplicationConfiguration configuration, IList <Connector> initialConnectorState)
 {
     this.InitializeComponent();
     this.scheduler             = scheduler;
     this.config                = configuration;
     this.initialConnectorState = initialConnectorState;
     this.ShowInTaskbar         = this.config.ShowInTaskbar;
     this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(this.ShowInTaskbar)));
     this.Topmost     = this.config.AlwaysOnTop;
     this.DataContext = this;
     this.mainTreeView.ConfigurationChanged += this.MainTreeViewOnConfigurationChanged;
     this.mainTreeView.EditItem             += this.EditTreeItem;
     this.mainTreeView.DeleteItem           += this.OnItemDeleted;
     this.mainTreeView.ExportItem           += this.ExportTreeItem;
 }
Beispiel #7
0
        public bool CheckNotificationShowTest(bool onlyIfChanged, ObservationState currentState, ObservationState historyState1, ObservationState historyState2, ObservationState historyState3, ObservationState historyState4)
        {
            var observationScheduler = new ObservationScheduler();
            var configuration        = new ApplicationConfiguration();

            configuration.OpenMinimized = true;
            var trayHandler = new TrayHandler(observationScheduler, configuration);

            var connectorViewModel = new ConnectorViewModel();
            var statusViewModel    = new StatusViewModel(connectorViewModel);

            statusViewModel.State = currentState;
            var status1 = new BuildStatusViewModel(connectorViewModel)
            {
                State = currentState
            };
            var status2 = new BuildStatusViewModel(connectorViewModel)
            {
                State = historyState1
            };
            var status3 = new BuildStatusViewModel(connectorViewModel)
            {
                State = historyState2
            };
            var status4 = new BuildStatusViewModel(connectorViewModel)
            {
                State = historyState3
            };
            var status5 = new BuildStatusViewModel(connectorViewModel)
            {
                State = historyState4
            };

            connectorViewModel.ConnectorSnapshots.Add(status5);
            connectorViewModel.ConnectorSnapshots.Add(status4);
            connectorViewModel.ConnectorSnapshots.Add(status3);
            connectorViewModel.ConnectorSnapshots.Add(status2);
            connectorViewModel.ConnectorSnapshots.Add(status1);

            var notificationConfiguration = new NotificationConfiguration();

            notificationConfiguration.OnlyIfChanged = onlyIfChanged;
            notificationConfiguration.RunningNotificationEnabled = false;

            return(trayHandler.CheckNotificationShow(statusViewModel, currentState, notificationConfiguration));
        }
Beispiel #8
0
        private static ObservationScheduler PrepareScheduler()
        {
            var scheduler = new ObservationScheduler();

            scheduler.StatusQueried += (s, sub) =>
            {
                lock (lockObj)
                {
                    if (sub.CurrentStatus != null)
                    {
                        Console.Write($"{sub.ConnectorConfiguration.Name} [{sub.CurrentStatus.Time}]: {sub.CurrentStatus.Name} - ");
                        var stateColor = ConsoleColor.DarkMagenta;
                        switch (sub.CurrentStatus.State)
                        {
                        case ObservationState.Success:
                            stateColor = ConsoleColor.DarkGreen;
                            break;

                        case ObservationState.Unstable:
                            stateColor = ConsoleColor.DarkYellow;
                            break;

                        case ObservationState.Failure:
                            stateColor = ConsoleColor.DarkRed;
                            break;

                        case ObservationState.Running:
                            stateColor = ConsoleColor.DarkCyan;
                            break;
                        }

                        Console.ForegroundColor = stateColor;
                        Console.Write($"{sub.CurrentStatus.State}\n");
                    }
                    else
                    {
                        Console.WriteLine(sub);
                    }

                    Console.ForegroundColor = ConsoleColor.Gray;
                }
            };

            return(scheduler);
        }
Beispiel #9
0
        public void BuildsShouldNotBeMissedWhenBuildsAreRunningOneAfterAnother()
        {
            var scheduler = new ObservationScheduler();
            var api       = new FakeJenkinsApi();

            int state = 0;

            api.JobRequest += (s, e) =>
            {
                if (state == 0)
                {
                    e.Result = ApiHelper.GetProject(ObservationState.Running, 10);
                    state++;
                }
                else if (state == 1)
                {
                    e.Result = ApiHelper.GetProject(ObservationState.Running, 11);
                    state++;
                }
                else
                {
                    e.Result = ApiHelper.GetProject(ObservationState.Running, 12);
                    state++;
                    scheduler.Stop(false);
                }
            };

            api.BuildsRequest += (s, e) =>
            {
                var buildsStates = new Dictionary <int, ObservationState>
                {
                    { 11, ObservationState.Failure },
                    { 10, ObservationState.Success },
                    { 9, ObservationState.Unstable },
                    { 8, ObservationState.Unstable },
                    { 7, ObservationState.Unstable },
                    { 6, ObservationState.Unstable },
                    { 5, ObservationState.Unstable },
                    { 4, ObservationState.Unstable },
                };

                int start = 0;
                int end   = 0;

                start = 8 + state;
                end   = 4 + state;

                for (int i = start; i >= end; i--)
                {
                    e.Builds.Add(ApiHelper.GetBuild(buildsStates[i], i));
                }
            };

            api.BuildRequest += (s, e) =>
            {
                if (e.BuildNumber < 10)
                {
                    e.Result = ApiHelper.GetBuild(ObservationState.Unstable, e.BuildNumber);
                }
                else if (state == 0)
                {
                    e.Result = ApiHelper.GetBuild(ObservationState.Running, e.BuildNumber);
                }
                else if (state == 1)
                {
                    var buildSt = e.BuildNumber == 10 ? ObservationState.Success : ObservationState.Running;
                    e.Result = ApiHelper.GetBuild(buildSt, e.BuildNumber);
                }
                else
                {
                    ObservationState buildSt;
                    if (e.BuildNumber == 10)
                    {
                        buildSt = ObservationState.Success;
                    }
                    else if (e.BuildNumber == 11)
                    {
                        buildSt = ObservationState.Failure;
                    }
                    else
                    {
                        buildSt = ObservationState.Running;
                    }

                    e.Result = ApiHelper.GetBuild(buildSt, e.BuildNumber);
                }
            };

            var subj = new JenkinsConnector(new ConnectorConfiguration("Jenkins", "name", "Address", "MyAddress", "ProjectName", "MyProject"), api);

            scheduler.Observe(subj, 0);
            scheduler.Start();
            while (scheduler.Running)
            {
            }

            var jenkinsStatuses = subj.Snapshots.Select(snap => snap.Status).OfType <JenkinsStatus>().ToList();

            Assert.That(jenkinsStatuses.Count, Is.EqualTo(5));

            var expectedBuilds = new[]
            {
                new Tuple <int, ObservationState>(11, ObservationState.Failure),
                new Tuple <int, ObservationState>(10, ObservationState.Success),
                new Tuple <int, ObservationState>(9, ObservationState.Unstable),
                new Tuple <int, ObservationState>(8, ObservationState.Unstable),
                new Tuple <int, ObservationState>(7, ObservationState.Unstable),
            };

            foreach (var expectedBuild in expectedBuilds)
            {
                Assert.That(jenkinsStatuses.Any(stat => stat.BuildNumber == expectedBuild.Item1 && stat.State == expectedBuild.Item2), Is.True, $"Build No. {expectedBuild} was not present in snapshots.");
            }
        }
Beispiel #10
0
 public NotificationsModel(ObservationScheduler scheduler)
 {
     this.connectors          = new ObservableCollection <ConnectorViewModel>();
     scheduler.StatusQueried += this.SchedulerStatusQueried;
 }