private TimeSpan updateTime; //wait this long between sendings

        #endregion Fields

        #region Constructors

        /// <summary>Create a new shared dictionary.</summary>
        /// <param name="s">A networked object channel.</param>
        /// <param name="updateTime">Batch updates until this amount of time has passed.</param>
        public AggregatingSharedDictionary(IObjectChannel s, TimeSpan updateTime)
            : base(s)
        {
            channel.Updated += channel_UpdateEvent;
            lastTimeSent = 0;
            this.updateTime = updateTime;
        }
示例#2
0
        public ClienteGT(string host, string port)
        {
            // this.form = f;

            // Set up GT
            client = new Client(new DefaultClientConfiguration());
            client.ErrorEvent += es => Console.WriteLine(es);
            // client.ErrorEvent += es => MessageBox.Show(es.ToString());

            // Evento do client
            client.ConnexionRemoved += client_ConnexionRemoved;
            client.Start();

            // Evento do client
            client.MessageSent += new MessageHandler(this.MensagemEnviada);

            // updates: controle de acesso à sessão
            updates = client.OpenSessionChannel(host, port, SessionUpdatesChannelId, ChannelDeliveryRequirements.SessionLike);

            // Evento do updates
            updates.MessagesReceived += updates_SessionMessagesReceived;

            // Utilizar o OpenObjectChannel para enviar objetos genéricos
            objts = client.OpenObjectChannel(host, port, ObjectChannelId, ChannelDeliveryRequirements.CommandsLike);

            objts.MessagesReceived += new Action<IObjectChannel>(objts_MessagesReceived);
        }
        private void channel_NewMessageEvent(IObjectChannel channel)
        {
            object o;
            while ((o = channel.DequeueMessage(0)) != null)
            {
                if (o is KeyValuePair<string, object>)    // push
                {
                    KeyValuePair<string, object> kvp = (KeyValuePair<string, object>)o;
                    //we don't accept updates on personal objects;
                    if (Master.Contains(kvp.Key))
                    {
                        //Console.WriteLine("{0}: key on master list: ignored push: {1}", this, kvp);
                        return;
                    }

                    //Console.WriteLine("{0}: received push: {1}", this, kvp);
                    //update or add our copy
                    if (sharedDictionary.ContainsKey(kvp.Key))
                    {
                        sharedDictionary[kvp.Key] = kvp.Value;
                    }
                    else
                    {
                        sharedDictionary.Add(kvp.Key, kvp.Value);
                    }

                    //inform our app that it has been updated
                    if (Changed != null) { Changed(kvp.Key); }
                }
                else if (o is string)
                {
                    //it's a pull.  if we have a copy, send it
                    string name = (string)o;
                    if (sharedDictionary.ContainsKey(name))
                    {
                        //Console.WriteLine("{0}: fulfilling request for: {1}", this, name);
                        PushKey(name, sharedDictionary[name]);
                    }
                    //else
                    //{
                    //    Console.WriteLine("{0}: cannot satisfy request: {1}", this, name);
                    //}
                }
                else
                {
                    Console.WriteLine("{0}: WARNING: received invalid object: {1} (ignored)", this, o);
                }
            }
        }
 /// <summary>Create a new shared dictionary.</summary>
 /// <param name="s">A networked object channel.</param>
 public SimpleSharedDictionary(IObjectChannel s)
 {
     this.channel = s;
     this.channel.MessagesReceived += channel_NewMessageEvent;
     this.Master = new List<string>();
     this.sharedDictionary = new Dictionary<string, object>();
 }
示例#5
0
        void objts_MessagesReceived(IObjectChannel obj)
        {
            Object desserializado;
            Object o;
            String nomeEvento;

            while ((desserializado = objts.DequeueMessage(0)) != null)
            {
                ArrayList list = (ArrayList)desserializado;

                o = list[0];
                nomeEvento = (String)list[1];

                #region mouseMovedPointer
                if (nomeEvento.Equals("mouseMovedPointer"))
                {

                    // ((frmKeyboard)this.Form).ContaTelefingerRemovido++;

                    // Recebe os dados do objeto de rede transportado
                    ArrayList dados_rec = (ArrayList)o;

                    // int pos =  int.Parse(dados_rec[2].ToString());

                    // this.Form.aTelepointers[pos].Visible = true;
                    // this.Form.aTelepointers[pos].Location = (Point)dados_rec[0];

                    // this.Form.OnMouseMoveImpl((Point) dados_rec[0], (Color) dados_rec[1], pos, dados_rec[3].ToString());

                    // Precisa utilizar delegates, pois existem problemas quando uma Thread que não é
                    // o formulário atualiza a interface gráfica
                   //  this.form.Invoke(new SmallKeyboard.frmKeyboard.DelegateGenerico(this.form.OnMouseMoveImpl), new object[] { dados_rec });

                }
                #endregion

                ContaRecebidas++;
            }
        }
