Пример #1
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
                });
            }
        }
        public void Build(PluginBuildContext ctx)
        {
            ctx.ClientCreated += client =>
            {
                var innerLoggerFactory = client.DependencyResolver.Resolve <ILogger>();
                _clientVM    = new StormancerClientViewModel(client);
                _clientVM.id = _id;
                client.DependencyResolver.Register <ILogger>(() => new InterceptorLogger(innerLoggerFactory, _clientVM));
                StormancerEditorDataCollector.Instance.clients.TryAdd(_id, _clientVM);
            };

            ctx.ClientDestroyed += client =>
            {
                StormancerClientViewModel temp;
                StormancerEditorDataCollector.Instance.clients.TryRemove(_id, out temp);
            };

            ctx.SceneCreated += scene =>
            {
                _clientVM.scenes.TryAdd(scene.Id, new StormancerSceneViewModel(scene));
            };

            ctx.SceneConnected += scene =>
            {
                if (StormancerEditorDataCollector.Instance.clients.ContainsKey(_id))
                {
                    if (StormancerEditorDataCollector.Instance.clients[_id].scenes.ContainsKey(scene.Id))
                    {
                        StormancerEditorDataCollector.Instance.clients[_id].scenes[scene.Id].connected = true;
                    }
                }
            };

            ctx.SceneDisconnected += scene =>
            {
                if (StormancerEditorDataCollector.Instance.clients.ContainsKey(_id))
                {
                    if (StormancerEditorDataCollector.Instance.clients[_id].scenes.ContainsKey(scene.Id))
                    {
                        StormancerEditorDataCollector.Instance.clients[_id].scenes[scene.Id].connected = false;
                    }
                }
            };

            ctx.RouteCreated += (Scene scene, Route route) =>
            {
                StormancerSceneViewModel sceneVM;
                if (_clientVM.scenes.TryGetValue(scene.Id, out sceneVM))
                {
                    sceneVM.routes.TryAdd(route.Name, new StormancerRouteViewModel(route));
                }
            };

            ctx.PacketReceived += (Packet packet) =>
            {
                if (_clientVM != null && _clientVM.exportLogs == true)
                {
                    var pos     = packet.Stream.Position;
                    var message = new List <byte>();
                    var buffer  = new byte[1024];

                    int readByte = 0;
                    do
                    {
                        readByte = packet.Stream.Read(buffer, 0, 1024);
                        message.AddRange(buffer.Take(readByte));
                    }while (readByte > 0);
                    packet.Stream.Seek(pos, SeekOrigin.Begin);

                    var scene   = (Scene)packet.Metadata["scene"];
                    var routeId = (ushort)packet.Metadata["routeId"];

                    StormancerRouteViewModel routeVM = null;
                    StormancerSceneViewModel sceneVM = null;
                    string route = "";
                    if (_clientVM.scenes.TryGetValue(scene.Id, out sceneVM))
                    {
                        routeVM = sceneVM.routes.Values.FirstOrDefault(r => r.Handle == routeId);
                    }
                    if (routeVM != null)
                    {
                        route = routeVM.Name;
                    }
                    if (route == "")
                    {
                        route = "system";
                    }
                    _clientVM.WritePacketLog(true, scene.Id, route, message);
                }
            };

            ctx.PacketReceived += (Packet packet) =>
            {
                if (packet.Metadata.ContainsKey("scene"))
                {
                    var scene = (Scene)packet.Metadata["scene"];
                    StormancerSceneViewModel sceneVM;
                    if (_clientVM.scenes.TryGetValue(scene.Id, out sceneVM))
                    {
                        var routeId = (ushort)packet.Metadata["routeId"];
                        var temp    = sceneVM.routes.Values.FirstOrDefault(r => r.Handle == routeId);
                        if (temp != null)
                        {
                            StormancerEditorDataCollector.Instance.GetDataStatistics(packet.Stream, _clientVM, temp);
                        }
                    }
                }
            };
        }
