public static PlaySession Create(string json)
        {
            dynamic sessionObject = JsonConvert.DeserializeObject (json);

            var key = string.Format ("{0}:{1}", sessionObject.GameId, sessionObject.ExecutableDirectory);

            if (!catalog.Games.ContainsKey (key))
                return null;

            var playSession = new PlaySession
            {
                Game = catalog.Games[key],
                StartDateTime = sessionObject.StartDate,
                EndDateTime = sessionObject.EndDate,
                Version = sessionObject.Version,
                IsInvisible = sessionObject.IsInvisible,
            };

            for (var i = 0; i < sessionObject.IdleTime.Count; i++)
            {
                playSession.IdleTime.Add (new IdleSegment {
                    StartDateTime = sessionObject.IdleTime[i].StartDate,
                    Duration = sessionObject.IdleTime[i].Duration,
                    IsClosed = sessionObject.IdleTime[i].IsClosed
                });
            }

            return playSession;
        }
        public void FinishSession( PlaySession playSession )
        {
            if( playSession == null )
                return;

            idleMonitor.RemoveProcess( playSession.ProcessId );

            // Start watching for changes since the game is stopped
            playSession.Game.StartWatchingForFileChanges();

            playSession.FinishSession();
        }
 private void SessionEvent( PlaySession playSession )
 {
     foreach (InstalledGameListViewItem listViewItem in listViewGames.ListView.Items)
     {
         if( listViewItem.Game.InstanceId == playSession.InstanceId )
         {
             listViewItem.SubItems[ 3 ].Text = playSession.ActiveDuration.ToReadableTime();
         }
     }
 }
 public void PlaySessionUpdated(PlaySession playSession)
 {
     SessionEvent(playSession);
 }
 public void UpdatePlaytime(PlaySession session)
 {
     this.labelPlaytime.Text = session.ActiveDuration.ToReadableTime ();
 }
 public void SubmitSession(PlaySession session)
 {
     this.queue.Enqueue(session);
 }
        public bool SubmitSession( PlaySession playSession )
        {
            // Serialize the session to json, and submit it
            var wasSubmittedSuccessfully = SubmitSession( playSession.ToJson() );

            // A successful submission will return the object id
            //  of the session
            if( wasSubmittedSuccessfully )
            {
                // Mark the session as submitted
                playSession.IsSubmitted = true;
            }

            return wasSubmittedSuccessfully;
        }
        public PlaySession StartSession( InstalledGame game, int processId )
        {
            var playSession = new PlaySession
            {
                Game = game,
                Version = game.Version,
                ProcessId = processId,
                StartDateTime = DateTime.UtcNow,
            };

            if( !sessions.ContainsKey( game.InstanceId ) )
            {
                sessions.Add( game.InstanceId, new List<PlaySession>() );
            }

            sessions[game.InstanceId].Add( playSession );

            // Stop watching for file changes while the game is running
            game.StopWatchingForFileChanges();

            return playSession;
        }
 public PlaySessionEventArgs( PlaySession session, PlaySessionActions action )
 {
     PlaySession = session;
     Action = action;
 }