示例#6
0
文件: Form1.cs 项目: solson/DSAE
        void Form1_Load(object sender, EventArgs e)
        {
            if (Program.kinectEnabled)
                kinectClient.RecalculateTable();

            // Set up GT
            var config = new DefaultClientConfiguration();
            client = new GT.Net.Client(config);

            client.ErrorEvent += delegate(ErrorSummary es)
            {
                Console.WriteLine(es);

                if (es.Context is GT.Net.CannotConnectException)
                {
                    Cursor.Show();
                    MessageBox.Show(this, "Could not connect to server. Make sure the ClientRepeater is started.");
                    quitting = true;
                }
            };

            client.ConnexionRemoved += client_ConnexionRemoved;
            client.Start();

            updates = client.OpenSessionChannel(host, port, SessionUpdatesChannelId,
                ChannelDeliveryRequirements.SessionLike);
            updates.MessagesReceived += updates_SessionMessagesReceived;

            coords = client.OpenStreamedTuple<int, int>(host, port, PointersChannelId,
                TimeSpan.FromMilliseconds(25),
                ChannelDeliveryRequirements.AwarenessLike);
            coords.StreamedTupleReceived += coords_StreamedTupleReceived;

            control = client.OpenStringChannel(host, port, ControlChannelId,
                ChannelDeliveryRequirements.CommandsLike);
            control.MessagesReceived += control_MessagesReceived;

            clicks = client.OpenStringChannel(host, port, ClickChannelId,
                ChannelDeliveryRequirements.CommandsLike);
            clicks.MessagesReceived += clicks_MessagesReceived;

            armImages = client.OpenObjectChannel(host, port, ArmImageChannelId,
                ChannelDeliveryRequirements.AwarenessLike);
            armImages.MessagesReceived += armImages_MessagesReceived;

            origins = client.OpenStreamedTuple<int, int>(host, port, OriginsChannelId,
                TimeSpan.FromMilliseconds(25),
                ChannelDeliveryRequirements.AwarenessLike);
            origins.StreamedTupleReceived += origins_StreamedTupleReceived;

            showArms = client.OpenStreamedTuple<bool>(host, port, ShowArmsChannelId,
                TimeSpan.FromMilliseconds(25),
                ChannelDeliveryRequirements.AwarenessLike);
            showArms.StreamedTupleReceived += showArms_StreamedTupleReceived;

            kinectCalibrationChannel = client.OpenObjectChannel(host, port, KinectCalibrationChannelId,
                ChannelDeliveryRequirements.CommandsLike);
            kinectCalibrationChannel.MessagesReceived += kinectCalibrationChannel_MessagesReceived;

            boxGrabChannel = client.OpenObjectChannel(host, port, BoxGrabChannelId,
                ChannelDeliveryRequirements.CommandsLike);
            boxGrabChannel.MessagesReceived += boxGrabChannel_MessagesReceived;

            if (Program.useTouch)
            {
                tuioClient = new TuioClient();
                tuioClient.addTuioListener(this);
                tuioClient.connect();
            }
        }
示例#7
0
文件: Form1.cs 项目: solson/DSAE
 private void kinectCalibrationChannel_MessagesReceived(IObjectChannel channel)
 {
     object obj;
     while ((obj = channel.DequeueMessage(0)) != null)
     {
         float[] vals = (float[])obj;
         theirCalibration = new Matrix(vals[0], vals[1], vals[2], vals[3], vals[4], vals[5]);
     }
 }
示例#8
0
文件: Form1.cs 项目: solson/DSAE
        private void armImages_MessagesReceived(IObjectChannel channel)
        {
            object obj;
            while ((obj = channel.DequeueMessage(0)) != null)
            {
                var msg = (ArmImageMessage)obj;

                theirArmImage = BitmapFromByteArray(msg.Image);
                theirArmRect = msg.Rect;
                theirArmMask = BitmapFromByteArray(msg.Mask);
                maskArm(theirArmImage, theirArmMask);
            }
        }
