コード例 #1
0
        /// <summary>
        /// Assigns from configuration setting based on <see cref="ObservationState"/>.
        /// </summary>
        /// <param name="observationState">The <see cref="ObservationState"/>.</param>
        /// <param name="isEnabled">if set to <c>true</c> setting related to given <see cref="observationState"/> will be enabled; otherwise disabled.</param>
        public void AssignFromObeservationStateActivity(ObservationState observationState, bool isEnabled)
        {
            switch (observationState)
            {
            case ObservationState.Failure:
                this.FailureNotificationEnabled = isEnabled;
                break;

            case ObservationState.Running:
                this.RunningNotificationEnabled = isEnabled;
                break;

            case ObservationState.Success:
                this.SuccessNotificationEnabled = isEnabled;
                break;

            case ObservationState.Unstable:
                this.UnstableNotificationEnabled = isEnabled;
                break;

            case ObservationState.Unknown:
                this.UnknownNotificationEnabled = isEnabled;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(observationState), observationState, null);
            }
        }
コード例 #2
0
        /// <summary>
        /// Checks if the notification should be shown.
        /// </summary>
        /// <param name="currentStatus">The current status.</param>
        /// <param name="stateToCheck">The state to check.</param>
        /// <param name="notificationConfiguration">The notification configuration.</param>
        /// <returns>True if the notification should be shown, otherwise false.</returns>
        internal bool CheckNotificationShow(StatusViewModel currentStatus, ObservationState stateToCheck, NotificationConfiguration notificationConfiguration)
        {
            var enabledCheck = this.GetEnabledStateCheck(stateToCheck, notificationConfiguration);

            if (!enabledCheck())
            {
                return(false);
            }

            var connectorSnapshots = currentStatus.Parent.ConnectorSnapshots;

            if (connectorSnapshots == null || connectorSnapshots.Count == 1 || notificationConfiguration.OnlyIfChanged == false)
            {
                return(currentStatus.State == stateToCheck);
            }

            var historicalOrderedConnectorSnapshots = connectorSnapshots.Reverse().Skip(1);

            foreach (var historicalOrderedConnectorSnapshot in historicalOrderedConnectorSnapshots)
            {
                var snapshotEnabledCheck = this.GetEnabledStateCheck(historicalOrderedConnectorSnapshot.State, notificationConfiguration);
                if (snapshotEnabledCheck() && currentStatus.State == stateToCheck)
                {
                    if (historicalOrderedConnectorSnapshot.State != currentStatus.State)
                    {
                        return(true);
                    }

                    return(false);
                }
            }

            return(false);
        }
コード例 #3
0
        /// <summary>
        /// Gets the enabled state check method call.
        /// </summary>
        /// <param name="stateToCheck">The state to check.</param>
        /// <param name="notificationConfiguration">The notification configuration.</param>
        /// <returns>The enabled state check method call.</returns>
        private Func <bool> GetEnabledStateCheck(ObservationState stateToCheck, NotificationConfiguration notificationConfiguration)
        {
            Func <bool> enabledCheck;

            switch (stateToCheck)
            {
            case ObservationState.Unknown:
                enabledCheck = () => notificationConfiguration.UnknownNotificationEnabled;
                break;

            case ObservationState.Unstable:
                enabledCheck = () => notificationConfiguration.UnstableNotificationEnabled;
                break;

            case ObservationState.Failure:
                enabledCheck = () => notificationConfiguration.FailureNotificationEnabled;
                break;

            case ObservationState.Success:
                enabledCheck = () => notificationConfiguration.SuccessNotificationEnabled;
                break;

            case ObservationState.Running:
                enabledCheck = () => notificationConfiguration.RunningNotificationEnabled;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(stateToCheck), stateToCheck, null);
            }

            return(enabledCheck);
        }
コード例 #4
0
        private static Color GetColor(ObservationState state)
        {
            switch (state)
            {
            case ObservationState.Unstable:
                return(System.Windows.Media.Colors.Orange);

                break;

            case ObservationState.Failure:
                return(Color.FromRgb(201, 42, 60));

                break;

            case ObservationState.Success:
                return(Color.FromRgb(66, 171, 20));

                break;

            case ObservationState.Running:
                return(System.Windows.Media.Colors.DarkCyan);

                break;

            default:
                return(Color.FromRgb(120, 144, 156));

                break;
            }
        }
