private static void GetDataRef(dynamic vaProxy)
        {
            string datarefName = vaProxy.GetText("~datarefName");
            string targetVar   = vaProxy.GetText("~targetVar");

            if (targetVar == null || targetVar.Length == 0)
            {
                targetVar = "~~datarefValue";
            }

            DataRef dr = link.GetDataref(datarefName);

            if (dr != null)
            {
                logger.Info("Got dataref: " + dr.ToString());

                if ((dr.DataType & DataRef.Type.Int) != 0)
                {
                    vaProxy.SetInt(targetVar, dr.IntVal);
                }
                else if ((dr.DataType & DataRef.Type.Float) != 0)
                {
                    decimal?d = (decimal)dr.FloatVal;
                    vaProxy.SetDecimal(targetVar, d);
                }
                else if ((dr.DataType & DataRef.Type.Double) != 0)
                {
                    decimal?d = (decimal)dr.DoubleVal;
                    vaProxy.SetDecimal(targetVar, d);
                }
                else if ((dr.DataType & DataRef.Type.IntArray) != 0)
                {
                    throw new ArgumentException("Array datarefs are not yet supported");
                }
                else if ((dr.DataType & DataRef.Type.FloatArray) != 0)
                {
                    throw new ArgumentException("Array datarefs are not yet supported");
                }
                else if ((dr.DataType & DataRef.Type.Data) != 0)
                {
                    vaProxy.SetText(targetVar, string.Join("", dr.Data.Split(',')));
                }
                else
                {
                    throw new ArgumentException("Unknown dataref type: " + dr.DataType);
                }
            }
            else
            {
                logger.Warn("Failed to get dataref: " + datarefName);
            }
        }
        public DataRef FromString(string expectedDataref, string retrievedDataref)
        {
            logger.Trace("Requested to build dataref " + expectedDataref + " from " + retrievedDataref);
            char[]   delims = { ':' };
            string[] parts  = retrievedDataref.Split(delims, 3);
            if (parts.Length != 3)
            {
                logger.Error("Expected 3 parts to dataref message, but got " + parts.Length);
                return(null);
            }
            string retrievedDatarefName = parts[0];
            int    datarefType          = int.Parse(parts[1]);
            string datarefValue         = parts[2];

            if (retrievedDatarefName != expectedDataref)
            {
                logger.Error("Dataref name mismatch: " + retrievedDataref + " vs " + expectedDataref);
                return(null);
            }

            try
            {
                DataRef r = new DataRef();
                r.Name     = expectedDataref;
                r.DataType = (DataRef.Type)datarefType;
                if ((r.DataType & DataRef.Type.Int) != 0)
                {
                    r.IntVal = int.Parse(datarefValue);
                }
                else if ((r.DataType & DataRef.Type.Float) != 0)
                {
                    r.FloatVal = float.Parse(datarefValue);
                }
                else if ((r.DataType & DataRef.Type.Double) != 0)
                {
                    r.DoubleVal = double.Parse(datarefValue);
                }
                else if ((r.DataType & DataRef.Type.IntArray) != 0)
                {
                    r.FloatArray = datarefValue
                                   .Split(',')
                                   .Select(f => float.Parse(f))
                                   .ToArray();
                }
                else if ((r.DataType & DataRef.Type.FloatArray) != 0)
                {
                    r.IntArray = datarefValue
                                 .Split(',')
                                 .Select(i => int.Parse(i))
                                 .ToArray();
                }
                else if ((r.DataType & DataRef.Type.Data) != 0)
                {
                    r.Data = datarefValue;
                }
                else
                {
                    logger.Error("r.DataType does not match any type: " + r.DataType);
                    return(null);
                }

                logger.Trace("Built dataref: " + r.ToString());
                return(r);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                return(null);
            }
        }