Ejemplo n.º 1
0
        public async Task <SceneEndpoint> GetSceneEndpoint <T>(string accountId, string applicationName, string sceneId, T userData)
        {
            using (var client = CreateHttpClient())
            {
                try
                {
                    using (var stream = new MemoryStream())
                    {
                        _serializer.Serialize(userData, stream);
                        stream.Seek(0, SeekOrigin.Begin);

                        var content = new StreamContent(stream);
                        var result  = await client.PostAsync(string.Format(CreateTokenUri, accountId, applicationName, sceneId), content);


                        result.EnsureSuccessStatusCode();


                        return(_tokenHandler.DecodeToken(await result.Content.ReadAsStringAsync()));
                    }
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("An error occured while retrieving the connection token. See the inner exception for more informations.", ex);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a private scene (requires a token obtained from strong authentication with the Stormancer API.
        /// </summary>
        /// <remarks>
        /// The connection happens when the method `Connect` is called on the scene object. Note that when you call GetScene,
        /// a connection token is requested from the Stormancer API.this token is only valid for a few minutes: Don't get scenes
        /// a long time before connecting to them.
        /// </remarks>
        /// <param name="token">The token securing the connection.</param>
        /// <returns>A task returning the scene object on completion.</returns>
        public async Task <Scene> GetScene(string token)
        {
            var ci = _tokenHandler.DecodeToken(token);

            return(await GetScene(ci.TokenData.SceneId, ci));
        }