コード例 #5
0
ファイル: MouseObserver.cs プロジェクト: karv/Moggle
		/// <summary>
		/// Empieza a observar un espacio
		/// </summary>
		/// <param name="obj">Objeto a observar</param>
		public void ObserveObject (ISpaceable obj)
		{
			if (IsBeingObserved (obj))
				throw new InvalidOperationException ("Object already being observed.");
			var state = new ObservationState (obj);
			observedObjects.Add (state);
		}
コード例 #6
0
ファイル: ApiHelper.cs プロジェクト: sven-n/whatson
 public static JenkinsJob GetProject(ObservationState state, int lastBuildNumber)
 {
     return(new JenkinsJob
     {
         LastBuild = GetBuild(state, lastBuildNumber),
     });
 }
コード例 #7
0
 public static JenkinsBuild GetBuild(ObservationState state, int number)
 {
     return(new JenkinsBuild
     {
         Number = number,
         Result = state.ToString(),
         Building = state == ObservationState.Running,
     });
 }
コード例 #8
0
ファイル: ApiHelper.cs プロジェクト: sven-n/whatson
 public static JenkinsBuild GetBuild(ObservationState state, int number)
 {
     return(new JenkinsBuild
     {
         Number = number,
         Result = state.ToString(),
         Building = state == ObservationState.Running,
         Timestamp = (long)(new DateTime(2020, 1, 1, 12, number, 0, 0) - new DateTime(1970, 1, 1)).TotalMilliseconds,
     });
 }
コード例 #9
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));
        }
コード例 #10
0
        /// <summary>
        /// RTeturns flag of <see cref="ObservationState"/> enabled state in the configuration.
        /// </summary>
        /// <param name="observationState">State of the observation.</param>
        /// <returns>True if given <see cref="ObservationState"/> is activated in the configuration, otherwise false.</returns>
        public bool AsObservationStateFlag(ObservationState observationState)
        {
            switch (observationState)
            {
            case ObservationState.Unstable:
                return(this.UnstableNotificationEnabled);

            case ObservationState.Failure:
                return(this.FailureNotificationEnabled);

            case ObservationState.Success:
                return(this.SuccessNotificationEnabled);

            case ObservationState.Running:
                return(this.RunningNotificationEnabled);

            case ObservationState.Unknown:
                return(this.UnknownNotificationEnabled);

            default:
                throw new ArgumentOutOfRangeException(nameof(observationState), observationState, null);
            }
        }
コード例 #11
0
        /// <summary>
        /// Removes the unsupported <see cref="ObservationState"/>s by plugin.
        /// </summary>
        /// <param name="observationStates">The observation states collection.</param>
        /// <param name="observationState"><see cref="ObservationState"/> to check it's support on plugin.</param>
        /// <param name="supportsState">Call to support state check.</param>
        private void RemoveNotSupportedObservationState(ICollection <ObservationState> observationStates, ObservationState observationState, Func <bool> supportsState)
        {
            var observationStateListItem = observationStates.FirstOrDefault(s => s == observationState);

            if (observationStateListItem != default(ObservationState) && !supportsState())
            {
                observationStates.Remove(observationStateListItem);
            }
        }
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServerHealthStatus"/> class.
 /// </summary>
 /// <param name="state">The state of job.</param>
 public ServerHealthStatus(ObservationState state)
     : base(state)
 {
 }
コード例 #13
0
ファイル: MouseObserver.cs プロジェクト: karv/Moggle
		/// <summary>
		/// Raises the ratón se fue event.
		/// </summary>
		/// <param name="e">E.</param>
		protected virtual void OnRatónSeFue (ObservationState e)
		{
			RatónSeFue?.Invoke (this, e);
		}
コード例 #14
0
ファイル: MouseObserver.cs プロジェクト: karv/Moggle
		/// <summary>
		/// Raises the ratón encima event.
		/// </summary>
		/// <param name="e">E.</param>
		protected virtual void OnRatónEncima (ObservationState e)
		{
			RatónEncima?.Invoke (this, e);
		}
コード例 #15
0
 public Status(ObservationState state)
 {
     this.State = state;
 }
コード例 #16
0
 public JenkinsStatus(ObservationState state)
     : base(state)
 {
 }
コード例 #17
0
 public Status(ObservationState state)
 {
     this.Properties = new Dictionary <string, string>();
     this.State      = state;
 }