Esempio n. 1
0
        protected void SendKinectMessageKeepAlive(object source, ElapsedEventArgs e)
        {
            if (Callback == null)
            {
                return;
            }

            KinectMessage kinectMessage = null;

            var channelState = ((IChannel)Callback).State;

            kinectMessage = new KinectMessage(MessageType.Information, "KeepAlive");
            if (channelState == CommunicationState.Opened)
            {
                try
                {
                    Callback.SendKinectMessage(kinectMessage.CreateBinaryMessage());
                }
                catch (Exception)
                {
                    _keepAliveFaulted      = true;
                    KeepAliveTimer.Enabled = false;
                    Console.WriteLine("Error sending keep-alive message.");
                    return;
                    //throw new FaultException<Exception>(new Exception("Client disconnected or unknown error."));
                }
            }
            else
            {
                _keepAliveFaulted      = true;
                KeepAliveTimer.Enabled = false;
            }
        }
Esempio n. 2
0
        protected async Task SendKinectMessage()
        {
            if (Callback == null)
            {
                return;
            }

            while (!_keepAliveFaulted)
            {
                if (NextKinectMessage != null && NextKinectMessage.MessageType != MessageType.None)
                {
                    //if (!KinectServiceBase.KinectMessages.TryDequeue(out kinectMessage)) continue;
                    switch (NextKinectMessage.MessageType)
                    {
                    case MessageType.HandPosition:
                    case MessageType.JointPosition:
                        //await
                        await Callback.SendKinectMessage(NextKinectMessage.CreateBinaryMessage());

                        break;

                    //kinectMessage = null;
                    case MessageType.DepthJpeg:
                    case MessageType.DepthArray:
                        var binaryMessage = NextKinectMessage.CreateBinaryMessage();
                        if (binaryMessage != null)
                        {
                            await
                            Callback.SendKinectMessage(
                                binaryMessage);
                        }
                        break;

                        //await callback.SendKinectMessage(kinectMessage.CreateBinaryMessage(kinectMessage.Depth));
                        //This option converts the message to a string and sends as Text
                        //var message = JsonConvert.SerializeObject(kinectMessage);
                        //await callback.SendKinectMessage(KinectMessage.CreateMessage(message));
                    }
                    //Resetting the next message
                    NextKinectMessage.MessageType = MessageType.None;
                }
                await Task.Delay(100);
            }
            Dispose();
        }