Пример #3
0
        public void Build(PluginBuildContext ctx)
        {
            ctx.ClientCreated += client =>
            {
                var innerLoggerFactory = client.DependencyResolver.GetComponent <ILogger>();
                _clientVM = new StormancerClientViewModel(client);
                client.DependencyResolver.RegisterComponent <ILogger>(() => new InterceptorLogger(innerLoggerFactory, _clientVM));
                StormancerEditorDataCollector.Instance.clients.TryAdd(_id, _clientVM);
            };

            ctx.ClientDestroyed += client =>
            {
                StormancerClientViewModel temp;
                StormancerEditorDataCollector.Instance.clients.TryRemove(_id, out temp);
            };

            ctx.SceneCreated += scene =>
            {
                _clientVM.scenes.TryAdd(scene.Id, new StormancerSceneViewModel(scene));
            };

            ctx.SceneConnected += scene =>
            {
                if (StormancerEditorDataCollector.Instance.clients.ContainsKey(_id))
                {
                    if (StormancerEditorDataCollector.Instance.clients[_id].scenes.ContainsKey(scene.Id))
                    {
                        StormancerEditorDataCollector.Instance.clients[_id].scenes[scene.Id].connected = true;
                    }
                }
            };

            ctx.SceneDisconnected += scene =>
            {
                if (StormancerEditorDataCollector.Instance.clients.ContainsKey(_id))
                {
                    if (StormancerEditorDataCollector.Instance.clients[_id].scenes.ContainsKey(scene.Id))
                    {
                        StormancerEditorDataCollector.Instance.clients[_id].scenes[scene.Id].connected = false;
                    }
                }
            };

            ctx.RouteCreated += (Scene scene, Route route) =>
            {
                StormancerSceneViewModel sceneVM;
                if (_clientVM.scenes.TryGetValue(scene.Id, out sceneVM))
                {
                    sceneVM.routes.TryAdd(route.Name, new StormancerRouteViewModel(route));
                }
            };

            ctx.PacketReceived += (Packet packet) =>
            {
                if (packet.Metadata.ContainsKey("scene"))
                {
                    var scene = (Scene)packet.Metadata["scene"];
                    StormancerSceneViewModel sceneVM;
                    if (_clientVM.scenes.TryGetValue(scene.Id, out sceneVM))
                    {
                        var routeId = (ushort)packet.Metadata["routeId"];
                        var temp    = sceneVM.routes.Values.FirstOrDefault(r => r.Handle == routeId);
                        if (temp != null)
                        {
                            temp.sizeStack  += packet.Stream.Length;
                            temp.messageNbr += 1;
                            if (temp.messageNbr == 1)
                            {
                                temp.averageSize = packet.Stream.Length;
                            }
                            else
                            {
                                temp.averageSize = (temp.averageSize * (temp.messageNbr - 1) + packet.Stream.Length) / temp.messageNbr;
                            }

                            if (temp.lastUpdate + 1000 < _clientVM.client.Clock)
                            {
                                if (temp.dataChart.Count >= 10800)
                                {
                                    temp.dataChart.RemoveAt(0);
                                }
                                if (temp.messageNbrChart.Count >= 10800)
                                {
                                    temp.messageNbrChart.RemoveAt(0);
                                }
                                if (temp.averageSizeChart.Count >= 10800)
                                {
                                    temp.averageSizeChart.RemoveAt(0);
                                }
                                temp.debit      = temp.sizeStack;
                                temp.lastUpdate = _clientVM.client.Clock;
                                temp.curve.AddKey(_clientVM.client.Clock, temp.sizeStack);
                                temp.dataChart.Add(temp.sizeStack);
                                temp.messageNbrChart.Add(temp.messageNbr);
                                temp.averageSizeChart.Add(temp.averageSize);

                                temp.messageNbr  = 0;
                                temp.averageSize = 0;
                                temp.sizeStack   = 0;
                            }
                        }
                    }
                }
            };
        }