示例#9
0
文件: Form1.cs 项目: solson/DSAE
        private void boxGrabChannel_MessagesReceived(IObjectChannel channel)
        {
            object obj;
            while ((obj = channel.DequeueMessage(0)) != null)
            {
                BoxGrabMessage msg = (BoxGrabMessage)obj;

                //updateRemoteMousePosition(msg.X, msg.Y);

                if (msg.Dropped)
                {
                    if (playerID == 0 && boxBeingDraggedByUser2 != null)
                    {
                        boxBeingDraggedByUser2.dropped();
                        boxBeingDraggedByUser2 = null;
                    }
                    else if (playerID == 1 && boxBeingDraggedByUser1 != null)
                    {
                        boxBeingDraggedByUser1.dropped();
                        boxBeingDraggedByUser1 = null;
                    }
                }
                else
                {
                    int otherPlayerID = (playerID == 0) ? 2 : 1;
                    toggleWordBoxUnderCursorNumberDragging(otherPlayerID, new Point(msg.X, msg.Y));
                }
            }
        }
示例#10
0
文件: Client.cs 项目: briandealwis/gt
        public void Start()
        {
            sw = new Stopwatch();

            client.Start();
            client.StartSeparateListeningThread();

            updates = client.OpenObjectChannel(host, port.ToString(), 1,
                ChannelDeliveryRequirements.MostStrict);
            updates.MessagesReceived += _updates_Received;

            timer.Start();
            sw.Start();
        }
示例#11
0
文件: Client.cs 项目: briandealwis/gt
 private void _updates_Received(IObjectChannel channel)
 {
     object obj;
     while((obj = channel.DequeueMessage(0)) != null)
     {
         if(obj is WindowBoundsChanged)
         {
             height = ((WindowBoundsChanged) obj).Height;
             width = ((WindowBoundsChanged)obj).Width;
             radius = ((WindowBoundsChanged)obj).Radius;
         } else
         {
             Console.WriteLine("Unknown message: " + obj);
         }
     }
 }
示例#12
0
        void objts_MessagesReceived(IObjectChannel obj)
        {
            // objts.Messages

            // label4.Text = "Qtd:" + objts.Messages.Count.ToString();

            Object o;

            while ((o = objts.DequeueMessage(0)) != null)
            {
                System.Collections.ArrayList l = (System.Collections.ArrayList)o;

                int x = (int)l[0];
                int y = (int)l[1];

                label3.Text = "X: " + x.ToString() + " Y: " + y.ToString();

                ContaRecebidas++;
                this.label2.Text = "Recebidas:" + ContaRecebidas.ToString();
            }

            // objts.DequeueMessage(0)

            // throw new NotImplementedException();
        }
示例#13
0
        private void Form1_Load(object sender, EventArgs e)
        {
            InputDialog d = new InputDialog("Connection details", "Which server:port ?", "localhost:9999");
            if (d.ShowDialog() != DialogResult.OK)
            {
                throw new InvalidOperationException();
            }
            string[] parts = d.Input.Split(':');
            string host = parts[0];
            string port = parts.Length > 1 ? parts[1] : "9999";

            // Aqui vou colocar a chamada para o cliente GT!
            // cGT = new ClienteGT(host, port);

            // Set up GT
            client = new Client(new DefaultClientConfiguration());
            client.ErrorEvent += es => Console.WriteLine(es);

            // Evento do client
            client.ConnexionRemoved += client_ConnexionRemoved;
            client.Start();

            // Evento do client
            client.MessageSent += new MessageHandler(this.MensagemEnviada);

            updates = client.OpenSessionChannel(host, port, SessionUpdatesChannelId,
                ChannelDeliveryRequirements.SessionLike);

            // Evento do updates
            updates.MessagesReceived += updates_SessionMessagesReceived;

            // coords armazena os dados recebidos (é a tupla)
               // coords = client.OpenStreamedTuple<int, int>(host, port, TelepointersChannelId,
               //     TimeSpan.FromMilliseconds(50),
               //     ChannelDeliveryRequirements.AwarenessLike);

            coords = client.OpenStreamedTuple<int, int>(host, port, TelepointersChannelId,
                TimeSpan.FromMilliseconds(50),
                ChannelDeliveryRequirements.AwarenessLike);

            // Evento do coords
            coords.StreamedTupleReceived += coords_StreamedTupleReceived;

            // coords.Identity

            // Utilizar o OpenObjectChannel para enviar um objeto ao invés de enviar uma tupla
            // objts = client.OpenObjectChannel(host, port, ObjectChannelId, ChannelDeliveryRequirements.AwarenessLike);
            objts = client.OpenObjectChannel(host, port, ObjectChannelId, ChannelDeliveryRequirements.CommandsLike);

            objts.MessagesReceived += new Action<IObjectChannel>(objts_MessagesReceived);
        }
