public void CreateSession() { RemoteRenderingClient client = GetClientWithAccountKey(); #region Snippet:CreateASession RenderingSessionOptions options = new RenderingSessionOptions(TimeSpan.FromMinutes(30), RenderingServerSize.Standard); // A randomly generated GUID is a good choice for a sessionId. string sessionId = Guid.NewGuid().ToString(); StartRenderingSessionOperation startSessionOperation = client.StartSession(sessionId, options); RenderingSession newSession = startSessionOperation.WaitForCompletionAsync().Result; if (newSession.Status == RenderingSessionStatus.Ready) { Console.WriteLine($"Session {sessionId} is ready."); } else if (newSession.Status == RenderingSessionStatus.Error) { Console.WriteLine($"Session {sessionId} encountered an error: {newSession.Error.Code} {newSession.Error.Message}"); } #endregion Snippet:CreateASession // Use the session here. // ... // The session will automatically timeout, but in this sample we also demonstrate how to shut it down explicitly. #region Snippet:StopSession client.StopSession(sessionId); #endregion Snippet:StopSession }
public async Task TestSimpleSession() { var client = GetClient(); RenderingSessionOptions options = new RenderingSessionOptions(TimeSpan.FromMinutes(4), RenderingServerSize.Standard); string sessionId = Recording.Random.NewGuid().ToString(); StartRenderingSessionOperation startSessionOperation = await client.StartSessionAsync(sessionId, options); Assert.IsTrue(startSessionOperation.HasValue); Assert.AreEqual(options.Size, startSessionOperation.Value.Size); Assert.AreEqual(sessionId, startSessionOperation.Value.SessionId); RenderingSession sessionProperties = await client.GetSessionAsync(sessionId); Assert.AreEqual(startSessionOperation.Value.CreatedOn, sessionProperties.CreatedOn); UpdateSessionOptions updateOptions = new UpdateSessionOptions(TimeSpan.FromMinutes(5)); RenderingSession updatedSession = await client.UpdateSessionAsync(sessionId, updateOptions); Assert.AreEqual(updatedSession.MaxLeaseTime, TimeSpan.FromMinutes(5)); RenderingSession readyRenderingSession = await startSessionOperation.WaitForCompletionAsync(); Assert.IsTrue((readyRenderingSession.MaxLeaseTime == TimeSpan.FromMinutes(4)) || (readyRenderingSession.MaxLeaseTime == TimeSpan.FromMinutes(5))); Assert.IsNotNull(readyRenderingSession.Host); Assert.IsNotNull(readyRenderingSession.ArrInspectorPort); Assert.IsNotNull(readyRenderingSession.HandshakePort); Assert.AreEqual(readyRenderingSession.Size, options.Size); UpdateSessionOptions updateOptions2 = new UpdateSessionOptions(TimeSpan.FromMinutes(6)); Assert.AreEqual(TimeSpan.FromMinutes(6), updateOptions2.MaxLeaseTime); bool foundSession = false; await foreach (var s in client.GetSessionsAsync()) { if (s.SessionId == sessionId) { foundSession = true; } } Assert.IsTrue(foundSession); await client.StopSessionAsync(sessionId); RenderingSession stoppedRenderingSession = await client.GetSessionAsync(sessionId); Assert.AreEqual(RenderingSessionStatus.Stopped, stoppedRenderingSession.Status); }