Beispiel #1
0
        private void ProcessSessionStateChanged(BaseResult rs, byte[] payload)
        {
            SessionStateChanged state = SessionStateChanged.Parser.ParseFrom(payload);

            switch (state.Param)
            {
            case SessionStateChanged.Types.Parameter.RowsAffected:
                rs._recordsAffected    = state.Value[0].VUnsignedInt;
                rs._affectedItemsCount = rs._recordsAffected;
                break;

            case SessionStateChanged.Types.Parameter.GeneratedInsertId:
                rs._autoIncrementValue = state.Value[0].VUnsignedInt;
                break;

            case SessionStateChanged.Types.Parameter.ProducedMessage:
                rs.AddWarning(new WarningInfo(0, state.Value[0].VString.Value.ToStringUtf8()));
                break;

            case SessionStateChanged.Types.Parameter.GeneratedDocumentIds:
                foreach (var value in state.Value)
                {
                    rs._documentIds.Add(value.VOctets.Value.ToStringUtf8());
                }
                break;
                //handle the other ones
                //default: SessionStateChanged(state);
            }
        }
Beispiel #2
0
        public void StartSession(CultureInfo?sourceLanguage, [NotNull] CultureInfo neutralResourcesLanguage, [NotNull][ItemNotNull] ICollection <ITranslationItem> items)
        {
            Task.Run(() =>
            {
                var session = new TranslationSession(_mainThread, sourceLanguage, neutralResourcesLanguage, items);
                Interlocked.Exchange(ref _activeSession, session)?.Dispose();

                SessionStateChanged?.Invoke(this, EventArgs.Empty);

                try
                {
                    var translatorTasks = Translators
                                          .Where(t => t.IsEnabled)
                                          .Select(t => t.Translate(session))
                                          .ToArray();

                    Task.WaitAll(translatorTasks);
                }
                finally
                {
                    session.Dispose();
                    SessionStateChanged?.Invoke(this, EventArgs.Empty);
                }
            });
        }
 public void OnSessionStateChanged(eSessionState state)
 {
     if (SessionStateChanged != null)
     {
         SessionStateChanged.Invoke(state);
     }
 }
 private void SetState(TorchSessionState state)
 {
     if (_currentSession == null)
     {
         return;
     }
     _currentSession.State = state;
     SessionStateChanged?.Invoke(_currentSession, _currentSession.State);
 }
Beispiel #5
0
        public bool EndSession(string sessionId)
        {
            var session = _sessionsRepository.Find(sessionId);
            var success = session.StartSession();

            SessionStateChanged?.Invoke(this, new SessionStateChangedEventArgs(sessionId, session.State));

            return(success);
        }
Beispiel #6
0
        private async Task RepopulateBacklog()
        {
            List <Track> tracks = await GetBacklogTracks();

            Shuffle(tracks);

            tracks.ForEach(CurrentBacklogQueue.Push);

            SessionStateChanged?.Invoke(this, EventArgs.Empty);
        }
Beispiel #7
0
        public void AddItemToBacklog(SpotifyBaseObject item)
        {
            if (!allowedBacklogItems.Contains(item.Type.ToLower()))
            {
                throw new InvalidOperationException($"Cannot add a SpotifyBaseIrem of type \"{item.Type}\" to the backlog");
            }

            BacklogItems.Add(item);

            SessionStateChanged?.Invoke(this, EventArgs.Empty);
        }
Beispiel #8
0
        private async Task <bool> PlayTrack(Track track, SessionContext context)
        {
            bool success = await Controller.GetInstance().PlayTrack(track.Uri, DeviceId);

            if (success)
            {
                CurrentTrack = track;
                _playedSongs.Add(new SessionHistoryItem()
                {
                    Context   = context,
                    TimeStamp = DateTime.Now,
                    Track     = track
                });
                SessionStateChanged?.Invoke(this, EventArgs.Empty);
            }

            return(success);
        }
Beispiel #9
0
        private IntPtr WindowHwndMessageFilter(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            switch (msg)
            {
            case WM_WTSSESSION_CHANGE:
                WTSSessionState param = (WTSSessionState)wParam;
                switch (param)
                {
                case WTSSessionState.WTS_SessionConnectedToConsole:
                    SessionStateChanged?.Invoke(this, param);
                    RemoteControlChanged?.Invoke(this, true);
                    break;

                case WTSSessionState.WTS_SessionDisconnectedFromConsole:
                    SessionStateChanged?.Invoke(this, param);
                    RemoteControlChanged?.Invoke(this, false);
                    break;

                case WTSSessionState.WTS_SessonConnectedToRemoteTerminal:
                    SessionStateChanged?.Invoke(this, param);
                    RemoteDesktopChanged?.Invoke(this, true);
                    break;

                case WTSSessionState.WTS_SessionDisconnectedFromRemoteTerminal:
                    SessionStateChanged?.Invoke(this, param);
                    RemoteDesktopChanged?.Invoke(this, false);
                    break;

                case WTSSessionState.WTS_UserLoggedOnToSession:
                case WTSSessionState.WTS_UserLoggedOffFromSession:
                case WTSSessionState.WTS_SessionLocked:
                case WTSSessionState.WTS_SessionUnlocked:
                case WTSSessionState.WTS_RemoteControlStatusChanged:
                    SessionStateChanged?.Invoke(this, param);
                    break;
                }
                break;

            default:
                break;
            }
            return(IntPtr.Zero);
        }
