コード例 #1
0
        public void MessageToString()
        {
          var message = new Message();

          message.Address = "Test";
          message.Init("foo", "bar");
          message.TimeStamp = Time.MinUTCTime();
          		
           Assert.AreEqual("Message Test (01.01.0001 01:00:00 [UTC])\n foo \t: bar \r\n", message.ToString());
        }
コード例 #2
0
        public void MessageToJson()
        {

            var message = new Message();
            message.Init("foo", "bar");
            message.Address = "Test";
            message.TimeStamp = Time.MinUTCTime();

            var settings = new JsonSerializerSettings { Formatting = Formatting.None, TypeNameHandling = TypeNameHandling.None };


            string json = JsonConvert.SerializeObject(message, settings);
            var newMessage = (Message)JsonConvert.DeserializeObject(json, typeof(Message));


            Assert.AreEqual("{\"Address\":\"Test\",\"TimeStamp\":{\"UTC\":\"0001-01-01 00:00:00.0000\",\"ZoneId\":\"UTC\"},\"Data\":{\"foo\":{\"string\":[\"bar\"]}}}", json);

            Assert.AreEqual(message.ToString(), newMessage.ToString());


        }
コード例 #3
0
ファイル: Message.cs プロジェクト: sebllll/vvvv-Message
		public object Clone() {
			Message m = new Message();
			m.Address = Address;
			m.TimeStamp = TimeStamp;
			
			foreach (string name in Data.Keys) {
				Bin list = Data[name];
				m.AssignFrom(name, list.Clone());
				
				// really deep cloning
				try {
					for(int i =0;i<list.Count;i++) {
						list[i] = ((ICloneable)list[i]).Clone();
					}
				} catch (Exception err) {
					err.ToString(); // no warning
					// not cloneble. so keep it
				}
			}
			
			return m;
		}
コード例 #4
0
ファイル: Message.cs プロジェクト: sebllll/vvvv-Message
        protected void ReplaceWith(Message message, bool AllowNew = false)
        {
            var keys = message.Attributes;
            if (!AllowNew) keys = keys.Intersect(this.Attributes);

            foreach (var name in keys)
            {
                if (!this.Data.ContainsKey(name))
                {
                    this.AssignFrom(name, message.Data[name]);
                }
                else
                {
                    var newType = message.Data[name].GetInnerType();
                    var oldType = this.Data[name].GetInnerType();

                    if (newType.IsCastableTo(oldType)) this.Data[name].AssignFrom(message.Data[name]); // autocast.

                    else
                    {
                        throw new Exception("Cannot replace Bin<" + TypeIdentity.Instance.FindAlias(oldType) +
                                            "> with Bin<" + TypeIdentity.Instance.FindAlias(newType) + "> implicitly.");
                    }
                }
            }
        }