Пример #1
0
    public void putEvent <T>(string type, T val, int sample)
    {
        if (!bufferClient.isConnected())            // re-connect if the connection was dropped
        {
            Debug.LogError("Buffer Connection reset detected!  reconnecting........");
            bufferClient.reconnect();
        }


        Type   cls       = typeof(T);
        string typeOfVal = cls.FullName;

        if (cls.IsArray)
        {
            Type elc = cls.GetElementType();
            if (!elc.IsPrimitive)
            {
                return;
            }

            if (typeOfVal == "System.String[]")
            {
                string[]    temp = (string[])(object)val;
                BufferEvent ev   = new BufferEvent(type, temp, sample);
                bufferClient.putEvent(ev);
            }
            else if (typeOfVal == "System.Byte[]")
            {
                byte[]      temp = (byte[])(object)val;
                BufferEvent ev   = new BufferEvent(type, temp, sample);
                bufferClient.putEvent(ev);
            }
            else if (typeOfVal == "System.Int16[]")
            {
                short[]     temp = (short[])(object)val;
                BufferEvent ev   = new BufferEvent(type, temp, sample);
                bufferClient.putEvent(ev);
            }
            else if (typeOfVal == "System.Int32[]")
            {
                int[]       temp = (int[])(object)val;
                BufferEvent ev   = new BufferEvent(type, temp, sample);
                bufferClient.putEvent(ev);
            }
            else if (typeOfVal == "System.Int64[]")
            {
                long[]      temp = (long[])(object)val;
                BufferEvent ev   = new BufferEvent(type, temp, sample);
                bufferClient.putEvent(ev);
            }
            else if (typeOfVal == "System.Single[]")
            {
                float[]     temp = (float[])(object)val;
                BufferEvent ev   = new BufferEvent(type, temp, sample);
                bufferClient.putEvent(ev);
            }
            else if (typeOfVal == "System.Double[]")
            {
                double[]    temp = (double[])(object)val;
                BufferEvent ev   = new BufferEvent(type, temp, sample);
                bufferClient.putEvent(ev);
            }
            else
            {
                Debug.LogError("Unknown/Unsupported value type");
            }
        }
        else
        {
            if (typeOfVal == "System.String")
            {
                string      temp = (string)(object)val;
                BufferEvent ev   = new BufferEvent(type, temp, sample);
                bufferClient.putEvent(ev);
            }
            else if (typeOfVal == "System.Byte")
            {
                byte        temp = (byte)(object)val;
                BufferEvent ev   = new BufferEvent(type, temp, sample);
                bufferClient.putEvent(ev);
            }
            else if (typeOfVal == "System.Int16")
            {
                short       temp = (short)(object)val;
                BufferEvent ev   = new BufferEvent(type, temp, sample);
                bufferClient.putEvent(ev);
            }
            else if (typeOfVal == "System.Int32")
            {
                int         temp = (int)(object)val;
                BufferEvent ev   = new BufferEvent(type, temp, sample);
                bufferClient.putEvent(ev);
            }
            else if (typeOfVal == "System.Int64")
            {
                long        temp = (long)(object)val;
                BufferEvent ev   = new BufferEvent(type, temp, sample);
                bufferClient.putEvent(ev);
            }
            else if (typeOfVal == "System.Single")
            {
                float       temp = (float)(object)val;
                BufferEvent ev   = new BufferEvent(type, temp, sample);
                bufferClient.putEvent(ev);
            }
            else if (typeOfVal == "System.Double")
            {
                double      temp = (double)(object)val;
                BufferEvent ev   = new BufferEvent(type, temp, sample);
                bufferClient.putEvent(ev);
            }
            else
            {
                Debug.LogError("Unknown/unsupported value type");
            }
        }
    }