Пример #1
0
        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
        }
Пример #2
0
        public void QueryAndUpdateASession()
        {
            RemoteRenderingClient client = GetClientWithAccountKey();

            string sessionId = Guid.NewGuid().ToString();

            RenderingSessionOptions settings = new RenderingSessionOptions(TimeSpan.FromMinutes(30), RenderingServerSize.Standard);

            RenderingSession newSession = client.StartSession(sessionId, settings).WaitForCompletionAsync().Result;

            #region Snippet:UpdateSession

            RenderingSession currentSession = client.GetSession(sessionId);

            if (currentSession.MaxLeaseTime - DateTimeOffset.Now.Subtract(currentSession.CreatedOn.Value) < TimeSpan.FromMinutes(2))
            {
                TimeSpan newLeaseTime = currentSession.MaxLeaseTime.Value.Add(TimeSpan.FromMinutes(30));

                UpdateSessionOptions longerLeaseSettings = new UpdateSessionOptions(newLeaseTime);

                client.UpdateSession(sessionId, longerLeaseSettings);
            }

            #endregion Snippet:UpdateSession

            client.StopSession(sessionId);
        }
Пример #3
0
        public void GetInformationAboutSessions()
        {
            RemoteRenderingClient client = GetClientWithAccountKey();

            // Ensure there's at least one session to query.
            string sessionId = Guid.NewGuid().ToString();
            RenderingSessionOptions settings = new RenderingSessionOptions(TimeSpan.FromMinutes(30), RenderingServerSize.Standard);

            client.StartSession(sessionId, settings);
            Thread.Sleep(TimeSpan.FromSeconds(10));

            #region Snippet:ListSessions

            foreach (var properties in client.GetSessions())
            {
                if (properties.Status == RenderingSessionStatus.Starting)
                {
                    Console.WriteLine($"Session \"{properties.SessionId}\" is starting.");
                }
                else if (properties.Status == RenderingSessionStatus.Ready)
                {
                    Console.WriteLine($"Session \"{properties.SessionId}\" is ready at host {properties.Host}");
                }
            }

            #endregion Snippet:ListSessions

            client.StopSession(sessionId);
        }
Пример #4
0
        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);
        }
Пример #5
0
        public void TestFailedSessionRequest()
        {
            var client = GetClient();

            // Make an invalid request (negative lease time).
            RenderingSessionOptions options = new RenderingSessionOptions(TimeSpan.FromMinutes(-4), RenderingServerSize.Standard);

            string sessionId = Recording.Random.NewGuid().ToString();

            RequestFailedException ex = Assert.ThrowsAsync <RequestFailedException>(() => client.StartSessionAsync(sessionId, options));

            Assert.AreEqual(400, ex.Status);

            // The maxLeaseTimeMinutes value cannot be negative
            Assert.IsTrue(ex.Message.ToLower().Contains("lease"));
            Assert.IsTrue(ex.Message.ToLower().Contains("negative"));
        }