Пример #1
0
        private void SendSessionStatus(SessionStatusType sessionStatus)
        {
            switch (sessionStatus)
            {
            case SessionStatusType.InPreparation:
                SessionChangedEvent?.Invoke(
                    sender: this,
                    e: new StateChangedArgs(SessionStatusType.InPreparation));
                break;

            case SessionStatusType.IsRunning:
                SessionChangedEvent?.Invoke(
                    sender: this,
                    e: new StateChangedArgs(SessionStatusType.IsRunning));
                break;

            case SessionStatusType.IsEnded:
                SessionChangedEvent?.Invoke(
                    sender: this,
                    e: new StateChangedArgs(SessionStatusType.IsEnded));
                break;

            case SessionStatusType.IsPaused:
                SessionChangedEvent?.Invoke(
                    sender: this,
                    e: new StateChangedArgs(SessionStatusType.IsPaused));
                break;
            }
        }
Пример #2
0
        private void OnSessionChanged(object sender, StateChangedArgs e)
        {
            if (e.State == SessionStatusType.IsRunning)
            {
                logger?.LogInformation("Sessionstart-Nachricht empfangen.");

                sessionCancellationTokenSource?.Cancel();

                currentState = e.State;
            }
            else if (e.State == SessionStatusType.IsPaused)
            {
                logger?.LogInformation("Sessionpause-Nachricht empfangen.");

                currentState = e.State;
            }
            else if (e.State == SessionStatusType.IsEnded)
            {
                logger?.LogInformation("Sessionende-Nachricht empfangen.");

                currentState = e.State;
            }
        }
Пример #3
0
        /// <summary>
        /// The Session object describes the Session and its properties
        /// where a group of EVSEs that belong together are installed.
        /// </summary>
        /// <param name="Id">Uniquely identifies the Session within the CPOs platform (and suboperator platforms).</param>
        /// <param name="Start">The time when the session became active.</param>
        /// <param name="End">The time when the session is completed.</param>
        /// <param name="kWh">How many kWh are charged.</param>
        /// <param name="AuthId">An id provided by the authentication used so that the eMSP knows to which driver the session belongs.</param>
        /// <param name="AuthMethod">Method used for authentication.</param>
        /// <param name="Location">The location where this session took place.</param>
        /// <param name="EVSE">The EVSE that was used for this session.</param>
        /// <param name="ConnectorId">Connector ID of the connector used at the EVSE.</param>
        /// <param name="MeterId">Optional identification of the kWh meter.</param>
        /// <param name="Currency">ISO 4217 code of the currency used for this session.</param>
        /// <param name="ChargingPeriods">An optional enumeration of charging periods that can be used to calculate and verify the total cost.</param>
        /// <param name="TotalCosts">The total cost (excluding VAT) of the session in the specified currency. This is the price that the eMSP will have to pay to the CPO.</param>
        /// <param name="Status">The status of the session.</param>
        public Session(Session_Id Id,
                       DateTime Start,
                       DateTime?End,
                       Decimal kWh,
                       Auth_Id AuthId,
                       AuthMethodType AuthMethod,
                       Location Location,
                       EVSE EVSE,
                       Connector_Id ConnectorId,
                       Meter_Id MeterId,
                       Currency Currency,
                       IEnumerable <ChargingPeriod> ChargingPeriods,
                       Decimal TotalCosts,
                       SessionStatusType Status)

            : base(Id)

        {
            #region Initial checks

            if (AuthId == null)
            {
                throw new ArgumentNullException("AuthId", "The given parameter must not be null!");
            }

            if (Location == null)
            {
                throw new ArgumentNullException("Location", "The given parameter must not be null!");
            }

            if (EVSE == null)
            {
                throw new ArgumentNullException("EVSE", "The given parameter must not be null!");
            }

            if (ConnectorId == null)
            {
                throw new ArgumentNullException("ConnectorId", "The given parameter must not be null!");
            }

            if (MeterId == null)
            {
                throw new ArgumentNullException("MeterId", "The given parameter must not be null!");
            }

            if (Currency == null)
            {
                throw new ArgumentNullException("Currency", "The given parameter must not be null!");
            }

            #endregion

            #region Init data and properties

            this._Start           = Start;
            this._End             = End;
            this._kWh             = kWh;
            this._AuthId          = AuthId;
            this._AuthMethod      = AuthMethod;
            this._Location        = Location;
            this._EVSE            = EVSE;
            this._ConnectorId     = ConnectorId;
            this._MeterId         = MeterId;
            this._Currency        = Currency;
            this._ChargingPeriods = ChargingPeriods;
            this._TotalCosts      = TotalCosts;
            this._Status          = Status;

            #endregion
        }
