Example #1
0
        internal Task ConnectToScene(Scene scene, string token, IEnumerable <Route> localRoutes)
        {
            var parameter = new Stormancer.Dto.ConnectToSceneMsg
            {
                Token  = token,
                Routes = localRoutes.Select(r => new Stormancer.Dto.RouteDto
                {
                    Handle   = r.Handle,
                    Metadata = r.Metadata,
                    Name     = r.Name
                }).ToList(),
                ConnectionMetadata = _serverConnection.Metadata
            };

            return(this.SendSystemRequest <Stormancer.Dto.ConnectToSceneMsg, Stormancer.Dto.ConnectionResult>((byte)SystemRequestIDTypes.ID_CONNECT_TO_SCENE, parameter)
                   .ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    var ex = t.Exception.InnerException;
                    this.Logger.Log(Stormancer.Diagnostics.LogLevel.Error, scene.Id, string.Format("Failed to connect to scene '{0}' : {1}", scene.Id, ex.Message));
                    throw t.Exception.InnerException;
                }
                var result = t.Result;
                this.Logger.Log(Stormancer.Diagnostics.LogLevel.Trace, scene.Id, string.Format("Received connection result. Scene handle: {0}", result.SceneHandle));
                scene.CompleteConnectionInitialization(result);
                _scenesDispatcher.AddScene(scene);
                if (_pluginCtx.SceneConnected != null)
                {
                    _pluginCtx.SceneConnected(scene);
                }
            }));
        }
Example #2
0
        internal async Task ConnectToScene(Scene scene, string token, IEnumerable <Route> localRoutes)
        {
            var parameter = new Stormancer.Dto.ConnectToSceneMsg
            {
                Token  = token,
                Routes = localRoutes.Select(r => new Stormancer.Dto.RouteDto
                {
                    Handle   = r.Handle,
                    Metadata = r.Metadata,
                    Name     = r.Name
                }).ToList(),
                ConnectionMetadata = _serverConnection.Metadata
            };
            var result = await this.SendSystemRequest <Stormancer.Dto.ConnectToSceneMsg, Stormancer.Dto.ConnectionResult>((byte)SystemRequestIDTypes.ID_CONNECT_TO_SCENE, parameter);

            scene.CompleteConnectionInitialization(result);
            _scenesDispatcher.AddScene(scene);

            //Send ready message. It will fires the Connected event on the server. If not sent, the connection to the scene will timeout.
            //await _requestProcessor.SendSystemRequest(_serverConnection, (byte)SystemRequestIDTypes.ID_SCENE_READY, s =>
            //{
            //    s.WriteByte(scene.Handle);
            //});

            if (_pluginCtx.SceneConnected != null)
            {
                _pluginCtx.SceneConnected(scene);
            }
        }