示例#14
0
        void objts_MessagesReceived(IObjectChannel obj)
        {
            Object desserializado;
            Object o;
            String nomeEvento;
            String login_recebido;
            String sessao_recebida;

            while ((desserializado = objts.DequeueMessage(0)) != null)
            {
                ArrayList list = (ArrayList)desserializado;

                o = list[0];
                nomeEvento = (String)list[1];
                ArrayList credencial = (ArrayList)list[2];

                #region VerificaUserSessao
                // Aqui vou verificar se a mensagem recebida não foi mandanda
                // por mim mesmo e se a mensagem faz parte da mesma sessão
                login_recebido = (string)credencial[0];
                sessao_recebida = (string)credencial[1];

                if (login_recebido.Equals(this.login))
                    continue;
                if(!sessao_recebida.Equals(this.sessao))
                    continue;
                #endregion

                #region mouseMovedPointer
                if (nomeEvento.Equals("mouseMovedPointer"))
                {

                    // ((frmKeyboard)this.Form).ContaTelefingerRemovido++;

                    // Recebe os dados do objeto de rede transportado
                    ArrayList dados_rec = (ArrayList)o;

                    // int pos =  int.Parse(dados_rec[2].ToString());

                    // this.Form.aTelepointers[pos].Visible = true;
                    // this.Form.aTelepointers[pos].Location = (Point)dados_rec[0];

                    // this.Form.OnMouseMoveImpl((Point) dados_rec[0], (Color) dados_rec[1], pos, dados_rec[3].ToString());

                    // Precisa utilizar delegates, pois existem problemas quando uma Thread que não é
                    // o formulário atualiza a interface gráfica
                    this.form.Invoke(new SmallKeyboard.frmKeyboard.DelegateGenerico(this.form.OnMouseMoveImpl), new object[] { dados_rec });

                }
                #endregion

                #region fingerCreatePointer, fingerMovePointer ou fingerRemovePointer
                if (nomeEvento.Equals("fingerCreatePointer")
                    || nomeEvento.Equals("fingerMovePointer")
                    || nomeEvento.Equals("fingerRemovePointer"))
                {
                    ArrayList dados_rec = (ArrayList)o;
                    dados_rec.Add(nomeEvento);

                    // Precisa utilizar delegates, pois existem problemas quando uma Thread que não é
                    // o formulário atualiza a interface gráfica
                    this.form.Invoke(new frmKeyboard.DelegateGenerico(this.form.OnTelefingerImpl), new object[] { dados_rec });

                }
                #endregion

                ContaRecebidas++;
            }
        }
示例#15
0
        public virtual void Start()
        {
            running = true;
            client.Start();
            objectChannel = client.OpenObjectChannel(host, port,
                0, ChannelDeliveryRequirements.MostStrict);
            objectChannel.MessagesReceived += client_ReceivedObjectMessage;
            stringChannel = client.OpenStringChannel(host, port,
                1, ChannelDeliveryRequirements.MostStrict);
            stringChannel.MessagesReceived += client_ReceivedStringMessage;
            binaryChannel = client.OpenBinaryChannel(host, port,
                2, ChannelDeliveryRequirements.MostStrict);
            binaryChannel.MessagesReceived += client_ReceivedBinaryMessage;

            client.StartSeparateListeningThread();
            for (int i = 0; i < numberSenders; i++)
            {
                Thread t = new Thread(client_StartThread);
                t.IsBackground = true;
                t.Name = "Client thread #" + i;
                t.Start(i);
                threads.Add(t);
            }
        }
示例#16
0
        private void client_ReceivedObjectMessage(IObjectChannel channel)
        {
            object message;
            while ((message = channel.DequeueMessage(0)) != null)
            {
                if (!StandardObjects.Equivalent(StandardObjects.ObjectMessage, message))
                {
                    Console.WriteLine("Invalid object message: {0}",
                        message);
                    errorOccurred = true;
                }

                if (random.Next(0, 100) < 10)
                {
                    objectChannel.Send(message);
                }
            }
        }