コード例 #1
0
        public static ScaleoutMessage FromBytes(DbDataReader record)
#endif
        {
            var message = ScaleoutMessage.FromBytes(record.GetBinary(1));

            return(message);
        }
コード例 #2
0
        // Process messages sent from the backplane to the server
        private void FileCreated(object sender, FileSystemEventArgs e)
        {
            byte[] bytes;
            while (true)
            {
                try
                {
                    bytes = File.ReadAllBytes(e.FullPath);
                    break;
                }
                catch                 // The file is still in use
                {
                    Thread.Sleep(10); // Let's wait for a short while
                }                     // and try again
            }
            var    scaleoutMessage = ScaleoutMessage.FromBytes(bytes);
            ulong  id;
            string fileName = Path.GetFileNameWithoutExtension(e.Name);

            ulong.TryParse(fileName, out id);
            foreach (var message in scaleoutMessage.Messages)
            {
                OnReceived(0, id,
                           new ScaleoutMessage(new[] { message }));
            }
        }
コード例 #3
0
        private bool PollMessages(CallContext cntx, ulong lastId)
        {
            var            msgsvc = new SignalRMessageServiceProxy();
            DateTime       dt     = DateTime.UtcNow.AddHours(-config.TimeWindowInHours);
            QueryExpresion qexpr  = new QueryExpresion();

            qexpr.OrderTks = new List <QToken>(new QToken[] {
                new QToken {
                    TkName = "ID"
                },
                new QToken {
                    TkName = "desc"
                }
            });
            qexpr.FilterTks = new List <QToken>(new QToken[] {
                new QToken {
                    TkName = "ApplicationID == \"" + config.App.ID + "\" && ID > " + lastId + " && TimeStamp > " + dt.Ticks
                }
            });
            var msgs = msgsvc.QueryDatabaseLimited(cntx, new SignalRMessageSet(), qexpr, config.MaxBacklogMessages).ToArray();

            if (msgs.Length > 0)
            {
                LastMessageId          = (ulong)msgs[0].ID;
                IsLastMessageIdChanged = true;
                foreach (var e in from d in msgs orderby d.ID ascending select d)
                {
                    var smsg = ScaleoutMessage.FromBytes(e.MesssageData);
                    forwardMessage((ulong)e.ID, smsg);
                }
            }
            return(msgs.Length > 0);
        }
コード例 #4
0
 public void EntityChanged(EntitySetType SetType, int Status, string Entity)
 {
     if ((Status & (int)EntityOpStatus.Added) != 0)
     {
         switch (SetType)
         {
         case EntitySetType.SignalRMessage:
         {
             DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(SignalRMessage));
             byte[]       bf   = Encoding.UTF8.GetBytes(Entity);
             MemoryStream strm = new MemoryStream(bf);
             strm.Position = 0;
             var e = ser.ReadObject(strm) as SignalRMessage;
             if (e.ApplicationID == config.App.ID)
             {
                 ulong msgId = (ulong)e.ID;
                 try
                 {
                     forwardMessage(msgId, ScaleoutMessage.FromBytes(e.MesssageData));
                 }
                 catch
                 {
                 }
                 LastMessageId          = msgId;
                 IsLastMessageIdChanged = true;
             }
         }
         break;
         }
     }
 }
コード例 #5
0
        public void Handle(MessagesAvailable message)
        {
            var messages = ScaleoutMessage.FromBytes(message.Payload);

            if (SignalRMessageBus != null)
            {
                SignalRMessageBus.OnReceived(message.StreamIndex, message.PayloadId, messages);
            }
        }
コード例 #6
0
        private void Received(int streamIndex, long id, byte[] data)
        {
            ScaleoutMessage message = ScaleoutMessage.FromBytes(data);
            ulong           uid     = unchecked ((ulong)id);

            lock (typeof(SignalRMessageBus))
            {
                base.OnReceived(streamIndex, uid, message);
            }
        }
