Exemple #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            SpreadList sl         = new SpreadList();
            JObject    jsonObject = JObject.Load(reader);
            string     typeName   = "string";

            var jT = jsonObject.GetValue("Type");

            typeName = (string)jT.ToObject(typeof(string), serializer);

            Type type = typeof(string);

            foreach (Type key in TypeIdentity.Instance.Keys)
            {
                if (TypeIdentity.Instance[key] == typeName)
                {
                    type = key;
                }
            }

            JArray jArray = (JArray)jsonObject.GetValue("Spread");

            foreach (var o in jArray)
            {
                var instance = o.ToObject(type, serializer);
                sl.Add(instance);
            }
            return(sl);
        }
Exemple #2
0
        public new SpreadList Clone()
        {
            SpreadList c = new SpreadList();

            c.AssignFrom(this);
            return(c);
        }
Exemple #3
0
        public static Message FromOSC(Stream stream, string messagePrefix = "OSC", int contractAddress = 1)
        {
            MemoryStream ms = new MemoryStream();
            stream.Position = 0;
            stream.CopyTo(ms);
            byte[] bytes = ms.ToArray();
            int start = 0;
            OSCBundle bundle = OSCBundle.Unpack(bytes, ref start, (int)stream.Length);

            Message message = new Message();

            //			yet unsupported:
            //			Message.TimeStamp = DateTime.FromFileTime(bundle.getTimeStamp());

            foreach (OSCMessage m in bundle.Values) {
                SpreadList sl = new SpreadList();
                sl.AssignFrom(m.Values); // does not clone implicitly

                string oldAddress = m.Address;
                while (oldAddress.StartsWith("/")) oldAddress = oldAddress.Substring(1);
                while (oldAddress.EndsWith("/")) oldAddress = oldAddress.Substring(0, oldAddress.Length-1);

                string[] address = oldAddress.Split('/');

                contractAddress = address.Length > contractAddress ? contractAddress : address.Length - ((messagePrefix.Trim() == "")? 1 : 0);
                string attribName = "";
                for (int i = address.Length - contractAddress ; i < address.Length; i++)
                {
                    attribName += ".";
                    attribName += address[i];
                    address[i] = "";
                }
                attribName = attribName.Substring(1);

                string messageAddress = "";
                foreach (string part in address) {
                    if (part.Trim() != "") messageAddress += "."+part;
                }
                if (messagePrefix.Trim() == "") message.Address = messageAddress.Substring(1);
                    else message.Address = messagePrefix + messageAddress;

                message[attribName] = sl;

            }
            return message;
        }
Exemple #4
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            SpreadList list = value as SpreadList;

            writer.WriteStartObject();
            writer.WritePropertyName("Type");


            Type type = (list == null) || (list.Count == 0)? typeof(string) : list.SpreadType;

            writer.WriteValue(TypeIdentity.Instance[type]);

            writer.WritePropertyName("Spread");
            writer.WriteStartArray();
            foreach (object o in list)
            {
                serializer.Serialize(writer, o);
            }
            writer.WriteEndArray();

            writer.WriteEndObject();
        }
Exemple #5
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            SpreadList sl = new SpreadList();
            JObject jsonObject = JObject.Load(reader);
            string typeName = "string";

            var jT = jsonObject.GetValue("Type");
            typeName = (string) jT.ToObject(typeof(string), serializer);

            Type type = typeof (string);
            foreach (Type key in TypeIdentity.Instance.Keys)
            {
                if (TypeIdentity.Instance[key] == typeName)
                {
                    type = key;
                }
            }

            JArray jArray = (JArray) jsonObject.GetValue("Spread");

            foreach (var o in jArray)
            {
                var instance = o.ToObject(type, serializer);
                sl.Add(instance);
            }
            return sl;
        }
Exemple #6
0
 public new SpreadList Clone()
 {
     SpreadList c = new SpreadList();
     c.AssignFrom(this);
     return c;
 }