Example #1
0
        //Direction :Settings To Target
        static public void copyProperty_STT(object rootTarget, object source, string propertySourceName, List <string> path, PropFilter filterAllow)
        {
            System.Reflection.PropertyInfo tinfo = null;
            System.Reflection.PropertyInfo sinfo = null;
            string ttype = "";
            string stype = "";
            object FinalTarget;
            object TerminalSource;


            computePropertyAccess(rootTarget, source, propertySourceName, path, out tinfo, out sinfo, out ttype, out stype, out FinalTarget, out TerminalSource);



            if (tinfo == null)
            {
                return;          // the property does not exists in the widget
            }
            if ((stype == "System.Drawing.Color") && (ttype == "System.Windows.Media.Color"))
            {
                Color c  = (Color)TerminalSource;
                Color C2 = Color.FromArgb(c.A, c.R, c.G, c.B);
                tinfo.SetValue(FinalTarget, C2, null);
            }
            else

            if ((stype == "YDataRendering.xAxisPosition") && (ttype == "System.Double"))
            {
                xAxisPosition v = (xAxisPosition)TerminalSource;
                tinfo.SetValue(FinalTarget, v.value, null);
            }
            else
            if ((stype == "YoctoVisualisation.doubleNan") && (ttype == "System.Double"))
            {
                doubleNan v = (doubleNan)TerminalSource;
                tinfo.SetValue(FinalTarget, v.value, null);
            }
            else
            if ((stype == "YoctoVisualisation.doubleNan") && (ttype.StartsWith("System.Nullable")))
            {
                if (Double.IsNaN(((doubleNan)TerminalSource).value))
                {
                    tinfo.SetValue(FinalTarget, null, null);
                }
                else
                {
                    tinfo.SetValue(FinalTarget, ((doubleNan)TerminalSource).value, null);
                }
            }


            else
            if ((stype == "System.String") && (ttype == "System.Windows.Media.FontFamily"))
            {
                string v = (string)TerminalSource;
                tinfo.SetValue(FinalTarget, new FontFamily(v), null);
            }


            else
            if ((stype == "System.Drawing.Color") && (ttype == "System.Windows.Media.Brush"))
            {
                Color c = (Color)TerminalSource;
                byte  a = c.A;
                if (propertySourceName == "Graph2_ScrollBarFill")
                {
                    a = 80;                                         // dirty hack to keep the navigator's cursor semi-transparent
                }
                Color      C2 = Color.FromArgb(a, c.R, c.G, c.B);
                SolidBrush b  = new SolidBrush(C2);
                tinfo.SetValue(FinalTarget, b, null);
            }
            else
            if ((stype == "YColors.YColor") && (ttype == "System.Drawing.Color"))
            {
                tinfo.SetValue(FinalTarget, ((YColor)TerminalSource).toColor(), null);
            }

            else
            if ((stype == "System.Drawing.Color") && (ttype == "System.Windows.Media.Brush"))
            {
                Color c = (Color)TerminalSource;
                byte  a = c.A;
                // if (propertySourceName == "Graph2_ScrollBarFill") a = 80; // dirty hack to keep the navigator's cursor semi-transparent
                Color      C2 = Color.FromArgb(a, c.R, c.G, c.B);
                SolidBrush b  = new SolidBrush(C2);
                tinfo.SetValue(FinalTarget, b, null);
            }
            else
            if ((stype == "YoctoVisualisation.DataTrackerDescription+DataPrecision") && (ttype == "YDataRendering.DataTracker+DataPrecision"))
            { // Mono doesn't like enums implicit conversions
                YoctoVisualisation.DataTrackerDescription.DataPrecision svalue = (YoctoVisualisation.DataTrackerDescription.DataPrecision)TerminalSource;
                int temp = (int)svalue;
                YDataRendering.DataTracker.DataPrecision tvalue = (YDataRendering.DataTracker.DataPrecision)(temp);
                tinfo.SetValue(FinalTarget, tvalue, null);
            }
            else
            {
                tinfo.SetValue(FinalTarget, TerminalSource, null);
            }
        }
Example #2
0
        public string getXml(int deep, Object o)
        {
            string res = "";

            string value = "";

            foreach (System.Reflection.PropertyInfo p in o.GetType().GetProperties())
            {
                if (p.CanWrite)
                {
                    bool     Mustsave = true;
                    object[] attrs    = p.GetCustomAttributes(true);
                    foreach (object a in attrs)
                    {
                        if (a is NotSavedInXMLAttribute)
                        {
                            Mustsave = !((NotSavedInXMLAttribute)a).mustSave;
                        }
                    }

                    var child = p.GetValue(o, null);


                    if (IsStructured(child))
                    {
                        if (Mustsave)
                        {
                            res = res + new String(' ', 2 * deep) + "<" + p.Name + ">\r\n"
                                  + getXml(deep + 1, child)
                                  + new String(' ', 2 * deep) + "</" + p.Name + ">\r\n";
                        }
                    }
                    else
                    {
                        string type = p.PropertyType.ToString();



                        if (Mustsave)
                        {
                            if (p.PropertyType.IsEnum)
                            {
                                value = p.GetValue(o, null).ToString();
                            }
                            else
                            {
                                switch (type)
                                {
                                case "System.Boolean": value = (bool)p.GetValue(o, null) ? "TRUE" : "FALSE"; break;

                                case "System.Double": value = System.Security.SecurityElement.Escape(((double)p.GetValue(o, null)).ToString(CultureInfo.InvariantCulture)); break;

                                case "System.Int32":
                                case "System.Windows.Media.FontFamily":
                                case "System.String": value = System.Security.SecurityElement.Escape(p.GetValue(o, null).ToString()); break;

                                case "System.Drawing.Color": value = colorConverter.colorToHex(((Color)p.GetValue(o, null))); break;

                                case "YColors.YColor": value = p.GetValue(o, null).ToString(); break;

                                case "YoctoVisualisation.doubleNan":
                                    double d = ((doubleNan)(p.GetValue(o, null))).value;
                                    value = d.ToString(CultureInfo.InvariantCulture); break;

                                case "YDataRendering.xAxisPosition":
                                    xAxisPosition it = (xAxisPosition)p.GetValue(o, null);
                                    value = it.value.ToString(CultureInfo.InvariantCulture) + "\" relative=\"" + it.relative.ToString(); break;

                                case "YoctoVisualisation.CustomYSensor":
                                    CustomYSensor s = (CustomYSensor)p.GetValue(o, null);
                                    value = ((s == null) || (s is NullYSensor)) ? "NULL" : s.get_hardwareId();
                                    break;

                                default:
                                    throw new ArgumentException("XML generation : unhandled type (" + type + ")");
                                }
                            }
                            res = res + new String(' ', 2 * deep) + "<" + p.Name + " value=\"" + value + "\"/>\n";
                        }
                    }
                }
            }
            return(res);
        }