Example #1
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);
     }
 }
Example #3
0
 private void SetState(TorchSessionState state)
 {
     if (_currentSession == null)
     {
         return;
     }
     _currentSession.State = state;
     SessionStateChanged?.Invoke(_currentSession, _currentSession.State);
 }
Example #4
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);
        }
Example #5
0
        private async Task RepopulateBacklog()
        {
            List <Track> tracks = await GetBacklogTracks();

            Shuffle(tracks);

            tracks.ForEach(CurrentBacklogQueue.Push);

            SessionStateChanged?.Invoke(this, EventArgs.Empty);
        }
Example #6
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);
        }
Example #7
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);
        }
Example #8
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);
        }
Example #9
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);
        }
Example #10
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);
        }
		private void ProcessSessionMessage(SessionMessage message)
		{
			var board = ExchangeBoard.GetOrCreateBoard(message.BoardCode);
			_sessionStates[board] = message.State;
			SessionStateChanged?.Invoke(board, message.State);
		}
Example #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);
                    }
                }
            });
        }
Example #13
0
 private void RaiseSessionStateChanged(ExchangeBoard board, SessionStates state)
 {
     SessionStateChanged?.Invoke(board, state);
 }
Example #14
0
 public void UpdateSessionState(DysproseSessionState newState)
 {
     SessionStateChanged?.Invoke(this, newState);
 }
Example #15
0
 void ChangeSessionState(SessionState state)
 {
     CurrentState = state;
     SessionStateChanged?.Invoke(state);
 }
Example #16
0
		private void ProcessSessionMessage(SessionMessage message)
		{
			var board = _entityCache.ExchangeInfoProvider.GetOrCreateBoard(message.BoardCode);
			_sessionStates[board] = message.State;
			SessionStateChanged?.Invoke(board, message.State);
		}