Пример #1
0
        public Session(ITransportChannel channel)
        {
            _channel = channel;
            Channel.Closed += _channel_Closed;
            _msgProc = new MessageProcessor(Channel, new MsgPackSerializer(new TypeResolver()));
            _msgProc.MessageReceived += msgProc_MessageReceived;
            MessageQueue.StartPolling();

            Thread commandPollThread = new Thread(new ThreadStart(() =>
            {
                var pendingCommands = MessageQueue.GetPendingCommands(Tracker.Id);
                if (pendingCommands.Length > 0)
                {
                    foreach (var command in pendingCommands)
                    {
                        //_msgProc.Send();
                        switch (command)
                        {
                            case "CMD.ACTIVATE":
                                _msgProc.Send(new CommandRequest{CommandId = 0});
                                break;
                            case "CMD.DEACTIVATE":
                                _msgProc.Send(new CommandRequest { CommandId = 1 });
                                break;
                            case "CMD.SIGNAL":
                                _msgProc.Send(new CommandRequest { CommandId = 2 });
                                break;
                        }
                    }
                }
            }));
            commandPollThread.Name = "StealME.Server.CommandSenderThread";
            commandPollThread.IsBackground = true;
            commandPollThread.Start();

            // Get Protocol version from Tracker
            _msgProc.Send(new GetRequest { GetTypeId = 2 });
        }
Пример #2
0
        public void Terminate()
        {
            // todo: mark Tracker OffLine in DB

            if(_msgProc != null)
                _msgProc.MessageReceived -= msgProc_MessageReceived;

            Channel.TerminateChannel();
            _msgProc = null;
            _channel = null;
            _protocol = null;
            _tracker = null;
        }