Пример #4
0
        /// <inheritdoc/>
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            // Restore window position. Please mind that screen's real-estate might have changed since the previous launch.
            switch (Properties.Settings.Default.WindowState)
            {
            case 1: WindowState = WindowState.Minimized; break;

            case 2: WindowState = WindowState.Maximized; break;
            }
            Height = !double.IsNaN(Properties.Settings.Default.WindowHeight) ?
                     Math.Min(Properties.Settings.Default.WindowHeight, SystemParameters.VirtualScreenHeight) :
                     MinHeight;
            Width = !double.IsNaN(Properties.Settings.Default.WindowWidth) ?
                    Math.Min(Properties.Settings.Default.WindowWidth, SystemParameters.VirtualScreenWidth) :
                    MinWidth;
            if (!double.IsNaN(Properties.Settings.Default.WindowLeft))
            {
                Left = Math.Min(Math.Max(Properties.Settings.Default.WindowLeft, SystemParameters.VirtualScreenLeft), SystemParameters.VirtualScreenLeft + SystemParameters.VirtualScreenWidth - Width);
            }
            if (!double.IsNaN(Properties.Settings.Default.WindowTop))
            {
                Top = Math.Min(Math.Max(Properties.Settings.Default.WindowTop, SystemParameters.VirtualScreenTop), SystemParameters.VirtualScreenTop + SystemParameters.VirtualScreenHeight - Height);
            }

            // Preload icons to be used on system tray.
            var iconSize = System.Windows.Forms.SystemInformation.SmallIconSize;

            Icons = new Dictionary <SessionStatusType, Icon>();
            foreach (var statusType in Enum.GetValues(typeof(SessionStatusType)).Cast <SessionStatusType>())
            {
                var iconUri = new Uri(string.Format("pack://application:,,,/eduVPN.Views;component/Resources/SessionStatusType{0}Icon.ico", Enum.GetName(typeof(SessionStatusType), statusType)));
                try { Icons.Add(statusType, new Icon(Application.GetResourceStream(iconUri).Stream, iconSize)); }
                catch { Icons.Add(statusType, new Icon(Application.GetResourceStream(new Uri("pack://application:,,,/Resources/App.ico")).Stream, iconSize)); }
            }

            // Attach to view model events.
            var viewModel = (ViewModels.Windows.ConnectWizard)DataContext;

            viewModel.QuitApplication += ConnectWizard_QuitApplication;

            // Create notify icon, set default icon, and setup events.
            // We need to do this programatically, since System.Windows.Forms.NotifyIcon is not WPF, but borrowed from WinForms.
            NotifyIcon = new System.Windows.Forms.NotifyIcon()
            {
                Text = TrayIconToolTipText,
                Icon = TrayIcon
            };
            NotifyIcon.Click             += NotifyIcon_Click;
            NotifyIcon.BalloonTipClicked += NotifyIcon_BalloonTipClicked;

            // Bind to "ConnectionPage.ActiveSession.StateDescription" and "ConnectionPage.ActiveSession.State" property to keep tray icon up-to-date.
            viewModel.ConnectionPage.PropertyChanged += (object sender, PropertyChangedEventArgs e2) =>
            {
                if (e2.PropertyName == nameof(viewModel.ConnectionPage.ActiveSession))
                {
                    // Active session changed: sync the tray icon.
                    NotifyIcon.Text = TrayIconToolTipText;
                    NotifyIcon.Icon = TrayIcon;

                    if (viewModel.ConnectionPage.ActiveSession != null)
                    {
                        // Initialize VPN session state.
                        SessionState = viewModel.ConnectionPage.ActiveSession.State;
                        WasSessionExpirationWarned = false;

                        // Bind to the session for property changes.
                        viewModel.ConnectionPage.ActiveSession.PropertyChanged += (object sender3, PropertyChangedEventArgs e3) =>
                        {
                            if (viewModel.ConnectionPage.ActiveSession != sender3)
                            {
                                return;
                            }

                            switch (e3.PropertyName)
                            {
                            case nameof(viewModel.ConnectionPage.ActiveSession.ConnectingProfile):
                            case nameof(viewModel.ConnectionPage.ActiveSession.StateDescription):
                                NotifyIcon.Text = TrayIconToolTipText;
                                break;

                            case nameof(viewModel.ConnectionPage.ActiveSession.State):
                            {
                                NotifyIcon.Icon = TrayIcon;

                                if (!IsActive)
                                {
                                    switch (viewModel.ConnectionPage.ActiveSession.State)
                                    {
                                    case SessionStatusType.Connected:
                                        // Client connected. Popup the balloon message.
                                        NotifyIcon.ShowBalloonTip(
                                            5000,
                                            string.Format(Views.Resources.Strings.SystemTrayBalloonConnectedTitle, viewModel.ConnectionPage.ActiveSession.ConnectingProfile),
                                            string.Format(Views.Resources.Strings.SystemTrayBalloonConnectedMessage, viewModel.ConnectionPage.ActiveSession.TunnelAddress, viewModel.ConnectionPage.ActiveSession.IPv6TunnelAddress),
                                            System.Windows.Forms.ToolTipIcon.Info);
                                        break;

                                    default:
                                        if (SessionState == SessionStatusType.Connected)
                                        {
                                            // Client has been disconnected. Popup the balloon message.
                                            NotifyIcon.ShowBalloonTip(
                                                5000,
                                                eduVPN.Properties.Settings.Default.ClientTitle,
                                                Views.Resources.Strings.SystemTrayBalloonDisconnectedMessage,
                                                System.Windows.Forms.ToolTipIcon.Warning);
                                        }
                                        break;
                                    }
                                }

                                // Save VPN session state.
                                SessionState = viewModel.ConnectionPage.ActiveSession.State;
                            }
                            break;

                            case nameof(viewModel.ConnectionPage.ActiveSession.Expired):
                            case nameof(viewModel.ConnectionPage.ActiveSession.SuggestRenewal):
                                if (!viewModel.ConnectionPage.ActiveSession.Expired &&
                                    viewModel.ConnectionPage.ActiveSession.SuggestRenewal)
                                {
                                    if (!WasSessionExpirationWarned && !IsActive)
                                    {
                                        NotifyIcon.ShowBalloonTip(
                                            5000,
                                            string.Format(Views.Resources.Strings.SystemTrayBalloonRenewSessionTitle, viewModel.ConnectionPage.ActiveSession.ConnectingProfile.Server),
                                            string.Format(Views.Resources.Strings.SystemTrayBalloonRenewSessionMessage, viewModel.ConnectionPage.ActiveSession.ValidTo.ToLocalTime().ToString("f")),
                                            System.Windows.Forms.ToolTipIcon.Info);
                                        WasSessionExpirationWarned = true;
                                    }
                                }
                                else
                                {
                                    WasSessionExpirationWarned = false;
                                }
                                break;
                            }
                        };
                    }
                    else
                    {
                        SessionState = SessionStatusType.Disconnected;
                    }
                }
            };

            Loaded  += Window_Loaded;
            Closing += Window_Closing;

            // Set context menu data context to allow bindings to work.
            if (Resources["SystemTrayMenu"] is ContextMenu menu)
            {
                menu.DataContext = DataContext;
            }
        }
Пример #5
0
 public StateChangedArgs(SessionStatusType state)
 {
     State = state;
 }
Пример #6
0
        private void SaveQuestionnaire(int sessionId, List <Question> questions, string current, SessionStatusType sessionStatus)
        {
            var session = _sessionRepository.Get(sessionId);

            if (session == null)
            {
                throw new SessionNotFoundException();
            }

            if (session.Reviewer.ToLower() != current.ToLower())
            {
                throw new AuthorizationException();
            }

            if (session.SessionStatus != SessionStatusType.Released)
            {
                throw new InvalidOperationException("Questionnare can only be saved when the session is in the released state.");
            }


            session.Questions = questions;

            // TODO - these shouldn't work unless we add patches for them
            session.SessionStatus = sessionStatus;
            session.LastModified  = DateTime.UtcNow;

            _sessionRepository.Patch(session, ReviewSession.SaveQuestionnairePatch);
        }