예제 #1
0
        static void Main(string[] args)
        {
            var config = Stormancer.ClientConfiguration.ForAccount("d81fc876-6094-3d92-a3d0-86d42d866b96", "hello-world-tutorial");
            //config.ServerEndpoint = "http://localhost:8081";

            var client = new Stormancer.Client(config);

            client.GetPublicScene("main", "hello").ContinueWith(
                t =>
            {
                var scene = t.Result;
                scene.AddRoute("msg", p =>
                {
                    Console.WriteLine(p.ReadObject <string>());
                }, null);

                scene.Connect().ContinueWith(t2 =>
                {
                    if (t2.IsCompleted)
                    {
                    }
                    else
                    {
                        Console.WriteLine("Bad stuff happened...");
                    }
                });
            });

            Console.ReadLine();
        }
        // Use this for initialization
        public Task <Scene> Connect()
        {
            ClientConfiguration config;

            config = ClientConfiguration.ForAccount(AccountId, Application);

            config.Logger = DebugLogger.Instance;

            _client = new Stormancer.Client(config);
            _client.GetPublicScene(this.SceneId, "")
            .ContinueWith <Scene>(task =>
            {
                if (task.IsFaulted)
                {
                    Debug.LogException(task.Exception);
                }
                return(task.Result);
            }).Then(scene =>
            {
                lock (this._configLock)
                {
                    this._scene = scene;
                    if (this._initConfig != null)
                    {
                        this._initConfig(this._scene);
                    }
                }
                return(scene.Connect());
            })
            .ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    this._connectedTcs.SetException(t.Exception);
                }
                else
                {
                    Debug.Log("Stormancer scene connected");
                    this._connectedTcs.SetResult(_scene);
                }
            });

            return(this.ConnectedTask);
        }
예제 #3
0
        private Task <Scene> GetAuthenticationScene()
        {
            if (_authenticationScene == null)
            {
                lock (this)
                {
                    if (_authenticationScene == null)
                    {
                        _authenticationScene = _client.GetPublicScene(_authenticationSceneName, "")
                                               .Then(authScene =>
                        {
                            return(authScene.Connect().Then(() => authScene));
                        });
                    }
                }
            }

            return(_authenticationScene);
        }