Beispiel #10
0
        public async Task UpdateSession()
        {
            DataLoader dataLoader = DataLoader.GetInstance();

            _playbackState = await dataLoader.GetCurrentlyPlaying();

            if (_playbackState != null && _playbackState.Is_Playing && CurrentTrack != null && _playbackState.Item.Id != CurrentTrack.Id && _playbackState.Item.Id != NextTrackPeek.Id)
            {
                long playBackStarted = _playbackState.Timestamp - _playbackState.Progress_ms;

                _playedSongs.Add(new SessionHistoryItem()
                {
                    Track     = _playbackState.Item,
                    TimeStamp = new DateTime(playBackStarted),
                    Context   = SessionContext.Unknown
                });
            }

            SessionStateChanged?.Invoke(this, EventArgs.Empty);
        }
Beispiel #11
0
        public async Task AddItemToQueue(SpotifyBaseObject item)
        {
            if (!allowedBacklogItems.Contains(item.Type.ToLower()))
            {
                throw new InvalidOperationException($"Cannot add a SpotifyBaseIrem of type \"{item.Type}\" to the manual queue");
            }

            if (item is Track singleTrack)
            {
                CurrentManualQueue.Push(singleTrack);
            }
            else
            {
                foreach (Track track in await ApiHelper.GetTracks(item, _user))
                {
                    CurrentManualQueue.Push(track);
                }
            }

            SessionStateChanged?.Invoke(this, EventArgs.Empty);
        }
Beispiel #12
0
        private async void RunInternal()
        {
            await Task.Run(async() =>
            {
                _playbackState = await DataLoader.GetInstance().GetCurrentlyPlaying(true, (int)SESSION_NEXT_SONG_BEVOR_END_MS - 50);

                long lastUpadte = _unixTimestamp;

                string lastDeviceId = null;

                long tickStart = 0;

                SessionStateChanged?.Invoke(this, EventArgs.Empty);

                while (IsRunning)
                {
                    tickStart = Environment.TickCount;

                    if (AMOUNT_ITEMS_LEFT_TO_REPOPULATED_BACKLOG >= CurrentBacklogQueue.Count())
                    {
                        await RepopulateBacklog();
                    }

                    if (_unixTimestamp >= lastUpadte + SESSION_UPDATE_SLEEP_PAUSE_MS || //update when "updatetimer" tiggers
                        _possibleMSLeftInTrack < SESSION_NEXT_SONG_BEVOR_END_MS)    //update befor a PlayTrack to check whether playback is paused
                    {
                        await UpdateSession();
                        lastUpadte = _unixTimestamp;
                    }

                    //if (CurrentTrack == null || (_playbackState.Is_Playing && _possibleMSLeftInTrack < SESSION_NEXT_SONG_BEVOR_END_MS))
                    if (CurrentTrack == null || (_playbackState != null && CurrentTrack.Id == _playbackState.Item.Id && !_playbackState.Is_Playing && _playbackState.Progress_ms == 0))
                    {
                        Tuple <Track, SessionContext> nextTrackContext = PullNextTrack();

                        if (await PlayTrack(nextTrackContext))
                        {
                            Thread.Sleep(10);
                            await UpdateSession();
                        }
                        else
                        {
                            CurrentManualQueue.Push(nextTrackContext.Item1);
                        }
                    }

                    if (DeviceId != null && DeviceId != lastDeviceId)
                    {
                        await Controller.GetInstance().TransferPlayback(DeviceId, true);
                    }

                    lastDeviceId = DeviceId;

                    int sleepTime = (int)(SESSION_TICK_SLEEP_PAUSE_MS - (Environment.TickCount - tickStart));

                    if (sleepTime > 0)
                    {
                        Thread.Sleep(sleepTime);
                    }
                }
            });
        }
Beispiel #13
0
 void ChangeSessionState(SessionState state)
 {
     CurrentState = state;
     SessionStateChanged?.Invoke(state);
 }
Beispiel #14
0
 private void RaiseSessionStateChanged(ExchangeBoard board, SessionStates state)
 {
     SessionStateChanged?.Invoke(board, state);
 }
Beispiel #15
0
 public void UpdateSessionState(DysproseSessionState newState)
 {
     SessionStateChanged?.Invoke(this, newState);
 }
Beispiel #16
0
 private void SessionStateChangedHandler(ExchangeBoard board, SessionStates state)
 {
     AddGuiAction(() => SessionStateChanged.SafeInvoke(board, state));
 }
		private void ProcessSessionMessage(SessionMessage message)
		{
			var board = ExchangeBoard.GetOrCreateBoard(message.BoardCode);
			_sessionStates[board] = message.State;
			SessionStateChanged?.Invoke(board, message.State);
		}
Beispiel #18
0
		private void ProcessSessionMessage(SessionMessage message)
		{
			var board = _entityCache.ExchangeInfoProvider.GetOrCreateBoard(message.BoardCode);
			_sessionStates[board] = message.State;
			SessionStateChanged?.Invoke(board, message.State);
		}