示例#1
0
        public void Get_NotFound(GetOperation operation)
        {
            // Arrange
            var         options  = new ProtocolOptions();
            var         protocol = new DefaultProtocol(m_mockFactory.Object, options);
            var         datakey  = new DataKey <int>("Key1");
            var         key      = new byte[] { };
            ValuePacket packet   = null;

            m_mockEncoder.Setup(encoder => encoder.GetBytes("Key1")).Returns(key);
            m_mockCommandWriter.Setup(writer => writer.Get(operation, key));
            m_mockFactory.Setup(factory => factory.Context(key))
            .Returns <byte[]>(state => (Action2 <IClientConnection, object> action) =>
            {
                action(m_mockClientConnection.Object, state);
                return(true);
            });
            m_mockClientConnection.SetupGet(connection => connection.Writer).Returns(m_mockBinaryWriter.Object);
            m_mockPacketBuilder.Setup(builder => builder.WriteTo(m_mockBinaryWriter.Object)).Returns(0);
            m_mockClientConnection.SetupGet(connection => connection.Reader).Returns(m_mockBinaryReader.Object);
            m_mockFactory.Setup(factory => factory.CreatePacketParser(m_mockBinaryReader.Object, It.IsAny <Buffer <byte> >())).Returns(m_mockPacketParser.Object);
            m_mockFactory.Setup(factory => factory.CreateCommandReader(m_mockPacketParser.Object)).Returns(m_mockCommandReader.Object);
            m_mockCommandReader.Setup(reader => reader.ReadValue(operation == GetOperation.Gets)).Returns(packet);

            // Act
            var result = protocol.Get(operation, datakey);

            // Assert
            Assert.True(result);
            Assert.False(datakey.HasValue);
        }
示例#2
0
        public void GetMany(GetOperation operation)
        {
            // Arrange
            var options  = new ProtocolOptions();
            var protocol = new DefaultProtocol(m_mockFactory.Object, options);
            var datakey1 = new DataKey <int>("Key1");
            var datakey2 = new DataKey <bool>("Key2");
            var key1     = new byte[] { 1 };
            var key2     = new byte[] { 2 };

            byte[][] keys   = null;
            var      packet = new ValuePacket()
            {
                Flags   = 101,
                Key     = key1,
                Value   = new ArraySegment <byte>(new byte[] { }),
                Version = 245
            };

            m_mockEncoder.Setup(encoder => encoder.GetBytes("Key1")).Returns(key1);
            m_mockEncoder.Setup(encoder => encoder.GetBytes("Key2")).Returns(key2);
            m_mockFactory.Setup(factory => factory.Context(It.IsAny <byte[][]>()))
            .Returns <byte[][]>(state => (Action2 <IClientConnection, object> action) =>
            {
                keys = (byte[][])state;
                action(m_mockClientConnection.Object, state);
                return(true);
            });
            m_mockCommandWriter.Setup(writer => writer.GetMany(operation, It.IsAny <byte[][]>()));
            m_mockClientConnection.SetupGet(connection => connection.Writer).Returns(m_mockBinaryWriter.Object);
            m_mockPacketBuilder.Setup(builder => builder.WriteTo(m_mockBinaryWriter.Object)).Returns(0);
            m_mockClientConnection.SetupGet(connection => connection.Reader).Returns(m_mockBinaryReader.Object);
            m_mockFactory.Setup(factory => factory.CreatePacketParser(m_mockBinaryReader.Object, It.IsAny <Buffer <byte> >())).Returns(m_mockPacketParser.Object);
            m_mockFactory.Setup(factory => factory.CreateCommandReader(m_mockPacketParser.Object)).Returns(m_mockCommandReader.Object);
            m_mockCommandReader.Setup(reader => reader.ReadValue(operation == GetOperation.Gets)).Returns(() =>
            {
                var p = packet;
                if (packet != null)
                {
                    packet = null;
                }

                return(p);
            });
            m_mockObjectFormatter.Setup(formatter => formatter.Deserialize <int>(packet.Value, packet.Flags)).Returns(507);

            // Act
            var result = protocol.GetMany(operation, new DataKey[] { datakey1, datakey2 });

            // Assert
            Assert.True(result);
            Assert.True(datakey1.HasValue);
            Assert.Equal(245, datakey1.Version);
            Assert.Equal(507, datakey1.Value);
            Assert.False(datakey2.HasValue);
        }
示例#3
0
        public void OnActualSizeChanged(double w, double h, bool control = false)
        {
            var nw = (w < 8 ? 8 : w);
            var nh = (h < 8 ? 8 : h);

            if (nw != sourceWidth || nh != sourceHeight)
            {
                lastWidth  = (ushort)nw;
                lastHeight = (ushort)nh;
            }

            if (control)
            {
                controlWidth = (ushort)nw;
            }

            var num = sourceWidth;
            var den = nw;

            if (nh < nw)
            {
                num = sourceHeight;
                den = nh;
            }

            if (den > num)
            {
                SuggestedDenominator = 1;
            }

            else
            {
                SuggestedDenominator = (uint)(num / den);
            }

            var values = Origin.GetDenominators();

            if (values.Count() > 0)
            {
                var sb = new StringBuilder();
                foreach (var d in values)
                {
                    sb.Append(d + "/");
                }

                sb.Remove(sb.Length - 1, 1);
                var vp = new ValuePacket();
                vp.Data["den"] = sb.ToString();
                Origin.SendPacket(vp).Flush();
            }

            invalHeader = true;
        }
示例#4
0
 private void Sync(ValuePacket p)
 {
     if (!SyncData)
     {
         return;
     }
     if (Constants.IsServer)
     {
         p.SendToOthers();
     }
     else
     {
         p.SendToServer();
     }
 }
示例#5
0
        protected override bool HandlePacket(string packet)
        {
            var pingPkt = new PingPacket();

            if (pingPkt.ParsePacket(packet))
            {
                SendPacket(new PongPacket()
                {
                    Text = pingPkt.Text
                }).Flush();
                return(true);
            }

            var errPkt = new ErrorPacket();

            if (errPkt.ParsePacket(packet))
            {
                return(false);
            }

            var dpPkt = new DisplayPortsPacket();

            if (dpPkt.ParsePacket(packet) && transmitter != null)
            {
                transmitter.Close();
                transmitter.Open(dpPkt.Ports);
                return(true);
            }

            var valPkt = new ValuePacket();

            if (valPkt.ParsePacket(packet))
            {
                if (valPkt.Data.ContainsKey("delay"))
                {
                    delay = (int)valPkt.Data["delay"];
                }

                if (valPkt.Data.ContainsKey("den"))
                {
                    var d = new List <uint>();
                    foreach (var v in valPkt.Data["den"].ToString().Split('/'))
                    {
                        d.Add(Convert.ToUInt32(v));
                    }

                    transmitter.SetDenominators(d);
                }

                return(true);
            }

            var ntPkt = new NotificationPacket();

            if (ntPkt.ParsePacket(packet))
            {
                SnvBackend.ShowNotification(ntPkt.Text, ntPkt.SoundAlert ? 1 : 0);
                return(true);
            }

            return(true);
        }