コード例 #7
0
        public void StartReceiving()
        {
            _hubProxy.On <byte[]>(BackplaneConstants.ReceiveNotification, m =>
            {
                ulong id = BitConverter.ToUInt64(m.Take(8).ToArray(), 0);
                ScaleoutMessage message = ScaleoutMessage.FromBytes(m.Skip(8).ToArray());

                foreach (Message msg in message.Messages)
                {
                    msg.MappingId = id;
                }

                _trace.TraceVerbose("Payload {0} containing {1} message(s) received", id, message.Messages.Count);
                Received(id, message);
            });
        }
コード例 #8
0
        private void ProcOldMessages(CallContext cntx, SignalRMessageServiceProxy msgsvc)
        {
            var hsvc = new SignalRHostStateServiceProxy();
            var host = hsvc.LoadEntityByNature(cntx, config.HostName, config.App.ID).SingleOrDefault();

            if (host == null)
            {
                host = new SignalRHostState
                {
                    HostName      = config.HostName,
                    ApplicationID = config.App.ID,
                    LastMsgId     = 0
                };
                var x = hsvc.AddOrUpdateEntities(cntx, new SignalRHostStateSet(), new SignalRHostState[] { host });
                host = x.ChangedEntities[0].UpdatedItem;
            }
            DateTime       dt    = DateTime.UtcNow.AddHours(-config.TimeWindowInHours);
            QueryExpresion qexpr = new QueryExpresion();

            qexpr.OrderTks = new List <QToken>(new QToken[] {
                new QToken {
                    TkName = "ID"
                },
                new QToken {
                    TkName = "desc"
                }
            });
            qexpr.FilterTks = new List <QToken>(new QToken[] {
                new QToken {
                    TkName = "ApplicationID == \"" + config.App.ID + "\" && ID > " + host.LastMsgId + " && TimeStamp > " + dt.Ticks
                }
            });
            var msgs = msgsvc.QueryDatabaseLimited(cntx, new SignalRMessageSet(), qexpr, config.MaxBacklogMessages).ToArray();

            if (msgs.Length > 0)
            {
                host.LastMsgId         = msgs[0].ID;
                LastMessageId          = (ulong)host.LastMsgId;
                IsLastMessageIdChanged = true;
                foreach (var e in from d in msgs orderby d.ID ascending select d)
                {
                    OnReceived(0, (ulong)e.ID, ScaleoutMessage.FromBytes(e.MesssageData));
                }
            }
        }
        void FromBytesToBytesProducesCorrectValues()
        {
            var message         = new Message("source", "key", "value");
            var message2        = new Message("string", "more", "str");
            var message3        = new Message("s", "l", "n");
            var scaleoutMessage = new ScaleoutMessage(new List <Message>()
            {
                message, message2, message3
            });

            var bytes = scaleoutMessage.ToBytes();
            var msg   = ScaleoutMessage.FromBytes(bytes);

            Assert.True(scaleoutMessage.Messages.Count == 3);
            Assert.True(scaleoutMessage.Messages[0].Source == msg.Messages[0].Source, "Source is not the same");
            Assert.True(scaleoutMessage.Messages[0].Key == msg.Messages[0].Key, "Key is not the same");
            Assert.True(scaleoutMessage.Messages[0].GetString() == msg.Messages[0].GetString(), "Value is not the same");
        }
コード例 #10
0
        public static ScaleoutMessage FromBrokeredMessage(BrokeredMessage brokeredMessage)
        {
            if (brokeredMessage == null)
            {
                throw new ArgumentNullException("brokeredMessage");
            }

            var stream = brokeredMessage.GetBody <Stream>();

            using (var ms = new MemoryStream())
            {
                stream.CopyTo(ms);

                var message = ScaleoutMessage.FromBytes(ms.ToArray());

                return(message);
            }
        }
