コード例 #1
0
        /// <summary>
        /// Creates a Stormancer client instance.
        /// </summary>
        /// <param name="configuration">A configuration instance containing options for the client.</param>
        public Client(ClientConfiguration configuration)
        {
            this._pingInterval = configuration.PingInterval;
            this._scheduler    = configuration.Scheduler;
            DependencyResolver = new StormancerResolver();
            DependencyResolver.Register <ILogger>(() => configuration.Logger);
            DependencyResolver.Register(() => new ApiClient(configuration, DependencyResolver));
            DependencyResolver.Register <ITokenHandler>(() => new TokenHandler());
            DependencyResolver.RegisterComponent <IConnectionHandler>(new IConnectionHandler());
            DependencyResolver.RegisterComponent <IClock>(new IClock(this));

#if UNITY_EDITOR
            IConnectionHandler temp = DependencyResolver.Resolve <IConnectionHandler>();
            temp.PeerConnected += (PeerConnectedContext pcc) =>
            {
                ConnectionWrapper connection = new ConnectionWrapper(pcc.Connection, configuration.Plugins.OfType <EditorPlugin.StormancerEditorPlugin>().First());
                pcc.Connection = connection;
            };
#endif

            this.DependencyResolver.Register <ITransport>(configuration.TransportFactory);
            this._accountId       = configuration.Account;
            this._applicationName = configuration.Application;
            //TODO handle scheduler in the transport
            this._dispatcher  = configuration.Dispatcher;
            _requestProcessor = new Stormancer.Networking.Processors.RequestProcessor(Logger, Enumerable.Empty <IRequestModule>());

            _scenesDispatcher = new Processors.SceneDispatcher();
            this._dispatcher.AddProcessor(_requestProcessor);
            this._dispatcher.AddProcessor(_scenesDispatcher);
            this._metadata = configuration._metadata;

            foreach (var serializer in configuration.Serializers)
            {
                this._serializers.Add(serializer.Name, serializer);
            }

            this._maxPeers = configuration.MaxPeers;

            foreach (var plugin in configuration.Plugins)
            {
                plugin.Build(_pluginCtx);
            }

            var ev = _pluginCtx.ClientCreated;
            if (ev != null)
            {
                ev(this);
            }

            _transport = DependencyResolver.Resolve <ITransport>();
            this._metadata.Add("serializers", string.Join(",", this._serializers.Keys.ToArray()));
            this._metadata.Add("transport", _transport.Name);
            this._metadata.Add("version", "1.1.0");
            this._metadata.Add("platform", "Unity");
            this._metadata.Add("protocol", "2");

            Initialize();
        }
コード例 #2
0
        internal Scene(IConnection connection, Client client, string id, string token, Stormancer.Dto.SceneInfosDto dto, PluginBuildContext pluginCtx, StormancerResolver res)
        {
            Id                 = id;
            this._peer         = connection;
            _token             = token;
            _client            = client;
            _metadata          = dto.Metadata;
            _pluginCtx         = pluginCtx;
            DependencyResolver = new StormancerResolver(res);

            foreach (var route in dto.Routes)
            {
                _remoteRoutesMap.Add(route.Name, new Route(this, route.Name, route.Metadata)
                {
                    Handle = route.Handle
                });
            }
        }
コード例 #3
0
 public ApiClient(ClientConfiguration configuration, StormancerResolver resolver)
 {
     _config   = configuration;
     _resolver = resolver;
 }
コード例 #4
0
 public StormancerResolver(StormancerResolver parent = null)
 {
     _parent = parent;
 }