コード例 #11
0
        private void OnReceived_P(byte[] data)
        {
            BinaryFormatter ser    = new BinaryFormatter();
            Packet          packet = null;

            using (MemoryStream ms = new MemoryStream())
            {
                ms.Write(data, 0, data.Length);
                ms.Seek(0, SeekOrigin.Begin);
                packet = ser.Deserialize(ms) as Packet;
            }


            var message = ScaleoutMessage.FromBytes(packet.Data);
            var args    = new OnReceivedArgs();

            args.Id      = packet.Id;
            args.Message = message;
            OnReceived(this, args);
        }
コード例 #12
0
 private ScaleoutMessage GetJsonMessage(dynamic msg, out ulong msgId)
 {
     msgId = 0;
     if ((string)msg["status"] == "added")
     {
         DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(SignalRMessage));
         byte[]       bf   = Encoding.UTF8.GetBytes((string)msg["data"]);
         MemoryStream strm = new MemoryStream(bf);
         strm.Position = 0;
         var e = ser.ReadObject(strm) as SignalRMessage;
         if (e.ApplicationID == config.App.ID)
         {
             msgId = (ulong)e.ID;
             return(ScaleoutMessage.FromBytes(e.MesssageData));
         }
         else
         {
             return(null);
         }
     }
     return(null);
 }
 public ScaleoutMessage ToScaleoutMessage()
 {
     return(ScaleoutMessage.FromBytes(Data));
 }
コード例 #14
0
        /* public static MongoMessage FromBytes(byte[] data)
         * {
         *   using (var stream = new MemoryStream(data))
         *   {
         *       var message = new MongoMessage();
         *
         *     /*  // read message id from memory stream until SPACE character
         *       var messageIdBuilder = new StringBuilder();
         *       do
         *       {
         *           // it is safe to read digits as bytes because they encoded by single byte in UTF-8
         *           int charCode = stream.ReadByte();
         *           if (charCode == -1)
         *           {
         *               throw new EndOfStreamException();
         *           }
         *           char c = (char)charCode;
         *           if (c == ' ')
         *           {
         *               message.Id = ulong.Parse(messageIdBuilder.ToString(), CultureInfo.InvariantCulture);
         *               messageIdBuilder = null;
         *           }
         *           else
         *           {
         *               messageIdBuilder.Append(c);
         *           }
         *       }
         *       while (messageIdBuilder != null);#1#
         *
         *       var binaryReader = new BinaryReader(stream);
         *       int count = binaryReader.ReadInt32();
         *       byte[] buffer = binaryReader.ReadBytes(count);
         *
         *       message = ScaleoutMessage.FromBytes(buffer);
         *       return message;
         *   }
         * }*/

        public static ScaleoutMessage FromBytes(MongoMessage msg)
        {
            return(ScaleoutMessage.FromBytes(msg.Value));
        }
        /// <summary>
        /// </summary>
        /// <param name="record"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static ScaleoutMessage FromBytes <T>(T record) where T : IMessagePayloadContainer
        {
            var message = ScaleoutMessage.FromBytes(record.Payload);

            return(message);
        }
コード例 #16
0
ファイル: SqlPayload.cs プロジェクト: fanikiwa/SignalR-dev
        public static ScaleoutMessage FromBytes(IDataRecord record)
        {
            var message = ScaleoutMessage.FromBytes(record.GetBinary(1));

            return(message);
        }
コード例 #17
0
        public static ScaleoutMessage FromBytes <T>(T record) where T : MessagesItemBase
        {
            var message = ScaleoutMessage.FromBytes(record.Payload);

            return(message);
        }
コード例 #18
0
        public override void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, byte[] body)
        {
            var msg = JsonConvert.DeserializeObject <RmqMessage>(Encoding.UTF8.GetString(body));

            this.onReceived(msg.StreamIndex, msg.Id, ScaleoutMessage.FromBytes(msg.Body));
        }
コード例 #19
0
 public object Deserialize(DataContractKey dataContractKey, Type dataType, byte[] body)
 {
     return(ScaleoutMessage.FromBytes(body));
 }
コード例 #20
0
 public object Deserialize(Type dataType, byte[] body)
 {
     return(ScaleoutMessage.FromBytes(body));
 }